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 ()
38 RegionSelection::RegionSelection (const RegionSelection& other)
40 for (RegionSelection::const_iterator i = other.begin(); i != other.end(); ++i) {
43 _current_start = other._current_start;
44 _current_end = other._current_end;
50 RegionSelection::operator= (const RegionSelection& other)
56 for (RegionSelection::const_iterator i = other.begin(); i != other.end(); ++i) {
60 _current_start = other._current_start;
61 _current_end = other._current_end;
68 RegionSelection::clear_all()
76 bool RegionSelection::contains (RegionView* rv)
78 return find (begin(), end(), rv) != end();
82 RegionSelection::add (RegionView* rv)
85 /* we already have it */
89 rv->RegionViewGoingAway.connect (mem_fun(*this, &RegionSelection::remove_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
107 RegionSelection::remove_it (RegionView *rv)
113 RegionSelection::remove (RegionView* rv)
115 RegionSelection::iterator i;
117 if ((i = find (begin(), end(), rv)) != end()) {
121 // remove from layer sorted list
122 _bylayer.remove (rv);
131 boost::shared_ptr<Region> region ((*i)->region());
133 if (region->first_frame() == _current_start) {
135 /* reset current start */
137 nframes_t ref = max_frames;
139 for (i = begin (); i != end(); ++i) {
140 if (region->first_frame() < ref) {
141 ref = region->first_frame();
145 _current_start = ref;
149 if (region->last_frame() == _current_end) {
151 /* reset current end */
155 for (i = begin (); i != end(); ++i) {
156 if (region->first_frame() > ref) {
157 ref = region->first_frame();
172 RegionSelection::add_to_layer (RegionView * rv)
174 // insert it into layer sorted position
176 list<RegionView*>::iterator i;
178 for (i = _bylayer.begin(); i != _bylayer.end(); ++i)
180 if (rv->region()->layer() < (*i)->region()->layer()) {
181 _bylayer.insert(i, rv);
186 // insert at end if we get here
187 _bylayer.insert(i, rv);
190 struct RegionSortByTime {
191 bool operator() (const RegionView* a, const RegionView* b) const {
192 return a->region()->position() < b->region()->position();
198 RegionSelection::by_position (list<RegionView*>& foo) const
200 list<RegionView*>::const_iterator i;
201 RegionSortByTime sorter;
203 for (i = _bylayer.begin(); i != _bylayer.end(); ++i) {
211 struct RegionSortByTrack {
212 bool operator() (const RegionView* a, const RegionView* b) const {
214 /* really, track and position */
216 if (a->get_trackview().order == b->get_trackview().order) {
217 return a->region()->position() < b->region()->position();
219 return a->get_trackview().order < b->get_trackview().order;
225 RegionSelection::by_track (list<RegionView*>& foo) const
227 list<RegionView*>::const_iterator i;
228 RegionSortByTrack sorter;
230 for (i = _bylayer.begin(); i != _bylayer.end(); ++i) {
239 RegionSelection::sort_by_position_and_track ()
241 RegionSortByTrack sorter;