From 9758e6280ff99208b3a3c971ec8f0fe40a2b6245 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Mon, 16 May 2022 15:24:27 -0600 Subject: [PATCH] use new event loop callback to ensure that all surface/control protocol threads have tempo map ptr set --- libs/surfaces/cc121/cc121.h | 2 ++ libs/surfaces/contourdesign/contourdesign.h | 2 ++ .../control_protocol/control_protocol.cc | 15 +++++++++++++++ .../control_protocol/control_protocol.h | 17 +++++++++++++++++ libs/surfaces/faderport/faderport.h | 2 ++ libs/surfaces/faderport8/faderport8.h | 2 ++ .../generic_midi_control_protocol.h | 2 ++ .../launch_control_xl/launch_control_xl.h | 2 ++ libs/surfaces/mackie/mackie_control_protocol.h | 2 ++ libs/surfaces/maschine2/maschine2.h | 2 ++ libs/surfaces/osc/osc.h | 2 ++ libs/surfaces/push2/push2.h | 2 ++ libs/surfaces/us2400/us2400_control_protocol.h | 2 ++ libs/surfaces/websockets/ardour_websockets.h | 2 ++ libs/surfaces/wiimote/wiimote.h | 2 ++ 15 files changed, 58 insertions(+) diff --git a/libs/surfaces/cc121/cc121.h b/libs/surfaces/cc121/cc121.h index dfd503f6a0..ef8ed6501a 100644 --- a/libs/surfaces/cc121/cc121.h +++ b/libs/surfaces/cc121/cc121.h @@ -162,6 +162,8 @@ class CC121 : public ARDOUR::ControlProtocol, public AbstractUI { std::list > bundles (); + CONTROL_PROTOCOL_THREADS_NEED_TEMPO_MAP_DECL(); + private: boost::shared_ptr _current_stripable; boost::weak_ptr pre_master_stripable; diff --git a/libs/surfaces/contourdesign/contourdesign.h b/libs/surfaces/contourdesign/contourdesign.h index 09da0c0240..7edffec469 100644 --- a/libs/surfaces/contourdesign/contourdesign.h +++ b/libs/surfaces/contourdesign/contourdesign.h @@ -128,6 +128,8 @@ public: PBD::Signal1 ButtonPress; PBD::Signal1 ButtonRelease; + CONTROL_PROTOCOL_THREADS_NEED_TEMPO_MAP_DECL(); + private: void do_request (ContourDesignControlUIRequest*); void start (); diff --git a/libs/surfaces/control_protocol/control_protocol.cc b/libs/surfaces/control_protocol/control_protocol.cc index d47ada96c7..42e7f05819 100644 --- a/libs/surfaces/control_protocol/control_protocol.cc +++ b/libs/surfaces/control_protocol/control_protocol.cc @@ -21,6 +21,7 @@ #include "pbd/convert.h" #include "pbd/error.h" +#include "pbd/pthread_utils.h" #include "temporal/superclock.h" #include "temporal/tempo.h" @@ -65,6 +66,7 @@ const std::string ControlProtocol::state_node_name ("Protocol"); ControlProtocol::ControlProtocol (Session& s, string str) : BasicUI (s) , _name (str) + , glib_event_callback (boost::bind (&ControlProtocol::event_loop_precall, this)) , _active (false) { if (!selection_connected) { @@ -78,6 +80,19 @@ ControlProtocol::~ControlProtocol () { } +void +ControlProtocol::event_loop_precall () +{ + /* reload the thread-local ptr to the tempo map */ + Temporal::TempoMap::fetch (); +} + +void +ControlProtocol::install_precall_handler (Glib::RefPtr context) +{ + glib_event_callback.attach (context); +} + int ControlProtocol::set_active (bool yn) { diff --git a/libs/surfaces/control_protocol/control_protocol/control_protocol.h b/libs/surfaces/control_protocol/control_protocol/control_protocol.h index cba8838d04..5a94ee7bc5 100644 --- a/libs/surfaces/control_protocol/control_protocol/control_protocol.h +++ b/libs/surfaces/control_protocol/control_protocol/control_protocol.h @@ -30,6 +30,7 @@ #include "pbd/signals.h" #include "pbd/stateful.h" +#include "pbd/glib_event_source.h" #include "control_protocol/basic_ui.h" #include "control_protocol/types.h" @@ -147,6 +148,9 @@ protected: std::vector > route_table; std::string _name; + GlibEventLoopCallback glib_event_callback; + virtual void event_loop_precall (); + void install_precall_handler (Glib::RefPtr); private: LIBCONTROLCP_LOCAL ControlProtocol (const ControlProtocol&); /* noncopyable */ @@ -184,4 +188,17 @@ public: } } +/* this is where the strange inheritance pattern hits the wall. A control + protocol thread/event loop is inherited from AbstractUI, but the precall + handler is inherited from ControlProtocol. When the AbstractUI sets up the + event loop, it will call attach_request_source() which will in turn pass a + Glib::MainContext to maybe_install_precall_handler(). We override the + definition of that method here to make it actuall install the + ControlProtocol's handler. +*/ + +#define CONTROL_PROTOCOL_THREADS_NEED_TEMPO_MAP_DECL() \ + void maybe_install_precall_handler (Glib::RefPtr ctxt) { install_precall_handler (ctxt); } + + #endif // ardour_control_protocols_h diff --git a/libs/surfaces/faderport/faderport.h b/libs/surfaces/faderport/faderport.h index 91872659f4..0c4e1cd413 100644 --- a/libs/surfaces/faderport/faderport.h +++ b/libs/surfaces/faderport/faderport.h @@ -162,6 +162,8 @@ class FaderPort : public ARDOUR::ControlProtocol, public AbstractUI > bundles (); + CONTROL_PROTOCOL_THREADS_NEED_TEMPO_MAP_DECL(); + private: boost::shared_ptr _current_stripable; boost::weak_ptr pre_master_stripable; diff --git a/libs/surfaces/faderport8/faderport8.h b/libs/surfaces/faderport8/faderport8.h index c52b844923..b0b13fe280 100644 --- a/libs/surfaces/faderport8/faderport8.h +++ b/libs/surfaces/faderport8/faderport8.h @@ -108,6 +108,8 @@ public: size_t tx_midi (std::vector const&) const; + CONTROL_PROTOCOL_THREADS_NEED_TEMPO_MAP_DECL(); + private: void close (); diff --git a/libs/surfaces/generic_midi/generic_midi_control_protocol.h b/libs/surfaces/generic_midi/generic_midi_control_protocol.h index a310aa6498..405f346352 100644 --- a/libs/surfaces/generic_midi/generic_midi_control_protocol.h +++ b/libs/surfaces/generic_midi/generic_midi_control_protocol.h @@ -128,6 +128,8 @@ public: PBD::Signal0 ConnectionChange; + CONTROL_PROTOCOL_THREADS_NEED_TEMPO_MAP_DECL(); + private: boost::shared_ptr _input_bundle; boost::shared_ptr _output_bundle; diff --git a/libs/surfaces/launch_control_xl/launch_control_xl.h b/libs/surfaces/launch_control_xl/launch_control_xl.h index 2a1bd1e78f..8fdc657e49 100644 --- a/libs/surfaces/launch_control_xl/launch_control_xl.h +++ b/libs/surfaces/launch_control_xl/launch_control_xl.h @@ -411,6 +411,8 @@ public: void send_bank_switch(bool up); int send_bank_base () const { return _send_bank_base; } + CONTROL_PROTOCOL_THREADS_NEED_TEMPO_MAP_DECL(); + private: bool in_use; TrackMode _track_mode; diff --git a/libs/surfaces/mackie/mackie_control_protocol.h b/libs/surfaces/mackie/mackie_control_protocol.h index c056a966e6..2d124fe103 100644 --- a/libs/surfaces/mackie/mackie_control_protocol.h +++ b/libs/surfaces/mackie/mackie_control_protocol.h @@ -276,6 +276,8 @@ class MackieControlProtocol bool stripable_is_locked_to_strip (boost::shared_ptr) const; + CONTROL_PROTOCOL_THREADS_NEED_TEMPO_MAP_DECL(); + private: struct ButtonHandlers { diff --git a/libs/surfaces/maschine2/maschine2.h b/libs/surfaces/maschine2/maschine2.h index 162f1bdbeb..d43e3f00ff 100644 --- a/libs/surfaces/maschine2/maschine2.h +++ b/libs/surfaces/maschine2/maschine2.h @@ -85,6 +85,8 @@ class Maschine2: public ARDOUR::ControlProtocol, public AbstractUI std::string get_remote_port () { return remote_port; } void set_remote_port (std::string pt) { remote_port = pt; } + CONTROL_PROTOCOL_THREADS_NEED_TEMPO_MAP_DECL(); + protected: void thread_init (); void do_request (OSCUIRequest*); diff --git a/libs/surfaces/push2/push2.h b/libs/surfaces/push2/push2.h index 70f1e9a854..9f64310665 100644 --- a/libs/surfaces/push2/push2.h +++ b/libs/surfaces/push2/push2.h @@ -362,6 +362,8 @@ class Push2 : public ARDOUR::ControlProtocol libusb_device_handle* usb_handle() const { return handle; } + CONTROL_PROTOCOL_THREADS_NEED_TEMPO_MAP_DECL(); + private: libusb_device_handle *handle; bool in_use; diff --git a/libs/surfaces/us2400/us2400_control_protocol.h b/libs/surfaces/us2400/us2400_control_protocol.h index 06da969d64..440e538233 100644 --- a/libs/surfaces/us2400/us2400_control_protocol.h +++ b/libs/surfaces/us2400/us2400_control_protocol.h @@ -216,6 +216,8 @@ class US2400Protocol int get_sends_bank (); + CONTROL_PROTOCOL_THREADS_NEED_TEMPO_MAP_DECL(); + protected: // shut down the surface void close(); diff --git a/libs/surfaces/websockets/ardour_websockets.h b/libs/surfaces/websockets/ardour_websockets.h index 2c71d09ed4..4d1fdc8a7d 100644 --- a/libs/surfaces/websockets/ardour_websockets.h +++ b/libs/surfaces/websockets/ardour_websockets.h @@ -85,6 +85,8 @@ public: /* ControlProtocol */ void stripable_selection_changed () {} + CONTROL_PROTOCOL_THREADS_NEED_TEMPO_MAP_DECL(); + protected: /* BaseUI */ void thread_init (); diff --git a/libs/surfaces/wiimote/wiimote.h b/libs/surfaces/wiimote/wiimote.h index 93c51cb3fb..21d2d6cbc0 100644 --- a/libs/surfaces/wiimote/wiimote.h +++ b/libs/surfaces/wiimote/wiimote.h @@ -55,6 +55,8 @@ public: void stripable_selection_changed () {} + CONTROL_PROTOCOL_THREADS_NEED_TEMPO_MAP_DECL(); + protected: void do_request (WiimoteControlUIRequest*); int start ();