triggerbox: flesh out Request mechanism

Still no actually active requests
This commit is contained in:
Paul Davis 2021-11-04 11:16:22 -06:00
parent b0176c21fb
commit a9adc3c5c6
3 changed files with 93 additions and 1 deletions

View File

@ -28,6 +28,7 @@
#include <glibmm/threads.h>
#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<Request> RequestBuffer;
typedef PBD::RingBuffer<Request*> RequestBuffer;
RequestBuffer requests;
void process_requests ();
void process_request (Request*);
};
namespace Properties {

View File

@ -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 ();

View File

@ -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 */
}