2006-07-31 23:23:35 -04:00
|
|
|
/*
|
|
|
|
Copyright (C) 2006 Paul Davis
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
#include <algorithm>
|
|
|
|
|
2006-07-31 23:23:35 -04:00
|
|
|
#include <ardour/region.h>
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2006-07-31 23:23:35 -04:00
|
|
|
#include "region_view.h"
|
2005-09-25 14:42:24 -04:00
|
|
|
#include "region_selection.h"
|
|
|
|
|
|
|
|
using namespace ARDOUR;
|
2006-06-21 19:01:03 -04:00
|
|
|
using namespace PBD;
|
2005-09-25 16:33:00 -04:00
|
|
|
using namespace sigc;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
|
|
|
|
bool
|
2006-07-31 23:23:35 -04:00
|
|
|
RegionComparator::operator() (const RegionView* a, const RegionView* b) const
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
|
|
|
if (a == b) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return a < b;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-31 23:23:35 -04:00
|
|
|
RegionSelection::RegionSelection ()
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
|
|
|
_current_start = 0;
|
|
|
|
_current_end = 0;
|
|
|
|
}
|
|
|
|
|
2006-07-31 23:23:35 -04:00
|
|
|
RegionSelection::RegionSelection (const RegionSelection& other)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
|
|
|
|
2006-07-31 23:23:35 -04:00
|
|
|
for (RegionSelection::const_iterator i = other.begin(); i != other.end(); ++i) {
|
2005-09-25 14:42:24 -04:00
|
|
|
add (*i, false);
|
|
|
|
}
|
|
|
|
_current_start = other._current_start;
|
|
|
|
_current_end = other._current_end;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-07-31 23:23:35 -04:00
|
|
|
RegionSelection&
|
|
|
|
RegionSelection::operator= (const RegionSelection& other)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
|
|
|
if (this != &other) {
|
|
|
|
|
|
|
|
clear_all();
|
|
|
|
|
2006-07-31 23:23:35 -04:00
|
|
|
for (RegionSelection::const_iterator i = other.begin(); i != other.end(); ++i) {
|
2005-09-25 14:42:24 -04:00
|
|
|
add (*i, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
_current_start = other._current_start;
|
|
|
|
_current_end = other._current_end;
|
|
|
|
}
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-07-31 23:23:35 -04:00
|
|
|
RegionSelection::clear_all()
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
|
|
|
clear();
|
|
|
|
_bylayer.clear();
|
|
|
|
}
|
|
|
|
|
2006-07-31 23:23:35 -04:00
|
|
|
bool RegionSelection::contains (RegionView* rv)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
|
|
|
if (this->find (rv) != end()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-07-31 23:23:35 -04:00
|
|
|
RegionSelection::add (RegionView* rv, bool dosort)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
|
|
|
if (this->find (rv) != end()) {
|
|
|
|
/* we already have it */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-07-31 23:23:35 -04:00
|
|
|
rv->RegionViewGoingAway.connect (mem_fun(*this, &RegionSelection::remove_it));
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2006-07-31 23:23:35 -04:00
|
|
|
if (rv->region().first_frame() < _current_start || empty()) {
|
|
|
|
_current_start = rv->region().first_frame();
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
2006-07-31 23:23:35 -04:00
|
|
|
if (rv->region().last_frame() > _current_end || empty()) {
|
|
|
|
_current_end = rv->region().last_frame();
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
insert (rv);
|
|
|
|
|
|
|
|
// add to layer sorted list
|
|
|
|
add_to_layer (rv);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-07-31 23:23:35 -04:00
|
|
|
RegionSelection::remove_it (RegionView *rv)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
|
|
|
remove (rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2006-07-31 23:23:35 -04:00
|
|
|
RegionSelection::remove (RegionView* rv)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2006-07-31 23:23:35 -04:00
|
|
|
RegionSelection::iterator i;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
if ((i = this->find (rv)) != end()) {
|
|
|
|
|
|
|
|
erase (i);
|
|
|
|
|
|
|
|
// remove from layer sorted list
|
|
|
|
_bylayer.remove (rv);
|
|
|
|
|
|
|
|
if (empty()) {
|
|
|
|
|
|
|
|
_current_start = 0;
|
|
|
|
_current_end = 0;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2006-07-31 23:23:35 -04:00
|
|
|
Region& region ((*i)->region());
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
if (region.first_frame() == _current_start) {
|
|
|
|
|
|
|
|
/* reset current start */
|
|
|
|
|
|
|
|
jack_nframes_t ref = max_frames;
|
|
|
|
|
|
|
|
for (i = begin (); i != end(); ++i) {
|
|
|
|
if (region.first_frame() < ref) {
|
|
|
|
ref = region.first_frame();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_current_start = ref;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (region.last_frame() == _current_end) {
|
|
|
|
|
|
|
|
/* reset current end */
|
|
|
|
|
|
|
|
jack_nframes_t ref = 0;
|
|
|
|
|
|
|
|
for (i = begin (); i != end(); ++i) {
|
|
|
|
if (region.first_frame() > ref) {
|
|
|
|
ref = region.first_frame();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_current_end = ref;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-07-31 23:23:35 -04:00
|
|
|
RegionSelection::add_to_layer (RegionView * rv)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
|
|
|
// insert it into layer sorted position
|
|
|
|
|
2006-07-31 23:23:35 -04:00
|
|
|
list<RegionView*>::iterator i;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
for (i = _bylayer.begin(); i != _bylayer.end(); ++i)
|
|
|
|
{
|
2006-07-31 23:23:35 -04:00
|
|
|
if (rv->region().layer() < (*i)->region().layer()) {
|
2005-09-25 14:42:24 -04:00
|
|
|
_bylayer.insert(i, rv);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// insert at end if we get here
|
|
|
|
_bylayer.insert(i, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct RegionSortByTime {
|
2006-07-31 23:23:35 -04:00
|
|
|
bool operator() (const RegionView* a, const RegionView* b) {
|
|
|
|
return a->region().position() < b->region().position();
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2006-07-31 23:23:35 -04:00
|
|
|
RegionSelection::by_position (list<RegionView*>& foo) const
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2006-07-31 23:23:35 -04:00
|
|
|
list<RegionView*>::const_iterator i;
|
2005-09-25 14:42:24 -04:00
|
|
|
RegionSortByTime sorter;
|
|
|
|
|
|
|
|
for (i = _bylayer.begin(); i != _bylayer.end(); ++i) {
|
|
|
|
foo.push_back (*i);
|
|
|
|
}
|
|
|
|
|
|
|
|
foo.sort (sorter);
|
|
|
|
return;
|
|
|
|
}
|