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()
86 bool RegionSelection::contains (RegionView* rv)
88 return this->find (rv) != end();
92 RegionSelection::add (RegionView* rv, bool dosort)
95 /* we already have it */
99 rv->RegionViewGoingAway.connect (mem_fun(*this, &RegionSelection::remove_it));
101 if (rv->region()->first_frame() < _current_start || empty()) {
102 _current_start = rv->region()->first_frame();
105 if (rv->region()->last_frame() > _current_end || empty()) {
106 _current_end = rv->region()->last_frame();
111 // add to layer sorted list
117 RegionSelection::remove_it (RegionView *rv)
123 RegionSelection::remove (RegionView* rv)
125 RegionSelection::iterator i;
127 if ((i = this->find (rv)) != end()) {
131 // remove from layer sorted list
132 _bylayer.remove (rv);
141 boost::shared_ptr<Region> region ((*i)->region());
143 if (region->first_frame() == _current_start) {
145 /* reset current start */
147 nframes_t ref = max_frames;
149 for (i = begin (); i != end(); ++i) {
150 if (region->first_frame() < ref) {
151 ref = region->first_frame();
155 _current_start = ref;
159 if (region->last_frame() == _current_end) {
161 /* reset current end */
165 for (i = begin (); i != end(); ++i) {
166 if (region->first_frame() > ref) {
167 ref = region->first_frame();
182 RegionSelection::add_to_layer (RegionView * rv)
184 // insert it into layer sorted position
186 list<RegionView*>::iterator i;
188 for (i = _bylayer.begin(); i != _bylayer.end(); ++i)
190 if (rv->region()->layer() < (*i)->region()->layer()) {
191 _bylayer.insert(i, rv);
196 // insert at end if we get here
197 _bylayer.insert(i, rv);
200 struct RegionSortByTime {
201 bool operator() (const RegionView* a, const RegionView* b) {
202 return a->region()->position() < b->region()->position();
208 RegionSelection::by_position (list<RegionView*>& foo) const
210 list<RegionView*>::const_iterator i;
211 RegionSortByTime sorter;
213 for (i = _bylayer.begin(); i != _bylayer.end(); ++i) {