ardour
time_selection.cc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003-2004 Paul Davis
3 
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.
8 
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.
13 
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.
17 
18 */
19 
20 #include <algorithm>
21 
22 #include "pbd/error.h"
23 #include "ardour/types.h"
24 
25 #include "time_selection.h"
26 
27 #include "i18n.h"
28 
29 using namespace ARDOUR;
30 using namespace PBD;
31 
34 {
35  for (std::list<AudioRange>::iterator i = begin(); i != end(); ++i) {
36  if ((*i).id == which) {
37  return *i;
38  }
39  }
40  fatal << string_compose (_("programming error: request for non-existent audio range (%1)!"), which) << endmsg;
41  abort(); /*NOTREACHED*/
42  return *(new AudioRange(0,0,0)); /* keep the compiler happy; never called */
43 }
44 
45 bool
47 {
48  bool changed = false;
49 
50  restart:
51  for (std::list<AudioRange>::iterator a = begin(); a != end(); ++a) {
52  for (std::list<AudioRange>::iterator b = begin(); b != end(); ++b) {
53 
54  if (&(*a) == &(*b)) {
55  continue;
56  }
57 
58  if (a->coverage (b->start, b->end) != Evoral::OverlapNone) {
59  a->start = std::min (a->start, b->start);
60  a->end = std::max (a->end, b->end);
61  erase (b);
62  changed = true;
63  goto restart;
64  }
65  }
66  }
67 
68  return changed;
69 }
70 
73 {
74  if (empty()) {
75  return 0;
76  }
77 
78  framepos_t first = max_framepos;
79 
80  for (std::list<AudioRange>::iterator i = begin(); i != end(); ++i) {
81  if ((*i).start < first) {
82  first = (*i).start;
83  }
84  }
85  return first;
86 }
87 
90 {
91  framepos_t last = 0;
92 
93  /* XXX make this work like RegionSelection: no linear search needed */
94 
95  for (std::list<AudioRange>::iterator i = begin(); i != end(); ++i) {
96  if ((*i).end > last) {
97  last = (*i).end;
98  }
99  }
100  return last;
101 }
102 
105 {
106  if (empty()) {
107  return 0;
108  }
109 
110  return end_frame() - start() + 1;
111 }
LIBPBD_API Transmitter fatal
ARDOUR::framepos_t end_frame()
std::ostream & endmsg(std::ostream &ostr)
Definition: transmitter.h:71
LIBARDOUR_API PBD::PropertyDescriptor< framepos_t > start
Definition: region.cc:63
ARDOUR::AudioRange & operator[](uint32_t)
#define _(Text)
Definition: i18n.h:11
int64_t framecnt_t
Definition: types.h:76
Definition: amp.h:29
int64_t framepos_t
Definition: types.h:66
ARDOUR::framepos_t start()
ARDOUR::framepos_t length()
Definition: debug.h:30
static const framepos_t max_framepos
Definition: types.h:78
std::string string_compose(const std::string &fmt, const T1 &o1)
Definition: compose.h:208