From 15c808c9f440feba41f528918c628f8c06bc82e8 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Mon, 7 Apr 2025 16:51:59 -0600 Subject: [PATCH] expand the dialog used for renaming location markers to allow scene editing This has no visible effect for anything that is not livetrax (for now). --- gtk2_ardour/editor.cc | 2 +- gtk2_ardour/editor.h | 3 +- gtk2_ardour/editor_canvas_events.cc | 2 +- gtk2_ardour/editor_drag.cc | 2 +- gtk2_ardour/editor_markers.cc | 152 +++++++++++++++++++++++++--- gtk2_ardour/editor_ops.cc | 7 +- 6 files changed, 146 insertions(+), 22 deletions(-) diff --git a/gtk2_ardour/editor.cc b/gtk2_ardour/editor.cc index 2cb9a5605b..d7a115189f 100644 --- a/gtk2_ardour/editor.cc +++ b/gtk2_ardour/editor.cc @@ -1520,7 +1520,7 @@ Editor::add_section_context_items (Gtk::Menu_Helpers::MenuList& items) assert (lm && lm->start); items.push_back (SeparatorElem()); items.push_back (MenuElem (_("Move Playhead to Marker"), sigc::bind (sigc::mem_fun(*_session, &Session::request_locate), start.samples (), false, MustStop, TRS_UI))); - items.push_back (MenuElem (_("Rename..."), sigc::bind (sigc::mem_fun(*this, &Editor::rename_marker), lm->start))); + items.push_back (MenuElem (_("Edit..."), sigc::bind (sigc::mem_fun(*this, &Editor::edit_marker), lm->start, true))); } items.push_back (SeparatorElem()); diff --git a/gtk2_ardour/editor.h b/gtk2_ardour/editor.h index 88be6e4c5a..36144bbf47 100644 --- a/gtk2_ardour/editor.h +++ b/gtk2_ardour/editor.h @@ -1668,7 +1668,8 @@ private: void marker_menu_edit (); void marker_menu_remove (); void marker_menu_rename (); - void rename_marker (ArdourMarker* marker); + void edit_marker (ArdourMarker* marker, bool with_scene); + bool edit_location (ARDOUR::Location& loc, bool with_scene, bool with_command); void toggle_tempo_continues (); void toggle_tempo_type (); void ramp_to_next_tempo (); diff --git a/gtk2_ardour/editor_canvas_events.cc b/gtk2_ardour/editor_canvas_events.cc index 48ac5accb4..b6dffbf555 100644 --- a/gtk2_ardour/editor_canvas_events.cc +++ b/gtk2_ardour/editor_canvas_events.cc @@ -1116,7 +1116,7 @@ Editor::section_rect_event (GdkEvent* ev, Location* loc, ArdourCanvas::Rectangle } if (ev->button.button == 1) { assert (find_location_markers (loc)); - rename_marker (find_location_markers (loc)->start); + edit_marker (find_location_markers (loc)->start, true); return true; } break; diff --git a/gtk2_ardour/editor_drag.cc b/gtk2_ardour/editor_drag.cc index 04ea0c0680..1dbf0c4c88 100644 --- a/gtk2_ardour/editor_drag.cc +++ b/gtk2_ardour/editor_drag.cc @@ -4621,7 +4621,7 @@ MarkerDrag::finished (GdkEvent* event, bool movement_occurred) { if (!movement_occurred) { if (was_double_click ()) { - _editor.rename_marker (_marker); + _editor.edit_marker (_marker, true); return; } diff --git a/gtk2_ardour/editor_markers.cc b/gtk2_ardour/editor_markers.cc index 353d184a25..6f3849638d 100644 --- a/gtk2_ardour/editor_markers.cc +++ b/gtk2_ardour/editor_markers.cc @@ -34,6 +34,7 @@ #include "ardour/session.h" #include "ardour/location.h" +#include "ardour/midi_scene_change.h" #include "ardour/profile.h" #include "pbd/memento_command.h" @@ -1825,11 +1826,11 @@ Editor::marker_menu_rename () } - rename_marker (marker); + edit_marker (marker, false); } void -Editor::rename_marker(ArdourMarker *marker) +Editor::edit_marker(ArdourMarker *marker, bool with_scene) { Location* loc; bool is_start; @@ -1844,26 +1845,114 @@ Editor::rename_marker(ArdourMarker *marker) return; } + edit_location (*loc, with_scene, true); +} + +bool +Editor::edit_location (Location& loc, bool with_scene, bool with_command) +{ ArdourWidgets::Prompter dialog (true); string txt; + string verb; + + if (!Profile->get_livetrax()) { + with_scene = false; + } + + if (with_scene) { + verb = _("Edit"); + } else { + verb = _("Rename"); + } dialog.set_prompt (_("New Name:")); - if (loc->is_section()) { - dialog.set_title (_("Rename Arrangement Section")); - } else if (loc->is_range()) { - dialog.set_title (_("Rename Range")); + if (loc.is_section()) { + dialog.set_title (string_compose (_("%1 Arrangement Section"), verb)); + } else if (loc.is_range()) { + dialog.set_title (string_compose (_("%1 Range"), verb)); } else { - dialog.set_title (_("Rename Mark")); + dialog.set_title (string_compose (_("%1 Mark"), verb)); } dialog.set_name ("MarkRenameWindow"); dialog.set_size_request (250, -1); dialog.set_position (Gtk::WIN_POS_MOUSE); - dialog.add_button (_("Rename"), RESPONSE_ACCEPT); + dialog.add_button (verb, RESPONSE_ACCEPT); dialog.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false); - dialog.set_initial_text (loc->name()); + dialog.set_initial_text (loc.name()); + + Gtk::Adjustment* program_adjust (nullptr); + Gtk::Adjustment* bank_adjust (nullptr); + Gtk::Adjustment* channel_adjust (nullptr); + Gtk::CheckButton* use_scene_button (nullptr); + + if (with_scene) { + program_adjust = new Gtk::Adjustment (1, 1, 128, 1, 10); + bank_adjust = new Gtk::Adjustment (1, 1, 128, 1, 10); + channel_adjust = new Gtk::Adjustment (1, 1, 16, 1, 4); + Gtk::SpinButton* program = manage (new Gtk::SpinButton (*program_adjust)); + Gtk::SpinButton* bank = manage (new Gtk::SpinButton (*bank_adjust)); + Gtk::SpinButton* channel = manage (new Gtk::SpinButton (*channel_adjust)); + Gtk::Label* l1 = manage (new Gtk::Label (_("Program Number"))); + Gtk::Label* l2 = manage (new Gtk::Label (_("Bank Number"))); + Gtk::Label* l3 = manage (new Gtk::Label (_("Channel"))); + + std::shared_ptr msc = std::dynamic_pointer_cast (loc.scene_change()); + if (msc) { + program_adjust->set_value (msc->program() + 1); + bank_adjust->set_value (msc->bank() + 1); + channel_adjust->set_value (msc->channel() + 1); + } + + program_adjust->signal_value_changed().connect (sigc::bind (sigc::mem_fun (dialog, &Gtk::Dialog::set_response_sensitive), Gtk::RESPONSE_ACCEPT, true)); + bank_adjust->signal_value_changed().connect (sigc::bind (sigc::mem_fun (dialog, &Gtk::Dialog::set_response_sensitive), Gtk::RESPONSE_ACCEPT, true)); + channel_adjust->signal_value_changed().connect (sigc::bind (sigc::mem_fun (dialog, &Gtk::Dialog::set_response_sensitive), Gtk::RESPONSE_ACCEPT, true)); + + Gtk::Label* scene_title = manage (new Gtk::Label (string_compose ("%1", _("Scene Change")))); + scene_title->set_use_markup (true); + + Gtk::HBox* b1 = manage (new Gtk::HBox); + b1->set_spacing (12); + b1->pack_start (*l1, true, true); + l1->set_alignment (1.0); + b1->pack_start (*program, true, false); + + Gtk::HBox* b2 = manage (new Gtk::HBox); + b2->set_spacing (12); + b2->pack_start (*l2, true, true); + l2->set_alignment (1.0); + b2->pack_start (*bank, true, false); + + Gtk::HBox* b3 = manage (new Gtk::HBox); + b3->set_spacing (12); + b3->pack_start (*l3, true, true); + l3->set_alignment (1.0); + b3->pack_start (*channel, true, false); + + use_scene_button = manage (new Gtk::CheckButton (_("Clear scene change"))); + if (!msc) { + use_scene_button->set_sensitive (false); + } else { + use_scene_button->signal_toggled().connect (sigc::bind (sigc::mem_fun (dialog, &Gtk::Dialog::set_response_sensitive), Gtk::RESPONSE_ACCEPT, true)); + } + + Gtk::HBox* b4 = manage (new Gtk::HBox); + b4->pack_start (*use_scene_button, true, false); + + Gtk::VBox* scene_box = manage (new Gtk::VBox); + scene_box->set_spacing (12); + scene_box->pack_start (*scene_title, false, false); + scene_box->pack_start (*b1, false, false); + scene_box->pack_start (*b2, false, false); + scene_box->pack_start (*b3, false, false); + scene_box->pack_start (*b4, true, true); + + scene_box->show_all (); + + dialog.get_vbox()->pack_end (*scene_box, false, false); + } dialog.show (); @@ -1871,19 +1960,50 @@ Editor::rename_marker(ArdourMarker *marker) case RESPONSE_ACCEPT: break; default: - return; + return false; } - begin_reversible_command ( _("rename marker") ); XMLNode &before = _session->locations()->get_state(); - dialog.get_result(txt); - loc->set_name (txt); + if (with_command) { + begin_reversible_command (with_scene ? _("edit marker") : _("rename marker")); + } + + dialog.get_result (txt); + loc.set_name (txt); + + if (with_scene) { + + if (use_scene_button->get_active()) { + loc.set_scene_change (nullptr); + } else { + + int pc = program_adjust->get_value() - 1; + int b = bank_adjust->get_value() - 1; + int chn = channel_adjust->get_value() - 1; + + std::shared_ptr msc = std::dynamic_pointer_cast (loc.scene_change ()); + if (!msc) { + msc.reset (new MIDISceneChange (chn, b, pc)); + loc.set_scene_change (msc); + } + msc->set_channel (chn); + msc->set_program (pc); + msc->set_bank (b); + } + } + _session->set_dirty (); - XMLNode &after = _session->locations()->get_state(); - _session->add_command (new MementoCommand(*(_session->locations()), &before, &after)); - commit_reversible_command (); + if (with_command) { + XMLNode &after = _session->locations()->get_state(); + _session->add_command (new MementoCommand(*(_session->locations()), &before, &after)); + commit_reversible_command (); + } else { + delete &before; + } + + return true; } void diff --git a/gtk2_ardour/editor_ops.cc b/gtk2_ardour/editor_ops.cc index 10028a6d44..256da3e011 100644 --- a/gtk2_ardour/editor_ops.cc +++ b/gtk2_ardour/editor_ops.cc @@ -1997,10 +1997,13 @@ Editor::add_location_mark_with_flag (timepos_t const & where, Location::Flags fl _session->locations()->next_available_name(markername, namebase); - if (!choose_new_marker_name (markername)) { + Location *location = new Location (*_session, where, where, markername, flags, cue_id); + + if (!edit_location (*location, true, false)) { + delete location; return; } - Location *location = new Location (*_session, where, where, markername, flags, cue_id); + begin_reversible_command (_("add marker")); XMLNode &before = _session->locations()->get_state();