From a9adc3c5c6d6bdcea6a702962627366ce5b28579 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Thu, 4 Nov 2021 11:16:22 -0600 Subject: [PATCH] triggerbox: flesh out Request mechanism Still no actually active requests --- libs/ardour/ardour/triggerbox.h | 23 ++++++++++- libs/ardour/globals.cc | 1 + libs/ardour/triggerbox.cc | 70 +++++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+), 1 deletion(-) diff --git a/libs/ardour/ardour/triggerbox.h b/libs/ardour/ardour/triggerbox.h index 17a408fb96..12cb568a97 100644 --- a/libs/ardour/ardour/triggerbox.h +++ b/libs/ardour/ardour/triggerbox.h @@ -28,6 +28,7 @@ #include #include "pbd/pcg_rand.h" +#include "pbd/pool.h" #include "pbd/properties.h" #include "pbd/ringbuffer.h" #include "pbd/stateful.h" @@ -366,6 +367,9 @@ class LIBARDOUR_API TriggerBox : public Processor void add_midi_sidechain (std::string const & name); + void request_reload (int32_t slot); + void request_use (int32_t slot, Trigger&); + enum TriggerMidiMapMode { AbletonPush, SequentialNote, @@ -386,6 +390,8 @@ class LIBARDOUR_API TriggerBox : public Processor static void scene_bang (uint32_t scene_number); static void scene_unbang (uint32_t scene_number); + static void init_pool(); + static const int32_t default_triggers_per_box; private: @@ -441,11 +447,26 @@ class LIBARDOUR_API TriggerBox : public Processor union { Trigger* trigger; }; + + union { + int32_t slot; + }; + + Request (Type t) : type (t) {} + + static MultiAllocSingleReleasePool* pool; + static void init_pool(); + + void* operator new (size_t); + void operator delete (void* ptr, size_t); }; - typedef PBD::RingBuffer RequestBuffer; + typedef PBD::RingBuffer RequestBuffer; RequestBuffer requests; + void process_requests (); + void process_request (Request*); + }; namespace Properties { diff --git a/libs/ardour/globals.cc b/libs/ardour/globals.cc index 18e7066b2c..9b0759a500 100644 --- a/libs/ardour/globals.cc +++ b/libs/ardour/globals.cc @@ -551,6 +551,7 @@ ARDOUR::init (bool try_optimization, const char* localedir, bool with_gui) SessionEvent::init_event_pool (); TransportFSM::Event::init_pool (); + TriggerBox::init_pool (); Operations::make_operations_quarks (); SessionObject::make_property_quarks (); diff --git a/libs/ardour/triggerbox.cc b/libs/ardour/triggerbox.cc index 184e6877c3..12fb2603df 100644 --- a/libs/ardour/triggerbox.cc +++ b/libs/ardour/triggerbox.cc @@ -2214,3 +2214,73 @@ TriggerBox::reconnect_to_default () _sidechain->input()->nth (0)->disconnect_all (); _sidechain->input()->nth (0)->connect (Config->get_default_trigger_input_port()); } + +MultiAllocSingleReleasePool* TriggerBox::Request::pool; + +void +TriggerBox::init_pool () +{ + /* "indirection" is because the Request struct is private, and so + nobody else can call its ::init_pool() static method. + */ + + Request::init_pool (); +} + +void +TriggerBox::Request::init_pool () +{ + pool = new MultiAllocSingleReleasePool (X_("TriggerBoxRequests"), sizeof (TriggerBox::Request), 1024); +} + +void* +TriggerBox::Request::operator new (size_t) +{ + return pool->alloc(); + } + +void +TriggerBox::Request::operator delete (void *ptr, size_t /*size*/) +{ + return pool->release (ptr); +} + +void +TriggerBox::request_reload (int32_t slot) +{ + Request* r = new Request (Request::Use); + r->slot = slot; + requests.write (&r, 1); +} + +void +TriggerBox::request_use (int32_t slot, Trigger& t) +{ + Request* r = new Request (Request::Use); + r->slot = slot; + r->trigger = &t; + requests.write (&r, 1); +} + +void +TriggerBox::process_requests () +{ + Request* r; + + while (requests.read (&r, 1) == 1) { + process_request (r); + } +} + +void +TriggerBox::process_request (Request* req) +{ + switch (req->type) { + case Request::Use: + break; + case Request::Reload: + break; + } + + delete req; /* back to the pool, RT-safe */ +}