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 r
;
119 if ((r
= find (begin(), end(), rv
)) != end()) {
121 // remove from layer sorted list
122 _bylayer
.remove (rv
);
126 /* this is the last one, so when we delete it
135 boost::shared_ptr
<Region
> region ((*r
)->region());
137 if (region
->first_frame() == _current_start
) {
139 /* reset current start */
141 nframes_t ref
= max_frames
;
143 for (RegionSelection::iterator i
= begin (); i
!= end(); ++i
) {
144 if (region
->first_frame() < ref
) {
145 ref
= region
->first_frame();
149 _current_start
= ref
;
153 if (region
->last_frame() == _current_end
) {
155 /* reset current end */
159 for (RegionSelection::iterator i
= begin (); i
!= end(); ++i
) {
160 if (region
->first_frame() > ref
) {
161 ref
= region
->first_frame();
178 RegionSelection::add_to_layer (RegionView
* rv
)
180 // insert it into layer sorted position
182 list
<RegionView
*>::iterator i
;
184 for (i
= _bylayer
.begin(); i
!= _bylayer
.end(); ++i
)
186 if (rv
->region()->layer() < (*i
)->region()->layer()) {
187 _bylayer
.insert(i
, rv
);
192 // insert at end if we get here
193 _bylayer
.insert(i
, rv
);
196 struct RegionSortByTime
{
197 bool operator() (const RegionView
* a
, const RegionView
* b
) const {
198 return a
->region()->position() < b
->region()->position();
204 RegionSelection::by_position (list
<RegionView
*>& foo
) const
206 list
<RegionView
*>::const_iterator i
;
207 RegionSortByTime sorter
;
209 for (i
= _bylayer
.begin(); i
!= _bylayer
.end(); ++i
) {
217 struct RegionSortByTrack
{
218 bool operator() (const RegionView
* a
, const RegionView
* b
) const {
220 /* really, track and position */
222 if (a
->get_trackview().order
== b
->get_trackview().order
) {
223 return a
->region()->position() < b
->region()->position();
225 return a
->get_trackview().order
< b
->get_trackview().order
;
231 RegionSelection::by_track (list
<RegionView
*>& foo
) const
233 list
<RegionView
*>::const_iterator i
;
234 RegionSortByTrack sorter
;
236 for (i
= _bylayer
.begin(); i
!= _bylayer
.end(); ++i
) {
245 RegionSelection::sort_by_position_and_track ()
247 RegionSortByTrack sorter
;
252 RegionSelection::involves (const TimeAxisView
& tv
) const
254 for (RegionSelection::const_iterator i
= begin(); i
!= end(); ++i
) {
255 if (&(*i
)->get_trackview() == &tv
) {