From 4ecb07aaee57e72aedb744f0cce885f418320e70 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Thu, 17 Jan 2013 13:19:16 +0000 Subject: fix up Location::first_location_(after|before) to do the right thing when marks + ranges are interleaved (functions renamed) git-svn-id: svn://localhost/ardour2/branches/3.0@13869 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/ardour/location.cc | 79 +++++++++++++++++++++++++++++-------------------- 1 file changed, 47 insertions(+), 32 deletions(-) (limited to 'libs/ardour/location.cc') diff --git a/libs/ardour/location.cc b/libs/ardour/location.cc index 4586fbee26..2a27fc318a 100644 --- a/libs/ardour/location.cc +++ b/libs/ardour/location.cc @@ -922,72 +922,87 @@ Locations::set_state (const XMLNode& node, int version) return 0; } + +typedef std::pair LocationPair; + struct LocationStartEarlierComparison { - bool operator() (Location *a, Location *b) { - return a->start() < b->start(); + bool operator() (LocationPair a, LocationPair b) { + return a.first < b.first; } }; struct LocationStartLaterComparison { - bool operator() (Location *a, Location *b) { - return a->start() > b->start(); + bool operator() (LocationPair a, LocationPair b) { + return a.first > b.first; } }; -Location * -Locations::first_location_before (framepos_t frame, bool include_special_ranges) +framepos_t +Locations::first_mark_before (framepos_t frame, bool include_special_ranges) { - LocationList locs; - - { - Glib::Threads::Mutex::Lock lm (lock); - locs = locations; + Glib::Threads::Mutex::Lock lm (lock); + vector locs; + + for (LocationList::iterator i = locations.begin(); i != locations.end(); ++i) { + locs.push_back (make_pair ((*i)->start(), (*i))); + if (!(*i)->is_mark()) { + locs.push_back (make_pair ((*i)->end(), (*i))); + } } LocationStartLaterComparison cmp; - locs.sort (cmp); + sort (locs.begin(), locs.end(), cmp); - /* locs is now sorted latest..earliest */ + /* locs is sorted in ascending order */ - for (LocationList::iterator i = locs.begin(); i != locs.end(); ++i) { - if (!include_special_ranges && ((*i)->is_auto_loop() || (*i)->is_auto_punch())) { + for (vector::iterator i = locs.begin(); i != locs.end(); ++i) { + if ((*i).second->is_hidden()) { + continue; + } + if (!include_special_ranges && ((*i).second->is_auto_loop() || (*i).second->is_auto_punch())) { continue; } - if (!(*i)->is_hidden() && (*i)->start() < frame) { - return (*i); + if ((*i).first < frame) { + return (*i).first; } } - return 0; + return -1; } -Location * -Locations::first_location_after (framepos_t frame, bool include_special_ranges) +framepos_t +Locations::first_mark_after (framepos_t frame, bool include_special_ranges) { - LocationList locs; + Glib::Threads::Mutex::Lock lm (lock); + vector locs; - { - Glib::Threads::Mutex::Lock lm (lock); - locs = locations; + for (LocationList::iterator i = locations.begin(); i != locations.end(); ++i) { + locs.push_back (make_pair ((*i)->start(), (*i))); + if (!(*i)->is_mark()) { + locs.push_back (make_pair ((*i)->end(), (*i))); + } } LocationStartEarlierComparison cmp; - locs.sort (cmp); - - /* locs is now sorted earliest..latest */ + sort (locs.begin(), locs.end(), cmp); + + /* locs is sorted in reverse order */ - for (LocationList::iterator i = locs.begin(); i != locs.end(); ++i) { - if (!include_special_ranges && ((*i)->is_auto_loop() || (*i)->is_auto_punch())) { + for (vector::iterator i = locs.begin(); i != locs.end(); ++i) { + if ((*i).second->is_hidden()) { continue; } - if (!(*i)->is_hidden() && (*i)->start() > frame) { - return (*i); + if (!include_special_ranges && ((*i).second->is_auto_loop() || (*i).second->is_auto_punch())) { + continue; + } + if ((*i).first > frame) { + return (*i).first; } } - return 0; + return -1; } /** Look for the `marks' (either locations which are marks, or start/end points of range markers) either -- cgit v1.2.3