From 2d5884ccb17a6df7ea56ea76be18f26b0b8a4ee4 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Tue, 21 May 2024 08:21:02 -0600 Subject: [PATCH] refactor methods to add a location/section marker so that there is only one method for this --- gtk2_ardour/editor.h | 3 +- gtk2_ardour/editor_canvas_events.cc | 2 +- gtk2_ardour/editor_markers.cc | 46 ----------------------------- gtk2_ardour/editor_mouse.cc | 4 +-- gtk2_ardour/editor_ops.cc | 25 ++++++++++++---- gtk2_ardour/editor_rulers.cc | 10 +++---- gtk2_ardour/luainstance.cc | 2 +- gtk2_ardour/public_editor.h | 6 ++-- 8 files changed, 34 insertions(+), 64 deletions(-) diff --git a/gtk2_ardour/editor.h b/gtk2_ardour/editor.h index 92f55f2716..8d78f15c15 100644 --- a/gtk2_ardour/editor.h +++ b/gtk2_ardour/editor.h @@ -601,7 +601,6 @@ public: void metric_get_minsec (std::vector&, int64_t, int64_t, gint); /* editing operations that need to be public */ - void mouse_add_new_marker (Temporal::timepos_t where, ARDOUR::Location::Flags extra_flags = ARDOUR::Location::Flags (0), int32_t cue_id = 0); void split_regions_at (Temporal::timepos_t const & , RegionSelection&); void split_region_at_points (std::shared_ptr, ARDOUR::AnalysisFeatureList&, bool can_ferret, bool select_new = false); RegionSelection get_regions_from_selection_and_mouse (Temporal::timepos_t const &); @@ -1620,7 +1619,7 @@ private: void set_selection_from_loop (); void set_selection_from_region (); - void add_location_mark (Temporal::timepos_t const & where); + void add_location_mark_with_flag (Temporal::timepos_t const & where, ARDOUR::Location::Flags flag, int32_t cue_id); void add_location_from_region (); void add_locations_from_region (); void add_location_from_selection (); diff --git a/gtk2_ardour/editor_canvas_events.cc b/gtk2_ardour/editor_canvas_events.cc index 15e18e6dff..4bbe149a64 100644 --- a/gtk2_ardour/editor_canvas_events.cc +++ b/gtk2_ardour/editor_canvas_events.cc @@ -1180,7 +1180,7 @@ Editor::section_rect_event (GdkEvent* ev, Location* loc, ArdourCanvas::Rectangle MenuList& items (section_box_menu.items()); items.clear (); - items.push_back (MenuElem (_("New Arrangement Marker"), sigc::bind (sigc::mem_fun(*this, &Editor::mouse_add_new_marker), where, Location::Flags(Location::IsMark | Location::IsSection), 0))); + items.push_back (MenuElem (_("New Arrangement Marker"), sigc::bind (sigc::mem_fun(*this, &Editor::add_location_mark_with_flag), where, Location::Flags(Location::IsMark | Location::IsSection), 0))); items.push_back (MenuElem (_("Select Arrangement Section"), sigc::bind (sigc::mem_fun(*_sections, &EditorSections::select), l))); #if 0 items.push_back (SeparatorElem()); diff --git a/gtk2_ardour/editor_markers.cc b/gtk2_ardour/editor_markers.cc index 1fdf1797bd..d2bd043a22 100644 --- a/gtk2_ardour/editor_markers.cc +++ b/gtk2_ardour/editor_markers.cc @@ -828,52 +828,6 @@ Editor::LocationMarkers::setup_lines () } } -void -Editor::mouse_add_new_marker (timepos_t where, Location::Flags extra_flags, int32_t cue_id) -{ - if (!_session) { - return; - } - - string markername; - string namebase; - Location::Flags flags = Location::Flags (extra_flags|Location::IsMark); - - if (flags & Location::IsCueMarker) { - /* XXX i18n needed for cue letter names */ - markername = string_compose (_("cue %1"), cue_marker_name (cue_id)); - } else { - if (flags & Location::IsSection) { - namebase = _("section"); - } else { - namebase = _("mark"); - } - _session->locations()->next_available_name (markername, namebase); - - if (!choose_new_marker_name (markername)) { - return; - } - } - - Location *location = new Location (*_session, where, where, markername, flags, cue_id); - begin_reversible_command (_("add marker")); - - XMLNode &before = _session->locations()->get_state(); - _session->locations()->add (location, true); - XMLNode &after = _session->locations()->get_state(); - _session->add_command (new MementoCommand(*(_session->locations()), &before, &after)); - - /* find the marker we just added */ - - LocationMarkers *lam = find_location_markers (location); - if (lam) { - /* make it the selected marker */ - selection->set (lam->start); - } - - commit_reversible_command (); -} - void Editor::mouse_add_new_loop (timepos_t where) { diff --git a/gtk2_ardour/editor_mouse.cc b/gtk2_ardour/editor_mouse.cc index d397185b00..8ad37b864c 100644 --- a/gtk2_ardour/editor_mouse.cc +++ b/gtk2_ardour/editor_mouse.cc @@ -1793,14 +1793,14 @@ Editor::button_release_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemT case MarkerBarItem: if (!_dragging_playhead) { snap_to_with_modifier (where, event, Temporal::RoundNearest, SnapToGrid_Scaled); - mouse_add_new_marker (where); + add_location_mark (where); } return true; case SectionMarkerBarItem: if (!_dragging_playhead && Keyboard::modifier_state_equals (event->button.state, Keyboard::PrimaryModifier)) { snap_to_with_modifier (where, event, Temporal::RoundNearest, SnapToGrid_Scaled); - mouse_add_new_marker (where, Location::IsSection); + add_location_mark (where, Location::IsSection); } return true; diff --git a/gtk2_ardour/editor_ops.cc b/gtk2_ardour/editor_ops.cc index b34abaa469..cd68bb926f 100644 --- a/gtk2_ardour/editor_ops.cc +++ b/gtk2_ardour/editor_ops.cc @@ -2348,21 +2348,36 @@ Editor::add_location_from_selection () } void -Editor::add_location_mark (timepos_t const & where) +Editor::add_location_mark_with_flag (timepos_t const & where, Location::Flags flags, int32_t cue_id) { + if (!_session) { + return; + } + if (_session->locations()->mark_at (where, timecnt_t (1))) { return; } string markername; + string namebase; select_new_marker = true; - _session->locations()->next_available_name(markername,"mark"); - if (!choose_new_marker_name(markername)) { + if (flags & Location::IsCueMarker) { + /* XXX i18n needed for cue letter names */ + markername = string_compose (_("cue %1"), cue_marker_name (cue_id)); + } else if (flags & Location::IsSection) { + namebase = _("section"); + } else { + namebase = _("mark"); + } + + _session->locations()->next_available_name(markername, namebase); + + if (!choose_new_marker_name (markername)) { return; } - Location *location = new Location (*_session, where, where, markername, Location::IsMark); + Location *location = new Location (*_session, where, where, markername, flags); begin_reversible_command (_("add marker")); XMLNode &before = _session->locations()->get_state(); @@ -7249,7 +7264,7 @@ Editor::set_edit_point () if (selection->markers.empty()) { - mouse_add_new_marker (where); + add_location_mark (where); } else { bool ignored; diff --git a/gtk2_ardour/editor_rulers.cc b/gtk2_ardour/editor_rulers.cc index 9cd52a10bc..a1dafb0892 100644 --- a/gtk2_ardour/editor_rulers.cc +++ b/gtk2_ardour/editor_rulers.cc @@ -286,16 +286,16 @@ Editor::popup_ruler_menu (timepos_t const & where, ItemType t) Gtk::MenuItem& add_menu = ruler_items.back(); Gtk::Menu* a_menu = new Gtk::Menu; MenuList& add_items = a_menu->items(); - add_items.push_back (MenuElem (_("Location Marker"), sigc::bind (sigc::mem_fun(*this, &Editor::mouse_add_new_marker), where, Location::Flags (0), 0))); - add_items.push_back (MenuElem (_("Arrangement Marker"), sigc::bind (sigc::mem_fun(*this, &Editor::mouse_add_new_marker), where, Location::Flags(Location::IsMark | Location::IsSection), 0))); - add_items.push_back (MenuElem (_("CD Track Marker"), sigc::bind (sigc::mem_fun(*this, &Editor::mouse_add_new_marker), where, Location::Flags(Location::IsMark |Location::IsCDMarker), 0))); + add_items.push_back (MenuElem (_("Location Marker"), sigc::bind (sigc::mem_fun(*this, &Editor::add_location_mark_with_flag), where, Location::Flags (0), 0))); + add_items.push_back (MenuElem (_("Arrangement Marker"), sigc::bind (sigc::mem_fun(*this, &Editor::add_location_mark_with_flag), where, Location::Flags(Location::IsMark | Location::IsSection), 0))); + add_items.push_back (MenuElem (_("CD Track Marker"), sigc::bind (sigc::mem_fun(*this, &Editor::add_location_mark_with_flag), where, Location::Flags(Location::IsMark |Location::IsCDMarker), 0))); add_items.push_back (MenuElem ("Cue Marker...")); Gtk::MenuItem& cue_submenu = add_items.back(); Gtk::Menu* cue_menu = new Gtk::Menu; MenuList& cue_items = cue_menu->items(); - cue_items.push_back (MenuElem (_("Stop All Cues"), sigc::bind (sigc::mem_fun (*this, &Editor::mouse_add_new_marker), where, Location::IsCueMarker, CueRecord::stop_all))); + cue_items.push_back (MenuElem (_("Stop All Cues"), sigc::bind (sigc::mem_fun (*this, &Editor::add_location_mark_with_flag), where, Location::IsCueMarker, CueRecord::stop_all))); for (int32_t n = 0; n < TriggerBox::default_triggers_per_box; ++n) { - cue_items.push_back (MenuElem (string_compose (_("Cue %1"), cue_marker_name (n)), sigc::bind (sigc::mem_fun(*this, &Editor::mouse_add_new_marker), where, Location::IsCueMarker, n))); + cue_items.push_back (MenuElem (string_compose (_("Cue %1"), cue_marker_name (n)), sigc::bind (sigc::mem_fun(*this, &Editor::add_location_mark_with_flag), where, Location::IsCueMarker, n))); } cue_submenu.set_submenu (*cue_menu); diff --git a/gtk2_ardour/luainstance.cc b/gtk2_ardour/luainstance.cc index 2d6c72ff21..21933c43c4 100644 --- a/gtk2_ardour/luainstance.cc +++ b/gtk2_ardour/luainstance.cc @@ -1036,7 +1036,7 @@ LuaInstance::register_classes (lua_State* L, bool sandbox) .addRefFunction ("find_location_from_marker", &PublicEditor::find_location_from_marker) .addFunction ("find_marker_from_location_id", &PublicEditor::find_marker_from_location_id) - .addFunction ("mouse_add_new_marker", &PublicEditor::mouse_add_new_marker) + .addFunction ("mouse_add_new_marker", &PublicEditor::add_location_mark) #if 0 .addFunction ("get_regions_at", &PublicEditor::get_regions_at) .addFunction ("get_regions_after", &PublicEditor::get_regions_after) diff --git a/gtk2_ardour/public_editor.h b/gtk2_ardour/public_editor.h index c7647aceb0..c4c2c3d1f5 100644 --- a/gtk2_ardour/public_editor.h +++ b/gtk2_ardour/public_editor.h @@ -257,7 +257,10 @@ public: virtual void add_bbt_marker_at_playhead_cursor () = 0; virtual void add_location_from_playhead_cursor () = 0; virtual void remove_location_at_playhead_cursor () = 0; - virtual void add_location_mark (Temporal::timepos_t const & where) = 0; + void add_location_mark (Temporal::timepos_t const & where, ARDOUR::Location::Flags flags = ARDOUR::Location::IsMark, int32_t cue_id = 0) { + add_location_mark_with_flag (where, flags, cue_id); + } + virtual void add_location_mark_with_flag (Temporal::timepos_t const & where, ARDOUR::Location::Flags, int32_t cue_id) = 0; virtual void update_grid () = 0; virtual void remove_tracks () = 0; virtual void set_loop_range (Temporal::timepos_t const & start, Temporal::timepos_t const & end, std::string cmd) = 0; @@ -391,7 +394,6 @@ public: virtual void toggle_meter_updating() = 0; virtual void split_regions_at (Temporal::timepos_t const &, RegionSelection&) = 0; virtual void split_region_at_points (std::shared_ptr, ARDOUR::AnalysisFeatureList&, bool can_ferret, bool select_new = false) = 0; - virtual void mouse_add_new_marker (Temporal::timepos_t where, ARDOUR::Location::Flags extra_flags = ARDOUR::Location::Flags (0), int32_t cue_id = 0) = 0; virtual void foreach_time_axis_view (sigc::slot) = 0; virtual void add_to_idle_resize (TimeAxisView*, int32_t) = 0; virtual Temporal::timecnt_t get_nudge_distance (Temporal::timepos_t const & pos, Temporal::timecnt_t& next) = 0;