2 Copyright (C) 2006 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.
21 #include <ardour/region.h>
23 #include "region_view.h"
24 #include "region_selection.h"
26 using namespace ARDOUR;
32 RegionComparator::operator() (const RegionView* a, const RegionView* b) const
41 RegionSelection::RegionSelection ()
47 RegionSelection::RegionSelection (const RegionSelection& other)
50 for (RegionSelection::const_iterator i = other.begin(); i != other.end(); ++i) {
53 _current_start = other._current_start;
54 _current_end = other._current_end;
60 RegionSelection::operator= (const RegionSelection& other)
66 for (RegionSelection::const_iterator i = other.begin(); i != other.end(); ++i) {
70 _current_start = other._current_start;
71 _current_end = other._current_end;
78 RegionSelection::clear_all()
84 bool RegionSelection::contains (RegionView* rv)
86 if (this->find (rv) != end()) {
96 RegionSelection::add (RegionView* rv, bool dosort)
98 if (this->find (rv) != end()) {
99 /* we already have it */
103 rv->RegionViewGoingAway.connect (mem_fun(*this, &RegionSelection::remove_it));
105 if (rv->region().first_frame() < _current_start || empty()) {
106 _current_start = rv->region().first_frame();
109 if (rv->region().last_frame() > _current_end || empty()) {
110 _current_end = rv->region().last_frame();
115 // add to layer sorted list
121 RegionSelection::remove_it (RegionView *rv)
127 RegionSelection::remove (RegionView* rv)
129 RegionSelection::iterator i;
131 if ((i = this->find (rv)) != end()) {
135 // remove from layer sorted list
136 _bylayer.remove (rv);
145 Region& region ((*i)->region());
147 if (region.first_frame() == _current_start) {
149 /* reset current start */
151 jack_nframes_t ref = max_frames;
153 for (i = begin (); i != end(); ++i) {
154 if (region.first_frame() < ref) {
155 ref = region.first_frame();
159 _current_start = ref;
163 if (region.last_frame() == _current_end) {
165 /* reset current end */
167 jack_nframes_t ref = 0;
169 for (i = begin (); i != end(); ++i) {
170 if (region.first_frame() > ref) {
171 ref = region.first_frame();
186 RegionSelection::add_to_layer (RegionView * rv)
188 // insert it into layer sorted position
190 list<RegionView*>::iterator i;
192 for (i = _bylayer.begin(); i != _bylayer.end(); ++i)
194 if (rv->region().layer() < (*i)->region().layer()) {
195 _bylayer.insert(i, rv);
200 // insert at end if we get here
201 _bylayer.insert(i, rv);
204 struct RegionSortByTime {
205 bool operator() (const RegionView* a, const RegionView* b) {
206 return a->region().position() < b->region().position();
212 RegionSelection::by_position (list<RegionView*>& foo) const
214 list<RegionView*>::const_iterator i;
215 RegionSortByTime sorter;
217 for (i = _bylayer.begin(); i != _bylayer.end(); ++i) {