summaryrefslogtreecommitdiff
path: root/libs/ardour/location.cc
diff options
context:
space:
mode:
authorCarl Hetherington <carl@carlh.net>2009-10-23 22:28:27 +0000
committerCarl Hetherington <carl@carlh.net>2009-10-23 22:28:27 +0000
commit1f2a518ee20a9e011f75fa2d961fd14f018445c0 (patch)
tree2c7eb00fd61312d1159928347c9b69abe723a681 /libs/ardour/location.cc
parentd2a11c8c02614c9cd9248fa17945923535110c98 (diff)
Clean up and simplify code to find marks before and after a position, and hence improve snap to markers so that both start and end positions of a range marker are taken into account.
git-svn-id: svn://localhost/ardour2/branches/3.0@5897 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour/location.cc')
-rw-r--r--libs/ardour/location.cc95
1 files changed, 40 insertions, 55 deletions
diff --git a/libs/ardour/location.cc b/libs/ardour/location.cc
index 02d355d915..b3421d2b0b 100644
--- a/libs/ardour/location.cc
+++ b/libs/ardour/location.cc
@@ -23,6 +23,8 @@
#include <unistd.h>
#include <cerrno>
#include <ctime>
+#include <list>
+
#include <sigc++/bind.h>
#include "pbd/stl_delete.h"
@@ -786,84 +788,67 @@ Locations::first_location_after (nframes64_t frame, bool include_special_ranges)
return 0;
}
-nframes64_t
-Locations::first_mark_before (nframes64_t frame, bool include_special_ranges)
+/** Look for the `marks' (either locations which are marks, or start/end points of range markers) either
+ * side of a frame.
+ * @param frame Frame to look for.
+ * @param before Filled in with the position of the last `mark' before `frame' (or max_frames if none exists)
+ * @param after Filled in with the position of the last `mark' after `frame' (or max_frames if none exists)
+ */
+void
+Locations::marks_either_side (nframes64_t const frame, nframes64_t& before, nframes64_t& after) const
{
+ before = after = max_frames;
+
LocationList locs;
{
- Glib::Mutex::Lock lm (lock);
+ Glib::Mutex::Lock lm (lock);
locs = locations;
}
- LocationStartLaterComparison cmp;
- locs.sort (cmp);
-
- /* locs is now sorted latest..earliest */
+ std::list<nframes64_t> positions;
- for (LocationList::iterator i = locs.begin(); i != locs.end(); ++i) {
- if (!include_special_ranges && ((*i)->is_auto_loop() || (*i)->is_auto_punch())) {
+ for (LocationList::const_iterator i = locs.begin(); i != locs.end(); ++i) {
+ if (((*i)->is_auto_loop() || (*i)->is_auto_punch())) {
continue;
}
+
if (!(*i)->is_hidden()) {
- if ((*i)->is_mark()) {
- /* MARK: start == end */
- if ((*i)->start() < frame) {
- return (*i)->start();
- }
+ if ((*i)->is_mark ()) {
+ positions.push_back ((*i)->start ());
} else {
- /* RANGE: start != end, compare start and end */
- if ((*i)->end() < frame) {
- return (*i)->end();
- }
- if ((*i)->start () < frame) {
- return (*i)->start();
- }
+ positions.push_back ((*i)->start ());
+ positions.push_back ((*i)->end ());
}
}
}
- return 0;
-}
+ if (positions.empty ()) {
+ return;
+ }
-nframes64_t
-Locations::first_mark_after (nframes64_t frame, bool include_special_ranges)
-{
- LocationList locs;
+ positions.sort ();
- {
- Glib::Mutex::Lock lm (lock);
- locs = locations;
+ std::list<nframes64_t>::iterator i = positions.begin ();
+ while (i != positions.end () && *i < frame) {
+ ++i;
}
- LocationStartEarlierComparison cmp;
- locs.sort (cmp);
+ if (i == positions.end ()) {
+ /* run out of marks */
+ before = positions.back ();
+ return;
+ }
- /* locs is now sorted earliest..latest */
+ after = *i;
- for (LocationList::iterator i = locs.begin(); i != locs.end(); ++i) {
- if (!include_special_ranges && ((*i)->is_auto_loop() || (*i)->is_auto_punch())) {
- continue;
- }
- if (!(*i)->is_hidden()) {
- if ((*i)->is_mark()) {
- /* MARK, start == end so just compare start */
- if ((*i)->start() > frame) {
- return (*i)->start();
- }
- } else {
- /* RANGE, start != end, compare start and end */
- if ((*i)->start() > frame ) {
- return (*i)->start ();
- }
- if ((*i)->end() > frame) {
- return (*i)->end ();
- }
- }
- }
+ if (i == positions.begin ()) {
+ /* none before */
+ return;
}
-
- return max_frames;
+
+ --i;
+ before = *i;
}
Location*