X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Fregion_selection.cc;h=8074383141fff7d7ca4e17042c80a84c314d37b2;hb=078151e4d43d83e13bad142d6b609db6ce6c5f8f;hp=f8c9f384a9b13ce5069dc233b9cb756029016c2c;hpb=6f4a92f740b2fd75794489ce58f9348f8adf6bf4;p=ardour.git diff --git a/gtk2_ardour/region_selection.cc b/gtk2_ardour/region_selection.cc index f8c9f384a9..8074383141 100644 --- a/gtk2_ardour/region_selection.cc +++ b/gtk2_ardour/region_selection.cc @@ -22,40 +22,32 @@ #include "region_view.h" #include "region_selection.h" +#include "time_axis_view.h" using namespace ARDOUR; using namespace PBD; using namespace sigc; -bool -RegionComparator::operator() (const RegionView* a, const RegionView* b) const -{ - if (a == b) { - return false; - } else { - return a < b; - } -} - RegionSelection::RegionSelection () { + RegionView::RegionViewGoingAway.connect (mem_fun(*this, &RegionSelection::remove_it)); + _current_start = 0; _current_end = 0; } RegionSelection::RegionSelection (const RegionSelection& other) { + RegionView::RegionViewGoingAway.connect (mem_fun(*this, &RegionSelection::remove_it)); for (RegionSelection::const_iterator i = other.begin(); i != other.end(); ++i) { - add (*i, false); + add (*i); } _current_start = other._current_start; _current_end = other._current_end; } - - RegionSelection& RegionSelection::operator= (const RegionSelection& other) { @@ -64,7 +56,7 @@ RegionSelection::operator= (const RegionSelection& other) clear_all(); for (RegionSelection::const_iterator i = other.begin(); i != other.end(); ++i) { - add (*i, false); + add (*i); } _current_start = other._current_start; @@ -79,42 +71,38 @@ RegionSelection::clear_all() { clear(); _bylayer.clear(); + _current_start = 0; + _current_end = 0; } -bool RegionSelection::contains (RegionView* rv) +bool RegionSelection::contains (RegionView* rv) const { - if (this->find (rv) != end()) { - return true; - } - else { - return false; - } - + return find (begin(), end(), rv) != end(); } -void -RegionSelection::add (RegionView* rv, bool dosort) +bool +RegionSelection::add (RegionView* rv) { - if (this->find (rv) != end()) { + if (contains (rv)) { /* we already have it */ - return; + return false; } - rv->RegionViewGoingAway.connect (mem_fun(*this, &RegionSelection::remove_it)); - - if (rv->region().first_frame() < _current_start || empty()) { - _current_start = rv->region().first_frame(); + if (rv->region()->first_frame() < _current_start || empty()) { + _current_start = rv->region()->first_frame(); } - if (rv->region().last_frame() > _current_end || empty()) { - _current_end = rv->region().last_frame(); + if (rv->region()->last_frame() > _current_end || empty()) { + _current_end = rv->region()->last_frame(); } - insert (rv); + push_back (rv); // add to layer sorted list + add_to_layer (rv); - + + return true; } void @@ -126,33 +114,35 @@ RegionSelection::remove_it (RegionView *rv) bool RegionSelection::remove (RegionView* rv) { - RegionSelection::iterator i; - - if ((i = this->find (rv)) != end()) { + RegionSelection::iterator r; - erase (i); + if ((r = find (begin(), end(), rv)) != end()) { // remove from layer sorted list _bylayer.remove (rv); - if (empty()) { + if (size() == 1) { + + /* this is the last one, so when we delete it + we will be empty. + */ _current_start = 0; _current_end = 0; } else { - Region& region ((*i)->region()); - - if (region.first_frame() == _current_start) { + boost::shared_ptr region ((*r)->region()); + + if (region->first_frame() == _current_start) { /* reset current start */ - jack_nframes_t ref = max_frames; + nframes_t ref = max_frames; - for (i = begin (); i != end(); ++i) { - if (region.first_frame() < ref) { - ref = region.first_frame(); + for (RegionSelection::iterator i = begin (); i != end(); ++i) { + if (region->first_frame() < ref) { + ref = region->first_frame(); } } @@ -160,15 +150,15 @@ RegionSelection::remove (RegionView* rv) } - if (region.last_frame() == _current_end) { + if (region->last_frame() == _current_end) { /* reset current end */ - jack_nframes_t ref = 0; + nframes_t ref = 0; - for (i = begin (); i != end(); ++i) { - if (region.first_frame() > ref) { - ref = region.first_frame(); + for (RegionSelection::iterator i = begin (); i != end(); ++i) { + if (region->first_frame() > ref) { + ref = region->first_frame(); } } @@ -176,6 +166,8 @@ RegionSelection::remove (RegionView* rv) } } + erase (r); + return true; } @@ -191,7 +183,7 @@ RegionSelection::add_to_layer (RegionView * rv) for (i = _bylayer.begin(); i != _bylayer.end(); ++i) { - if (rv->region().layer() < (*i)->region().layer()) { + if (rv->region()->layer() < (*i)->region()->layer()) { _bylayer.insert(i, rv); return; } @@ -202,8 +194,8 @@ RegionSelection::add_to_layer (RegionView * rv) } struct RegionSortByTime { - bool operator() (const RegionView* a, const RegionView* b) { - return a->region().position() < b->region().position(); + bool operator() (const RegionView* a, const RegionView* b) const { + return a->region()->position() < b->region()->position(); } }; @@ -221,3 +213,49 @@ RegionSelection::by_position (list& foo) const foo.sort (sorter); return; } + +struct RegionSortByTrack { + bool operator() (const RegionView* a, const RegionView* b) const { + + /* really, track and position */ + + if (a->get_trackview().order == b->get_trackview().order) { + return a->region()->position() < b->region()->position(); + } else { + return a->get_trackview().order < b->get_trackview().order; + } + } +}; + +void +RegionSelection::by_track (list& foo) const +{ + list::const_iterator i; + RegionSortByTrack sorter; + + for (i = _bylayer.begin(); i != _bylayer.end(); ++i) { + foo.push_back (*i); + } + + foo.sort (sorter); + return; +} + +void +RegionSelection::sort_by_position_and_track () +{ + RegionSortByTrack sorter; + sort (sorter); +} + +bool +RegionSelection::involves (const TimeAxisView& tv) const +{ + for (RegionSelection::const_iterator i = begin(); i != end(); ++i) { + if (&(*i)->get_trackview() == &tv) { + return true; + } + } + return false; +} +