diff --git a/libs/ardour/ardour/triggerbox.h b/libs/ardour/ardour/triggerbox.h index 12524be70b..0e90ee1034 100644 --- a/libs/ardour/ardour/triggerbox.h +++ b/libs/ardour/ardour/triggerbox.h @@ -244,6 +244,8 @@ class LIBARDOUR_API Trigger : public PBD::Stateful { virtual SegmentDescriptor get_segment_descriptor () const = 0; + static void request_trigger_delete (Trigger* t); + protected: struct UIRequests { std::atomic stop; @@ -432,6 +434,7 @@ class LIBARDOUR_API TriggerBoxThread static void init_request_pool() { Request::init_pool(); } void set_region (TriggerBox&, uint32_t slot, boost::shared_ptr); + void request_delete_trigger (Trigger* t); void summon(); void stop(); @@ -443,7 +446,8 @@ class LIBARDOUR_API TriggerBoxThread enum RequestType { Quit, - SetRegion + SetRegion, + DeleteTrigger }; struct Request { @@ -455,6 +459,8 @@ class LIBARDOUR_API TriggerBoxThread TriggerBox* box; uint32_t slot; boost::shared_ptr region; + /* for DeleteTrigger */ + Trigger* trigger; void* operator new (size_t); void operator delete (void* ptr, size_t); @@ -468,6 +474,7 @@ class LIBARDOUR_API TriggerBoxThread CrossThreadChannel _xthread; void queue_request (Request*); + void delete_trigger (Trigger*); }; @@ -620,6 +627,10 @@ class LIBARDOUR_API TriggerBox : public Processor Type type; + /* cannot use a union here because we need Request to have a + * "trivial" constructor. + */ + TriggerPtr trigger; void* ptr; int32_t slot; diff --git a/libs/ardour/triggerbox.cc b/libs/ardour/triggerbox.cc index c66fd95da2..8a1b67df07 100644 --- a/libs/ardour/triggerbox.cc +++ b/libs/ardour/triggerbox.cc @@ -110,6 +110,13 @@ Trigger::Trigger (uint32_t n, TriggerBox& b) add_property (_isolated); } +void +Trigger::request_trigger_delete (Trigger* t) +{ + std::cerr << "RTD\n"; + TriggerBox::worker->request_delete_trigger (t); +} + void Trigger::set_pending (Trigger* t) { @@ -2735,7 +2742,7 @@ TriggerBox::set_state (const XMLNode& node, int version) TriggerPtr trig; if (_data_type == DataType::AUDIO) { - trig = boost::make_shared (all_triggers.size(), *this); + trig.reset (new AudioTrigger (all_triggers.size(), *this), Trigger::request_trigger_delete); all_triggers.push_back (trig); trig->set_state (**t, version); } else if (_data_type == DataType::MIDI) { @@ -2918,6 +2925,9 @@ TriggerBoxThread::thread_work () case SetRegion: req->box->set_region (req->slot, req->region); break; + case DeleteTrigger: + delete_trigger (req->trigger); + break; default: break; } @@ -2976,3 +2986,19 @@ TriggerBoxThread::set_region (TriggerBox& box, uint32_t slot, boost::shared_ptr< queue_request (req); } + +void +TriggerBoxThread::request_delete_trigger (Trigger* t) +{ + std::cerr << "RDT\n"; + TriggerBoxThread::Request* req = new TriggerBoxThread::Request (DeleteTrigger); + req->trigger = t; + queue_request (req); +} + +void +TriggerBoxThread::delete_trigger (Trigger* t) +{ + std::cerr << "trigger delete for " << t << endl; + delete t; +}