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"
|
2007-01-16 20:42:44 -05:00
|
|
|
#include "time_axis_view.h"
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
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
|
|
|
|
2007-10-06 13:27:07 -04:00
|
|
|
/**
|
|
|
|
* Construct an empty RegionSelection.
|
|
|
|
*/
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2006-07-31 23:23:35 -04:00
|
|
|
RegionSelection::RegionSelection ()
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2007-04-06 19:42:07 -04:00
|
|
|
RegionView::RegionViewGoingAway.connect (mem_fun(*this, &RegionSelection::remove_it));
|
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
_current_start = 0;
|
|
|
|
_current_end = 0;
|
|
|
|
}
|
|
|
|
|
2007-10-06 13:27:07 -04:00
|
|
|
/**
|
|
|
|
* Copy constructor.
|
|
|
|
* @param other RegionSelection to copy.
|
|
|
|
*/
|
|
|
|
|
2006-07-31 23:23:35 -04:00
|
|
|
RegionSelection::RegionSelection (const RegionSelection& other)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2007-04-06 19:42:07 -04:00
|
|
|
RegionView::RegionViewGoingAway.connect (mem_fun(*this, &RegionSelection::remove_it));
|
|
|
|
|
2006-07-31 23:23:35 -04:00
|
|
|
for (RegionSelection::const_iterator i = other.begin(); i != other.end(); ++i) {
|
2007-01-16 20:42:44 -05:00
|
|
|
add (*i);
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
_current_start = other._current_start;
|
|
|
|
_current_end = other._current_end;
|
|
|
|
}
|
|
|
|
|
2007-10-06 13:27:07 -04:00
|
|
|
/**
|
|
|
|
* operator= to set a RegionSelection to be the same as another.
|
|
|
|
* @param other Other RegionSelection.
|
|
|
|
*/
|
|
|
|
|
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) {
|
2007-01-16 20:42:44 -05:00
|
|
|
add (*i);
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
_current_start = other._current_start;
|
|
|
|
_current_end = other._current_end;
|
|
|
|
}
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2007-10-06 13:27:07 -04:00
|
|
|
/**
|
|
|
|
* Empty this RegionSelection.
|
|
|
|
*/
|
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
void
|
2006-07-31 23:23:35 -04:00
|
|
|
RegionSelection::clear_all()
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
|
|
|
clear();
|
|
|
|
_bylayer.clear();
|
2006-11-09 15:38:39 -05:00
|
|
|
_current_start = 0;
|
|
|
|
_current_end = 0;
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
2007-10-06 13:27:07 -04:00
|
|
|
/**
|
|
|
|
* @param rv RegionView.
|
|
|
|
* @return true if this selection contains rv.
|
|
|
|
*/
|
|
|
|
|
2007-01-17 22:06:15 -05:00
|
|
|
bool RegionSelection::contains (RegionView* rv) const
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2007-01-16 20:42:44 -05:00
|
|
|
return find (begin(), end(), rv) != end();
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
2007-10-06 13:27:07 -04:00
|
|
|
/**
|
|
|
|
* Add a region to the selection.
|
|
|
|
* @param rv Region to add.
|
|
|
|
* @return false if we already had the region, otherwise true.
|
|
|
|
*/
|
|
|
|
|
2007-01-18 11:45:29 -05:00
|
|
|
bool
|
2007-01-16 20:42:44 -05:00
|
|
|
RegionSelection::add (RegionView* rv)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2006-11-09 15:38:39 -05:00
|
|
|
if (contains (rv)) {
|
2005-09-25 14:42:24 -04:00
|
|
|
/* we already have it */
|
2007-01-18 11:45:29 -05:00
|
|
|
return false;
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
2006-08-24 21:07:15 -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-08-24 21:07:15 -04:00
|
|
|
if (rv->region()->last_frame() > _current_end || empty()) {
|
|
|
|
_current_end = rv->region()->last_frame();
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
2007-01-16 20:42:44 -05:00
|
|
|
push_back (rv);
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2007-10-06 13:27:07 -04:00
|
|
|
/* add to layer sorted list */
|
2007-01-16 20:42:44 -05:00
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
add_to_layer (rv);
|
2007-01-18 11:45:29 -05:00
|
|
|
|
|
|
|
return true;
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
2007-10-06 13:27:07 -04:00
|
|
|
/**
|
|
|
|
* Remove a region from the selection.
|
|
|
|
* @param rv Region to remove.
|
|
|
|
*/
|
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
void
|
2006-07-31 23:23:35 -04:00
|
|
|
RegionSelection::remove_it (RegionView *rv)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
|
|
|
remove (rv);
|
|
|
|
}
|
|
|
|
|
2007-10-06 13:27:07 -04:00
|
|
|
/**
|
|
|
|
* Remove a region from the selection.
|
|
|
|
* @param rv Region to remove.
|
|
|
|
* @return true if the region was in the selection, false if not.
|
|
|
|
*/
|
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
bool
|
2006-07-31 23:23:35 -04:00
|
|
|
RegionSelection::remove (RegionView* rv)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2007-04-10 07:46:12 -04:00
|
|
|
RegionSelection::iterator r;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2007-04-10 07:46:12 -04:00
|
|
|
if ((r = find (begin(), end(), rv)) != end()) {
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
// remove from layer sorted list
|
|
|
|
_bylayer.remove (rv);
|
|
|
|
|
2007-04-10 07:46:12 -04:00
|
|
|
if (size() == 1) {
|
|
|
|
|
|
|
|
/* this is the last one, so when we delete it
|
|
|
|
we will be empty.
|
|
|
|
*/
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
_current_start = 0;
|
|
|
|
_current_end = 0;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2007-04-10 07:46:12 -04:00
|
|
|
boost::shared_ptr<Region> region ((*r)->region());
|
|
|
|
|
2006-08-24 21:07:15 -04:00
|
|
|
if (region->first_frame() == _current_start) {
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
/* reset current start */
|
|
|
|
|
2006-09-28 13:23:52 -04:00
|
|
|
nframes_t ref = max_frames;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2007-04-10 07:46:12 -04:00
|
|
|
for (RegionSelection::iterator i = begin (); i != end(); ++i) {
|
2006-08-24 21:07:15 -04:00
|
|
|
if (region->first_frame() < ref) {
|
|
|
|
ref = region->first_frame();
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_current_start = ref;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2006-08-24 21:07:15 -04:00
|
|
|
if (region->last_frame() == _current_end) {
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
/* reset current end */
|
|
|
|
|
2006-09-28 13:23:52 -04:00
|
|
|
nframes_t ref = 0;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2007-04-10 07:46:12 -04:00
|
|
|
for (RegionSelection::iterator i = begin (); i != end(); ++i) {
|
2006-08-24 21:07:15 -04:00
|
|
|
if (region->first_frame() > ref) {
|
|
|
|
ref = region->first_frame();
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_current_end = ref;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-10 07:46:12 -04:00
|
|
|
erase (r);
|
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-10-06 13:27:07 -04:00
|
|
|
/**
|
|
|
|
* Add a region to the list sorted by layer.
|
|
|
|
* @param rv Region to add.
|
|
|
|
*/
|
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
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-08-24 21:07:15 -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 {
|
2007-01-16 20:42:44 -05:00
|
|
|
bool operator() (const RegionView* a, const RegionView* b) const {
|
2006-08-24 21:07:15 -04:00
|
|
|
return a->region()->position() < b->region()->position();
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-10-06 13:27:07 -04:00
|
|
|
/**
|
|
|
|
* @param foo List which will be filled with the selection's regions
|
|
|
|
* sorted by 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;
|
|
|
|
}
|
2007-01-16 20:42:44 -05:00
|
|
|
|
|
|
|
struct RegionSortByTrack {
|
|
|
|
bool operator() (const RegionView* a, const RegionView* b) const {
|
|
|
|
|
|
|
|
/* really, track and position */
|
|
|
|
|
2009-01-01 19:17:55 -05:00
|
|
|
if (a->get_trackview().order() == b->get_trackview().order()) {
|
2007-01-16 20:42:44 -05:00
|
|
|
return a->region()->position() < b->region()->position();
|
|
|
|
} else {
|
2009-01-01 19:17:55 -05:00
|
|
|
return a->get_trackview().order() < b->get_trackview().order();
|
2007-01-16 20:42:44 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2007-10-06 13:27:07 -04:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param List which will be filled with the selection's regions
|
|
|
|
* sorted by track and position.
|
|
|
|
*/
|
|
|
|
|
2007-01-16 20:42:44 -05:00
|
|
|
void
|
|
|
|
RegionSelection::by_track (list<RegionView*>& foo) const
|
|
|
|
{
|
|
|
|
list<RegionView*>::const_iterator i;
|
|
|
|
RegionSortByTrack sorter;
|
|
|
|
|
|
|
|
for (i = _bylayer.begin(); i != _bylayer.end(); ++i) {
|
|
|
|
foo.push_back (*i);
|
|
|
|
}
|
|
|
|
|
|
|
|
foo.sort (sorter);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-10-06 13:27:07 -04:00
|
|
|
/**
|
|
|
|
* @param Sort the selection by position and track.
|
|
|
|
*/
|
|
|
|
|
2007-01-16 20:42:44 -05:00
|
|
|
void
|
|
|
|
RegionSelection::sort_by_position_and_track ()
|
|
|
|
{
|
|
|
|
RegionSortByTrack sorter;
|
|
|
|
sort (sorter);
|
|
|
|
}
|
2007-01-17 22:06:15 -05:00
|
|
|
|
2007-10-06 13:27:07 -04:00
|
|
|
/**
|
|
|
|
* @param tv Track.
|
|
|
|
* @return true if any of the selection's regions are on tv.
|
|
|
|
*/
|
|
|
|
|
2007-01-17 22:06:15 -05:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|