*/
+#include <algorithm>
+#include <cstdlib>
+
#include <pbd/stacktrace.h>
#include <ardour/diskstream.h>
#include <ardour/playlist.h>
#include <ardour/route_group.h>
+#include <ardour/profile.h>
#include "editor.h"
#include "actions.h"
selection->set (track_views);
}
-bool
-Editor::set_selected_track (TimeAxisView& view, Selection::Operation op, bool no_remove)
+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
/* select this point and any others that it represents */
double y1, y2;
- nframes_t x1, x2;
+ nframes64_t x1, x2;
x1 = pixel_to_frame (clicked_control_point->get_x() - 10);
x2 = pixel_to_frame (clicked_control_point->get_x() + 10);
equivalent_regions.push_back (basis);
}
+int
+Editor::get_regionview_count_from_region_list (boost::shared_ptr<Region> region)
+{
+ int region_count = 0;
+
+ 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) {
+ region_count++;
+ }
+ }
+
+ }
+ }
+
+ return region_count;
+}
+
+
bool
Editor::set_selected_regionview_from_click (bool press, Selection::Operation op, bool no_track_remove)
{
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
break;
case Selection::Set:
- if (!clicked_regionview->get_selected()) {
+ if (!selection->selected (clicked_regionview)) {
selection->set (clicked_regionview);
commit = true;
} else {
} else if (op == Selection::Extend) {
list<Selectable*> 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 */
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();
+ /* 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;
}
- 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;
+ } else {
- 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();
+ /* 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.
+ */
+
+
+ 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();
+ }
}
- break;
+ }
+
+ /* 2. find all the tracks we should select in */
- case OverlapStart:
- case OverlapEnd:
- /* nothing to do except add clicked region to selection, since it
- overlaps with the existing selection in this track.
+ set<RouteTimeAxisView*> relevant_tracks;
+ set<RouteTimeAxisView*> already_in_selection;
+
+ get_relevant_tracks (relevant_tracks);
+
+ if (relevant_tracks.empty()) {
+
+ /* no relevant tracks -> 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.
*/
- break;
+
+ if (!selection->selected (entered_regionview)) {
+
+ RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (&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<RouteTimeAxisView*>(&(*x)->get_time_axis_view());
+
+ if (artv && artv != rtv) {
+
+ pair<set<RouteTimeAxisView*>::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<RouteTimeAxisView*>(*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);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
}
- /* 2. find all selectable objects (regionviews in this case) between that one and the end of the
- one that was clicked.
+ /* 3. find all selectable objects (regionviews in this case) between that one and the end of the
+ one that was clicked.
*/
- set<RouteTimeAxisView*> relevant_tracks;
-
get_relevant_tracks (relevant_tracks);
for (set<RouteTimeAxisView*>::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<RegionView*> regions;
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);
- }
- }
-
- }
+ get_regions_corresponding_to (region, all_equivalent_regions);
+
+ if (all_equivalent_regions.empty()) {
+ return;
}
-
+
begin_reversible_command (_("set selected regions"));
switch (op) {
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;
+ }
+
+ if ((rv = sv->find_view (r)) == 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::track_selection_changed ()
{
(*i)->set_selected (false);
}
}
+
+ 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 ();
}
}
+void
+Editor::sensitize_the_right_region_actions (bool have_selected_regions)
+{
+ for (vector<Glib::RefPtr<Action> >::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 ()
{
for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
(*i)->set_selected_regionviews (selection->regions);
}
+
+ sensitize_the_right_region_actions (!selection->regions.empty());
+
+ zoomed_to_region = false;
}
void
}
}
-/** Select everything in the selected tracks
- * @param Selection operation to apply.
- */
void
-Editor::select_all_in_selected_tracks (Selection::Operation op)
+Editor::select_all_in_track (Selection::Operation op)
{
list<Selectable *> touched;
- for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
- (*i)->get_selectables (0, max_frames, 0, DBL_MAX, touched);
+ if (!clicked_routeview) {
+ return;
}
+
+ clicked_routeview->get_selectables (0, max_frames, 0, DBL_MAX, touched);
switch (op) {
case Selection::Toggle:
Editor::select_all (Selection::Operation op)
{
list<Selectable *> touched;
-
+
for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
if ((*iter)->hidden()) {
continue;
}
commit_reversible_command ();
}
-
-/** Invert the selection in the selected tracks */
void
-Editor::invert_selection_in_selected_tracks ()
+Editor::invert_selection_in_track ()
{
list<Selectable *> touched;
- for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
- (*i)->get_inverted_selectables (*selection, touched);
+ if (!clicked_routeview) {
+ return;
}
+ clicked_routeview->get_inverted_selectables (*selection, touched);
selection->set (touched);
}
}
bool
-Editor::select_all_within (nframes_t start, nframes_t end, double top, double bot, const TrackViewList& tracklist, Selection::Operation op)
+Editor::select_all_within (nframes64_t start, nframes64_t end, double top, double bot, const TrackViewList& tracklist, Selection::Operation op)
{
list<Selectable*> touched;
list<Selectable*>::size_type n = 0;
}
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> 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 (0, selection->regions.start(), selection->regions.end_frame());
+ if (!Profile->get_sae()) {
+ set_mouse_mode (Editing::MouseRange, false);
+ }
}
void
selection->set (0, loc.start(), loc.end());
commit_reversible_command ();
- set_mouse_mode (Editing::MouseRange, false);
+ if (!Profile->get_sae()) {
+ set_mouse_mode (Editing::MouseRange, false);
+ }
}
void
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) {
+ TrackSelection* 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;
}
return;
}
- for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
+
+ TrackSelection* 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;
}
return;
}
- for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
+
+ TrackSelection* 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;
}
void
Editor::select_all_selectables_using_cursor (Cursor *cursor, bool after)
{
- nframes_t start;
- nframes_t end;
+ nframes64_t start;
+ nframes64_t end;
list<Selectable *> touched;
if (after) {
}
}
- for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
+
+ TrackSelection* 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;
}
}
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<Selectable *> 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;
-
+
+ TrackSelection* 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;
}
commit_reversible_command ();
}
+void
+Editor::select_all_selectables_between (bool within)
+{
+ nframes64_t start;
+ nframes64_t end;
+ list<Selectable *> touched;
+
+ if (!get_edit_op_range (start, end)) {
+ return;
+ }
+
+ TrackSelection* 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 ((TimeAxisView*) 0, 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 ();
+}
+
+