13
0

TriggerReference requires some sort of lifetime tracking

For now we use std::weak_ptr and std::enable_shared_from_this to accomplish tracking. There
may be an argument for using our own (PBD::Destructible) mechanisms instead.
This commit is contained in:
Paul Davis 2024-09-17 10:55:11 -06:00
parent e3ff81efcb
commit 8baaa7eb66
2 changed files with 20 additions and 7 deletions

View File

@ -23,6 +23,7 @@
#include <atomic>
#include <map>
#include <memory>
#include <vector>
#include <string>
#include <exception>
@ -375,6 +376,7 @@ class LIBARDOUR_API Trigger : public PBD::Stateful {
void* ui () const { return _ui; }
TriggerBox& box() const { return _box; }
std::shared_ptr<TriggerBox> boxptr() const;
double estimated_tempo() const { return _estimated_tempo; }
@ -731,7 +733,7 @@ struct CueRecord {
typedef PBD::RingBuffer<CueRecord> CueRecords;
class LIBARDOUR_API TriggerBox : public Processor
class LIBARDOUR_API TriggerBox : public Processor, public std::enable_shared_from_this<TriggerBox>
{
public:
@ -980,13 +982,17 @@ class LIBARDOUR_API TriggerBox : public Processor
class TriggerReference
{
public:
TriggerReference () : box (0), slot (0) {}
TriggerReference (ARDOUR::TriggerBox& b, uint32_t s) : box (&b), slot (s) {}
TriggerReference () : _slot (0) {}
TriggerReference (std::shared_ptr<ARDOUR::TriggerBox> b, uint32_t s) : weak_box (b), _slot (s) {}
std::shared_ptr<ARDOUR::Trigger> trigger() const { assert (box); return box->trigger (slot); }
std::shared_ptr<ARDOUR::Trigger> trigger() const { std::shared_ptr<ARDOUR::TriggerBox> box (weak_box.lock()); return box ? box->trigger (_slot) : std::shared_ptr<ARDOUR::Trigger>(); }
void set (std::shared_ptr<ARDOUR::TriggerBox> b, uint32_t s) { weak_box = b; _slot = s; }
uint32_t slot() const { return _slot; }
std::shared_ptr<ARDOUR::TriggerBox> box() const { return weak_box.lock(); }
ARDOUR::TriggerBox* box;
uint32_t slot;
private:
std::weak_ptr<ARDOUR::TriggerBox> weak_box;
uint32_t _slot;
};
namespace Properties {

View File

@ -268,6 +268,12 @@ Trigger::Trigger (uint32_t n, TriggerBox& b)
copy_to_ui_state ();
}
std::shared_ptr<TriggerBox>
Trigger::boxptr() const
{
return _box.shared_from_this();
}
void
Trigger::request_trigger_delete (Trigger* t)
{
@ -5133,3 +5139,4 @@ TriggerBoxThread::delete_trigger (Trigger* t)
{
delete t;
}