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"
25 #include "time_axis_view.h"
27 using namespace ARDOUR;
32 RegionSelection::RegionSelection ()
34 RegionView::RegionViewGoingAway.connect (mem_fun(*this, &RegionSelection::remove_it));
40 RegionSelection::RegionSelection (const RegionSelection& other)
42 RegionView::RegionViewGoingAway.connect (mem_fun(*this, &RegionSelection::remove_it));
44 for (RegionSelection::const_iterator i = other.begin(); i != other.end(); ++i) {
47 _current_start = other._current_start;
48 _current_end = other._current_end;
52 RegionSelection::operator= (const RegionSelection& other)
58 for (RegionSelection::const_iterator i = other.begin(); i != other.end(); ++i) {
62 _current_start = other._current_start;
63 _current_end = other._current_end;
70 RegionSelection::clear_all()
78 bool RegionSelection::contains (RegionView* rv) const
80 return find (begin(), end(), rv) != end();
84 RegionSelection::add (RegionView* rv)
87 /* we already have it */
91 if (rv->region()->first_frame() < _current_start || empty()) {
92 _current_start = rv->region()->first_frame();
95 if (rv->region()->last_frame() > _current_end || empty()) {
96 _current_end = rv->region()->last_frame();
101 // add to layer sorted list
109 RegionSelection::remove_it (RegionView *rv)
115 RegionSelection::remove (RegionView* rv)
117 RegionSelection::iterator i;
119 if ((i = find (begin(), end(), rv)) != end()) {
123 // remove from layer sorted list
124 _bylayer.remove (rv);
133 boost::shared_ptr<Region> region ((*i)->region());
135 if (region->first_frame() == _current_start) {
137 /* reset current start */
139 nframes_t ref = max_frames;
141 for (i = begin (); i != end(); ++i) {
142 if (region->first_frame() < ref) {
143 ref = region->first_frame();
147 _current_start = ref;
151 if (region->last_frame() == _current_end) {
153 /* reset current end */
157 for (i = begin (); i != end(); ++i) {
158 if (region->first_frame() > ref) {
159 ref = region->first_frame();
174 RegionSelection::add_to_layer (RegionView * rv)
176 // insert it into layer sorted position
178 list<RegionView*>::iterator i;
180 for (i = _bylayer.begin(); i != _bylayer.end(); ++i)
182 if (rv->region()->layer() < (*i)->region()->layer()) {
183 _bylayer.insert(i, rv);
188 // insert at end if we get here
189 _bylayer.insert(i, rv);
192 struct RegionSortByTime {
193 bool operator() (const RegionView* a, const RegionView* b) const {
194 return a->region()->position() < b->region()->position();
200 RegionSelection::by_position (list<RegionView*>& foo) const
202 list<RegionView*>::const_iterator i;
203 RegionSortByTime sorter;
205 for (i = _bylayer.begin(); i != _bylayer.end(); ++i) {
213 struct RegionSortByTrack {
214 bool operator() (const RegionView* a, const RegionView* b) const {
216 /* really, track and position */
218 if (a->get_trackview().order == b->get_trackview().order) {
219 return a->region()->position() < b->region()->position();
221 return a->get_trackview().order < b->get_trackview().order;
227 RegionSelection::by_track (list<RegionView*>& foo) const
229 list<RegionView*>::const_iterator i;
230 RegionSortByTrack sorter;
232 for (i = _bylayer.begin(); i != _bylayer.end(); ++i) {
241 RegionSelection::sort_by_position_and_track ()
243 RegionSortByTrack sorter;
248 RegionSelection::involves (const TimeAxisView& tv) const
250 for (RegionSelection::const_iterator i = begin(); i != end(); ++i) {
251 if (&(*i)->get_trackview() == &tv) {