3 #include <ardour/audioregion.h>
5 #include "regionview.h"
6 #include "region_selection.h"
8 using namespace ARDOUR;
14 AudioRegionComparator::operator() (const AudioRegionView* a, const AudioRegionView* b) const
23 AudioRegionSelection::AudioRegionSelection ()
29 AudioRegionSelection::AudioRegionSelection (const AudioRegionSelection& other)
32 for (AudioRegionSelection::const_iterator i = other.begin(); i != other.end(); ++i) {
35 _current_start = other._current_start;
36 _current_end = other._current_end;
42 AudioRegionSelection::operator= (const AudioRegionSelection& other)
48 for (AudioRegionSelection::const_iterator i = other.begin(); i != other.end(); ++i) {
52 _current_start = other._current_start;
53 _current_end = other._current_end;
60 AudioRegionSelection::clear_all()
66 bool AudioRegionSelection::contains (AudioRegionView* rv)
68 if (this->find (rv) != end()) {
78 AudioRegionSelection::add (AudioRegionView* rv, bool dosort)
80 if (this->find (rv) != end()) {
81 /* we already have it */
85 rv->AudioRegionViewGoingAway.connect (mem_fun(*this, &AudioRegionSelection::remove_it));
87 if (rv->region.first_frame() < _current_start || empty()) {
88 _current_start = rv->region.first_frame();
91 if (rv->region.last_frame() > _current_end || empty()) {
92 _current_end = rv->region.last_frame();
97 // add to layer sorted list
103 AudioRegionSelection::remove_it (AudioRegionView *rv)
109 AudioRegionSelection::remove (AudioRegionView* rv)
111 AudioRegionSelection::iterator i;
113 if ((i = this->find (rv)) != end()) {
117 // remove from layer sorted list
118 _bylayer.remove (rv);
127 AudioRegion& region ((*i)->region);
129 if (region.first_frame() == _current_start) {
131 /* reset current start */
133 jack_nframes_t ref = max_frames;
135 for (i = begin (); i != end(); ++i) {
136 if (region.first_frame() < ref) {
137 ref = region.first_frame();
141 _current_start = ref;
145 if (region.last_frame() == _current_end) {
147 /* reset current end */
149 jack_nframes_t ref = 0;
151 for (i = begin (); i != end(); ++i) {
152 if (region.first_frame() > ref) {
153 ref = region.first_frame();
168 AudioRegionSelection::add_to_layer (AudioRegionView * rv)
170 // insert it into layer sorted position
172 list<AudioRegionView*>::iterator i;
174 for (i = _bylayer.begin(); i != _bylayer.end(); ++i)
176 if (rv->region.layer() < (*i)->region.layer()) {
177 _bylayer.insert(i, rv);
182 // insert at end if we get here
183 _bylayer.insert(i, rv);
186 struct RegionSortByTime {
187 bool operator() (const AudioRegionView* a, const AudioRegionView* b) {
188 return a->region.position() < b->region.position();
194 AudioRegionSelection::by_position (list<AudioRegionView*>& foo) const
196 list<AudioRegionView*>::const_iterator i;
197 RegionSortByTime sorter;
199 for (i = _bylayer.begin(); i != _bylayer.end(); ++i) {