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:
parent
e3ff81efcb
commit
8baaa7eb66
@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
@ -375,6 +376,7 @@ class LIBARDOUR_API Trigger : public PBD::Stateful {
|
|||||||
void* ui () const { return _ui; }
|
void* ui () const { return _ui; }
|
||||||
|
|
||||||
TriggerBox& box() const { return _box; }
|
TriggerBox& box() const { return _box; }
|
||||||
|
std::shared_ptr<TriggerBox> boxptr() const;
|
||||||
|
|
||||||
double estimated_tempo() const { return _estimated_tempo; }
|
double estimated_tempo() const { return _estimated_tempo; }
|
||||||
|
|
||||||
@ -731,7 +733,7 @@ struct CueRecord {
|
|||||||
|
|
||||||
typedef PBD::RingBuffer<CueRecord> CueRecords;
|
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:
|
public:
|
||||||
|
|
||||||
@ -979,14 +981,18 @@ class LIBARDOUR_API TriggerBox : public Processor
|
|||||||
|
|
||||||
class TriggerReference
|
class TriggerReference
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TriggerReference () : box (0), slot (0) {}
|
TriggerReference () : _slot (0) {}
|
||||||
TriggerReference (ARDOUR::TriggerBox& b, uint32_t s) : box (&b), slot (s) {}
|
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;
|
private:
|
||||||
uint32_t slot;
|
std::weak_ptr<ARDOUR::TriggerBox> weak_box;
|
||||||
|
uint32_t _slot;
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace Properties {
|
namespace Properties {
|
||||||
|
@ -268,6 +268,12 @@ Trigger::Trigger (uint32_t n, TriggerBox& b)
|
|||||||
copy_to_ui_state ();
|
copy_to_ui_state ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<TriggerBox>
|
||||||
|
Trigger::boxptr() const
|
||||||
|
{
|
||||||
|
return _box.shared_from_this();
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Trigger::request_trigger_delete (Trigger* t)
|
Trigger::request_trigger_delete (Trigger* t)
|
||||||
{
|
{
|
||||||
@ -5133,3 +5139,4 @@ TriggerBoxThread::delete_trigger (Trigger* t)
|
|||||||
{
|
{
|
||||||
delete t;
|
delete t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user