catch markers as they go away, to avoid selection corruption; add select-range-betwee...
[ardour.git] / gtk2_ardour / editor.cc
index 844fea9905000b52c17e6cd4ed5e3e4f6e0c8288..bde42378e9ddfb56bb8f32aaf589f11f00a0e02d 100644 (file)
@@ -121,7 +121,7 @@ static const gchar *_snap_type_strings[] = {
        N_("Beats"),
        N_("Bars"),
        N_("Marks"),
-       N_("Edit Cursor"),
+       N_("Edit Point"),
        N_("Region starts"),
        N_("Region ends"),
        N_("Region syncs"),
@@ -148,7 +148,7 @@ static const gchar *_zoom_focus_strings[] = {
        N_("Center"),
        N_("Playhead"),
        N_("Mouse"),
-       N_("Edit Cursor"),
+       N_("Marker"),
        0
 };
 
@@ -227,6 +227,7 @@ Editor::Editor ()
        selection->TracksChanged.connect (mem_fun(*this, &Editor::track_selection_changed));
        selection->RegionsChanged.connect (mem_fun(*this, &Editor::region_selection_changed));
        selection->PointsChanged.connect (mem_fun(*this, &Editor::point_selection_changed));
+       selection->MarkersChanged.connect (mem_fun(*this, &Editor::marker_selection_changed));
 
        clicked_regionview = 0;
        clicked_trackview = 0;
@@ -238,7 +239,7 @@ Editor::Editor ()
        drag_info.item = 0;
        current_mixer_strip = 0;
        current_bbt_points = 0;
-
+       
        snap_type_strings =  I18N (_snap_type_strings);
        snap_mode_strings =  I18N (_snap_mode_strings);
        zoom_focus_strings = I18N (_zoom_focus_strings);
@@ -251,7 +252,7 @@ Editor::Editor ()
        set_snap_mode (snap_mode);
 
        _edit_point = EditAtMouse;
-       set_edit_point (_edit_point);
+       set_edit_point_preference (_edit_point);
 
        snap_threshold = 5.0;
        bbt_beat_subdivision = 4;
@@ -305,12 +306,12 @@ Editor::Editor ()
        current_stepping_trackview = 0;
        entered_track = 0;
        entered_regionview = 0;
+       entered_marker = 0;
        clear_entered_track = false;
        _new_regionviews_show_envelope = false;
        current_timestretch = 0;
        in_edit_group_row_change = false;
        last_canvas_frame = 0;
-       edit_cursor = 0;
        playhead_cursor = 0;
        button_release_can_deselect = true;
        canvas_idle_queued = false;
@@ -846,7 +847,6 @@ Editor::tie_vertical_scrolling ()
        double y1 = vertical_adjustment.get_value();
 
        playhead_cursor->set_y_axis (y1);
-       edit_cursor->set_y_axis (y1);
        if (logo_item) {
                logo_item->property_y() = y1;
        }
@@ -884,12 +884,8 @@ Editor::instant_save ()
 void
 Editor::edit_cursor_clock_changed()
 {
-       if (edit_cursor->current_frame != edit_cursor_clock.current_time()) {
-               edit_cursor->set_position (edit_cursor_clock.current_time());
-       }
 }
 
-
 void
 Editor::zoom_adjustment_changed ()
 {
@@ -1404,9 +1400,9 @@ Editor::popup_track_context_menu (int button, int32_t time, ItemType item_type,
                if (!with_selection) {
                        if (region_edit_menu_split_item) {
                                if (clicked_regionview && clicked_regionview->region()->covers (get_preferred_edit_position())) {
-                                       ActionManager::set_sensitive (ActionManager::edit_cursor_in_region_sensitive_actions, true);
+                                       ActionManager::set_sensitive (ActionManager::edit_point_in_region_sensitive_actions, true);
                                } else {
-                                       ActionManager::set_sensitive (ActionManager::edit_cursor_in_region_sensitive_actions, false);
+                                       ActionManager::set_sensitive (ActionManager::edit_point_in_region_sensitive_actions, false);
                                }
                        }
                        /*
@@ -1690,7 +1686,7 @@ Editor::add_region_context_items (AudioStreamView* sv, boost::shared_ptr<Region>
        items.push_back (MenuElem (_("Raise to top layer"), mem_fun(*this, &Editor::raise_region_to_top)));
        items.push_back (MenuElem (_("Lower to bottom layer"), mem_fun  (*this, &Editor::lower_region_to_bottom)));
        items.push_back (SeparatorElem());
-       items.push_back (MenuElem (_("Define sync point"), mem_fun(*this, &Editor::set_region_sync_from_edit_cursor)));
+       items.push_back (MenuElem (_("Define sync point"), mem_fun(*this, &Editor::set_region_sync_from_edit_point)));
        items.push_back (MenuElem (_("Remove sync point"), mem_fun(*this, &Editor::remove_region_sync)));
        items.push_back (SeparatorElem());
 
@@ -1805,8 +1801,8 @@ Editor::add_region_context_items (AudioStreamView* sv, boost::shared_ptr<Region>
        MenuList& trim_items = trim_menu->items();
        trim_menu->set_name ("ArdourContextMenu");
        
-       trim_items.push_back (MenuElem (_("Start to edit cursor"), mem_fun(*this, &Editor::trim_region_from_edit_cursor)));
-       trim_items.push_back (MenuElem (_("Edit cursor to end"), mem_fun(*this, &Editor::trim_region_to_edit_cursor)));
+       trim_items.push_back (MenuElem (_("Start to edit point"), mem_fun(*this, &Editor::trim_region_from_edit_point)));
+       trim_items.push_back (MenuElem (_("Edit point to end"), mem_fun(*this, &Editor::trim_region_to_edit_point)));
                             
        items.push_back (MenuElem (_("Trim"), *trim_menu));
        items.push_back (SeparatorElem());
@@ -1893,7 +1889,7 @@ Editor::add_dstream_context_items (Menu_Helpers::MenuList& edit_items)
        MenuList& play_items = play_menu->items();
        play_menu->set_name ("ArdourContextMenu");
        
-       play_items.push_back (MenuElem (_("Play from edit cursor"), mem_fun(*this, &Editor::play_from_edit_cursor)));
+       play_items.push_back (MenuElem (_("Play from edit point"), mem_fun(*this, &Editor::play_from_edit_point)));
        play_items.push_back (MenuElem (_("Play from start"), mem_fun(*this, &Editor::play_from_start)));
        play_items.push_back (MenuElem (_("Play region"), mem_fun(*this, &Editor::play_selected_region)));
        play_items.push_back (SeparatorElem());
@@ -1915,11 +1911,15 @@ Editor::add_dstream_context_items (Menu_Helpers::MenuList& edit_items)
        select_items.push_back (MenuElem (_("Set range to loop range"), mem_fun(*this, &Editor::set_selection_from_loop)));
        select_items.push_back (MenuElem (_("Set range to punch range"), mem_fun(*this, &Editor::set_selection_from_punch)));
        select_items.push_back (SeparatorElem());
-       select_items.push_back (MenuElem (_("Select all after edit cursor"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), edit_cursor, true)));
-       select_items.push_back (MenuElem (_("Select all before edit cursor"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), edit_cursor, false)));
-       select_items.push_back (MenuElem (_("Select all after playhead"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, true)));
-       select_items.push_back (MenuElem (_("Select all before playhead"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, false)));
-       select_items.push_back (MenuElem (_("Select all between cursors"), bind (mem_fun(*this, &Editor::select_all_selectables_between_cursors), playhead_cursor, edit_cursor)));
+       select_items.push_back (MenuElem (_("Select All After Edit Point"), bind (mem_fun(*this, &Editor::select_all_selectables_using_edit), true)));
+       select_items.push_back (MenuElem (_("Select All Before Edit Point"), bind (mem_fun(*this, &Editor::select_all_selectables_using_edit), false)));
+       select_items.push_back (MenuElem (_("Select All After Playhead"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, true)));
+       select_items.push_back (MenuElem (_("Select All Before Playhead"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, false)));
+       select_items.push_back (MenuElem (_("Select All Between Playhead & Edit Point"), bind (mem_fun(*this, &Editor::select_all_selectables_between), false)));
+       select_items.push_back (MenuElem (_("Select All Within Playhead & Edit Point"), bind (mem_fun(*this, &Editor::select_all_selectables_between), true)));
+       select_items.push_back (MenuElem (_("Select Range Between Playhead & Edit Point"), mem_fun(*this, &Editor::select_range_between)));
+
+
        select_items.push_back (SeparatorElem());
 
        edit_items.push_back (MenuElem (_("Select"), *select_menu));
@@ -1932,8 +1932,7 @@ Editor::add_dstream_context_items (Menu_Helpers::MenuList& edit_items)
        
        cutnpaste_items.push_back (MenuElem (_("Cut"), mem_fun(*this, &Editor::cut)));
        cutnpaste_items.push_back (MenuElem (_("Copy"), mem_fun(*this, &Editor::copy)));
-       cutnpaste_items.push_back (MenuElem (_("Paste at edit cursor"), bind (mem_fun(*this, &Editor::paste), 1.0f)));
-       cutnpaste_items.push_back (MenuElem (_("Paste at mouse"), mem_fun(*this, &Editor::mouse_paste)));
+       cutnpaste_items.push_back (MenuElem (_("Paste"), bind (mem_fun(*this, &Editor::paste), 1.0f)));
 
        cutnpaste_items.push_back (SeparatorElem());
 
@@ -1960,9 +1959,9 @@ Editor::add_dstream_context_items (Menu_Helpers::MenuList& edit_items)
        
        edit_items.push_back (SeparatorElem());
        nudge_items.push_back (MenuElem (_("Nudge entire track fwd"), (bind (mem_fun(*this, &Editor::nudge_track), false, true))));
-       nudge_items.push_back (MenuElem (_("Nudge track after edit cursor fwd"), (bind (mem_fun(*this, &Editor::nudge_track), true, true))));
+       nudge_items.push_back (MenuElem (_("Nudge track after edit point fwd"), (bind (mem_fun(*this, &Editor::nudge_track), true, true))));
        nudge_items.push_back (MenuElem (_("Nudge entire track bwd"), (bind (mem_fun(*this, &Editor::nudge_track), false, false))));
-       nudge_items.push_back (MenuElem (_("Nudge track after edit cursor bwd"), (bind (mem_fun(*this, &Editor::nudge_track), true, false))));
+       nudge_items.push_back (MenuElem (_("Nudge track after edit point bwd"), (bind (mem_fun(*this, &Editor::nudge_track), true, false))));
 
        edit_items.push_back (MenuElem (_("Nudge"), *nudge_menu));
 }
@@ -1978,7 +1977,7 @@ Editor::add_bus_context_items (Menu_Helpers::MenuList& edit_items)
        MenuList& play_items = play_menu->items();
        play_menu->set_name ("ArdourContextMenu");
        
-       play_items.push_back (MenuElem (_("Play from edit cursor"), mem_fun(*this, &Editor::play_from_edit_cursor)));
+       play_items.push_back (MenuElem (_("Play from edit point"), mem_fun(*this, &Editor::play_from_edit_point)));
        play_items.push_back (MenuElem (_("Play from start"), mem_fun(*this, &Editor::play_from_start)));
        edit_items.push_back (MenuElem (_("Play"), *play_menu));
 
@@ -1993,8 +1992,8 @@ Editor::add_bus_context_items (Menu_Helpers::MenuList& edit_items)
        select_items.push_back (MenuElem (_("Invert selection in track"), mem_fun(*this, &Editor::invert_selection_in_track)));
        select_items.push_back (MenuElem (_("Invert selection"), mem_fun(*this, &Editor::invert_selection)));
        select_items.push_back (SeparatorElem());
-       select_items.push_back (MenuElem (_("Select all after edit cursor"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), edit_cursor, true)));
-       select_items.push_back (MenuElem (_("Select all before edit cursor"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), edit_cursor, false)));
+       select_items.push_back (MenuElem (_("Select all after edit point"), bind (mem_fun(*this, &Editor::select_all_selectables_using_edit), true)));
+       select_items.push_back (MenuElem (_("Select all before edit point"), bind (mem_fun(*this, &Editor::select_all_selectables_using_edit), false)));
        select_items.push_back (MenuElem (_("Select all after playhead"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, true)));
        select_items.push_back (MenuElem (_("Select all before playhead"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, false)));
 
@@ -2016,9 +2015,9 @@ Editor::add_bus_context_items (Menu_Helpers::MenuList& edit_items)
        
        edit_items.push_back (SeparatorElem());
        nudge_items.push_back (MenuElem (_("Nudge entire track fwd"), (bind (mem_fun(*this, &Editor::nudge_track), false, true))));
-       nudge_items.push_back (MenuElem (_("Nudge track after edit cursor fwd"), (bind (mem_fun(*this, &Editor::nudge_track), true, true))));
+       nudge_items.push_back (MenuElem (_("Nudge track after edit point fwd"), (bind (mem_fun(*this, &Editor::nudge_track), true, true))));
        nudge_items.push_back (MenuElem (_("Nudge entire track bwd"), (bind (mem_fun(*this, &Editor::nudge_track), false, false))));
-       nudge_items.push_back (MenuElem (_("Nudge track after edit cursor bwd"), (bind (mem_fun(*this, &Editor::nudge_track), true, false))));
+       nudge_items.push_back (MenuElem (_("Nudge track after edit point bwd"), (bind (mem_fun(*this, &Editor::nudge_track), true, false))));
 
        edit_items.push_back (MenuElem (_("Nudge"), *nudge_menu));
 }
@@ -2063,7 +2062,7 @@ Editor::set_snap_mode (SnapMode mode)
        instant_save ();
 }
 void
-Editor::set_edit_point (EditPoint ep)
+Editor::set_edit_point_preference (EditPoint ep)
 {
        _edit_point = ep;
        string str = edit_point_strings[(int)ep];
@@ -2124,13 +2123,6 @@ Editor::set_state (const XMLNode& node)
                horizontal_adjustment.set_value (0);
        }
 
-       if (session && (prop = node.property ("edit-cursor"))) {
-               nframes_t pos = atol (prop->value().c_str());
-               edit_cursor->set_position (pos);
-       } else {
-               edit_cursor->set_position (0);
-       }
-
        if ((prop = node.property ("mixer-width"))) {
                editor_mixer_strip_width = Width (string_2_enum (prop->value(), editor_mixer_strip_width));
        }
@@ -2152,7 +2144,7 @@ Editor::set_state (const XMLNode& node)
        }
 
        if ((prop = node.property ("edit-point"))) {
-               set_edit_point ((EditPoint) string_2_enum (prop->value(), _edit_point));
+               set_edit_point_preference ((EditPoint) string_2_enum (prop->value(), _edit_point));
        }
 
        if ((prop = node.property ("mouse-mode"))) {
@@ -2294,8 +2286,6 @@ Editor::get_state ()
 
        snprintf (buf, sizeof (buf), "%" PRIu32, playhead_cursor->current_frame);
        node->add_property ("playhead", buf);
-       snprintf (buf, sizeof (buf), "%" PRIu32, edit_cursor->current_frame);
-       node->add_property ("edit-cursor", buf);
 
        node->add_property ("show-waveforms", _show_waveforms ? "yes" : "no");
        node->add_property ("show-waveforms-recording", _show_waveforms_recording ? "yes" : "no");
@@ -2452,7 +2442,7 @@ Editor::snap_to (nframes64_t& start, int32_t direction, bool for_mark)
                 start = session->tempo_map().round_to_beat_subdivision (start, 3);
                 break;
 
-       case SnapToEditCursor:
+       case SnapToEditPoint:
                start = get_preferred_edit_position ();
                break;
 
@@ -2667,7 +2657,7 @@ Editor::setup_toolbar ()
        ARDOUR_UI::instance()->tooltips().set_tip (zoom_out_full_button, _("Zoom to Session"));
 
        zoom_focus_selector.set_name ("ZoomFocusSelector");
-       Gtkmm2ext::set_size_request_to_display_given_text (zoom_focus_selector, "Edit Cursor", FUDGE, 0);
+       Gtkmm2ext::set_size_request_to_display_given_text (zoom_focus_selector, "Playhead", FUDGE, 0);
        set_popdown_strings (zoom_focus_selector, zoom_focus_strings);
        zoom_focus_selector.signal_changed().connect (mem_fun(*this, &Editor::zoom_focus_selection_done));
        ARDOUR_UI::instance()->tooltips().set_tip (zoom_focus_selector, _("Zoom focus"));
@@ -2677,8 +2667,6 @@ Editor::setup_toolbar ()
        zoom_box.pack_start (zoom_in_button, false, false);
        zoom_box.pack_start (zoom_out_full_button, false, false);
 
-       /* Edit Cursor / Snap */
-
        snap_box.set_spacing (1);
        snap_box.set_border_width (2);
 
@@ -3105,8 +3093,8 @@ Editor::snap_type_selection_done ()
                snaptype = SnapToBar;
        } else if (choice == _("Marks")) {
                snaptype = SnapToMark;
-       } else if (choice == _("Edit Cursor")) {
-               snaptype = SnapToEditCursor;
+       } else if (choice == _("Edit Point")) {
+               snaptype = SnapToEditPoint;
        } else if (choice == _("Region starts")) {
                snaptype = SnapToRegionStart;
        } else if (choice == _("Region ends")) {
@@ -3193,7 +3181,7 @@ Editor::zoom_focus_selection_done ()
                focus_type = ZoomFocusPlayhead;
        } else if (choice == _("Mouse")) {
                focus_type = ZoomFocusMouse;
-       } else if (choice == _("Edit Cursor")) {
+       } else if (choice == _("Edit Point")) {
                focus_type = ZoomFocusEdit;
        } 
        
@@ -3898,7 +3886,6 @@ Editor::set_frames_per_unit (double fpu)
        reset_hscrollbar_stepping ();
        reset_scrolling_region ();
        
-       if (edit_cursor) edit_cursor->set_position (edit_cursor->current_frame);
        if (playhead_cursor) playhead_cursor->set_position (playhead_cursor->current_frame);
 
        instant_save ();
@@ -3970,22 +3957,14 @@ Editor::sort_track_selection ()
        selection->tracks.sort (cmp);
 }
 
-nframes_t
-Editor::edit_cursor_position(bool sync)
-{
-       if (sync && edit_cursor->current_frame != edit_cursor_clock.current_time()) {
-               edit_cursor_clock.set(edit_cursor->current_frame, true);
-       }
-
-       return edit_cursor->current_frame;
-}
-
 nframes64_t
 Editor::get_preferred_edit_position() const
 {
        bool ignored;
        nframes64_t where;
 
+       // XXX EDIT CURSOR used to sync with edit cursor clock
+
        switch (_edit_point) {
        case EditAtPlayhead:
                return playhead_cursor->current_frame;
@@ -4066,3 +4045,43 @@ Editor::set_punch_range (nframes_t start, nframes_t end, string cmd)
        commit_reversible_command ();
 }
 
+RegionSelection
+Editor::get_regions_at (nframes64_t where, const TrackSelection& ts) const
+{
+       RegionSelection rs;
+       const TrackSelection* tracks;
+
+       if (ts.empty()) {
+               tracks = &track_views;
+       } else {
+               tracks = &ts;
+       }
+
+       for (TrackSelection::const_iterator t = tracks->begin(); t != tracks->end(); ++t) {
+       
+               AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*>(*t);
+
+               if (atv) {
+                       boost::shared_ptr<Diskstream> ds;
+                       boost::shared_ptr<Playlist> pl;
+                       
+                       if ((ds = atv->get_diskstream()) && ((pl = ds->playlist()))) {
+
+                               Playlist::RegionList* regions = pl->regions_at ((nframes_t) floor ( (double)where * ds->speed()));
+
+                               for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
+
+                                       RegionView* rv = atv->audio_view()->find_view (*i);
+
+                                       if (rv) {
+                                               rs.push_back (rv);
+                                       }
+                               }
+
+                               delete regions;
+                       }
+               }
+       }
+
+       return rs;
+}