2006-07-31 23:23:35 -04:00
|
|
|
/*
|
2019-08-02 17:26:43 -04:00
|
|
|
* Copyright (C) 2005 Taybin Rutkin <taybin@taybin.com>
|
|
|
|
* Copyright (C) 2006-2014 David Robillard <d@drobilla.net>
|
|
|
|
* Copyright (C) 2006-2017 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
* Copyright (C) 2007-2012 Carl Hetherington <carl@carlh.net>
|
|
|
|
* Copyright (C) 2014-2016 Nick Mainsbridge <mainsbridge@gmail.com>
|
|
|
|
* Copyright (C) 2016-2017 Robin Gareus <robin@gareus.org>
|
|
|
|
*
|
|
|
|
* 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.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2006-07-31 23:23:35 -04:00
|
|
|
|
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"
|
2014-12-25 15:32:10 -05:00
|
|
|
#include "midi_region_view.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
|
|
|
}
|
|
|
|
|
2017-03-11 19:20:14 -05:00
|
|
|
bool RegionSelection::contains (boost::shared_ptr<ARDOUR::Region> region) const
|
|
|
|
{
|
|
|
|
for (const_iterator r = begin (); r != end (); ++r) {
|
|
|
|
if ((*r)->region () == region) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2017-04-01 11:13:32 -04:00
|
|
|
if (!rv->region()->playlist()) {
|
2017-07-01 12:42:24 -04:00
|
|
|
/* not attached to a playlist - selection not allowed.
|
|
|
|
This happens if the user tries to select a region
|
|
|
|
during a capture pass.
|
|
|
|
*/
|
|
|
|
return false;
|
|
|
|
}
|
2010-09-15 10:37:08 -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
|
|
|
}
|
|
|
|
|
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);
|
2016-11-22 23:36:26 -05:00
|
|
|
pending.remove (rv->region()->id());
|
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 {
|
2017-07-01 12:42:24 -04:00
|
|
|
bool operator() (const RegionView* a, const RegionView* b) const {
|
|
|
|
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 {
|
2017-07-01 12:42:24 -04:00
|
|
|
bool operator() (const RegionView* a, const RegionView* b) const {
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2017-07-01 12:42:24 -04:00
|
|
|
/* really, track and position */
|
2007-01-16 20:42:44 -05:00
|
|
|
|
2017-07-01 12:42:24 -04:00
|
|
|
if (a->get_time_axis_view().order() == b->get_time_axis_view().order()) {
|
|
|
|
return a->region()->position() < b->region()->position();
|
|
|
|
} else {
|
|
|
|
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
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
samplepos_t
|
2010-11-04 14:05:17 -04:00
|
|
|
RegionSelection::start () const
|
|
|
|
{
|
2017-09-18 12:39:17 -04:00
|
|
|
samplepos_t s = max_samplepos;
|
2010-11-04 14:05:17 -04:00
|
|
|
for (RegionSelection::const_iterator i = begin(); i != end(); ++i) {
|
|
|
|
s = min (s, (*i)->region()->position ());
|
|
|
|
}
|
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
if (s == max_samplepos) {
|
2010-11-04 14:05:17 -04:00
|
|
|
return 0;
|
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-11-04 14:05:17 -04:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
samplepos_t
|
|
|
|
RegionSelection::end_sample () const
|
2010-11-04 14:05:17 -04:00
|
|
|
{
|
2017-09-18 12:39:17 -04:00
|
|
|
samplepos_t e = 0;
|
2010-11-04 14:05:17 -04:00
|
|
|
for (RegionSelection::const_iterator i = begin(); i != end(); ++i) {
|
2017-09-18 12:39:17 -04:00
|
|
|
e = max (e, (*i)->region()->last_sample ());
|
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;
|
|
|
|
}
|
2014-12-25 15:32:10 -05:00
|
|
|
|
|
|
|
size_t
|
|
|
|
RegionSelection::n_midi_regions () const
|
|
|
|
{
|
|
|
|
size_t count = 0;
|
|
|
|
|
|
|
|
for (const_iterator r = begin(); r != end(); ++r) {
|
|
|
|
MidiRegionView* const mrv = dynamic_cast<MidiRegionView*> (*r);
|
|
|
|
if (mrv) {
|
|
|
|
++count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
2016-04-10 12:57:52 -04:00
|
|
|
|
|
|
|
ARDOUR::RegionList
|
|
|
|
RegionSelection::regionlist () const
|
|
|
|
{
|
|
|
|
ARDOUR::RegionList rl;
|
|
|
|
for (const_iterator r = begin (); r != end (); ++r) {
|
|
|
|
rl.push_back ((*r)->region ());
|
|
|
|
}
|
|
|
|
return rl;
|
|
|
|
}
|