13
0

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.
This commit is contained in:
Mads Kiilerich 2022-11-06 19:12:20 +01:00
parent 75f6b8fb66
commit 38d7d28b25
3 changed files with 25 additions and 34 deletions

View File

@ -379,21 +379,9 @@ ARDOUR_UI::parameter_changed (std::string p)
} else if (p == "show-track-meters") { } else if (p == "show-track-meters") {
if (editor) editor->toggle_meter_updating(); if (editor) editor->toggle_meter_updating();
} else if (p == "primary-clock-delta-mode") { } else if (p == "primary-clock-delta-mode") {
if (UIConfiguration::instance().get_primary_clock_delta_mode() != NoDelta) { primary_clock->set_display_delta_mode(UIConfiguration::instance().get_primary_clock_delta_mode());
primary_clock->set_editable (false);
primary_clock->set_widget_name ("transport delta");
} else {
primary_clock->set_editable (true);
primary_clock->set_widget_name ("transport");
}
} else if (p == "secondary-clock-delta-mode") { } else if (p == "secondary-clock-delta-mode") {
if (UIConfiguration::instance().get_secondary_clock_delta_mode() != NoDelta) { secondary_clock->set_display_delta_mode(UIConfiguration::instance().get_secondary_clock_delta_mode());
secondary_clock->set_editable (false);
secondary_clock->set_widget_name ("secondary delta");
} else {
secondary_clock->set_editable (true);
secondary_clock->set_widget_name ("secondary");
}
} else if (p == "super-rapid-clock-update") { } else if (p == "super-rapid-clock-update") {
if (_session) { if (_session) {
stop_clocking (); stop_clocking ();

View File

@ -28,7 +28,6 @@
#include "actions.h" #include "actions.h"
#include "main_clock.h" #include "main_clock.h"
#include "ui_config.h"
#include "public_editor.h" #include "public_editor.h"
#include "pbd/i18n.h" #include "pbd/i18n.h"
@ -44,6 +43,7 @@ MainClock::MainClock (
: AudioClock (clock_name, false, widget_name, true, true, false, true) : AudioClock (clock_name, false, widget_name, true, true, false, true)
, _primary (primary) , _primary (primary)
, _suspend_delta_mode_signal (false) , _suspend_delta_mode_signal (false)
, _widget_name(widget_name)
{ {
} }
@ -64,27 +64,21 @@ MainClock::build_ops_menu ()
MenuList& ops_items = ops_menu->items(); MenuList& ops_items = ops_menu->items();
ops_items.push_back (SeparatorElem ()); ops_items.push_back (SeparatorElem ());
RadioMenuItem::Group group; RadioMenuItem::Group group;
PBD::Unwinder<bool> uw (_suspend_delta_mode_signal, true); PBD::Unwinder<bool> 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))); 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<RadioMenuItem *> (&ops_items.back ()); RadioMenuItem* i = dynamic_cast<RadioMenuItem *> (&ops_items.back ());
i->set_active (true); 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))); 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<RadioMenuItem *> (&ops_items.back ()); RadioMenuItem* i = dynamic_cast<RadioMenuItem *> (&ops_items.back ());
i->set_active (true); 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))); 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<RadioMenuItem *> (&ops_items.back ()); RadioMenuItem* i = dynamic_cast<RadioMenuItem *> (&ops_items.back ());
i->set_active (true); i->set_active (true);
} }
@ -100,18 +94,11 @@ MainClock::build_ops_menu ()
void void
MainClock::set (timepos_t const & when, bool force) 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()) { if (!AudioEngine::instance()->session()) {
mode = NoDelta; _delta_mode = NoDelta;
} }
switch (mode) { switch (_delta_mode) {
case NoDelta: case NoDelta:
AudioClock::set (when, force); AudioClock::set (when, force);
break; 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 void
MainClock::edit_current_tempo () MainClock::edit_current_tempo ()
{ {

View File

@ -30,6 +30,7 @@ class MainClock : public AudioClock
public: public:
MainClock (const std::string& clock_name, const std::string& widget_name, bool primary); MainClock (const std::string& clock_name, const std::string& widget_name, bool primary);
void set_session (ARDOUR::Session *s); void set_session (ARDOUR::Session *s);
void set_display_delta_mode (ARDOUR::ClockDeltaMode m);
void set (Temporal::timepos_t const &, bool force = false); void set (Temporal::timepos_t const &, bool force = false);
private: private:
@ -41,6 +42,8 @@ private:
void insert_new_meter (); void insert_new_meter ();
bool _primary; bool _primary;
bool _suspend_delta_mode_signal; bool _suspend_delta_mode_signal;
std::string _widget_name;
ARDOUR::ClockDeltaMode _delta_mode;
}; };
#endif // __gtk_ardour_main_clock_h__ #endif // __gtk_ardour_main_clock_h__