Zrythm v2.0.0-alpha.1+31.4967fd053471
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
port_observation_token.h
1// SPDX-FileCopyrightText: © 2026 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include "dsp/port_observation_cache.h"
7#include "dsp/port_observation_manager.h"
8
9#include <QPointer>
10
11namespace zrythm::dsp
12{
13
14class ObservationToken
15{
16public:
17 ObservationToken (PortObservationManager &manager, const Port &port)
18 : manager_ (&manager), port_uuid_ (port.get_uuid ()),
19 id_ (manager.register_request (port))
20 {
21 }
22
23 ~ObservationToken ()
24 {
25 if (manager_ != nullptr && id_ >= 0)
26 manager_->unregister_request (id_);
27 }
28
29 ObservationToken (const ObservationToken &) = delete;
30 ObservationToken &operator= (const ObservationToken &) = delete;
31
32 ObservationToken (ObservationToken &&other) noexcept
33 : manager_ (other.manager_), port_uuid_ (other.port_uuid_), id_ (other.id_)
34 {
35 other.manager_ = nullptr;
36 other.id_ = -1;
37 }
38
39 ObservationToken &operator= (ObservationToken &&other) noexcept
40 {
41 if (this != &other)
42 {
43 if (manager_ != nullptr && id_ >= 0)
44 manager_->unregister_request (id_);
45 manager_ = other.manager_;
46 port_uuid_ = other.port_uuid_;
47 id_ = other.id_;
48 other.manager_ = nullptr;
49 other.id_ = -1;
50 }
51 return *this;
52 }
53
54 PortUuid port_uuid () const { return port_uuid_; }
55
56 PortObservationCache &cache ()
57 {
58 if (manager_ == nullptr)
59 throw std::runtime_error ("ObservationToken: manager destroyed");
60 return manager_->cache (id_);
61 }
62
63private:
64 QPointer<PortObservationManager> manager_;
65 PortUuid port_uuid_;
66 PortObservationManager::RegistrationId id_;
67};
68
69}
Manages port observer lifecycle and runs a drain timer.
A base class for ports used for connecting processors in the DSP graph.
Definition port.h:37
Per-requester cache for drained observation data.