X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Feditor_selection.cc;h=fda5155e03d1fe6ed69505ab4f2bf8c253b8383a;hb=e33d4553b2b333c30835b00741fc5c1fd0e2b36d;hp=c1f563658b571aa7a8131bbea6559531b27ab224;hpb=f9f5ec85fbfd15d0008f70d4185a84eeadfd3891;p=ardour.git diff --git a/gtk2_ardour/editor_selection.cc b/gtk2_ardour/editor_selection.cc index c1f563658b..fda5155e03 100644 --- a/gtk2_ardour/editor_selection.cc +++ b/gtk2_ardour/editor_selection.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2000-2006 Paul Davis + 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 @@ -15,14 +15,17 @@ 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 +#include +#include -#include -#include -#include +#include "pbd/stacktrace.h" + +#include "ardour/session.h" +#include "ardour/playlist.h" +#include "ardour/route_group.h" +#include "ardour/profile.h" #include "editor.h" #include "actions.h" @@ -30,11 +33,12 @@ #include "audio_region_view.h" #include "audio_streamview.h" #include "automation_line.h" +#include "control_point.h" +#include "editor_regions.h" #include "i18n.h" using namespace std; -using namespace sigc; using namespace ARDOUR; using namespace PBD; using namespace Gtk; @@ -45,7 +49,7 @@ using namespace Editing; struct TrackViewByPositionSorter { bool operator() (const TimeAxisView* a, const TimeAxisView *b) { - return a->y_position < b->y_position; + return a->y_position() < b->y_position(); } }; @@ -65,10 +69,10 @@ Editor::extend_selection_to_track (TimeAxisView& view) } 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; @@ -98,18 +102,18 @@ Editor::extend_selection_to_track (TimeAxisView& view) 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; @@ -125,18 +129,18 @@ Editor::extend_selection_to_track (TimeAxisView& view) } 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()) { @@ -145,164 +149,188 @@ Editor::extend_selection_to_track (TimeAxisView& view) } } } - + if (!to_be_added.empty()) { selection->add (to_be_added); return true; } - + return false; } +void +Editor::select_all_tracks () +{ + TrackViewList visible_views; + for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) { + if ((*i)->marked_for_display()) { + visible_views.push_back (*i); + } + } + selection->set (visible_views); +} -bool -Editor::set_selected_track (TimeAxisView& view, Selection::Operation op, bool no_remove) +/** Select clicked_routeview, unless there are no currently selected + * tracks, in which case nothing will happen unless `force' is true. + */ +void +Editor::set_selected_track_as_side_effect (bool force) { - bool commit = false; + if (!clicked_routeview) { + return; + } + if (!selection->tracks.empty()) { + if (!selection->selected (clicked_routeview)) { + selection->add (clicked_routeview); + } + + } else if (force) { + selection->set (clicked_routeview); + } +} + +void +Editor::set_selected_track (TimeAxisView& view, Selection::Operation op, bool no_remove) +{ 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; - } - } + selection->set (&view); break; - + case Selection::Extend: - commit = extend_selection_to_track (view); + extend_selection_to_track (view); break; } - - return commit; } -bool +void Editor::set_selected_track_from_click (bool press, Selection::Operation op, bool no_remove) { if (!clicked_routeview) { - return false; + return; } - + if (!press) { - return false; + return; } - return set_selected_track (*clicked_routeview, op, no_remove); + set_selected_track (*clicked_routeview, op, no_remove); } bool -Editor::set_selected_control_point_from_click (Selection::Operation op, bool no_remove) +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; + if (clicked_control_point->selected()) { + /* the clicked control point is already selected; others may be as well, so + don't change the selection. + */ + return true; + } - 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; + /* We know the ControlPoint that was clicked, but (as discussed in automation_selectable.h) + * selected automation data are described by areas on the AutomationLine. A ControlPoint + * represents any model points in the space that it takes up, so the AutomationSelectable + * needs to be the size of the ControlPoint. + */ - return select_all_within (x1, x2, y1, y2, op); + double const size = clicked_control_point->size (); + + nframes64_t const x1 = pixel_to_frame (clicked_control_point->get_x() - size / 2); + nframes64_t const x2 = pixel_to_frame (clicked_control_point->get_x() + size / 2); + double y1 = clicked_control_point->get_y() - size / 2; + double y2 = clicked_control_point->get_y() + size / 2; + + /* convert the y values to trackview space */ + double dummy = 0; + clicked_control_point->line().parent_group().i2w (dummy, y1); + clicked_control_point->line().parent_group().i2w (dummy, y2); + _trackview_group->w2i (dummy, y1); + _trackview_group->w2i (dummy, y2); + + /* and set up the selection */ + return select_all_within (x1, x2, y1, y2, selection->tracks, Selection::Set); } void -Editor::get_relevant_tracks (set& relevant_tracks) +Editor::get_onscreen_tracks (TrackViewList& tvl) { - /* step one: get all selected tracks and all tracks in the relevant edit groups */ + for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) { + if ((*i)->y_position() < _canvas_height) { + tvl.push_back (*i); + } + } +} - for (TrackSelection::iterator ti = selection->tracks.begin(); ti != selection->tracks.end(); ++ti) { +/** Call a slot for a given `basis' track and also for any track that is in the same + * active route group with a particular set of properties. + * + * @param sl Slot to call. + * @param basis Basis track. + * @param prop Properties that active edit groups must share to be included in the map. + */ - RouteTimeAxisView* rtv = dynamic_cast(*ti); +void +Editor::mapover_tracks (sigc::slot sl, TimeAxisView* basis, PBD::PropertyID prop) const +{ + RouteTimeAxisView* route_basis = dynamic_cast (basis); + if (route_basis == 0) { + return; + } - if (!rtv) { - continue; - } + set tracks; + tracks.insert (route_basis); - RouteGroup* group = rtv->route()->edit_group(); + RouteGroup* group = route_basis->route()->route_group(); + if (group && group->enabled_property (prop)) { - if (group && group->is_active()) { - - /* active group for this track, loop over all tracks and get every member of the group */ + /* the basis is a member of an active route group, with the appropriate + properties; find other members */ - for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) { - - RouteTimeAxisView* trtv; - - if ((trtv = dynamic_cast (*i)) != 0) { - - if (trtv->route()->edit_group() == group) { - relevant_tracks.insert (trtv); - } - } + for (TrackViewList::const_iterator i = track_views.begin(); i != track_views.end(); ++i) { + RouteTimeAxisView* v = dynamic_cast (*i); + if (v && v->route()->route_group() == group) { + tracks.insert (v); } - } else { - relevant_tracks.insert (rtv); } } -} -void -Editor::mapover_tracks (slot sl) -{ - set relevant_tracks; - - get_relevant_tracks (relevant_tracks); - - uint32_t sz = relevant_tracks.size(); - - for (set::iterator rti = relevant_tracks.begin(); rti != relevant_tracks.end(); ++rti) { - sl (**rti, sz); + /* call the slots */ + uint32_t const sz = tracks.size (); + for (set::iterator i = tracks.begin(); i != tracks.end(); ++i) { + sl (**i, sz); } } void -Editor::mapped_get_equivalent_regions (RouteTimeAxisView& tv, uint32_t ignored, RegionView* basis, vector* all_equivs) +Editor::mapped_get_equivalent_regions (RouteTimeAxisView& tv, uint32_t, RegionView * basis, vector* all_equivs) const { boost::shared_ptr pl; vector > results; RegionView* marv; - boost::shared_ptr ds; + boost::shared_ptr tr; - if ((ds = tv.get_diskstream()) == 0) { + if ((tr = tv.track()) == 0) { /* bus */ return; } @@ -312,7 +340,7 @@ Editor::mapped_get_equivalent_regions (RouteTimeAxisView& tv, uint32_t ignored, return; } - if ((pl = ds->playlist()) != 0) { + if ((pl = tr->playlist()) != 0) { pl->get_equivalent_regions (basis->region(), results); } @@ -324,17 +352,80 @@ Editor::mapped_get_equivalent_regions (RouteTimeAxisView& tv, uint32_t ignored, } void -Editor::get_equivalent_regions (RegionView* basis, vector& equivalent_regions) +Editor::get_equivalent_regions (RegionView* basis, vector& equivalent_regions, PBD::PropertyID property) const { - mapover_tracks (bind (mem_fun (*this, &Editor::mapped_get_equivalent_regions), basis, &equivalent_regions)); - + mapover_tracks (sigc::bind (sigc::mem_fun (*this, &Editor::mapped_get_equivalent_regions), basis, &equivalent_regions), &basis->get_trackview(), property); + /* add clicked regionview since we skipped all other regions in the same track as the one it was in */ - + equivalent_regions.push_back (basis); } +RegionSelection +Editor::get_equivalent_regions (RegionSelection & basis, PBD::PropertyID prop) const +{ + RegionSelection equivalent; + + for (RegionSelection::const_iterator i = basis.begin(); i != basis.end(); ++i) { + + vector eq; + + mapover_tracks ( + sigc::bind (sigc::mem_fun (*this, &Editor::mapped_get_equivalent_regions), *i, &eq), + &(*i)->get_trackview(), prop + ); + + for (vector::iterator j = eq.begin(); j != eq.end(); ++j) { + equivalent.add (*j); + } + + equivalent.add (*i); + } + + return equivalent; +} + + +int +Editor::get_regionview_count_from_region_list (boost::shared_ptr region) +{ + int region_count = 0; + + for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) { + + RouteTimeAxisView* tatv; + + if ((tatv = dynamic_cast (*i)) != 0) { + + boost::shared_ptr pl; + vector > results; + RegionView* marv; + boost::shared_ptr tr; + + if ((tr = tatv->track()) == 0) { + /* bus */ + continue; + } + + if ((pl = (tr->playlist())) != 0) { + pl->get_region_list_equivalent_regions (region, results); + } + + for (vector >::iterator ir = results.begin(); ir != results.end(); ++ir) { + if ((marv = tatv->view()->find_view (*ir)) != 0) { + region_count++; + } + } + + } + } + + return region_count; +} + + bool -Editor::set_selected_regionview_from_click (bool press, Selection::Operation op, bool no_track_remove) +Editor::set_selected_regionview_from_click (bool press, Selection::Operation op, bool /*no_track_remove*/) { vector all_equivalent_regions; bool commit = false; @@ -345,15 +436,15 @@ Editor::set_selected_regionview_from_click (bool press, Selection::Operation op, if (press) { button_release_can_deselect = false; - } + } if (op == Selection::Toggle || op == Selection::Set) { switch (op) { case Selection::Toggle: - - if (clicked_regionview->get_selected()) { + + if (selection->selected (clicked_regionview)) { if (press) { /* whatever was clicked was selected already; do nothing here but allow @@ -377,40 +468,32 @@ Editor::set_selected_regionview_from_click (bool press, Selection::Operation op, button_release_can_deselect = false; } - } + } } else { if (press) { if (selection->selected (clicked_routeview)) { - get_equivalent_regions (clicked_regionview, all_equivalent_regions); + get_equivalent_regions (clicked_regionview, all_equivalent_regions, ARDOUR::Properties::select.property_id); } else { all_equivalent_regions.push_back (clicked_regionview); } /* 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()) { - - if (selection->selected (clicked_routeview)) { - get_equivalent_regions (clicked_regionview, all_equivalent_regions); - } else { - all_equivalent_regions.push_back (clicked_regionview); - } + case Selection::Set: + if (!selection->selected (clicked_regionview)) { + get_equivalent_regions (clicked_regionview, all_equivalent_regions, ARDOUR::Properties::select.property_id); selection->set (all_equivalent_regions); commit = true; } else { @@ -427,8 +510,9 @@ Editor::set_selected_regionview_from_click (bool press, Selection::Operation op, } else if (op == Selection::Extend) { list results; - nframes_t last_frame; - nframes_t first_frame; + nframes64_t last_frame; + nframes64_t first_frame; + bool same_track = false; /* 1. find the last selected regionview in the track that was clicked in */ @@ -445,66 +529,190 @@ Editor::set_selected_regionview_from_click (bool press, Selection::Operation op, if ((*x)->region()->first_frame() < first_frame) { first_frame = (*x)->region()->first_frame(); } + + same_track = true; } } - /* 2. figure out the boundaries for our search for new objects */ + if (same_track) { - 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; + /* 2. figure out the boundaries for our search for new objects */ - 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; + 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 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(); + 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; } - break; - case OverlapStart: - case OverlapEnd: - /* nothing to do except add clicked region to selection, since it - overlaps with the existing selection in this track. + } else { + + /* click in a track that has no regions selected, so extend vertically + to pick out all regions that are defined by the existing selection + plus this one. */ - break; + + + first_frame = entered_regionview->region()->position(); + last_frame = entered_regionview->region()->last_frame(); + + for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) { + if ((*i)->region()->position() < first_frame) { + first_frame = (*i)->region()->position(); + } + if ((*i)->region()->last_frame() + 1 > last_frame) { + last_frame = (*i)->region()->last_frame(); + } + } } - /* 2. find all selectable objects (regionviews in this case) between that one and the end of the - one that was clicked. - */ + /* 2. find all the tracks we should select in */ set relevant_tracks; + + for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) { + RouteTimeAxisView* r = dynamic_cast (*i); + if (r) { + relevant_tracks.insert (r); + } + } - get_relevant_tracks (relevant_tracks); + set already_in_selection; + + if (relevant_tracks.empty()) { + + /* no tracks selected .. thus .. if the + regionview we're in isn't selected + (i.e. we're about to extend to it), then + find all tracks between the this one and + any selected ones. + */ + + if (!selection->selected (entered_regionview)) { + + RouteTimeAxisView* rtv = dynamic_cast (&entered_regionview->get_time_axis_view()); + + if (rtv) { + + /* add this track to the ones we will search */ + + relevant_tracks.insert (rtv); + + /* find the track closest to this one that + already a selected region. + */ + + RouteTimeAxisView* closest = 0; + int distance = INT_MAX; + int key = rtv->route()->order_key ("editor"); + + for (RegionSelection::iterator x = selection->regions.begin(); x != selection->regions.end(); ++x) { + + RouteTimeAxisView* artv = dynamic_cast(&(*x)->get_time_axis_view()); + + if (artv && artv != rtv) { + + pair::iterator,bool> result; + + result = already_in_selection.insert (artv); + + if (result.second) { + /* newly added to already_in_selection */ + + int d = artv->route()->order_key ("editor"); + + d -= key; + + if (abs (d) < distance) { + distance = abs (d); + closest = artv; + } + } + } + } + + if (closest) { + + /* now add all tracks between that one and this one */ + + int okey = closest->route()->order_key ("editor"); + + if (okey > key) { + swap (okey, key); + } + + for (TrackViewList::iterator x = track_views.begin(); x != track_views.end(); ++x) { + RouteTimeAxisView* artv = dynamic_cast(*x); + if (artv && artv != rtv) { + + int k = artv->route()->order_key ("editor"); + + if (k >= okey && k <= key) { + + /* in range but don't add it if + it already has tracks selected. + this avoids odd selection + behaviour that feels wrong. + */ + + if (find (already_in_selection.begin(), + already_in_selection.end(), + artv) == already_in_selection.end()) { + + relevant_tracks.insert (artv); + } + } + } + } + } + } + } + } + + /* 3. find all selectable objects (regionviews in this case) between that one and the end of the + one that was clicked. + */ for (set::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 */ + + /* 4. convert to a vector of regions */ vector regions; - + for (list::iterator x = results.begin(); x != results.end(); ++x) { RegionView* arv; @@ -523,42 +731,20 @@ Editor::set_selected_regionview_from_click (bool press, Selection::Operation op, return commit; } + void Editor::set_selected_regionview_from_region_list (boost::shared_ptr region, Selection::Operation op) { vector all_equivalent_regions; - for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) { - - RouteTimeAxisView* tatv; - - if ((tatv = dynamic_cast (*i)) != 0) { - - boost::shared_ptr pl; - vector > results; - RegionView* marv; - boost::shared_ptr ds; - - if ((ds = tatv->get_diskstream()) == 0) { - /* bus */ - continue; - } - - if ((pl = (ds->playlist())) != 0) { - pl->get_region_list_equivalent_regions (region, results); - } - - for (vector >::iterator ir = results.begin(); ir != results.end(); ++ir) { - if ((marv = tatv->view()->find_view (*ir)) != 0) { - all_equivalent_regions.push_back (marv); - } - } - - } + get_regions_corresponding_to (region, all_equivalent_regions); + + if (all_equivalent_regions.empty()) { + return; } - + begin_reversible_command (_("set selected regions")); - + switch (op) { case Selection::Toggle: /* XXX this is not correct */ @@ -579,7 +765,7 @@ Editor::set_selected_regionview_from_region_list (boost::shared_ptr regi } bool -Editor::set_selected_regionview_from_map_event (GdkEventAny* ev, StreamView* sv, boost::weak_ptr weak_r) +Editor::set_selected_regionview_from_map_event (GdkEventAny* /*ev*/, StreamView* sv, boost::weak_ptr weak_r) { RegionView* rv; boost::shared_ptr r (weak_r.lock()); @@ -588,26 +774,20 @@ Editor::set_selected_regionview_from_map_event (GdkEventAny* ev, StreamView* sv, return true; } - boost::shared_ptr ar; - - if ((ar = boost::dynamic_pointer_cast (r)) == 0) { - return true; - } - - if ((rv = sv->find_view (ar)) == 0) { + if ((rv = sv->find_view (r)) == 0) { return true; } - /* don't reset the selection if its something other than + /* 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 () ; @@ -627,35 +807,29 @@ Editor::track_selection_changed () } for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) { - (*i)->set_selected (false); - if (mouse_mode == MouseRange) { - (*i)->hide_selection (); + if (find (selection->tracks.begin(), selection->tracks.end(), *i) != selection->tracks.end()) { + (*i)->set_selected (true); + } else { + (*i)->set_selected (false); } } - for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) { - (*i)->set_selected (true); - if (mouse_mode == MouseRange) { - (*i)->show_selection (selection->time); - } - } + ActionManager::set_sensitive (ActionManager::track_selection_sensitive_actions, !selection->tracks.empty()); } void Editor::time_selection_changed () { + if (Profile->get_sae()) { + return; + } + for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) { (*i)->hide_selection (); } - if (selection->tracks.empty()) { - for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) { - (*i)->show_selection (selection->time); - } - } else { - for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) { - (*i)->show_selection (selection->time); - } + for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) { + (*i)->show_selection (selection->time); } if (selection->time.empty()) { @@ -665,12 +839,48 @@ Editor::time_selection_changed () } } +void +Editor::sensitize_the_right_region_actions (bool have_selected_regions) +{ + for (vector >::iterator x = ActionManager::region_selection_sensitive_actions.begin(); + x != ActionManager::region_selection_sensitive_actions.end(); ++x) { + + string accel_path = (*x)->get_accel_path (); + AccelKey key; + + /* if there is an accelerator, it should always be sensitive + to allow for keyboard ops on entered regions. + */ + + bool known = ActionManager::lookup_entry (accel_path, key); + + if (known && ((key.get_key() != GDK_VoidSymbol) && (key.get_key() != 0))) { + (*x)->set_sensitive (true); + } else { + (*x)->set_sensitive (have_selected_regions); + } + } +} + + void Editor::region_selection_changed () { + _regions->block_change_connection (true); + editor_regions_selection_changed_connection.block(true); + + _regions->unselect_all (); + for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) { (*i)->set_selected_regionviews (selection->regions); } + + _regions->set_selected (selection->regions); + + sensitize_the_right_region_actions (!selection->regions.empty()); + + _regions->block_change_connection (false); + editor_regions_selection_changed_connection.block(false); } void @@ -689,7 +899,7 @@ Editor::select_all_in_track (Selection::Operation op) if (!clicked_routeview) { return; } - + clicked_routeview->get_selectables (0, max_frames, 0, DBL_MAX, touched); switch (op) { @@ -712,7 +922,7 @@ void Editor::select_all (Selection::Operation op) { list touched; - + for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) { if ((*iter)->hidden()) { continue; @@ -736,7 +946,6 @@ Editor::select_all (Selection::Operation op) } commit_reversible_command (); } - void Editor::invert_selection_in_track () { @@ -745,7 +954,7 @@ Editor::invert_selection_in_track () if (!clicked_routeview) { return; } - + clicked_routeview->get_inverted_selectables (*selection, touched); selection->set (touched); } @@ -754,7 +963,7 @@ void Editor::invert_selection () { list touched; - + for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) { if ((*iter)->hidden()) { continue; @@ -765,54 +974,37 @@ Editor::invert_selection () selection->set (touched); } +/** @param top Top (lower) y limit in trackview coordinates. + * @param bottom Bottom (higher) y limit in trackview coordinates. + */ bool -Editor::select_all_within (nframes_t start, nframes_t end, double top, double bot, Selection::Operation op) +Editor::select_all_within (nframes64_t start, nframes64_t end, double top, double bot, const TrackViewList& tracklist, Selection::Operation op) { - list touched; - list::size_type n = 0; - TrackViewList touched_tracks; + list found; - for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) { + for (TrackViewList::const_iterator iter = tracklist.begin(); iter != tracklist.end(); ++iter) { + if ((*iter)->hidden()) { continue; } - n = touched.size(); - - (*iter)->get_selectables (start, end, top, bot, touched); - - if (n != touched.size()) { - touched_tracks.push_back (*iter); - } + (*iter)->get_selectables (start, end, top, bot, found); } - - if (!touched_tracks.empty()) { - switch (op) { - case Selection::Add: - selection->add (touched_tracks); - break; - case Selection::Toggle: - selection->toggle (touched_tracks); - break; - case Selection::Set: - selection->set (touched_tracks); - break; - case Selection::Extend: - /* not defined yet */ - break; - } + + if (found.empty()) { + return false; } - + begin_reversible_command (_("select all within")); switch (op) { case Selection::Add: - selection->add (touched); + selection->add (found); break; case Selection::Toggle: - selection->toggle (touched); + selection->toggle (found); break; case Selection::Set: - selection->set (touched); + selection->set (found); break; case Selection::Extend: /* not defined yet */ @@ -820,24 +1012,21 @@ Editor::select_all_within (nframes_t start, nframes_t end, double top, double bo } commit_reversible_command (); - return !touched.empty(); + + return !found.empty(); } void -Editor::set_selection_from_audio_region () +Editor::set_selection_from_region () { if (selection->regions.empty()) { return; } - RegionView* rv = *(selection->regions.begin()); - boost::shared_ptr region = rv->region(); - - begin_reversible_command (_("set selection from region")); - selection->set (0, region->position(), region->last_frame()); - commit_reversible_command (); - - set_mouse_mode (Editing::MouseRange, false); + selection->set (selection->regions.start(), selection->regions.end_frame()); + if (!Profile->get_sae()) { + set_mouse_mode (Editing::MouseRange, false); + } } void @@ -845,7 +1034,7 @@ Editor::set_selection_from_punch() { Location* location; - if ((location = session->locations()->auto_punch_location()) == 0) { + if ((location = _session->locations()->auto_punch_location()) == 0) { return; } @@ -857,7 +1046,7 @@ Editor::set_selection_from_loop() { Location* location; - if ((location = session->locations()->auto_loop_location()) == 0) { + if ((location = _session->locations()->auto_loop_location()) == 0) { return; } set_selection_from_range (*location); @@ -867,10 +1056,12 @@ void Editor::set_selection_from_range (Location& loc) { begin_reversible_command (_("set selection from range")); - selection->set (0, loc.start(), loc.end()); + selection->set (loc.start(), loc.end()); commit_reversible_command (); - set_mouse_mode (Editing::MouseRange, false); + if (!Profile->get_sae()) { + set_mouse_mode (Editing::MouseRange, false); + } } void @@ -882,14 +1073,22 @@ Editor::select_all_selectables_using_time_selection () return; } - nframes_t start = selection->time[clicked_selection].start; - nframes_t end = selection->time[clicked_selection].end; + nframes64_t start = selection->time[clicked_selection].start; + nframes64_t end = selection->time[clicked_selection].end; if (end - start < 1) { return; } - for (TrackViewList::iterator iter = selection->tracks.begin(); iter != selection->tracks.end(); ++iter) { + TrackViewList* ts; + + if (selection->tracks.empty()) { + ts = &track_views; + } else { + ts = &selection->tracks; + } + + for (TrackViewList::iterator iter = ts->begin(); iter != ts->end(); ++iter) { if ((*iter)->hidden()) { continue; } @@ -905,14 +1104,23 @@ Editor::select_all_selectables_using_time_selection () void Editor::select_all_selectables_using_punch() { - Location* location = session->locations()->auto_punch_location(); + Location* location = _session->locations()->auto_punch_location(); list touched; if (location == 0 || (location->end() - location->start() <= 1)) { return; } - for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) { + + TrackViewList* ts; + + if (selection->tracks.empty()) { + ts = &track_views; + } else { + ts = &selection->tracks; + } + + for (TrackViewList::iterator iter = ts->begin(); iter != ts->end(); ++iter) { if ((*iter)->hidden()) { continue; } @@ -927,14 +1135,23 @@ Editor::select_all_selectables_using_punch() void Editor::select_all_selectables_using_loop() { - Location* location = session->locations()->auto_loop_location(); + Location* location = _session->locations()->auto_loop_location(); list touched; if (location == 0 || (location->end() - location->start() <= 1)) { return; } - for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) { + + TrackViewList* ts; + + if (selection->tracks.empty()) { + ts = &track_views; + } else { + ts = &selection->tracks; + } + + for (TrackViewList::iterator iter = ts->begin(); iter != ts->end(); ++iter) { if ((*iter)->hidden()) { continue; } @@ -947,16 +1164,16 @@ Editor::select_all_selectables_using_loop() } void -Editor::select_all_selectables_using_cursor (Cursor *cursor, bool after) +Editor::select_all_selectables_using_cursor (EditorCursor *cursor, bool after) { - nframes_t start; - nframes_t end; + nframes64_t start; + nframes64_t end; list touched; if (after) { begin_reversible_command (_("select all after cursor")); start = cursor->current_frame ; - end = session->current_end_frame(); + end = _session->current_end_frame(); } else { if (cursor->current_frame > 0) { begin_reversible_command (_("select all before cursor")); @@ -967,7 +1184,16 @@ Editor::select_all_selectables_using_cursor (Cursor *cursor, bool after) } } - for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) { + + TrackViewList* ts; + + if (selection->tracks.empty()) { + ts = &track_views; + } else { + ts = &selection->tracks; + } + + for (TrackViewList::iterator iter = ts->begin(); iter != ts->end(); ++iter) { if ((*iter)->hidden()) { continue; } @@ -978,28 +1204,36 @@ Editor::select_all_selectables_using_cursor (Cursor *cursor, bool after) } void -Editor::select_all_selectables_between_cursors (Cursor *cursor, Cursor *other_cursor) +Editor::select_all_selectables_using_edit (bool after) { - nframes_t start; - nframes_t end; + nframes64_t start; + nframes64_t end; list touched; - bool other_cursor_is_first = cursor->current_frame > other_cursor->current_frame; - if (cursor->current_frame == other_cursor->current_frame) { - return; + if (after) { + begin_reversible_command (_("select all after edit")); + start = get_preferred_edit_position(); + end = _session->current_end_frame(); + } else { + if ((end = get_preferred_edit_position()) > 1) { + begin_reversible_command (_("select all before edit")); + start = 0; + end -= 1; + } else { + return; + } } - begin_reversible_command (_("select all between cursors")); - if (other_cursor_is_first) { - start = other_cursor->current_frame; - end = cursor->current_frame - 1; - + + TrackViewList* ts; + + if (selection->tracks.empty()) { + ts = &track_views; } else { - start = cursor->current_frame; - end = other_cursor->current_frame - 1; + ts = &selection->tracks; } - - for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) { + + for (TrackViewList::iterator iter = ts->begin(); iter != ts->end(); ++iter) { if ((*iter)->hidden()) { continue; } @@ -1009,3 +1243,160 @@ Editor::select_all_selectables_between_cursors (Cursor *cursor, Cursor *other_cu commit_reversible_command (); } +void +Editor::select_all_selectables_between (bool /*within*/) +{ + nframes64_t start; + nframes64_t end; + list touched; + + if (!get_edit_op_range (start, end)) { + return; + } + + TrackViewList* ts; + + if (selection->tracks.empty()) { + ts = &track_views; + } else { + ts = &selection->tracks; + } + + for (TrackViewList::iterator iter = ts->begin(); iter != ts->end(); ++iter) { + if ((*iter)->hidden()) { + continue; + } + (*iter)->get_selectables (start, end, 0, DBL_MAX, touched); + } + + selection->set (touched); +} + +void +Editor::select_range_between () +{ + nframes64_t start; + nframes64_t end; + + if (!get_edit_op_range (start, end)) { + return; + } + + set_mouse_mode (MouseRange); + selection->set (start, end); +} + +bool +Editor::get_edit_op_range (nframes64_t& start, nframes64_t& end) const +{ + nframes64_t m; + bool ignored; + + /* in range mode, use any existing selection */ + + if (mouse_mode == MouseRange && !selection->time.empty()) { + /* we know that these are ordered */ + start = selection->time.start(); + end = selection->time.end_frame(); + return true; + } + + if (!mouse_frame (m, ignored)) { + /* mouse is not in a canvas, try playhead+selected marker. + this is probably most true when using menus. + */ + + if (selection->markers.empty()) { + return false; + } + + start = selection->markers.front()->position(); + end = _session->audible_frame(); + + } else { + + switch (_edit_point) { + case EditAtPlayhead: + if (selection->markers.empty()) { + /* use mouse + playhead */ + start = m; + end = _session->audible_frame(); + } else { + /* use playhead + selected marker */ + start = _session->audible_frame(); + end = selection->markers.front()->position(); + } + break; + + case EditAtMouse: + /* use mouse + selected marker */ + if (selection->markers.empty()) { + start = m; + end = _session->audible_frame(); + } else { + start = selection->markers.front()->position(); + end = m; + } + break; + + case EditAtSelectedMarker: + /* use mouse + selected marker */ + if (selection->markers.empty()) { + + MessageDialog win (_("No edit range defined"), + false, + MESSAGE_INFO, + BUTTONS_OK); + + win.set_secondary_text ( + _("the edit point is Selected Marker\nbut there is no selected marker.")); + + + win.set_default_response (RESPONSE_CLOSE); + win.set_position (Gtk::WIN_POS_MOUSE); + win.show_all(); + + win.run (); + + return false; // NO RANGE + } + start = selection->markers.front()->position(); + end = m; + break; + } + } + + if (start == end) { + return false; + } + + if (start > end) { + swap (start, end); + } + + /* turn range into one delimited by start...end, + not start...end-1 + */ + + end++; + + return true; +} + +void +Editor::deselect_all () +{ + selection->clear (); +} + +long +Editor::select_range_around_region (RegionView* rv) +{ + assert (rv); + + selection->set (&rv->get_time_axis_view()); + + selection->time.clear (); + boost::shared_ptr r = rv->region (); + return selection->set (r->position(), r->position() + r->length()); +}