13
0

refactor methods to add a location/section marker so that there is only one method for this

This commit is contained in:
Paul Davis 2024-05-21 08:21:02 -06:00
parent 8ad53bc96c
commit 2d5884ccb1
8 changed files with 34 additions and 64 deletions

View File

@ -601,7 +601,6 @@ public:
void metric_get_minsec (std::vector<ArdourCanvas::Ruler::Mark>&, 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::Region>, 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 ();

View File

@ -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());

View File

@ -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<Locations>(*(_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)
{

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -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)

View File

@ -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::Region>, 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<void,TimeAxisView&>) = 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;