X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Flocation.cc;h=f855cb75cffff6c67248eaf0befb18d3461b714d;hb=8f59346592b8232e910ce0bbdc247cf8cecde4dd;hp=7b9e706c36bc9de7b07e93344dbb00f0141bd9a1;hpb=8713667ec1a6cc9ba56c07f763e5a422cc47fbef;p=ardour.git diff --git a/libs/ardour/location.cc b/libs/ardour/location.cc index 7b9e706c36..f855cb75cf 100644 --- a/libs/ardour/location.cc +++ b/libs/ardour/location.cc @@ -23,7 +23,8 @@ #include #include #include -#include +#include + #include "pbd/stl_delete.h" #include "pbd/xml++.h" @@ -39,7 +40,6 @@ using namespace std; using namespace ARDOUR; -using namespace sigc; using namespace PBD; Location::Location (const Location& other) @@ -49,11 +49,6 @@ Location::Location (const Location& other) _end (other._end), _flags (other._flags) { - /* start and end flags can never be copied, because there can only ever be one of each */ - - _flags = Flags (_flags & ~IsStart); - _flags = Flags (_flags & ~IsEnd); - /* copy is not locked even if original was */ _locked = false; @@ -94,35 +89,27 @@ Location::set_start (nframes64_t s) return -1; } + if (((is_auto_punch() || is_auto_loop()) && s >= _end) || (!is_mark() && s > _end)) { + return -1; + } + if (is_mark()) { if (_start != s) { - _start = s; _end = s; - - start_changed(this); /* EMIT SIGNAL */ - end_changed(this); /* EMIT SIGNAL */ - - if ( is_start() ) { - - Session::StartTimeChanged (); /* EMIT SIGNAL */ - AudioFileSource::set_header_position_offset ( s ); - } - - if ( is_end() ) { - Session::EndTimeChanged (); /* EMIT SIGNAL */ - } + start_changed (this); /* EMIT SIGNAL */ + end_changed (this); /* EMIT SIGNAL */ } return 0; } - - if (((is_auto_punch() || is_auto_loop()) && s >= _end) || s > _end) { - return -1; - } - + if (s != _start) { _start = s; - start_changed(this); /* EMIT SIGNAL */ + start_changed (this); /* EMIT SIGNAL */ + if (is_session_range ()) { + Session::StartTimeChanged (); /* EMIT SIGNAL */ + AudioFileSource::set_header_position_offset (s); + } } return 0; @@ -135,59 +122,39 @@ Location::set_end (nframes64_t e) return -1; } + if (((is_auto_punch() || is_auto_loop()) && e <= _start) || e < _start) { + return -1; + } + if (is_mark()) { if (_start != e) { _start = e; _end = e; - start_changed(this); /* EMIT SIGNAL */ - end_changed(this); /* EMIT SIGNAL */ - - if ( is_start() ) { - Session::StartTimeChanged (); /* EMIT SIGNAL */ - } - - if ( is_end() ) { - Session::EndTimeChanged (); /* EMIT SIGNAL */ - } - + start_changed (this); /* EMIT SIGNAL */ + end_changed (this); /* EMIT SIGNAL */ } return 0; } - if (((is_auto_punch() || is_auto_loop()) && e <= _start) || e < _start) { - return -1; - } - if (e != _end) { _end = e; - end_changed(this); /* EMIT SIGNAL */ + end_changed(this); /* EMIT SIGNAL */ + + if (is_session_range()) { + Session::EndTimeChanged (); /* EMIT SIGNAL */ + } } + return 0; } int Location::set (nframes64_t start, nframes64_t end) { - if (_locked) { - return -1; - } - - if (is_mark() && start != end) { - return -1; - } else if (((is_auto_punch() || is_auto_loop()) && start >= end) || (start > end)) { - return -1; - } - - if (_start != start) { - _start = start; - start_changed(this); /* EMIT SIGNAL */ - } + int const s = set_start (start); + int const e = set_end (end); - if (_end != end) { - _end = end; - end_changed(this); /* EMIT SIGNAL */ - } - return 0; + return (s == 0 && e == 0) ? 0 : -1; } int @@ -231,22 +198,6 @@ Location::set_cd (bool yn, void *src) } } -void -Location::set_is_end (bool yn, void *src) -{ - if (set_flag_internal (yn, IsEnd)) { - FlagsChanged (this, src); /* EMIT SIGNAL */ - } -} - -void -Location::set_is_start (bool yn, void *src) -{ - if (set_flag_internal (yn, IsStart)) { - FlagsChanged (this, src); /* EMIT SIGNAL */ - } -} - void Location::set_is_range_marker (bool yn, void *src) { @@ -347,7 +298,7 @@ Location::get_state (void) } int -Location::set_state (const XMLNode& node, int version) +Location::set_state (const XMLNode& node, int /*version*/) { const XMLProperty *prop; @@ -531,7 +482,7 @@ Locations::clear () LocationList::iterator tmp = i; ++tmp; - if (!(*i)->is_end() && !(*i)->is_start()) { + if (!(*i)->is_session_range()) { locations.erase (i); } @@ -556,7 +507,7 @@ Locations::clear_markers () tmp = i; ++tmp; - if ((*i)->is_mark() && !(*i)->is_end() && !(*i)->is_start()) { + if ((*i)->is_mark() && !(*i)->is_session_range()) { locations.erase (i); } @@ -621,7 +572,7 @@ Locations::remove (Location *loc) bool was_current = false; LocationList::iterator i; - if (loc->is_end() || loc->is_start()) { + if (loc->is_session_range()) { return; } @@ -676,28 +627,64 @@ Locations::get_state () int Locations::set_state (const XMLNode& node, int version) { - XMLNodeList nlist; - XMLNodeConstIterator niter; - if (node.name() != "Locations") { error << _("incorrect XML mode passed to Locations::set_state") << endmsg; return -1; } - nlist = node.children(); + XMLNodeList nlist = node.children(); locations.clear (); current_location = 0; + Location* session_range_location = 0; + if (version < 3000) { + session_range_location = new Location (0, 0, _("session"), Location::IsSessionRange); + locations.push_back (session_range_location); + } + { Glib::Mutex::Lock lm (lock); + XMLNodeConstIterator niter; for (niter = nlist.begin(); niter != nlist.end(); ++niter) { try { Location *loc = new Location (**niter); - locations.push_back (loc); + + bool add = true; + + if (version < 3000) { + /* look for old-style IsStart / IsEnd properties in this location; + if they are present, update the session_range_location accordingly + */ + XMLProperty const * prop = (*niter)->property ("flags"); + if (prop) { + string v = prop->value (); + while (1) { + string::size_type const c = v.find_first_of (','); + string const s = v.substr (0, c); + if (s == X_("IsStart")) { + session_range_location->set_start (loc->start()); + add = false; + } else if (s == X_("IsEnd")) { + session_range_location->set_end (loc->start()); + add = false; + } + + if (c == string::npos) { + break; + } + + v = v.substr (c + 1); + } + } + } + + if (add) { + locations.push_back (loc); + } } catch (failed_constructor& err) { @@ -706,7 +693,6 @@ Locations::set_state (const XMLNode& node, int version) } if (locations.size()) { - current_location = locations.front(); } else { current_location = 0; @@ -786,102 +772,74 @@ 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 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; -} - -nframes64_t -Locations::first_mark_after (nframes64_t frame, bool include_special_ranges) -{ - LocationList locs; - - { - Glib::Mutex::Lock lm (lock); - locs = locations; + if (positions.empty ()) { + return; } - LocationStartEarlierComparison cmp; - locs.sort (cmp); + positions.sort (); - /* locs is now sorted earliest..latest */ + std::list::iterator i = positions.begin (); + while (i != positions.end () && *i < frame) { + ++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.end ()) { + /* run out of marks */ + before = positions.back (); + return; } - return max_frames; -} + after = *i; -Location* -Locations::end_location () const -{ - for (LocationList::const_iterator i = locations.begin(); i != locations.end(); ++i) { - if ((*i)->is_end()) { - return const_cast (*i); - } + if (i == positions.begin ()) { + /* none before */ + return; } - return 0; + + --i; + before = *i; } Location* -Locations::start_location () const +Locations::session_range_location () const { for (LocationList::const_iterator i = locations.begin(); i != locations.end(); ++i) { - if ((*i)->is_start()) { + if ((*i)->is_session_range()) { return const_cast (*i); } } @@ -927,7 +885,7 @@ Location * Locations::get_location_by_id(PBD::ID id) { LocationList::iterator it; - for (it = locations.begin(); it != locations.end(); it++) + for (it = locations.begin(); it != locations.end(); ++it) if (id == (*it)->id()) return *it;