2006-07-31 23:23:35 -04:00
|
|
|
/*
|
2009-10-14 12:10:01 -04:00
|
|
|
Copyright (C) 2006 Paul Davis
|
2006-07-31 23:23:35 -04:00
|
|
|
|
|
|
|
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>
|
|
|
|
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "ardour/region.h"
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2009-12-21 13:23:07 -05:00
|
|
|
#include "gui_thread.h"
|
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
|
|
|
|
2009-05-12 13:03:42 -04:00
|
|
|
using namespace std;
|
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 14:42:24 -04:00
|
|
|
|
2009-02-25 19:58:35 -05:00
|
|
|
/** Construct an empty RegionSelection.
|
2007-10-06 13:27:07 -04:00
|
|
|
*/
|
2006-07-31 23:23:35 -04:00
|
|
|
RegionSelection::RegionSelection ()
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2012-04-25 08:58:19 -04:00
|
|
|
RegionView::RegionViewGoingAway.connect (death_connection, MISSING_INVALIDATOR, boost::bind (&RegionSelection::remove_it, this, _1), gui_context());
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
2009-02-25 19:58:35 -05:00
|
|
|
/** Copy constructor.
|
2007-10-06 13:27:07 -04:00
|
|
|
* @param other RegionSelection to copy.
|
|
|
|
*/
|
2006-07-31 23:23:35 -04:00
|
|
|
RegionSelection::RegionSelection (const RegionSelection& other)
|
2009-02-25 19:58:35 -05:00
|
|
|
: std::list<RegionView*>()
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2012-04-25 08:58:19 -04:00
|
|
|
RegionView::RegionViewGoingAway.connect (death_connection, MISSING_INVALIDATOR, boost::bind (&RegionSelection::remove_it, this, _1), gui_context());
|
2007-04-06 19:42:07 -04:00
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-25 19:58:35 -05:00
|
|
|
/** operator= to set a RegionSelection to be the same as another.
|
2007-10-06 13:27:07 -04:00
|
|
|
* @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();
|
2009-10-14 12:10:01 -04:00
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2009-02-25 19:58:35 -05:00
|
|
|
/** Empty this RegionSelection.
|
2007-10-06 13:27:07 -04:00
|
|
|
*/
|
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();
|
2014-12-14 08:13:38 -05:00
|
|
|
pending.clear ();
|
2005-09-25 14:42:24 -04:00
|
|
|
_bylayer.clear();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2009-02-25 19:58:35 -05:00
|
|
|
/** Add a region to the selection.
|
2007-10-06 13:27:07 -04:00
|
|
|
* @param rv Region to add.
|
2011-06-01 13:00:29 -04:00
|
|
|
* @return false if we already had the region or if it cannot be added,
|
2010-09-15 10:37:08 -04:00
|
|
|
* otherwise true.
|
2007-10-06 13:27:07 -04:00
|
|
|
*/
|
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
|
|
|
{
|
2010-09-15 10:37:08 -04:00
|
|
|
if (!rv->region()->playlist()) {
|
|
|
|
/* not attached to a playlist - selection not allowed.
|
|
|
|
This happens if the user tries to select a region
|
|
|
|
during a capture pass.
|
|
|
|
*/
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2009-02-25 19:58:35 -05:00
|
|
|
/** Remove a region from the selection.
|
2007-10-06 13:27:07 -04:00
|
|
|
* @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);
|
|
|
|
}
|
|
|
|
|
2009-02-25 19:58:35 -05:00
|
|
|
/** Remove a region from the selection.
|
2007-10-06 13:27:07 -04:00
|
|
|
* @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);
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2007-04-10 07:46:12 -04:00
|
|
|
erase (r);
|
2005-09-25 14:42:24 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-02-25 19:58:35 -05:00
|
|
|
/** Add a region to the list sorted by layer.
|
2007-10-06 13:27:07 -04:00
|
|
|
* @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 {
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2007-01-16 20:42:44 -05:00
|
|
|
/* really, track and position */
|
|
|
|
|
2010-09-06 08:34:11 -04:00
|
|
|
if (a->get_time_axis_view().order() == b->get_time_axis_view().order()) {
|
2007-01-16 20:42:44 -05:00
|
|
|
return a->region()->position() < b->region()->position();
|
|
|
|
} else {
|
2010-09-06 08:34:11 -04:00
|
|
|
return a->get_time_axis_view().order() < b->get_time_axis_view().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
|
2009-07-09 13:58:13 -04:00
|
|
|
RegionSelection::involves (const TimeAxisView& tv) const
|
2007-01-17 22:06:15 -05:00
|
|
|
{
|
|
|
|
for (RegionSelection::const_iterator i = begin(); i != end(); ++i) {
|
2010-09-06 08:34:11 -04:00
|
|
|
if (&(*i)->get_time_axis_view() == &tv) {
|
2007-01-17 22:06:15 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2009-02-25 19:58:35 -05:00
|
|
|
|
2010-11-04 14:05:17 -04:00
|
|
|
framepos_t
|
|
|
|
RegionSelection::start () const
|
|
|
|
{
|
|
|
|
framepos_t s = max_framepos;
|
|
|
|
for (RegionSelection::const_iterator i = begin(); i != end(); ++i) {
|
|
|
|
s = min (s, (*i)->region()->position ());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (s == max_framepos) {
|
|
|
|
return 0;
|
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-11-04 14:05:17 -04:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
framepos_t
|
|
|
|
RegionSelection::end_frame () const
|
|
|
|
{
|
|
|
|
framepos_t e = 0;
|
|
|
|
for (RegionSelection::const_iterator i = begin(); i != end(); ++i) {
|
2012-01-29 16:27:51 -05:00
|
|
|
e = max (e, (*i)->region()->last_frame ());
|
2010-11-04 14:05:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return e;
|
|
|
|
}
|
2011-12-27 15:21:00 -05:00
|
|
|
|
|
|
|
/** @return the playlists that the regions in the selection are on */
|
|
|
|
set<boost::shared_ptr<Playlist> >
|
|
|
|
RegionSelection::playlists () const
|
|
|
|
{
|
|
|
|
set<boost::shared_ptr<Playlist> > pl;
|
|
|
|
for (RegionSelection::const_iterator i = begin(); i != end(); ++i) {
|
|
|
|
pl.insert ((*i)->region()->playlist ());
|
|
|
|
}
|
|
|
|
|
|
|
|
return pl;
|
|
|
|
}
|