- UndoAction ua = get_memento();
- session->commit_reversible_command (&ua);
- }
-}
-
-bool
-Editor::set_selected_track_from_click (bool press, Selection::Operation op, bool with_undo, bool no_remove)
-{
- bool commit = false;
-
- if (!clicked_trackview) {
- return false;
- }
-
- switch (op) {
- case Selection::Toggle:
- if (selection->selected (clicked_trackview)) {
- if (!no_remove) {
- selection->remove (clicked_trackview);
- commit = true;
- }
- } else {
- selection->add (clicked_trackview);
- commit = false;
- }
- break;
-
- case Selection::Set:
- if (selection->selected (clicked_trackview) && selection->tracks.size() == 1) {
- /* no commit necessary */
- }
-
- selection->set (clicked_trackview);
- break;
-
- case Selection::Extend:
- /* not defined yet */
- break;
- }
-
- return commit;
-}
-
-bool
-Editor::set_selected_control_point_from_click (bool press, Selection::Operation op, bool with_undo, bool no_remove)
-{
- if (!clicked_control_point) {
- return false;
- }
-
- /* select this point and any others that it represents */
-
- double y1, y2;
- jack_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 (AudioTimeAxisView& base, 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 {
-
- /* no active group, or no group */
-
- relevant_tracks.insert (&base);
- }
-
- }
-}
-
-void
-Editor::mapover_audio_tracks (slot<void,AudioTimeAxisView&,uint32_t> sl)
-{
- set<AudioTimeAxisView*> relevant_tracks;
-
- if (!clicked_audio_trackview) {
- return;
- }
-
- get_relevant_audio_tracks (*clicked_audio_trackview, 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 (AudioTimeAxisView& atv, uint32_t ignored,
- AudioRegionView* basis, vector<AudioRegionView*>* all_equivs)
-{
- AudioPlaylist* pl;
- vector<AudioRegion*> results;
- AudioRegionView* marv;
- AudioDiskstream* ds;
-
- if ((ds = atv.get_diskstream()) == 0) {
- /* bus */
- return;
- }
-
- if (&atv == &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<AudioRegion*>::iterator ir = results.begin(); ir != results.end(); ++ir) {
- if ((marv = atv.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<AudioRegionView*> all_equivalent_regions;
- bool commit = false;
-
- if (!clicked_regionview || !clicked_audio_trackview) {
- return 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<AudioRegionView*>::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;
- jack_nframes_t last_frame;
- jack_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 (AudioRegionSelection::iterator x = selection->audio_regions.begin(); x != selection->audio_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:
- cerr << "no overlap, first = " << first_frame << " last = " << last_frame << " region = "
- << clicked_regionview->region.first_frame() << " .. " << clicked_regionview->region.last_frame() << endl;
-
- 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:
- cerr << "external overlap, first = " << first_frame << " last = " << last_frame << " region = "
- << clicked_regionview->region.first_frame() << " .. " << clicked_regionview->region.last_frame() << endl;
-
- 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:
- cerr << "internal overlap, first = " << first_frame << " last = " << last_frame << " region = "
- << clicked_regionview->region.first_frame() << " .. " << clicked_regionview->region.last_frame() << endl;
-
- 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 (*clicked_audio_trackview, 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<AudioRegionView*> audio_regions;
-
- for (list<Selectable*>::iterator x = results.begin(); x != results.end(); ++x) {
- AudioRegionView* arv;
-
- if ((arv = dynamic_cast<AudioRegionView*>(*x)) != 0) {
- audio_regions.push_back (arv);
- }
- }
-
- if (!audio_regions.empty()) {
- selection->add (audio_regions);
- commit = true;
- }
- }
-
- out:
- return commit;
-}
-
-void
-Editor::set_selected_regionview_from_region_list (Region& r, Selection::Operation op)
-{
- vector<AudioRegionView*> all_equivalent_regions;
- AudioRegion* region;
-
- if ((region = dynamic_cast<AudioRegion*>(&r)) == 0) {
- return;
- }
-
- for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
-
- AudioTimeAxisView* tatv;
-
- if ((tatv = dynamic_cast<AudioTimeAxisView*> (*i)) != 0) {
-
- AudioPlaylist* pl;
- vector<AudioRegion*> results;
- AudioRegionView* marv;
- AudioDiskstream* ds;
-
- if ((ds = tatv->get_diskstream()) == 0) {
- /* bus */
- continue;
- }
-
- if ((pl = ds->playlist()) != 0) {
- pl->get_region_list_equivalent_regions (*region, results);
- }
-
- for (vector<AudioRegion*>::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;
- }
-
- commit_reversible_command () ;
-}
-
-bool
-Editor::set_selected_regionview_from_map_event (GdkEventAny* ev, StreamView* sv, Region* r)
-{
- AudioRegionView* rv;
- AudioRegion* ar;
-
- if ((ar = dynamic_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->audio_regions.size() > 1) {
- return TRUE;