summaryrefslogtreecommitdiff
path: root/libs/ardour/location.cc
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2013-01-17 13:19:16 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2013-01-17 13:19:16 +0000
commit4ecb07aaee57e72aedb744f0cce885f418320e70 (patch)
treeba548f5fa7c686ada88138662ef2888b38f3dc55 /libs/ardour/location.cc
parent53f162f9219a65d716a2523288b69d9469fb6cea (diff)
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
Diffstat (limited to 'libs/ardour/location.cc')
-rw-r--r--libs/ardour/location.cc79
1 files changed, 47 insertions, 32 deletions
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<framepos_t,Location*> 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<LocationPair> 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<LocationPair>::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<LocationPair> 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<LocationPair>::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