Loading...
Searching...
No Matches
LocalTreeDocumentPlugin.hpp
1#pragma once
2
3#include <LocalTree/Device/LocalDevice.hpp>
4#include <LocalTree/ReferenceIndex.hpp>
5#include <LocalTree/ScriptableProcessComponent.hpp>
6#include <LocalTree/ScriptableReference.hpp>
7
8#include <score/plugins/documentdelegate/plugin/DocumentPlugin.hpp>
9#include <score/tools/Metadata.hpp>
10
11#include <ossia/detail/hash_map.hpp>
12#include <ossia/detail/small_vector.hpp>
13
14#include <QPointer>
15
16#include <atomic>
17#include <memory>
18
19#include <score_plugin_engine_export.h>
20namespace score
21{
22class ModelMetadata;
23}
24
25namespace Scenario
26{
27class ProcessModel;
28class IntervalModel;
29class EventModel;
30class TimeSyncModel;
31class StateModel;
32}
33
34namespace ossia::net
35{
36class node_base;
37class parameter_base;
38}
39namespace Execution
40{
41class DocumentPlugin;
42}
43namespace score
44{
45struct DocumentContext;
46}
47namespace LocalTree
48{
49class DocumentPlugin;
50
52struct SCORE_PLUGIN_ENGINE_TEST_EXPORT StateRecall
53{
56 StateRecall(const StateRecall&) = delete;
57 StateRecall& operator=(const StateRecall&) = delete;
58
59private:
60 DocumentPlugin* m_tree{};
61};
62
63class Interval;
66class SCORE_PLUGIN_ENGINE_EXPORT DocumentPlugin final : public ScriptableTreeBase
67{
68public:
69 DocumentPlugin(const score::DocumentContext& doc, QObject* parent);
70
72
73 void init();
74
75 void on_documentClosing() override;
76 ossia::net::device_base& device() const noexcept override { return *m_localDevice; }
77
78 Protocols::LocalDevice& localDevice() { return m_localDeviceWrapper; }
79
81 std::shared_ptr<const ScriptableSnapshot> snapshot() const noexcept override;
82
83 const ReferenceIndex& references() const noexcept { return m_references; }
84 ReferenceIndex& references() noexcept { return m_references; }
85
86 std::vector<QObject*> referrers(const QObject& target) const override
87 {
88 return m_references.referrers(target);
89 }
90 std::vector<QObject*> targets(const QObject& referrer) const override
91 {
92 return m_references.targets(referrer);
93 }
94 ossia::net::parameter_base*
95 reserve(const ::State::Address& address, const ossia::value& sample) override;
96 void follow(QObject& referrer) override;
97 bool hasPlayedValues() const noexcept override;
98 void keepPlayedValues() override;
99
100 QObject*
101 objectAt(const ossia::net::node_base& node, QString& member) const noexcept override;
102 ossia::net::node_base*
103 nodeOf(const QObject& object, const QString& member) const noexcept override;
104
105 void connectToStop();
106
107private:
108 void create();
109 void cleanup();
110 void createScriptable();
111 void cleanupScriptable();
112 void anchorDocument();
113 void retire(ossia::net::node_base& node);
114 ossia::net::node_base* revive(ossia::net::node_base& parent, const std::string& name);
115 void flushRetired();
116 ControlWrites controlWrites(Recall recall);
117 void recorded(Process::ControlInlet& port, const ossia::value& before);
118 void played(Process::ControlInlet& port, const ossia::value& value);
120 std::optional<::State::AddressAccessor>
121 migrated(const ::State::AddressAccessor& a) const;
122 void commitRecorded(Recall recall);
123
124public:
127 void beginRecall(Recall recall);
128 void endRecall(Recall recall);
129
130private:
131 void tag(ossia::net::node_base& node, const QObject& object, const QString& member);
132 void onTreeChanged();
133 void onNodeChanged(ossia::net::node_base&) { onTreeChanged(); }
134 void onNodeRenamed(ossia::net::node_base&, std::string);
135 void onAttributeChanged(ossia::net::node_base&, const std::string&) { onTreeChanged(); }
136 void onParameterChanged(const ossia::net::parameter_base&) { onTreeChanged(); }
137 void rebuildSnapshot();
138
139 Interval* m_root{};
140 ScriptableInterval* m_scriptable{};
141 ossia::net::node_base* m_controls{};
142 ossia::net::node_base* m_triggers{};
143 ossia::net::node_base* m_conditions{};
144 std::vector<std::pair<ossia::net::node_base*, std::string>> m_retired;
145 bool m_flushConnected{};
146 bool m_stopConnected{};
147 std::vector<std::pair<QPointer<Process::ControlInlet>, ossia::value>> m_recorded;
149 std::vector<std::pair<QPointer<Process::ControlInlet>, ossia::value>> m_played;
150
151 void untag(const ossia::net::node_base& node);
152
153 struct Tagged
154 {
155 QPointer<QObject> object;
157 const QObject* key{};
158 QString member;
159 };
160 ossia::hash_map<const ossia::net::node_base*, Tagged> m_byNode;
161 ossia::hash_map<const QObject*, ossia::small_vector<std::pair<QString, ossia::net::node_base*>, 2>>
162 m_byObject;
163 std::shared_ptr<const ScriptableSnapshot> m_snapshot;
164 bool m_snapshotScheduled{};
165 ReferenceIndex m_references{*this};
166 std::unique_ptr<ossia::net::device_base> m_localDevice;
167 Protocols::LocalDevice m_localDeviceWrapper;
168};
169}
Definition plugins/score-plugin-engine/Execution/DocumentPlugin.hpp:61
Definition LocalTreeDocumentPlugin.hpp:67
std::vector< QObject * > referrers(const QObject &target) const override
The states, ports, events and syncs holding an address anchored to the object.
Definition LocalTreeDocumentPlugin.hpp:86
std::vector< QObject * > targets(const QObject &referrer) const override
The objects the addresses of a state, port, event or sync are anchored to.
Definition LocalTreeDocumentPlugin.hpp:90
Definition LocalTree/IntervalComponent.hpp:48
Definition ReferenceIndex.hpp:32
Tracks the processes of an interval, and the hierarchy below a scenario.
Definition ScriptableScenarioComponent.hpp:115
Publishes the scriptable namespace and maps addresses to objects and back.
Definition ScriptableReference.hpp:46
Definition LocalDevice.hpp:25
Components used for the execution of a score.
Definition PortTap.cpp:24
Local tree provides a way to extend the tree given through the Engine::Network::LocalDevice.
Definition BaseCallbackWrapper.hpp:9
ControlWrites
What a value written into a published control does.
Definition ScriptableProcessComponent.hpp:46
Recall
Which state sent outside of a scenario run the values of published controls come from.
Definition ScriptableReference.hpp:36
Base classes and tools to implement processes and layers.
Definition JSONVisitor.hpp:1115
Main plug-in of score.
Definition ConnectionsList.hpp:22
Utilities for OSSIA data structures.
Definition DeviceInterface.hpp:35
Base toolkit upon which the software is built.
Definition Application.cpp:83
STL namespace.
Copy of the namespace for scripts on other threads, rebuilt on the GUI thread.
Definition ScriptableProcessComponent.hpp:297
Scope of a state played from the UI: an undoable edit while stopped.
Definition LocalTreeDocumentPlugin.hpp:53
Definition DocumentContext.hpp:18