From 38d7d28b25aeec1794c3e579c36889d13130f8fe Mon Sep 17 00:00:00 2001 From: Mads Kiilerich Date: Sun, 6 Nov 2022 19:12:20 +0100 Subject: [PATCH] MainClock: introduce actual set_display_delta_mode Make MainClock more self-contained and generic by moving logic from the Config system and to the class itself, while making the class less aware of how it is used in the config system. It is slightly dirty to store the initial AudioClock widget name in MainClock, but less dirty than having to pass the whole name correctly every time the delta mode changes. Also avoid confusing use of 'mode', which in AudioClock is used for the units/formatting of the clock. --- gtk2_ardour/ardour_ui_options.cc | 16 ++----------- gtk2_ardour/main_clock.cc | 40 ++++++++++++++++---------------- gtk2_ardour/main_clock.h | 3 +++ 3 files changed, 25 insertions(+), 34 deletions(-) diff --git a/gtk2_ardour/ardour_ui_options.cc b/gtk2_ardour/ardour_ui_options.cc index 68de11e1df..c9cd7ebb5b 100644 --- a/gtk2_ardour/ardour_ui_options.cc +++ b/gtk2_ardour/ardour_ui_options.cc @@ -379,21 +379,9 @@ ARDOUR_UI::parameter_changed (std::string p) } else if (p == "show-track-meters") { if (editor) editor->toggle_meter_updating(); } else if (p == "primary-clock-delta-mode") { - if (UIConfiguration::instance().get_primary_clock_delta_mode() != NoDelta) { - primary_clock->set_editable (false); - primary_clock->set_widget_name ("transport delta"); - } else { - primary_clock->set_editable (true); - primary_clock->set_widget_name ("transport"); - } + primary_clock->set_display_delta_mode(UIConfiguration::instance().get_primary_clock_delta_mode()); } else if (p == "secondary-clock-delta-mode") { - if (UIConfiguration::instance().get_secondary_clock_delta_mode() != NoDelta) { - secondary_clock->set_editable (false); - secondary_clock->set_widget_name ("secondary delta"); - } else { - secondary_clock->set_editable (true); - secondary_clock->set_widget_name ("secondary"); - } + secondary_clock->set_display_delta_mode(UIConfiguration::instance().get_secondary_clock_delta_mode()); } else if (p == "super-rapid-clock-update") { if (_session) { stop_clocking (); diff --git a/gtk2_ardour/main_clock.cc b/gtk2_ardour/main_clock.cc index 78f8150fdd..d76577b4dc 100644 --- a/gtk2_ardour/main_clock.cc +++ b/gtk2_ardour/main_clock.cc @@ -28,7 +28,6 @@ #include "actions.h" #include "main_clock.h" -#include "ui_config.h" #include "public_editor.h" #include "pbd/i18n.h" @@ -44,6 +43,7 @@ MainClock::MainClock ( : AudioClock (clock_name, false, widget_name, true, true, false, true) , _primary (primary) , _suspend_delta_mode_signal (false) + , _widget_name(widget_name) { } @@ -64,27 +64,21 @@ MainClock::build_ops_menu () MenuList& ops_items = ops_menu->items(); ops_items.push_back (SeparatorElem ()); + RadioMenuItem::Group group; PBD::Unwinder uw (_suspend_delta_mode_signal, true); - ClockDeltaMode mode; - if (_primary) { - mode = UIConfiguration::instance().get_primary_clock_delta_mode (); - } else { - mode = UIConfiguration::instance().get_secondary_clock_delta_mode (); - } - ops_items.push_back (RadioMenuElem (group, _("Display absolute time"), sigc::bind (sigc::mem_fun (*this, &MainClock::change_display_delta_mode), NoDelta))); - if (mode == NoDelta) { + if (_delta_mode == NoDelta) { RadioMenuItem* i = dynamic_cast (&ops_items.back ()); i->set_active (true); } ops_items.push_back (RadioMenuElem (group, _("Display delta to edit cursor"), sigc::bind (sigc::mem_fun (*this, &MainClock::change_display_delta_mode), DeltaEditPoint))); - if (mode == DeltaEditPoint) { + if (_delta_mode == DeltaEditPoint) { RadioMenuItem* i = dynamic_cast (&ops_items.back ()); i->set_active (true); } ops_items.push_back (RadioMenuElem (group, _("Display delta to origin marker"), sigc::bind (sigc::mem_fun (*this, &MainClock::change_display_delta_mode), DeltaOriginMarker))); - if (mode == DeltaOriginMarker) { + if (_delta_mode == DeltaOriginMarker) { RadioMenuItem* i = dynamic_cast (&ops_items.back ()); i->set_active (true); } @@ -100,18 +94,11 @@ MainClock::build_ops_menu () void MainClock::set (timepos_t const & when, bool force) { - ClockDeltaMode mode; - if (_primary) { - mode = UIConfiguration::instance().get_primary_clock_delta_mode (); - } else { - mode = UIConfiguration::instance().get_secondary_clock_delta_mode (); - } - if (!AudioEngine::instance()->session()) { - mode = NoDelta; + _delta_mode = NoDelta; } - switch (mode) { + switch (_delta_mode) { case NoDelta: AudioClock::set (when, force); break; @@ -140,6 +127,19 @@ MainClock::change_display_delta_mode (ClockDeltaMode m) } } +void +MainClock::set_display_delta_mode (ClockDeltaMode m) +{ + _delta_mode = m; + if (_delta_mode != NoDelta) { + set_editable (false); + set_widget_name (_widget_name + " delta"); + } else { + set_editable (true); + set_widget_name (_widget_name); + } +} + void MainClock::edit_current_tempo () { diff --git a/gtk2_ardour/main_clock.h b/gtk2_ardour/main_clock.h index b74048e46f..11a086977e 100644 --- a/gtk2_ardour/main_clock.h +++ b/gtk2_ardour/main_clock.h @@ -30,6 +30,7 @@ class MainClock : public AudioClock public: MainClock (const std::string& clock_name, const std::string& widget_name, bool primary); void set_session (ARDOUR::Session *s); + void set_display_delta_mode (ARDOUR::ClockDeltaMode m); void set (Temporal::timepos_t const &, bool force = false); private: @@ -41,6 +42,8 @@ private: void insert_new_meter (); bool _primary; bool _suspend_delta_mode_signal; + std::string _widget_name; + ARDOUR::ClockDeltaMode _delta_mode; }; #endif // __gtk_ardour_main_clock_h__