2 Copyright (C) 2000 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include <cstdio> /* for sprintf */
28 #include "pbd/stl_delete.h"
29 #include "pbd/xml++.h"
30 #include "pbd/enumwriter.h"
32 #include "ardour/location.h"
33 #include "ardour/midi_scene_change.h"
34 #include "ardour/session.h"
35 #include "ardour/audiofilesource.h"
36 #include "ardour/tempo.h"
43 using namespace ARDOUR;
46 PBD::Signal0<void> Location::scene_changed;
47 PBD::Signal1<void,Location*> Location::name_changed;
48 PBD::Signal1<void,Location*> Location::end_changed;
49 PBD::Signal1<void,Location*> Location::start_changed;
50 PBD::Signal1<void,Location*> Location::flags_changed;
51 PBD::Signal1<void,Location*> Location::lock_changed;
52 PBD::Signal1<void,Location*> Location::position_lock_style_changed;
53 PBD::Signal1<void,Location*> Location::changed;
55 Location::Location (Session& s)
56 : SessionHandleRef (s)
61 , _position_lock_style (AudioTime)
67 /** Construct a new Location, giving it the position lock style determined by glue-new-markers-to-bars-and-beats */
68 Location::Location (Session& s, framepos_t sample_start, framepos_t sample_end, const std::string &name, Flags bits)
69 : SessionHandleRef (s)
71 , _start (sample_start)
75 , _position_lock_style (s.config.get_glue_new_markers_to_bars_and_beats() ? MusicTime : AudioTime)
77 recompute_bbt_from_frames ();
83 Location::Location (const Location& other)
84 : SessionHandleRef (other._session)
85 , StatefulDestructible()
87 , _start (other._start)
88 , _bbt_start (other._bbt_start)
90 , _bbt_end (other._bbt_end)
91 , _flags (other._flags)
92 , _position_lock_style (other._position_lock_style)
94 /* copy is not locked even if original was */
101 /* scene change is NOT COPIED */
104 Location::Location (Session& s, const XMLNode& node)
105 : SessionHandleRef (s)
106 , _position_lock_style (AudioTime)
108 /* Note: _position_lock_style is initialised above in case set_state doesn't set it
109 (for 2.X session file compatibility).
112 if (set_state (node, Stateful::loading_state_version)) {
113 throw failed_constructor ();
116 assert (_start >= 0);
121 Location::operator== (const Location& other)
123 if (_name != other._name ||
124 _start != other._start ||
125 _end != other._end ||
126 _bbt_start != other._bbt_start ||
127 _bbt_end != other._bbt_end ||
128 _flags != other._flags ||
129 _position_lock_style != other._position_lock_style) {
136 Location::operator= (const Location& other)
138 if (this == &other) {
143 _start = other._start;
144 _bbt_start = other._bbt_start;
146 _bbt_end = other._bbt_end;
147 _flags = other._flags;
148 _position_lock_style = other._position_lock_style;
150 /* XXX need to copy scene change */
152 /* copy is not locked even if original was */
156 /* "changed" not emitted on purpose */
158 assert (_start >= 0);
164 /** Set start position.
165 * @param s New start.
166 * @param force true to force setting, even if the given new start is after the current end.
167 * @param allow_bbt_recompute True to recompute BBT start time from the new given start time.
170 Location::set_start (framepos_t s, bool force, bool allow_bbt_recompute)
181 if (((is_auto_punch() || is_auto_loop()) && s >= _end) || (!is_mark() && s > _end)) {
190 if (allow_bbt_recompute) {
191 recompute_bbt_from_frames ();
194 start_changed (this); /* EMIT SIGNAL */
195 StartChanged (); /* EMIT SIGNAL */
196 end_changed (this); /* EMIT SIGNAL */
197 EndChanged (); /* EMIT SIGNAL */
200 /* moving the start (position) of a marker with a scene change
201 requires an update in the Scene Changer.
205 scene_changed (); /* EMIT SIGNAL */
208 assert (_start >= 0);
216 framepos_t const old = _start;
219 if (allow_bbt_recompute) {
220 recompute_bbt_from_frames ();
222 start_changed (this); /* EMIT SIGNAL */
223 StartChanged (); /* EMIT SIGNAL */
225 if (is_session_range ()) {
226 Session::StartTimeChanged (old); /* EMIT SIGNAL */
227 AudioFileSource::set_header_position_offset (s);
231 assert (_start >= 0);
236 /** Set end position.
238 * @param force true to force setting, even if the given new start is after the current end.
239 * @param allow_bbt_recompute True to recompute BBT end time from the new given end time.
242 Location::set_end (framepos_t e, bool force, bool allow_bbt_recompute)
253 if (((is_auto_punch() || is_auto_loop()) && e <= _start) || e < _start) {
262 if (allow_bbt_recompute) {
263 recompute_bbt_from_frames ();
265 start_changed (this); /* EMIT SIGNAL */
266 StartChanged (); /* EMIT SIGNAL */
267 end_changed (this); /* EMIT SIGNAL */
268 EndChanged (); /* EMIT SIGNAL */
271 assert (_start >= 0);
279 framepos_t const old = _end;
282 if (allow_bbt_recompute) {
283 recompute_bbt_from_frames ();
285 end_changed(this); /* EMIT SIGNAL */
286 EndChanged(); /* EMIT SIGNAL */
288 if (is_session_range()) {
289 Session::EndTimeChanged (old); /* EMIT SIGNAL */
299 Location::set (framepos_t start, framepos_t end, bool allow_bbt_recompute)
301 if (start < 0 || end < 0) {
306 if (((is_auto_punch() || is_auto_loop()) && start >= end) || (!is_mark() && start > end)) {
310 /* now we know these values are ok, so force-set them */
311 int const s = set_start (start, true, allow_bbt_recompute);
312 int const e = set_end (end, true, allow_bbt_recompute);
314 return (s == 0 && e == 0) ? 0 : -1;
318 Location::move_to (framepos_t pos)
330 _end = _start + length();
331 recompute_bbt_from_frames ();
333 changed (this); /* EMIT SIGNAL */
334 Changed (); /* EMIT SIGNAL */
337 assert (_start >= 0);
344 Location::set_hidden (bool yn, void*)
346 if (set_flag_internal (yn, IsHidden)) {
347 flags_changed (this); /* EMIT SIGNAL */
353 Location::set_cd (bool yn, void*)
355 // XXX this really needs to be session start
356 // but its not available here - leave to GUI
358 if (yn && _start == 0) {
359 error << _("You cannot put a CD marker at this position") << endmsg;
363 if (set_flag_internal (yn, IsCDMarker)) {
364 flags_changed (this); /* EMIT SIGNAL */
370 Location::set_is_range_marker (bool yn, void*)
372 if (set_flag_internal (yn, IsRangeMarker)) {
373 flags_changed (this);
374 FlagsChanged (); /* EMIT SIGNAL */
379 Location::set_skip (bool yn)
381 if (is_range_marker() && length() > 0) {
382 if (set_flag_internal (yn, IsSkip)) {
383 flags_changed (this);
390 Location::set_auto_punch (bool yn, void*)
392 if (is_mark() || _start == _end) {
396 if (set_flag_internal (yn, IsAutoPunch)) {
397 flags_changed (this); /* EMIT SIGNAL */
398 FlagsChanged (); /* EMIT SIGNAL */
403 Location::set_auto_loop (bool yn, void*)
405 if (is_mark() || _start == _end) {
409 if (set_flag_internal (yn, IsAutoLoop)) {
410 flags_changed (this); /* EMIT SIGNAL */
411 FlagsChanged (); /* EMIT SIGNAL */
416 Location::set_flag_internal (bool yn, Flags flag)
419 if (!(_flags & flag)) {
420 _flags = Flags (_flags | flag);
425 _flags = Flags (_flags & ~flag);
433 Location::set_mark (bool yn)
435 /* This function is private, and so does not emit signals */
437 if (_start != _end) {
441 set_flag_internal (yn, IsMark);
446 Location::cd_info_node(const string & name, const string & value)
448 XMLNode* root = new XMLNode("CD-Info");
450 root->add_property("name", name);
451 root->add_property("value", value);
458 Location::get_state ()
460 XMLNode *node = new XMLNode ("Location");
463 typedef map<string, string>::const_iterator CI;
465 for(CI m = cd_info.begin(); m != cd_info.end(); ++m){
466 node->add_child_nocopy(cd_info_node(m->first, m->second));
469 id().print (buf, sizeof (buf));
470 node->add_property("id", buf);
471 node->add_property ("name", name());
472 snprintf (buf, sizeof (buf), "%" PRId64, start());
473 node->add_property ("start", buf);
474 snprintf (buf, sizeof (buf), "%" PRId64, end());
475 node->add_property ("end", buf);
476 node->add_property ("flags", enum_2_string (_flags));
477 node->add_property ("locked", (_locked ? "yes" : "no"));
478 node->add_property ("position-lock-style", enum_2_string (_position_lock_style));
481 node->add_child_nocopy (_scene_change->get_state());
488 Location::set_state (const XMLNode& node, int version)
490 const XMLProperty *prop;
492 XMLNodeList cd_list = node.children();
493 XMLNodeConstIterator cd_iter;
499 if (node.name() != "Location") {
500 error << _("incorrect XML node passed to Location::set_state") << endmsg;
504 if (!set_id (node)) {
505 warning << _("XML node for Location has no ID information") << endmsg;
508 if ((prop = node.property ("name")) == 0) {
509 error << _("XML node for Location has no name information") << endmsg;
513 set_name (prop->value());
515 if ((prop = node.property ("start")) == 0) {
516 error << _("XML node for Location has no start information") << endmsg;
520 /* can't use set_start() here, because _end
521 may make the value of _start illegal.
524 sscanf (prop->value().c_str(), "%" PRId64, &_start);
526 if ((prop = node.property ("end")) == 0) {
527 error << _("XML node for Location has no end information") << endmsg;
531 sscanf (prop->value().c_str(), "%" PRId64, &_end);
533 if ((prop = node.property ("flags")) == 0) {
534 error << _("XML node for Location has no flags information") << endmsg;
538 _flags = Flags (string_2_enum (prop->value(), _flags));
540 if ((prop = node.property ("locked")) != 0) {
541 _locked = string_is_affirmative (prop->value());
546 for (cd_iter = cd_list.begin(); cd_iter != cd_list.end(); ++cd_iter) {
550 if (cd_node->name() != "CD-Info") {
554 if ((prop = cd_node->property ("name")) != 0) {
555 cd_name = prop->value();
557 throw failed_constructor ();
560 if ((prop = cd_node->property ("value")) != 0) {
561 cd_value = prop->value();
563 throw failed_constructor ();
567 cd_info[cd_name] = cd_value;
570 if ((prop = node.property ("position-lock-style")) != 0) {
571 _position_lock_style = PositionLockStyle (string_2_enum (prop->value(), _position_lock_style));
574 XMLNode* scene_child = find_named_node (node, SceneChange::xml_node_name);
577 _scene_change = SceneChange::factory (*scene_child, version);
580 recompute_bbt_from_frames ();
582 changed (this); /* EMIT SIGNAL */
583 Changed (); /* EMIT SIGNAL */
585 assert (_start >= 0);
592 Location::set_position_lock_style (PositionLockStyle ps)
594 if (_position_lock_style == ps) {
598 _position_lock_style = ps;
600 recompute_bbt_from_frames ();
602 position_lock_style_changed (this); /* EMIT SIGNAL */
603 PositionLockStyleChanged (); /* EMIT SIGNAL */
607 Location::recompute_bbt_from_frames ()
609 if (_position_lock_style != MusicTime) {
613 _session.bbt_time (_start, _bbt_start);
614 _session.bbt_time (_end, _bbt_end);
618 Location::recompute_frames_from_bbt ()
620 if (_position_lock_style != MusicTime) {
624 TempoMap& map (_session.tempo_map());
625 set (map.frame_time (_bbt_start), map.frame_time (_bbt_end), false);
645 Location::set_scene_change (boost::shared_ptr<SceneChange> sc)
649 scene_changed (); /* EMIT SIGNAL */
652 /*---------------------------------------------------------------------- */
654 Locations::Locations (Session& s)
655 : SessionHandleRef (s)
657 current_location = 0;
659 Location::changed.connect_same_thread (*this, boost::bind (&Locations::location_changed, this, _1));
660 Location::start_changed.connect_same_thread (*this, boost::bind (&Locations::location_changed, this, _1));
661 Location::end_changed.connect_same_thread (*this, boost::bind (&Locations::location_changed, this, _1));
662 Location::flags_changed.connect_same_thread (*this, boost::bind (&Locations::location_changed, this, _1));
665 Locations::~Locations ()
667 for (LocationList::iterator i = locations.begin(); i != locations.end(); ) {
668 LocationList::iterator tmp = i;
676 Locations::set_current (Location *loc, bool want_lock)
681 Glib::Threads::Mutex::Lock lm (lock);
682 ret = set_current_unlocked (loc);
684 ret = set_current_unlocked (loc);
688 current_changed (current_location); /* EMIT SIGNAL */
694 Locations::next_available_name(string& result,string base)
696 LocationList::iterator i;
702 bool available[SUFFIX_MAX+1];
705 for (int k=1; k<SUFFIX_MAX; k++) {
709 for (i = locations.begin(); i != locations.end(); ++i) {
711 temp = location->name();
712 if (l && !temp.find(base,0)) {
713 suffix = atoi(temp.substr(l,3).c_str());
714 if (suffix) available[suffix] = false;
717 for (int k=1; k<=SUFFIX_MAX; k++) {
719 snprintf (buf, 31, "%d", k);
728 Locations::set_current_unlocked (Location *loc)
730 if (find (locations.begin(), locations.end(), loc) == locations.end()) {
731 error << _("Locations: attempt to use unknown location as selected location") << endmsg;
735 current_location = loc;
743 Glib::Threads::Mutex::Lock lm (lock);
745 for (LocationList::iterator i = locations.begin(); i != locations.end(); ) {
747 LocationList::iterator tmp = i;
750 if (!(*i)->is_session_range()) {
758 current_location = 0;
761 changed (OTHER); /* EMIT SIGNAL */
762 current_changed (0); /* EMIT SIGNAL */
766 Locations::clear_markers ()
769 Glib::Threads::Mutex::Lock lm (lock);
770 LocationList::iterator tmp;
772 for (LocationList::iterator i = locations.begin(); i != locations.end(); ) {
776 if ((*i)->is_mark() && !(*i)->is_session_range()) {
785 changed (OTHER); /* EMIT SIGNAL */
789 Locations::clear_ranges ()
792 Glib::Threads::Mutex::Lock lm (lock);
793 LocationList::iterator tmp;
795 for (LocationList::iterator i = locations.begin(); i != locations.end(); ) {
800 /* We do not remove these ranges as part of this
804 if ((*i)->is_auto_punch() ||
805 (*i)->is_auto_loop() ||
806 (*i)->is_session_range()) {
811 if (!(*i)->is_mark()) {
820 current_location = 0;
823 changed (OTHER); /* EMIT SIGNAL */
824 current_changed (0); /* EMIT SIGNAL */
828 Locations::add (Location *loc, bool make_current)
833 Glib::Threads::Mutex::Lock lm (lock);
834 locations.push_back (loc);
837 current_location = loc;
841 added (loc); /* EMIT SIGNAL */
844 current_changed (current_location); /* EMIT SIGNAL */
847 if (loc->is_session_range()) {
848 Session::StartTimeChanged (0);
849 Session::EndTimeChanged (1);
854 Locations::remove (Location *loc)
856 bool was_removed = false;
857 bool was_current = false;
858 LocationList::iterator i;
860 if (loc->is_session_range()) {
865 Glib::Threads::Mutex::Lock lm (lock);
867 for (i = locations.begin(); i != locations.end(); ++i) {
872 if (current_location == loc) {
873 current_location = 0;
883 removed (loc); /* EMIT SIGNAL */
886 current_changed (0); /* EMIT SIGNAL */
889 changed (REMOVAL); /* EMIT_SIGNAL */
894 Locations::location_changed (Location* /*loc*/)
896 changed (OTHER); /* EMIT SIGNAL */
900 Locations::get_state ()
902 XMLNode *node = new XMLNode ("Locations");
903 LocationList::iterator iter;
904 Glib::Threads::Mutex::Lock lm (lock);
906 for (iter = locations.begin(); iter != locations.end(); ++iter) {
907 node->add_child_nocopy ((*iter)->get_state ());
914 Locations::set_state (const XMLNode& node, int version)
916 if (node.name() != "Locations") {
917 error << _("incorrect XML mode passed to Locations::set_state") << endmsg;
921 XMLNodeList nlist = node.children();
923 /* build up a new locations list in here */
924 LocationList new_locations;
926 current_location = 0;
928 Location* session_range_location = 0;
929 if (version < 3000) {
930 session_range_location = new Location (_session, 0, 0, _("session"), Location::IsSessionRange);
931 new_locations.push_back (session_range_location);
935 Glib::Threads::Mutex::Lock lm (lock);
937 XMLNodeConstIterator niter;
938 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
942 XMLProperty const * prop_id = (*niter)->property ("id");
944 PBD::ID id (prop_id->value ());
946 LocationList::const_iterator i = locations.begin();
947 while (i != locations.end () && (*i)->id() != id) {
952 if (i != locations.end()) {
953 /* we can re-use an old Location object */
955 loc->set_state (**niter, version);
957 loc = new Location (_session, **niter);
962 if (version < 3000) {
963 /* look for old-style IsStart / IsEnd properties in this location;
964 if they are present, update the session_range_location accordingly
966 XMLProperty const * prop = (*niter)->property ("flags");
968 string v = prop->value ();
970 string::size_type const c = v.find_first_of (',');
971 string const s = v.substr (0, c);
972 if (s == X_("IsStart")) {
973 session_range_location->set_start (loc->start(), true);
975 } else if (s == X_("IsEnd")) {
976 session_range_location->set_end (loc->start(), true);
980 if (c == string::npos) {
984 v = v.substr (c + 1);
990 new_locations.push_back (loc);
994 catch (failed_constructor& err) {
995 error << _("could not load location from session file - ignored") << endmsg;
999 locations = new_locations;
1001 if (locations.size()) {
1002 current_location = locations.front();
1004 current_location = 0;
1008 changed (OTHER); /* EMIT SIGNAL */
1014 typedef std::pair<framepos_t,Location*> LocationPair;
1016 struct LocationStartEarlierComparison
1018 bool operator() (LocationPair a, LocationPair b) {
1019 return a.first < b.first;
1023 struct LocationStartLaterComparison
1025 bool operator() (LocationPair a, LocationPair b) {
1026 return a.first > b.first;
1031 Locations::first_mark_before (framepos_t frame, bool include_special_ranges)
1033 Glib::Threads::Mutex::Lock lm (lock);
1034 vector<LocationPair> locs;
1036 for (LocationList::iterator i = locations.begin(); i != locations.end(); ++i) {
1037 locs.push_back (make_pair ((*i)->start(), (*i)));
1038 if (!(*i)->is_mark()) {
1039 locs.push_back (make_pair ((*i)->end(), (*i)));
1043 LocationStartLaterComparison cmp;
1044 sort (locs.begin(), locs.end(), cmp);
1046 /* locs is sorted in ascending order */
1048 for (vector<LocationPair>::iterator i = locs.begin(); i != locs.end(); ++i) {
1049 if ((*i).second->is_hidden()) {
1052 if (!include_special_ranges && ((*i).second->is_auto_loop() || (*i).second->is_auto_punch())) {
1055 if ((*i).first < frame) {
1064 Locations::mark_at (framepos_t pos, framecnt_t slop) const
1066 Glib::Threads::Mutex::Lock lm (lock);
1067 Location* closest = 0;
1068 frameoffset_t mindelta = max_framepos;
1069 frameoffset_t delta;
1071 /* locations are not necessarily stored in linear time order so we have
1072 * to iterate across all of them to find the one closest to a give point.
1075 for (LocationList::const_iterator i = locations.begin(); i != locations.end(); ++i) {
1077 if ((*i)->is_mark()) {
1078 if (pos > (*i)->start()) {
1079 delta = pos - (*i)->start();
1081 delta = (*i)->start() - pos;
1084 if (slop == 0 && delta == 0) {
1085 /* special case: no slop, and direct hit for position */
1089 if (delta <= slop) {
1090 if (delta < mindelta) {
1102 Locations::first_mark_after (framepos_t frame, bool include_special_ranges)
1104 Glib::Threads::Mutex::Lock lm (lock);
1105 vector<LocationPair> locs;
1107 for (LocationList::iterator i = locations.begin(); i != locations.end(); ++i) {
1108 locs.push_back (make_pair ((*i)->start(), (*i)));
1109 if (!(*i)->is_mark()) {
1110 locs.push_back (make_pair ((*i)->end(), (*i)));
1114 LocationStartEarlierComparison cmp;
1115 sort (locs.begin(), locs.end(), cmp);
1117 /* locs is sorted in reverse order */
1119 for (vector<LocationPair>::iterator i = locs.begin(); i != locs.end(); ++i) {
1120 if ((*i).second->is_hidden()) {
1123 if (!include_special_ranges && ((*i).second->is_auto_loop() || (*i).second->is_auto_punch())) {
1126 if ((*i).first > frame) {
1134 /** Look for the `marks' (either locations which are marks, or start/end points of range markers) either
1135 * side of a frame. Note that if frame is exactly on a `mark', that mark will not be considered for returning
1137 * @param frame Frame to look for.
1138 * @param before Filled in with the position of the last `mark' before `frame' (or max_framepos if none exists)
1139 * @param after Filled in with the position of the next `mark' after `frame' (or max_framepos if none exists)
1142 Locations::marks_either_side (framepos_t const frame, framepos_t& before, framepos_t& after) const
1144 before = after = max_framepos;
1149 Glib::Threads::Mutex::Lock lm (lock);
1153 /* Get a list of positions; don't store any that are exactly on our requested position */
1155 std::list<framepos_t> positions;
1157 for (LocationList::const_iterator i = locs.begin(); i != locs.end(); ++i) {
1158 if (((*i)->is_auto_loop() || (*i)->is_auto_punch())) {
1162 if (!(*i)->is_hidden()) {
1163 if ((*i)->is_mark ()) {
1164 if ((*i)->start() != frame) {
1165 positions.push_back ((*i)->start ());
1168 if ((*i)->start() != frame) {
1169 positions.push_back ((*i)->start ());
1171 if ((*i)->end() != frame) {
1172 positions.push_back ((*i)->end ());
1178 if (positions.empty ()) {
1184 std::list<framepos_t>::iterator i = positions.begin ();
1185 while (i != positions.end () && *i < frame) {
1189 if (i == positions.end ()) {
1190 /* run out of marks */
1191 before = positions.back ();
1197 if (i == positions.begin ()) {
1207 Locations::session_range_location () const
1209 for (LocationList::const_iterator i = locations.begin(); i != locations.end(); ++i) {
1210 if ((*i)->is_session_range()) {
1211 return const_cast<Location*> (*i);
1218 Locations::auto_loop_location () const
1220 for (LocationList::const_iterator i = locations.begin(); i != locations.end(); ++i) {
1221 if ((*i)->is_auto_loop()) {
1222 return const_cast<Location*> (*i);
1229 Locations::auto_punch_location () const
1231 for (LocationList::const_iterator i = locations.begin(); i != locations.end(); ++i) {
1232 if ((*i)->is_auto_punch()) {
1233 return const_cast<Location*> (*i);
1240 Locations::num_range_markers () const
1243 Glib::Threads::Mutex::Lock lm (lock);
1244 for (LocationList::const_iterator i = locations.begin(); i != locations.end(); ++i) {
1245 if ((*i)->is_range_marker()) {
1253 Locations::get_location_by_id(PBD::ID id)
1255 LocationList::iterator it;
1256 for (it = locations.begin(); it != locations.end(); ++it)
1257 if (id == (*it)->id())
1264 Locations::find_all_between (framepos_t start, framepos_t end, LocationList& ll, Location::Flags flags)
1266 Glib::Threads::Mutex::Lock lm (lock);
1268 for (LocationList::const_iterator i = locations.begin(); i != locations.end(); ++i) {
1269 if ((flags == 0 || (*i)->matches (flags)) &&
1270 ((*i)->start() >= start && (*i)->end() < end)) {