From c5b6d7f9d24ee8b3c64c93b7c7025640c54820fb Mon Sep 17 00:00:00 2001 From: Ben Loftis Date: Thu, 30 Dec 2021 12:10:50 -0600 Subject: [PATCH] trigger_ui: TriggerEntry is-a TriggerUI --- gtk2_ardour/editor.cc | 2 +- gtk2_ardour/slot_properties_box.cc | 2 +- gtk2_ardour/slot_properties_box.h | 2 +- gtk2_ardour/trigger_ui.cc | 22 ++++++++++++++++++++- gtk2_ardour/trigger_ui.h | 19 ++++++++++++++---- gtk2_ardour/triggerbox_ui.cc | 31 ++++++++---------------------- gtk2_ardour/triggerbox_ui.h | 23 ++++------------------ 7 files changed, 51 insertions(+), 50 deletions(-) diff --git a/gtk2_ardour/editor.cc b/gtk2_ardour/editor.cc index dbb72f6614..4a3586b1fe 100644 --- a/gtk2_ardour/editor.cc +++ b/gtk2_ardour/editor.cc @@ -716,7 +716,7 @@ Editor::Editor () VBox* summary_arrows_right = manage (new VBox); summary_arrows_right->pack_start (*summary_arrow_right); - Frame* summary_frame = manage (new Frame); + Gtk::Frame* summary_frame = manage (new Gtk::Frame); summary_frame->set_shadow_type (Gtk::SHADOW_ETCHED_IN); summary_frame->add (*_summary); diff --git a/gtk2_ardour/slot_properties_box.cc b/gtk2_ardour/slot_properties_box.cc index 3a892591c5..4439e6603a 100644 --- a/gtk2_ardour/slot_properties_box.cc +++ b/gtk2_ardour/slot_properties_box.cc @@ -347,7 +347,7 @@ SlotPropertyTable::set_follow_action (Trigger::FollowAction fa, uint64_t idx) } void -SlotPropertyTable::on_trigger_changed (PropertyChange pc) +SlotPropertyTable::on_trigger_changed (PropertyChange const& pc) { if (pc.contains (Properties::name)) { _name_label.set_text (trigger()->name()); diff --git a/gtk2_ardour/slot_properties_box.h b/gtk2_ardour/slot_properties_box.h index 81f22791d5..9cabbacf98 100644 --- a/gtk2_ardour/slot_properties_box.h +++ b/gtk2_ardour/slot_properties_box.h @@ -90,7 +90,7 @@ class SlotPropertyTable : public TriggerUI, public Gtk::Table void set_launch_style (ARDOUR::Trigger::LaunchStyle); void set_follow_action (ARDOUR::Trigger::FollowAction, uint64_t); - void on_trigger_changed (PBD::PropertyChange); + void on_trigger_changed (PBD::PropertyChange const& ); bool follow_action_button_event (GdkEvent*); bool legato_button_event (GdkEvent*); diff --git a/gtk2_ardour/trigger_ui.cc b/gtk2_ardour/trigger_ui.cc index 597fb79419..c688e96ca8 100644 --- a/gtk2_ardour/trigger_ui.cc +++ b/gtk2_ardour/trigger_ui.cc @@ -97,8 +97,23 @@ TriggerUI::TriggerUI () TriggerUI::~TriggerUI() { + trigger_swap_connection.disconnect (); + trigger_connections.disconnect (); } +void +TriggerUI::trigger_swap (uint32_t n) +{ + if (n != tref.slot) { + /* some other slot in the same box got swapped. we don't care */ + return; + } + trigger_connections.disconnect (); + trigger()->PropertyChanged.connect (trigger_connections, MISSING_INVALIDATOR, boost::bind (&TriggerEntry::trigger_changed, this, _1), gui_context ()); + trigger_changed (Properties::name); +} + + void TriggerUI::setup_actions_and_bindings () { @@ -458,7 +473,7 @@ TriggerUI::trigger() const } void -TriggerUI::trigger_changed (PropertyChange what) +TriggerUI::trigger_changed (PropertyChange const& what) { on_trigger_changed(what); } @@ -467,6 +482,9 @@ TriggerUI::trigger_changed (PropertyChange what) void TriggerUI::set_trigger (ARDOUR::TriggerReference tr) { +// trigger_connections.clear(); +// trigger_swap_connection.clear(); + tref = tr; PropertyChange pc; @@ -486,4 +504,6 @@ TriggerUI::set_trigger (ARDOUR::TriggerReference tr) trigger_changed (pc); trigger()->PropertyChanged.connect (trigger_connections, MISSING_INVALIDATOR, boost::bind (&TriggerUI::trigger_changed, this, _1), gui_context()); + + tref.box->TriggerSwapped.connect (trigger_swap_connection, MISSING_INVALIDATOR, boost::bind (&TriggerUI::trigger_swap, this, _1), gui_context ()); } diff --git a/gtk2_ardour/trigger_ui.h b/gtk2_ardour/trigger_ui.h index a4cc7e2700..e142065f28 100644 --- a/gtk2_ardour/trigger_ui.h +++ b/gtk2_ardour/trigger_ui.h @@ -29,6 +29,12 @@ #include "widgets/slider_controller.h" #include "widgets/frame.h" +namespace Gtk +{ + class FileChooserDialog; + class Menu; +} + class TriggerUI { public: @@ -37,7 +43,7 @@ public: void set_trigger (ARDOUR::TriggerReference); - virtual void on_trigger_changed (PBD::PropertyChange) = 0; + virtual void on_trigger_changed (PBD::PropertyChange const& ) = 0; static std::string follow_action_to_string (ARDOUR::Trigger::FollowAction); static ARDOUR::Trigger::FollowAction string_to_follow_action (std::string const &); @@ -53,8 +59,11 @@ public: static void setup_actions_and_bindings (); + ARDOUR::TriggerReference trigger_reference() const { return tref; } + ARDOUR::TriggerPtr trigger() const; + private: - void trigger_changed (PBD::PropertyChange); //calls on_trigger_changed to subclasses + void trigger_changed (PBD::PropertyChange const& ); //calls on_trigger_changed to subclasses /* Actions for Triggers: accessed via ardour_ui and shortcuts and lua */ static Glib::RefPtr trigger_actions; @@ -92,9 +101,11 @@ protected: sigc::connection _file_chooser_connection; Gtk::FileChooserDialog* _file_chooser; + void trigger_swap (uint32_t); + PBD::ScopedConnection trigger_swap_connection; + ARDOUR::TriggerReference tref; - ARDOUR::TriggerPtr trigger() const; - PBD::ScopedConnectionList trigger_connections; + PBD::ScopedConnection trigger_connections; }; diff --git a/gtk2_ardour/triggerbox_ui.cc b/gtk2_ardour/triggerbox_ui.cc index d9f6840eee..028b82699f 100644 --- a/gtk2_ardour/triggerbox_ui.cc +++ b/gtk2_ardour/triggerbox_ui.cc @@ -66,18 +66,17 @@ using namespace PBD; TriggerEntry::TriggerEntry (Item* item, TriggerReference tr) : ArdourCanvas::Rectangle (item) - , tref (tr) { set_layout_sensitive (true); // why??? - name = string_compose ("trigger %1", tref.slot); + name = string_compose ("trigger %1", tr.slot); set_outline (false); play_button = new ArdourCanvas::Rectangle (this); play_button->set_outline (false); play_button->set_fill (true); - play_button->name = string_compose ("playbutton %1", tref.slot); + play_button->name = string_compose ("playbutton %1", tr.slot); play_button->show (); follow_button = new ArdourCanvas::Rectangle (this); @@ -96,19 +95,15 @@ TriggerEntry::TriggerEntry (Item* item, TriggerReference tr) name_text->set_ignore_events (false); name_text->show (); + /* this will trigger a call to on_trigger_changed() */ + set_trigger(tr); + /* watch for change in theme */ UIConfiguration::instance ().ParameterChanged.connect (sigc::mem_fun (*this, &TriggerEntry::ui_parameter_changed)); set_default_colors (); - trigger()->PropertyChanged.connect (trigger_prop_connection, MISSING_INVALIDATOR, boost::bind (&TriggerEntry::prop_change, this, _1), gui_context ()); - tref.box->TriggerSwapped.connect (trigger_swap_connection, MISSING_INVALIDATOR, boost::bind (&TriggerEntry::trigger_swap, this, _1), gui_context ()); dynamic_cast (tref.box->owner ())->presentation_info ().Change.connect (owner_prop_connection, MISSING_INVALIDATOR, boost::bind (&TriggerEntry::owner_prop_change, this, _1), gui_context ()); - PropertyChange changed; - changed.add (ARDOUR::Properties::name); - changed.add (ARDOUR::Properties::running); - prop_change (changed); - selection_change (); } @@ -116,18 +111,6 @@ TriggerEntry::~TriggerEntry () { } -void -TriggerEntry::trigger_swap (uint32_t n) -{ - if (n != tref.slot) { - /* some other slot in the same box got swapped. we don't care */ - return; - } - trigger_prop_connection.disconnect (); - trigger()->PropertyChanged.connect (trigger_prop_connection, MISSING_INVALIDATOR, boost::bind (&TriggerEntry::prop_change, this, _1), gui_context ()); - prop_change (Properties::name); -} - void TriggerEntry::owner_prop_change (PropertyChange const& pc) { @@ -420,7 +403,7 @@ TriggerEntry::render (ArdourCanvas::Rect const& area, Cairo::RefPtrregion ()) { @@ -1175,6 +1158,8 @@ TriggerBoxUI::rapid_update () } } +/* ********************************************** */ + TriggerBoxWidget::TriggerBoxWidget (float w, float h) : FittedCanvasWidget (w, h) , ui (0) diff --git a/gtk2_ardour/triggerbox_ui.h b/gtk2_ardour/triggerbox_ui.h index 96f371f17e..c11d1b4c86 100644 --- a/gtk2_ardour/triggerbox_ui.h +++ b/gtk2_ardour/triggerbox_ui.h @@ -30,11 +30,7 @@ #include "fitted_canvas_widget.h" -namespace Gtk -{ - class FileChooserDialog; - class Menu; -} +#include "trigger_ui.h" namespace Temporal { @@ -47,18 +43,12 @@ namespace ArdourCanvas class Polygon; } -class TriggerEntry : public ArdourCanvas::Rectangle +class TriggerEntry : public ArdourCanvas::Rectangle, public TriggerUI { public: TriggerEntry (ArdourCanvas::Item* item, ARDOUR::TriggerReference rf); ~TriggerEntry (); - boost::shared_ptr trigger () const - { - return tref.trigger(); - } - ARDOUR::TriggerReference trigger_reference() const { return tref; } - ArdourCanvas::Rectangle* play_button; ArdourCanvas::Rectangle* name_button; ArdourCanvas::Rectangle* follow_button; @@ -72,21 +62,16 @@ public: void _size_allocate (ArdourCanvas::Rect const&); void maybe_update (); + void on_trigger_changed (PBD::PropertyChange const& change); + void selection_change (); void set_default_colors (); private: - ARDOUR::TriggerReference tref; double _poly_size; double _poly_margin; - PBD::ScopedConnection trigger_prop_connection; - PBD::ScopedConnection trigger_swap_connection; - void prop_change (PBD::PropertyChange const& change); - - void trigger_swap (uint32_t); - PBD::ScopedConnection owner_prop_connection; void owner_prop_change (PBD::PropertyChange const&); void owner_color_changed ();