From 8baaa7eb66988d7a062e6efad1905a16fe4173b1 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Tue, 17 Sep 2024 10:55:11 -0600 Subject: [PATCH] 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. --- libs/ardour/ardour/triggerbox.h | 20 +++++++++++++------- libs/ardour/triggerbox.cc | 7 +++++++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/libs/ardour/ardour/triggerbox.h b/libs/ardour/ardour/triggerbox.h index 5b6c4a2b74..6a5b9d0933 100644 --- a/libs/ardour/ardour/triggerbox.h +++ b/libs/ardour/ardour/triggerbox.h @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -375,6 +376,7 @@ class LIBARDOUR_API Trigger : public PBD::Stateful { void* ui () const { return _ui; } TriggerBox& box() const { return _box; } + std::shared_ptr boxptr() const; double estimated_tempo() const { return _estimated_tempo; } @@ -731,7 +733,7 @@ struct CueRecord { typedef PBD::RingBuffer CueRecords; -class LIBARDOUR_API TriggerBox : public Processor +class LIBARDOUR_API TriggerBox : public Processor, public std::enable_shared_from_this { public: @@ -979,14 +981,18 @@ 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) {} + public: + TriggerReference () : _slot (0) {} + TriggerReference (std::shared_ptr b, uint32_t s) : weak_box (b), _slot (s) {} - std::shared_ptr trigger() const { assert (box); return box->trigger (slot); } + std::shared_ptr trigger() const { std::shared_ptr box (weak_box.lock()); return box ? box->trigger (_slot) : std::shared_ptr(); } + void set (std::shared_ptr b, uint32_t s) { weak_box = b; _slot = s; } + uint32_t slot() const { return _slot; } + std::shared_ptr box() const { return weak_box.lock(); } - ARDOUR::TriggerBox* box; - uint32_t slot; + private: + std::weak_ptr weak_box; + uint32_t _slot; }; namespace Properties { diff --git a/libs/ardour/triggerbox.cc b/libs/ardour/triggerbox.cc index 4746229749..273e130699 100644 --- a/libs/ardour/triggerbox.cc +++ b/libs/ardour/triggerbox.cc @@ -268,6 +268,12 @@ Trigger::Trigger (uint32_t n, TriggerBox& b) copy_to_ui_state (); } +std::shared_ptr +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; } +