2 Copyright (C) 2003-2004 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.
23 #include <pbd/error.h>
24 #include <ardour/ardour.h>
26 #include "time_selection.h"
30 using namespace ARDOUR;
34 TimeSelection::operator[] (uint32_t which)
36 for (std::list<AudioRange>::iterator i = begin(); i != end(); ++i) {
37 if ((*i).id == which) {
41 fatal << string_compose (_("programming error: request for non-existent audio range (%1)!"), which) << endmsg;
43 return *(new AudioRange(0,0,0)); /* keep the compiler happy; never called */
47 TimeSelection::consolidate ()
52 for (std::list<AudioRange>::iterator a = begin(); a != end(); ++a) {
53 for (std::list<AudioRange>::iterator b = begin(); b != end(); ++b) {
59 if ((*a).coverage ((*b).start, (*b).end) != OverlapNone) {
60 (*a).start = std::min ((*a).start, (*b).start);
61 (*a).end = std::max ((*a).end, (*b).end);
73 TimeSelection::start ()
79 nframes_t first = max_frames;
81 for (std::list<AudioRange>::iterator i = begin(); i != end(); ++i) {
82 if ((*i).start < first) {
90 TimeSelection::end_frame ()
94 /* XXX make this work like RegionSelection: no linear search needed */
96 for (std::list<AudioRange>::iterator i = begin(); i != end(); ++i) {
97 if ((*i).end > last) {
105 TimeSelection::length()
107 return end_frame() - start() + 1;