more games with selection
git-svn-id: svn://localhost/ardour2/trunk@1360 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
parent
058911a1d8
commit
f4fe4d36b1
|
@ -134,6 +134,7 @@ editor_region_list.cc
|
|||
editor_route_list.cc
|
||||
editor_rulers.cc
|
||||
editor_scrub.cc
|
||||
editor_selection.cc
|
||||
editor_selection_list.cc
|
||||
editor_tempodisplay.cc
|
||||
editor_timefx.cc
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
; ardour-2.0beta10 GtkAccelMap rc-file -*- scheme -*-
|
||||
; ardour-2.0beta11.1 GtkAccelMap rc-file -*- scheme -*-
|
||||
; this file is an automated accelerator map dump
|
||||
;
|
||||
; (gtk_accel_path "<Actions>/RegionList/RegionListSort" "")
|
||||
|
|
|
@ -1608,7 +1608,7 @@ Editor::add_region_context_items (AudioStreamView* sv, boost::shared_ptr<Region>
|
|||
become selected.
|
||||
*/
|
||||
|
||||
// region_menu->signal_map_event().connect (bind (mem_fun(*this, &Editor::set_selected_regionview_from_map_event), sv, boost::weak_ptr<Region>(region)));
|
||||
region_menu->signal_map_event().connect (bind (mem_fun(*this, &Editor::set_selected_regionview_from_map_event), sv, boost::weak_ptr<Region>(region)));
|
||||
|
||||
items.push_back (MenuElem (_("Popup region editor"), mem_fun(*this, &Editor::edit_region)));
|
||||
items.push_back (MenuElem (_("Raise to top layer"), mem_fun(*this, &Editor::raise_region_to_top)));
|
||||
|
@ -2779,563 +2779,6 @@ Editor::commit_reversible_command ()
|
|||
}
|
||||
}
|
||||
|
||||
struct TrackViewByPositionSorter
|
||||
{
|
||||
bool operator() (const TimeAxisView* a, const TimeAxisView *b) {
|
||||
return a->y_position < b->y_position;
|
||||
}
|
||||
};
|
||||
|
||||
bool
|
||||
Editor::extend_selection_to_track (TimeAxisView& view)
|
||||
{
|
||||
if (selection->selected (&view)) {
|
||||
/* already selected, do nothing */
|
||||
return false;
|
||||
}
|
||||
|
||||
if (selection->tracks.empty()) {
|
||||
|
||||
if (!selection->selected (&view)) {
|
||||
selection->set (&view);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* something is already selected, so figure out which range of things to add */
|
||||
|
||||
TrackViewList to_be_added;
|
||||
TrackViewList sorted = track_views;
|
||||
TrackViewByPositionSorter cmp;
|
||||
bool passed_clicked = false;
|
||||
bool forwards = true;
|
||||
|
||||
sorted.sort (cmp);
|
||||
|
||||
if (!selection->selected (&view)) {
|
||||
to_be_added.push_back (&view);
|
||||
}
|
||||
|
||||
/* figure out if we should go forward or backwards */
|
||||
|
||||
for (TrackViewList::iterator i = sorted.begin(); i != sorted.end(); ++i) {
|
||||
|
||||
if ((*i) == &view) {
|
||||
passed_clicked = true;
|
||||
}
|
||||
|
||||
if (selection->selected (*i)) {
|
||||
if (passed_clicked) {
|
||||
forwards = true;
|
||||
} else {
|
||||
forwards = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
passed_clicked = false;
|
||||
|
||||
if (forwards) {
|
||||
|
||||
for (TrackViewList::iterator i = sorted.begin(); i != sorted.end(); ++i) {
|
||||
|
||||
if ((*i) == &view) {
|
||||
passed_clicked = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (passed_clicked) {
|
||||
if ((*i)->hidden()) {
|
||||
continue;
|
||||
}
|
||||
if (selection->selected (*i)) {
|
||||
break;
|
||||
} else if (!(*i)->hidden()) {
|
||||
to_be_added.push_back (*i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
for (TrackViewList::reverse_iterator r = sorted.rbegin(); r != sorted.rend(); ++r) {
|
||||
|
||||
if ((*r) == &view) {
|
||||
passed_clicked = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (passed_clicked) {
|
||||
|
||||
if ((*r)->hidden()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (selection->selected (*r)) {
|
||||
break;
|
||||
} else if (!(*r)->hidden()) {
|
||||
to_be_added.push_back (*r);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!to_be_added.empty()) {
|
||||
selection->add (to_be_added);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
Editor::set_selected_track (TimeAxisView& view, Selection::Operation op, bool no_remove)
|
||||
{
|
||||
bool commit = false;
|
||||
|
||||
switch (op) {
|
||||
case Selection::Toggle:
|
||||
if (selection->selected (&view)) {
|
||||
if (!no_remove) {
|
||||
selection->remove (&view);
|
||||
commit = true;
|
||||
}
|
||||
} else {
|
||||
selection->add (&view);
|
||||
commit = false;
|
||||
}
|
||||
break;
|
||||
|
||||
case Selection::Add:
|
||||
if (!selection->selected (&view)) {
|
||||
selection->add (&view);
|
||||
commit = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case Selection::Set:
|
||||
if (selection->selected (&view) && selection->tracks.size() == 1) {
|
||||
/* no commit necessary */
|
||||
} else {
|
||||
|
||||
/* reset track selection if there is only 1 other track
|
||||
selected OR if no_remove is not set (its there to
|
||||
prevent deselecting a multi-track selection
|
||||
when clicking on an already selected track
|
||||
for some reason.
|
||||
*/
|
||||
|
||||
if (selection->tracks.empty()) {
|
||||
selection->set (&view);
|
||||
commit = true;
|
||||
} else if (selection->tracks.size() == 1 || !no_remove) {
|
||||
selection->set (&view);
|
||||
commit = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case Selection::Extend:
|
||||
commit = extend_selection_to_track (view);
|
||||
break;
|
||||
}
|
||||
|
||||
return commit;
|
||||
}
|
||||
|
||||
bool
|
||||
Editor::set_selected_track_from_click (bool press, Selection::Operation op, bool no_remove)
|
||||
{
|
||||
if (!clicked_trackview) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!press) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return set_selected_track (*clicked_trackview, op, no_remove);
|
||||
}
|
||||
|
||||
bool
|
||||
Editor::set_selected_control_point_from_click (Selection::Operation op, bool no_remove)
|
||||
{
|
||||
if (!clicked_control_point) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* select this point and any others that it represents */
|
||||
|
||||
double y1, y2;
|
||||
nframes_t x1, x2;
|
||||
|
||||
x1 = pixel_to_frame (clicked_control_point->get_x() - 10);
|
||||
x2 = pixel_to_frame (clicked_control_point->get_x() + 10);
|
||||
y1 = clicked_control_point->get_x() - 10;
|
||||
y2 = clicked_control_point->get_y() + 10;
|
||||
|
||||
return select_all_within (x1, x2, y1, y2, op);
|
||||
}
|
||||
|
||||
void
|
||||
Editor::get_relevant_audio_tracks (set<AudioTimeAxisView*>& relevant_tracks)
|
||||
{
|
||||
/* step one: get all selected tracks and all tracks in the relevant edit groups */
|
||||
|
||||
for (TrackSelection::iterator ti = selection->tracks.begin(); ti != selection->tracks.end(); ++ti) {
|
||||
|
||||
AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*>(*ti);
|
||||
|
||||
if (!atv) {
|
||||
continue;
|
||||
}
|
||||
|
||||
RouteGroup* group = atv->route()->edit_group();
|
||||
|
||||
if (group && group->is_active()) {
|
||||
|
||||
/* active group for this track, loop over all tracks and get every member of the group */
|
||||
|
||||
for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
|
||||
|
||||
AudioTimeAxisView* tatv;
|
||||
|
||||
if ((tatv = dynamic_cast<AudioTimeAxisView*> (*i)) != 0) {
|
||||
|
||||
if (tatv->route()->edit_group() == group) {
|
||||
relevant_tracks.insert (tatv);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
relevant_tracks.insert (atv);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Editor::mapover_audio_tracks (slot<void,AudioTimeAxisView&,uint32_t> sl)
|
||||
{
|
||||
set<AudioTimeAxisView*> relevant_tracks;
|
||||
|
||||
get_relevant_audio_tracks (relevant_tracks);
|
||||
|
||||
uint32_t sz = relevant_tracks.size();
|
||||
|
||||
for (set<AudioTimeAxisView*>::iterator ati = relevant_tracks.begin(); ati != relevant_tracks.end(); ++ati) {
|
||||
sl (**ati, sz);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Editor::mapped_set_selected_regionview_from_click (RouteTimeAxisView& tv, uint32_t ignored,
|
||||
RegionView* basis, vector<RegionView*>* all_equivs)
|
||||
{
|
||||
boost::shared_ptr<Playlist> pl;
|
||||
vector<boost::shared_ptr<Region> > results;
|
||||
RegionView* marv;
|
||||
boost::shared_ptr<Diskstream> ds;
|
||||
|
||||
if ((ds = tv.get_diskstream()) == 0) {
|
||||
/* bus */
|
||||
return;
|
||||
}
|
||||
|
||||
if (&tv == &basis->get_time_axis_view()) {
|
||||
/* looking in same track as the original */
|
||||
return;
|
||||
}
|
||||
|
||||
if ((pl = ds->playlist()) != 0) {
|
||||
pl->get_equivalent_regions (basis->region(), results);
|
||||
}
|
||||
|
||||
for (vector<boost::shared_ptr<Region> >::iterator ir = results.begin(); ir != results.end(); ++ir) {
|
||||
if ((marv = tv.view()->find_view (*ir)) != 0) {
|
||||
all_equivs->push_back (marv);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
Editor::set_selected_regionview_from_click (bool press, Selection::Operation op, bool no_track_remove)
|
||||
{
|
||||
vector<RegionView*> all_equivalent_regions;
|
||||
bool commit = false;
|
||||
|
||||
if (!clicked_regionview || !clicked_audio_trackview) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (press) {
|
||||
button_release_can_deselect = false;
|
||||
}
|
||||
|
||||
if (op == Selection::Toggle || op == Selection::Set) {
|
||||
|
||||
mapover_audio_tracks (bind (mem_fun (*this, &Editor::mapped_set_selected_regionview_from_click),
|
||||
clicked_regionview, &all_equivalent_regions));
|
||||
|
||||
|
||||
/* add clicked regionview since we skipped all other regions in the same track as the one it was in */
|
||||
|
||||
all_equivalent_regions.push_back (clicked_regionview);
|
||||
|
||||
switch (op) {
|
||||
case Selection::Toggle:
|
||||
|
||||
if (clicked_regionview->get_selected()) {
|
||||
if (press) {
|
||||
|
||||
/* whatever was clicked was selected already; do nothing here but allow
|
||||
the button release to deselect it
|
||||
*/
|
||||
|
||||
button_release_can_deselect = true;
|
||||
|
||||
} else {
|
||||
|
||||
if (button_release_can_deselect) {
|
||||
|
||||
/* just remove this one region, but only on a permitted button release */
|
||||
|
||||
selection->remove (clicked_regionview);
|
||||
commit = true;
|
||||
|
||||
/* no more deselect action on button release till a new press
|
||||
finds an already selected object.
|
||||
*/
|
||||
|
||||
button_release_can_deselect = false;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if (press) {
|
||||
/* add all the equivalent regions, but only on button press */
|
||||
|
||||
if (!all_equivalent_regions.empty()) {
|
||||
commit = true;
|
||||
}
|
||||
|
||||
for (vector<RegionView*>::iterator i = all_equivalent_regions.begin(); i != all_equivalent_regions.end(); ++i) {
|
||||
selection->add (*i);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case Selection::Set:
|
||||
if (!clicked_regionview->get_selected()) {
|
||||
selection->set (all_equivalent_regions);
|
||||
commit = true;
|
||||
} else {
|
||||
/* no commit necessary: clicked on an already selected region */
|
||||
goto out;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
/* silly compiler */
|
||||
break;
|
||||
}
|
||||
|
||||
} else if (op == Selection::Extend) {
|
||||
|
||||
list<Selectable*> results;
|
||||
nframes_t last_frame;
|
||||
nframes_t first_frame;
|
||||
|
||||
/* 1. find the last selected regionview in the track that was clicked in */
|
||||
|
||||
last_frame = 0;
|
||||
first_frame = max_frames;
|
||||
|
||||
for (RegionSelection::iterator x = selection->regions.begin(); x != selection->regions.end(); ++x) {
|
||||
if (&(*x)->get_time_axis_view() == &clicked_regionview->get_time_axis_view()) {
|
||||
|
||||
if ((*x)->region()->last_frame() > last_frame) {
|
||||
last_frame = (*x)->region()->last_frame();
|
||||
}
|
||||
|
||||
if ((*x)->region()->first_frame() < first_frame) {
|
||||
first_frame = (*x)->region()->first_frame();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 2. figure out the boundaries for our search for new objects */
|
||||
|
||||
switch (clicked_regionview->region()->coverage (first_frame, last_frame)) {
|
||||
case OverlapNone:
|
||||
if (last_frame < clicked_regionview->region()->first_frame()) {
|
||||
first_frame = last_frame;
|
||||
last_frame = clicked_regionview->region()->last_frame();
|
||||
} else {
|
||||
last_frame = first_frame;
|
||||
first_frame = clicked_regionview->region()->first_frame();
|
||||
}
|
||||
break;
|
||||
|
||||
case OverlapExternal:
|
||||
if (last_frame < clicked_regionview->region()->first_frame()) {
|
||||
first_frame = last_frame;
|
||||
last_frame = clicked_regionview->region()->last_frame();
|
||||
} else {
|
||||
last_frame = first_frame;
|
||||
first_frame = clicked_regionview->region()->first_frame();
|
||||
}
|
||||
break;
|
||||
|
||||
case OverlapInternal:
|
||||
if (last_frame < clicked_regionview->region()->first_frame()) {
|
||||
first_frame = last_frame;
|
||||
last_frame = clicked_regionview->region()->last_frame();
|
||||
} else {
|
||||
last_frame = first_frame;
|
||||
first_frame = clicked_regionview->region()->first_frame();
|
||||
}
|
||||
break;
|
||||
|
||||
case OverlapStart:
|
||||
case OverlapEnd:
|
||||
/* nothing to do except add clicked region to selection, since it
|
||||
overlaps with the existing selection in this track.
|
||||
*/
|
||||
break;
|
||||
}
|
||||
|
||||
/* 2. find all selectable objects (regionviews in this case) between that one and the end of the
|
||||
one that was clicked.
|
||||
*/
|
||||
|
||||
set<AudioTimeAxisView*> relevant_tracks;
|
||||
|
||||
get_relevant_audio_tracks (relevant_tracks);
|
||||
|
||||
for (set<AudioTimeAxisView*>::iterator t = relevant_tracks.begin(); t != relevant_tracks.end(); ++t) {
|
||||
(*t)->get_selectables (first_frame, last_frame, -1.0, -1.0, results);
|
||||
}
|
||||
|
||||
/* 3. convert to a vector of audio regions */
|
||||
|
||||
vector<RegionView*> regions;
|
||||
|
||||
for (list<Selectable*>::iterator x = results.begin(); x != results.end(); ++x) {
|
||||
RegionView* arv;
|
||||
|
||||
if ((arv = dynamic_cast<RegionView*>(*x)) != 0) {
|
||||
regions.push_back (arv);
|
||||
}
|
||||
}
|
||||
|
||||
if (!regions.empty()) {
|
||||
selection->add (regions);
|
||||
commit = true;
|
||||
}
|
||||
}
|
||||
|
||||
out:
|
||||
return commit;
|
||||
}
|
||||
|
||||
void
|
||||
Editor::set_selected_regionview_from_region_list (boost::shared_ptr<Region> region, Selection::Operation op)
|
||||
{
|
||||
vector<RegionView*> all_equivalent_regions;
|
||||
|
||||
for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
|
||||
|
||||
RouteTimeAxisView* tatv;
|
||||
|
||||
if ((tatv = dynamic_cast<RouteTimeAxisView*> (*i)) != 0) {
|
||||
|
||||
boost::shared_ptr<Playlist> pl;
|
||||
vector<boost::shared_ptr<Region> > results;
|
||||
RegionView* marv;
|
||||
boost::shared_ptr<Diskstream> ds;
|
||||
|
||||
if ((ds = tatv->get_diskstream()) == 0) {
|
||||
/* bus */
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((pl = (ds->playlist())) != 0) {
|
||||
pl->get_region_list_equivalent_regions (region, results);
|
||||
}
|
||||
|
||||
for (vector<boost::shared_ptr<Region> >::iterator ir = results.begin(); ir != results.end(); ++ir) {
|
||||
if ((marv = tatv->view()->find_view (*ir)) != 0) {
|
||||
all_equivalent_regions.push_back (marv);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
begin_reversible_command (_("set selected regions"));
|
||||
|
||||
switch (op) {
|
||||
case Selection::Toggle:
|
||||
/* XXX this is not correct */
|
||||
selection->toggle (all_equivalent_regions);
|
||||
break;
|
||||
case Selection::Set:
|
||||
selection->set (all_equivalent_regions);
|
||||
break;
|
||||
case Selection::Extend:
|
||||
selection->add (all_equivalent_regions);
|
||||
break;
|
||||
case Selection::Add:
|
||||
selection->add (all_equivalent_regions);
|
||||
break;
|
||||
}
|
||||
|
||||
commit_reversible_command () ;
|
||||
}
|
||||
|
||||
bool
|
||||
Editor::set_selected_regionview_from_map_event (GdkEventAny* ev, StreamView* sv, boost::weak_ptr<Region> weak_r)
|
||||
{
|
||||
RegionView* rv;
|
||||
boost::shared_ptr<Region> r (weak_r.lock());
|
||||
|
||||
if (!r) {
|
||||
return true;
|
||||
}
|
||||
|
||||
boost::shared_ptr<AudioRegion> ar;
|
||||
|
||||
if ((ar = boost::dynamic_pointer_cast<AudioRegion> (r)) == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((rv = sv->find_view (ar)) == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* don't reset the selection if its something other than
|
||||
a single other region.
|
||||
*/
|
||||
|
||||
if (selection->regions.size() > 1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
begin_reversible_command (_("set selected regions"));
|
||||
|
||||
selection->set (rv);
|
||||
|
||||
commit_reversible_command () ;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
Editor::set_edit_group_solo (Route& route, bool yn)
|
||||
{
|
||||
|
|
|
@ -422,11 +422,12 @@ class Editor : public PublicEditor
|
|||
void sort_track_selection ();
|
||||
|
||||
void get_relevant_audio_tracks (std::set<AudioTimeAxisView*>& relevant_tracks);
|
||||
void get_equivalent_regions (RegionView* rv, std::vector<RegionView*>&);
|
||||
void mapover_audio_tracks (sigc::slot<void,AudioTimeAxisView&,uint32_t> sl);
|
||||
|
||||
/* functions to be passed to mapover_audio_tracks(), possibly with sigc::bind()-supplied arguments */
|
||||
|
||||
void mapped_set_selected_regionview_from_click (RouteTimeAxisView&, uint32_t, RegionView*, vector<RegionView*>*);
|
||||
void mapped_get_equivalent_regions (RouteTimeAxisView&, uint32_t, RegionView*, vector<RegionView*>*);
|
||||
void mapped_use_new_playlist (AudioTimeAxisView&, uint32_t);
|
||||
void mapped_use_copy_playlist (AudioTimeAxisView&, uint32_t);
|
||||
void mapped_clear_playlist (AudioTimeAxisView&, uint32_t);
|
||||
|
|
|
@ -290,8 +290,6 @@ void
|
|||
Editor::button_selection (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_type)
|
||||
{
|
||||
bool commit = false;
|
||||
bool c1;
|
||||
bool c2;
|
||||
|
||||
/* in object/audition/timefx mode, any button press sets
|
||||
the selection if the object can be selected. this is a
|
||||
|
@ -316,36 +314,25 @@ Editor::button_selection (ArdourCanvas::Item* item, GdkEvent* event, ItemType it
|
|||
|
||||
switch (item_type) {
|
||||
case RegionItem:
|
||||
/* XXX make tying track/region selection optional */
|
||||
c1 = set_selected_track_from_click (press, op, true);
|
||||
c2 = set_selected_regionview_from_click (press, op, true);
|
||||
commit = (c1 || c2);
|
||||
commit = set_selected_regionview_from_click (press, op, true);
|
||||
break;
|
||||
|
||||
case RegionViewNameHighlight:
|
||||
case RegionViewName:
|
||||
/* XXX make tying track/region selection optional */
|
||||
c1 = set_selected_track_from_click (press, op, true);
|
||||
c2 = set_selected_regionview_from_click (press, op, true);
|
||||
commit = (c1 || c2);
|
||||
commit = set_selected_regionview_from_click (press, op, true);
|
||||
break;
|
||||
|
||||
case FadeInHandleItem:
|
||||
case FadeInItem:
|
||||
case FadeOutHandleItem:
|
||||
case FadeOutItem:
|
||||
/* XXX make tying track/region selection optional */
|
||||
c1 = set_selected_track_from_click (press, op, true);
|
||||
c2 = set_selected_regionview_from_click (press, op, true);
|
||||
commit = (c1 || c2);
|
||||
commit = set_selected_regionview_from_click (press, op, true);
|
||||
break;
|
||||
|
||||
case GainAutomationControlPointItem:
|
||||
case PanAutomationControlPointItem:
|
||||
case RedirectAutomationControlPointItem:
|
||||
/* XXX make tying track/region selection optional */
|
||||
c1 = set_selected_track_from_click (press, op, true);
|
||||
c2 = set_selected_control_point_from_click (op, false);
|
||||
commit = (c1 || c2);
|
||||
commit = set_selected_control_point_from_click (op, false);
|
||||
break;
|
||||
|
||||
case StreamItem:
|
||||
|
|
|
@ -1331,6 +1331,8 @@ Editor::select_all (Selection::Operation op)
|
|||
begin_reversible_command (_("select all"));
|
||||
switch (op) {
|
||||
case Selection::Add:
|
||||
selection->add (touched);
|
||||
break;
|
||||
case Selection::Toggle:
|
||||
selection->add (touched);
|
||||
break;
|
||||
|
|
|
@ -0,0 +1,599 @@
|
|||
/*
|
||||
Copyright (C) 2000-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.
|
||||
|
||||
$Id: editor.cc 1353 2007-01-18 03:06:15Z paul $
|
||||
*/
|
||||
|
||||
#include <ardour/diskstream.h>
|
||||
#include <ardour/playlist.h>
|
||||
#include <ardour/route_group.h>
|
||||
|
||||
#include "editor.h"
|
||||
#include "audio_time_axis.h"
|
||||
#include "audio_region_view.h"
|
||||
#include "audio_streamview.h"
|
||||
#include "automation_line.h"
|
||||
|
||||
#include "i18n.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace sigc;
|
||||
using namespace ARDOUR;
|
||||
using namespace PBD;
|
||||
using namespace Gtk;
|
||||
using namespace Glib;
|
||||
using namespace Gtkmm2ext;
|
||||
using namespace Editing;
|
||||
|
||||
struct TrackViewByPositionSorter
|
||||
{
|
||||
bool operator() (const TimeAxisView* a, const TimeAxisView *b) {
|
||||
return a->y_position < b->y_position;
|
||||
}
|
||||
};
|
||||
|
||||
bool
|
||||
Editor::extend_selection_to_track (TimeAxisView& view)
|
||||
{
|
||||
if (selection->selected (&view)) {
|
||||
/* already selected, do nothing */
|
||||
return false;
|
||||
}
|
||||
|
||||
if (selection->tracks.empty()) {
|
||||
|
||||
if (!selection->selected (&view)) {
|
||||
selection->set (&view);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* something is already selected, so figure out which range of things to add */
|
||||
|
||||
TrackViewList to_be_added;
|
||||
TrackViewList sorted = track_views;
|
||||
TrackViewByPositionSorter cmp;
|
||||
bool passed_clicked = false;
|
||||
bool forwards = true;
|
||||
|
||||
sorted.sort (cmp);
|
||||
|
||||
if (!selection->selected (&view)) {
|
||||
to_be_added.push_back (&view);
|
||||
}
|
||||
|
||||
/* figure out if we should go forward or backwards */
|
||||
|
||||
for (TrackViewList::iterator i = sorted.begin(); i != sorted.end(); ++i) {
|
||||
|
||||
if ((*i) == &view) {
|
||||
passed_clicked = true;
|
||||
}
|
||||
|
||||
if (selection->selected (*i)) {
|
||||
if (passed_clicked) {
|
||||
forwards = true;
|
||||
} else {
|
||||
forwards = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
passed_clicked = false;
|
||||
|
||||
if (forwards) {
|
||||
|
||||
for (TrackViewList::iterator i = sorted.begin(); i != sorted.end(); ++i) {
|
||||
|
||||
if ((*i) == &view) {
|
||||
passed_clicked = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (passed_clicked) {
|
||||
if ((*i)->hidden()) {
|
||||
continue;
|
||||
}
|
||||
if (selection->selected (*i)) {
|
||||
break;
|
||||
} else if (!(*i)->hidden()) {
|
||||
to_be_added.push_back (*i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
for (TrackViewList::reverse_iterator r = sorted.rbegin(); r != sorted.rend(); ++r) {
|
||||
|
||||
if ((*r) == &view) {
|
||||
passed_clicked = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (passed_clicked) {
|
||||
|
||||
if ((*r)->hidden()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (selection->selected (*r)) {
|
||||
break;
|
||||
} else if (!(*r)->hidden()) {
|
||||
to_be_added.push_back (*r);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!to_be_added.empty()) {
|
||||
selection->add (to_be_added);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
Editor::set_selected_track (TimeAxisView& view, Selection::Operation op, bool no_remove)
|
||||
{
|
||||
bool commit = false;
|
||||
|
||||
switch (op) {
|
||||
case Selection::Toggle:
|
||||
if (selection->selected (&view)) {
|
||||
if (!no_remove) {
|
||||
selection->remove (&view);
|
||||
commit = true;
|
||||
}
|
||||
} else {
|
||||
selection->add (&view);
|
||||
commit = false;
|
||||
}
|
||||
break;
|
||||
|
||||
case Selection::Add:
|
||||
if (!selection->selected (&view)) {
|
||||
selection->add (&view);
|
||||
commit = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case Selection::Set:
|
||||
if (selection->selected (&view) && selection->tracks.size() == 1) {
|
||||
/* no commit necessary */
|
||||
} else {
|
||||
|
||||
/* reset track selection if there is only 1 other track
|
||||
selected OR if no_remove is not set (its there to
|
||||
prevent deselecting a multi-track selection
|
||||
when clicking on an already selected track
|
||||
for some reason.
|
||||
*/
|
||||
|
||||
if (selection->tracks.empty()) {
|
||||
selection->set (&view);
|
||||
commit = true;
|
||||
} else if (selection->tracks.size() == 1 || !no_remove) {
|
||||
selection->set (&view);
|
||||
commit = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case Selection::Extend:
|
||||
commit = extend_selection_to_track (view);
|
||||
break;
|
||||
}
|
||||
|
||||
return commit;
|
||||
}
|
||||
|
||||
bool
|
||||
Editor::set_selected_track_from_click (bool press, Selection::Operation op, bool no_remove)
|
||||
{
|
||||
if (!clicked_trackview) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!press) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return set_selected_track (*clicked_trackview, op, no_remove);
|
||||
}
|
||||
|
||||
bool
|
||||
Editor::set_selected_control_point_from_click (Selection::Operation op, bool no_remove)
|
||||
{
|
||||
if (!clicked_control_point) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* select this point and any others that it represents */
|
||||
|
||||
double y1, y2;
|
||||
nframes_t x1, x2;
|
||||
|
||||
x1 = pixel_to_frame (clicked_control_point->get_x() - 10);
|
||||
x2 = pixel_to_frame (clicked_control_point->get_x() + 10);
|
||||
y1 = clicked_control_point->get_x() - 10;
|
||||
y2 = clicked_control_point->get_y() + 10;
|
||||
|
||||
return select_all_within (x1, x2, y1, y2, op);
|
||||
}
|
||||
|
||||
void
|
||||
Editor::get_relevant_audio_tracks (set<AudioTimeAxisView*>& relevant_tracks)
|
||||
{
|
||||
/* step one: get all selected tracks and all tracks in the relevant edit groups */
|
||||
|
||||
for (TrackSelection::iterator ti = selection->tracks.begin(); ti != selection->tracks.end(); ++ti) {
|
||||
|
||||
AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*>(*ti);
|
||||
|
||||
if (!atv) {
|
||||
continue;
|
||||
}
|
||||
|
||||
RouteGroup* group = atv->route()->edit_group();
|
||||
|
||||
if (group && group->is_active()) {
|
||||
|
||||
/* active group for this track, loop over all tracks and get every member of the group */
|
||||
|
||||
for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
|
||||
|
||||
AudioTimeAxisView* tatv;
|
||||
|
||||
if ((tatv = dynamic_cast<AudioTimeAxisView*> (*i)) != 0) {
|
||||
|
||||
if (tatv->route()->edit_group() == group) {
|
||||
relevant_tracks.insert (tatv);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
relevant_tracks.insert (atv);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Editor::mapover_audio_tracks (slot<void,AudioTimeAxisView&,uint32_t> sl)
|
||||
{
|
||||
set<AudioTimeAxisView*> relevant_tracks;
|
||||
|
||||
get_relevant_audio_tracks (relevant_tracks);
|
||||
|
||||
uint32_t sz = relevant_tracks.size();
|
||||
|
||||
for (set<AudioTimeAxisView*>::iterator ati = relevant_tracks.begin(); ati != relevant_tracks.end(); ++ati) {
|
||||
sl (**ati, sz);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Editor::mapped_get_equivalent_regions (RouteTimeAxisView& tv, uint32_t ignored, RegionView* basis, vector<RegionView*>* all_equivs)
|
||||
{
|
||||
boost::shared_ptr<Playlist> pl;
|
||||
vector<boost::shared_ptr<Region> > results;
|
||||
RegionView* marv;
|
||||
boost::shared_ptr<Diskstream> ds;
|
||||
|
||||
if ((ds = tv.get_diskstream()) == 0) {
|
||||
/* bus */
|
||||
return;
|
||||
}
|
||||
|
||||
if (&tv == &basis->get_time_axis_view()) {
|
||||
/* looking in same track as the original */
|
||||
return;
|
||||
}
|
||||
|
||||
if ((pl = ds->playlist()) != 0) {
|
||||
pl->get_equivalent_regions (basis->region(), results);
|
||||
}
|
||||
|
||||
for (vector<boost::shared_ptr<Region> >::iterator ir = results.begin(); ir != results.end(); ++ir) {
|
||||
if ((marv = tv.view()->find_view (*ir)) != 0) {
|
||||
all_equivs->push_back (marv);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Editor::get_equivalent_regions (RegionView* basis, vector<RegionView*>& equivalent_regions)
|
||||
{
|
||||
mapover_audio_tracks (bind (mem_fun (*this, &Editor::mapped_get_equivalent_regions), basis, &equivalent_regions));
|
||||
|
||||
/* add clicked regionview since we skipped all other regions in the same track as the one it was in */
|
||||
|
||||
equivalent_regions.push_back (basis);
|
||||
}
|
||||
|
||||
bool
|
||||
Editor::set_selected_regionview_from_click (bool press, Selection::Operation op, bool no_track_remove)
|
||||
{
|
||||
vector<RegionView*> all_equivalent_regions;
|
||||
bool commit = false;
|
||||
|
||||
if (!clicked_regionview || !clicked_audio_trackview) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (press) {
|
||||
button_release_can_deselect = false;
|
||||
}
|
||||
|
||||
if (op == Selection::Toggle || op == Selection::Set) {
|
||||
|
||||
get_equivalent_regions (clicked_regionview, all_equivalent_regions);
|
||||
|
||||
switch (op) {
|
||||
case Selection::Toggle:
|
||||
|
||||
if (clicked_regionview->get_selected()) {
|
||||
if (press) {
|
||||
|
||||
/* whatever was clicked was selected already; do nothing here but allow
|
||||
the button release to deselect it
|
||||
*/
|
||||
|
||||
button_release_can_deselect = true;
|
||||
|
||||
} else {
|
||||
|
||||
if (button_release_can_deselect) {
|
||||
|
||||
/* just remove this one region, but only on a permitted button release */
|
||||
|
||||
selection->remove (clicked_regionview);
|
||||
commit = true;
|
||||
|
||||
/* no more deselect action on button release till a new press
|
||||
finds an already selected object.
|
||||
*/
|
||||
|
||||
button_release_can_deselect = false;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if (press) {
|
||||
/* add all the equivalent regions, but only on button press */
|
||||
|
||||
if (!all_equivalent_regions.empty()) {
|
||||
commit = true;
|
||||
}
|
||||
|
||||
selection->add (all_equivalent_regions);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case Selection::Set:
|
||||
if (!clicked_regionview->get_selected()) {
|
||||
selection->set (all_equivalent_regions);
|
||||
commit = true;
|
||||
} else {
|
||||
/* no commit necessary: clicked on an already selected region */
|
||||
goto out;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
/* silly compiler */
|
||||
break;
|
||||
}
|
||||
|
||||
} else if (op == Selection::Extend) {
|
||||
|
||||
list<Selectable*> results;
|
||||
nframes_t last_frame;
|
||||
nframes_t first_frame;
|
||||
|
||||
/* 1. find the last selected regionview in the track that was clicked in */
|
||||
|
||||
last_frame = 0;
|
||||
first_frame = max_frames;
|
||||
|
||||
for (RegionSelection::iterator x = selection->regions.begin(); x != selection->regions.end(); ++x) {
|
||||
if (&(*x)->get_time_axis_view() == &clicked_regionview->get_time_axis_view()) {
|
||||
|
||||
if ((*x)->region()->last_frame() > last_frame) {
|
||||
last_frame = (*x)->region()->last_frame();
|
||||
}
|
||||
|
||||
if ((*x)->region()->first_frame() < first_frame) {
|
||||
first_frame = (*x)->region()->first_frame();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 2. figure out the boundaries for our search for new objects */
|
||||
|
||||
switch (clicked_regionview->region()->coverage (first_frame, last_frame)) {
|
||||
case OverlapNone:
|
||||
if (last_frame < clicked_regionview->region()->first_frame()) {
|
||||
first_frame = last_frame;
|
||||
last_frame = clicked_regionview->region()->last_frame();
|
||||
} else {
|
||||
last_frame = first_frame;
|
||||
first_frame = clicked_regionview->region()->first_frame();
|
||||
}
|
||||
break;
|
||||
|
||||
case OverlapExternal:
|
||||
if (last_frame < clicked_regionview->region()->first_frame()) {
|
||||
first_frame = last_frame;
|
||||
last_frame = clicked_regionview->region()->last_frame();
|
||||
} else {
|
||||
last_frame = first_frame;
|
||||
first_frame = clicked_regionview->region()->first_frame();
|
||||
}
|
||||
break;
|
||||
|
||||
case OverlapInternal:
|
||||
if (last_frame < clicked_regionview->region()->first_frame()) {
|
||||
first_frame = last_frame;
|
||||
last_frame = clicked_regionview->region()->last_frame();
|
||||
} else {
|
||||
last_frame = first_frame;
|
||||
first_frame = clicked_regionview->region()->first_frame();
|
||||
}
|
||||
break;
|
||||
|
||||
case OverlapStart:
|
||||
case OverlapEnd:
|
||||
/* nothing to do except add clicked region to selection, since it
|
||||
overlaps with the existing selection in this track.
|
||||
*/
|
||||
break;
|
||||
}
|
||||
|
||||
/* 2. find all selectable objects (regionviews in this case) between that one and the end of the
|
||||
one that was clicked.
|
||||
*/
|
||||
|
||||
set<AudioTimeAxisView*> relevant_tracks;
|
||||
|
||||
get_relevant_audio_tracks (relevant_tracks);
|
||||
|
||||
for (set<AudioTimeAxisView*>::iterator t = relevant_tracks.begin(); t != relevant_tracks.end(); ++t) {
|
||||
(*t)->get_selectables (first_frame, last_frame, -1.0, -1.0, results);
|
||||
}
|
||||
|
||||
/* 3. convert to a vector of audio regions */
|
||||
|
||||
vector<RegionView*> regions;
|
||||
|
||||
for (list<Selectable*>::iterator x = results.begin(); x != results.end(); ++x) {
|
||||
RegionView* arv;
|
||||
|
||||
if ((arv = dynamic_cast<RegionView*>(*x)) != 0) {
|
||||
regions.push_back (arv);
|
||||
}
|
||||
}
|
||||
|
||||
if (!regions.empty()) {
|
||||
selection->add (regions);
|
||||
commit = true;
|
||||
}
|
||||
}
|
||||
|
||||
out:
|
||||
return commit;
|
||||
}
|
||||
|
||||
void
|
||||
Editor::set_selected_regionview_from_region_list (boost::shared_ptr<Region> region, Selection::Operation op)
|
||||
{
|
||||
vector<RegionView*> all_equivalent_regions;
|
||||
|
||||
for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
|
||||
|
||||
RouteTimeAxisView* tatv;
|
||||
|
||||
if ((tatv = dynamic_cast<RouteTimeAxisView*> (*i)) != 0) {
|
||||
|
||||
boost::shared_ptr<Playlist> pl;
|
||||
vector<boost::shared_ptr<Region> > results;
|
||||
RegionView* marv;
|
||||
boost::shared_ptr<Diskstream> ds;
|
||||
|
||||
if ((ds = tatv->get_diskstream()) == 0) {
|
||||
/* bus */
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((pl = (ds->playlist())) != 0) {
|
||||
pl->get_region_list_equivalent_regions (region, results);
|
||||
}
|
||||
|
||||
for (vector<boost::shared_ptr<Region> >::iterator ir = results.begin(); ir != results.end(); ++ir) {
|
||||
if ((marv = tatv->view()->find_view (*ir)) != 0) {
|
||||
all_equivalent_regions.push_back (marv);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
begin_reversible_command (_("set selected regions"));
|
||||
|
||||
switch (op) {
|
||||
case Selection::Toggle:
|
||||
/* XXX this is not correct */
|
||||
selection->toggle (all_equivalent_regions);
|
||||
break;
|
||||
case Selection::Set:
|
||||
selection->set (all_equivalent_regions);
|
||||
break;
|
||||
case Selection::Extend:
|
||||
selection->add (all_equivalent_regions);
|
||||
break;
|
||||
case Selection::Add:
|
||||
selection->add (all_equivalent_regions);
|
||||
break;
|
||||
}
|
||||
|
||||
commit_reversible_command () ;
|
||||
}
|
||||
|
||||
bool
|
||||
Editor::set_selected_regionview_from_map_event (GdkEventAny* ev, StreamView* sv, boost::weak_ptr<Region> weak_r)
|
||||
{
|
||||
RegionView* rv;
|
||||
boost::shared_ptr<Region> r (weak_r.lock());
|
||||
|
||||
if (!r) {
|
||||
return true;
|
||||
}
|
||||
|
||||
boost::shared_ptr<AudioRegion> ar;
|
||||
|
||||
if ((ar = boost::dynamic_pointer_cast<AudioRegion> (r)) == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((rv = sv->find_view (ar)) == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* don't reset the selection if its something other than
|
||||
a single other region.
|
||||
*/
|
||||
|
||||
if (selection->regions.size() > 1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
begin_reversible_command (_("set selected regions"));
|
||||
|
||||
selection->set (rv);
|
||||
|
||||
commit_reversible_command () ;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -78,12 +78,12 @@ bool RegionSelection::contains (RegionView* rv) const
|
|||
return find (begin(), end(), rv) != end();
|
||||
}
|
||||
|
||||
void
|
||||
bool
|
||||
RegionSelection::add (RegionView* rv)
|
||||
{
|
||||
if (contains (rv)) {
|
||||
/* we already have it */
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
rv->RegionViewGoingAway.connect (mem_fun(*this, &RegionSelection::remove_it));
|
||||
|
@ -101,6 +101,8 @@ RegionSelection::add (RegionView* rv)
|
|||
// add to layer sorted list
|
||||
|
||||
add_to_layer (rv);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -37,7 +37,7 @@ class RegionSelection : public std::list<RegionView*>, public sigc::trackable
|
|||
|
||||
RegionSelection& operator= (const RegionSelection&);
|
||||
|
||||
void add (RegionView*);
|
||||
bool add (RegionView*);
|
||||
bool remove (RegionView*);
|
||||
void sort_by_position_and_track ();
|
||||
|
||||
|
|
|
@ -334,8 +334,10 @@ Selection::add (vector<RegionView*>& v)
|
|||
|
||||
for (vector<RegionView*>::iterator i = v.begin(); i != v.end(); ++i) {
|
||||
if (find (regions.begin(), regions.end(), (*i)) == regions.end()) {
|
||||
regions.add ((*i));
|
||||
changed = true;
|
||||
changed = regions.add ((*i));
|
||||
if (changed) {
|
||||
add (&(*i)->get_trackview());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -543,12 +545,14 @@ void
|
|||
Selection::set (RegionView* r)
|
||||
{
|
||||
clear_regions ();
|
||||
clear_tracks ();
|
||||
add (r);
|
||||
}
|
||||
|
||||
void
|
||||
Selection::set (vector<RegionView*>& v)
|
||||
{
|
||||
clear_tracks ();
|
||||
clear_regions ();
|
||||
// make sure to deselect any automation selections
|
||||
clear_points();
|
||||
|
|
Loading…
Reference in New Issue