3 #include <ardour/audioregion.h>
5 #include "regionview.h"
6 #include "region_selection.h"
8 using namespace ARDOUR;
13 AudioRegionComparator::operator() (const AudioRegionView* a, const AudioRegionView* b) const
22 AudioRegionSelection::AudioRegionSelection ()
28 AudioRegionSelection::AudioRegionSelection (const AudioRegionSelection& other)
31 for (AudioRegionSelection::const_iterator i = other.begin(); i != other.end(); ++i) {
34 _current_start = other._current_start;
35 _current_end = other._current_end;
41 AudioRegionSelection::operator= (const AudioRegionSelection& other)
47 for (AudioRegionSelection::const_iterator i = other.begin(); i != other.end(); ++i) {
51 _current_start = other._current_start;
52 _current_end = other._current_end;
59 AudioRegionSelection::clear_all()
65 bool AudioRegionSelection::contains (AudioRegionView* rv)
67 if (this->find (rv) != end()) {
77 AudioRegionSelection::add (AudioRegionView* rv, bool dosort)
79 if (this->find (rv) != end()) {
80 /* we already have it */
84 rv->AudioRegionViewGoingAway.connect (mem_fun(*this, &AudioRegionSelection::remove_it));
86 if (rv->region.first_frame() < _current_start || empty()) {
87 _current_start = rv->region.first_frame();
90 if (rv->region.last_frame() > _current_end || empty()) {
91 _current_end = rv->region.last_frame();
96 // add to layer sorted list
102 AudioRegionSelection::remove_it (AudioRegionView *rv)
108 AudioRegionSelection::remove (AudioRegionView* rv)
110 AudioRegionSelection::iterator i;
112 if ((i = this->find (rv)) != end()) {
116 // remove from layer sorted list
117 _bylayer.remove (rv);
126 AudioRegion& region ((*i)->region);
128 if (region.first_frame() == _current_start) {
130 /* reset current start */
132 jack_nframes_t ref = max_frames;
134 for (i = begin (); i != end(); ++i) {
135 if (region.first_frame() < ref) {
136 ref = region.first_frame();
140 _current_start = ref;
144 if (region.last_frame() == _current_end) {
146 /* reset current end */
148 jack_nframes_t ref = 0;
150 for (i = begin (); i != end(); ++i) {
151 if (region.first_frame() > ref) {
152 ref = region.first_frame();
167 AudioRegionSelection::add_to_layer (AudioRegionView * rv)
169 // insert it into layer sorted position
171 list<AudioRegionView*>::iterator i;
173 for (i = _bylayer.begin(); i != _bylayer.end(); ++i)
175 if (rv->region.layer() < (*i)->region.layer()) {
176 _bylayer.insert(i, rv);
181 // insert at end if we get here
182 _bylayer.insert(i, rv);
185 struct RegionSortByTime {
186 bool operator() (const AudioRegionView* a, const AudioRegionView* b) {
187 return a->region.position() < b->region.position();
193 AudioRegionSelection::by_position (list<AudioRegionView*>& foo) const
195 list<AudioRegionView*>::const_iterator i;
196 RegionSortByTime sorter;
198 for (i = _bylayer.begin(); i != _bylayer.end(); ++i) {