Loading...
Searching...
No Matches
ScriptableReference.hpp
1#pragma once
2#include <State/Address.hpp>
3#include <State/Expression.hpp>
4
5#include <Process/State/MessageNode.hpp>
6
7#include <score/plugins/documentdelegate/plugin/DocumentPlugin.hpp>
8
9#include <score_lib_process_export.h>
10
11#include <ossia/detail/hash_map.hpp>
12
13#include <QPointer>
14
15#include <verdigris>
16
17#include <atomic>
18#include <cstdint>
19#include <functional>
20#include <memory>
21#include <optional>
22
23namespace ossia::net
24{
25class device_base;
26class node_base;
27class parameter_base;
28}
29
30namespace LocalTree
31{
32struct ScriptableSnapshot;
33
35enum class Recall : uint8_t
36{
37 None,
39 Stop,
41 State
42};
43
45class SCORE_LIB_PROCESS_EXPORT ScriptableTreeBase : public score::DocumentPlugin
46{
47 W_OBJECT(ScriptableTreeBase)
48public:
49 using score::DocumentPlugin::DocumentPlugin;
50 ~ScriptableTreeBase() override;
51
52 virtual ossia::net::device_base& device() const noexcept = 0;
54 virtual std::shared_ptr<const ScriptableSnapshot> snapshot() const noexcept = 0;
55 void snapshotChanged() E_SIGNAL(SCORE_LIB_PROCESS_EXPORT, snapshotChanged)
56
58 virtual QObject*
59 objectAt(const ossia::net::node_base& node, QString& member) const noexcept = 0;
60 virtual ossia::net::node_base*
61 nodeOf(const QObject& object, const QString& member) const noexcept = 0;
62
64 virtual std::vector<QObject*> referrers(const QObject& target) const = 0;
66 virtual std::vector<QObject*> targets(const QObject& referrer) const = 0;
67
70 virtual void follow(QObject& referrer) = 0;
71
74 virtual ossia::net::parameter_base*
75 reserve(const ::State::Address& address, const ossia::value& sample) = 0;
76
78 void setEmphasized(std::vector<const QObject*> objects);
79 bool emphasized(const QObject& object) const noexcept;
80 void emphasisChanged() E_SIGNAL(SCORE_LIB_PROCESS_EXPORT, emphasisChanged)
82 void published(QObject* object) E_SIGNAL(SCORE_LIB_PROCESS_EXPORT, published, object)
84 void referencesChanged(QObject* referrer)
85 E_SIGNAL(SCORE_LIB_PROCESS_EXPORT, referencesChanged, referrer)
86 void executionStarted() E_SIGNAL(SCORE_LIB_PROCESS_EXPORT, executionStarted)
88 void executionStopped() E_SIGNAL(SCORE_LIB_PROCESS_EXPORT, executionStopped)
89
91 virtual bool hasPlayedValues() const noexcept = 0;
93 virtual void keepPlayedValues() = 0;
94 void playedValuesChanged() E_SIGNAL(SCORE_LIB_PROCESS_EXPORT, playedValuesChanged)
95
97 Recall recall() const noexcept { return m_recall.load(std::memory_order_acquire); }
99 uint32_t runsEnded() const noexcept
100 {
101 return m_runsEnded.load(std::memory_order_acquire);
102 }
104 Recall recallAt(Recall recall, uint32_t run) const noexcept
105 {
106 return (recall == Recall::None && run != runsEnded()) ? Recall::Stop : recall;
107 }
108
109protected:
110 std::atomic<Recall> m_recall{Recall::None};
111 std::atomic<uint32_t> m_runsEnded{};
112
113private:
115 ossia::hash_map<const QObject*, QPointer<const QObject>> m_emphasized;
116};
117
119SCORE_LIB_PROCESS_EXPORT bool anchor(::State::Address& a, const score::DocumentContext& ctx);
120SCORE_LIB_PROCESS_EXPORT bool
123SCORE_LIB_PROCESS_EXPORT void anchor(::State::Expression& e, const score::DocumentContext& ctx);
124
127SCORE_LIB_PROCESS_EXPORT void settle(::State::Address& a, const score::DocumentContext& ctx);
128SCORE_LIB_PROCESS_EXPORT void
131SCORE_LIB_PROCESS_EXPORT void settle(::State::Expression& e, const score::DocumentContext& ctx);
133SCORE_LIB_PROCESS_EXPORT bool
135
137SCORE_LIB_PROCESS_EXPORT ::State::Address
138derive(const ::State::Anchor& a, const score::DocumentContext& ctx);
139
141SCORE_LIB_PROCESS_EXPORT QObject* publishedObject(
142 const ::State::Address& a, const score::DocumentContext& ctx, QString& member);
143
146SCORE_LIB_PROCESS_EXPORT std::optional<bool>
147published(const ::State::Address& a, const score::DocumentContext& ctx);
151{
152 Found,
155 NoDevice,
156 NoNode
157};
158SCORE_LIB_PROCESS_EXPORT AddressStatus
159addressStatus(const ::State::Address& a, const score::DocumentContext& ctx);
161SCORE_LIB_PROCESS_EXPORT QString describe(AddressStatus s);
162SCORE_LIB_PROCESS_EXPORT bool broken(const ::State::Address& a, const score::DocumentContext& ctx);
165SCORE_LIB_PROCESS_EXPORT bool
166isProcessState(const ::State::Address& a, const score::DocumentContext& ctx);
167
170using AnchorMapping = std::function<std::shared_ptr<const ::State::Anchor>(
171 const std::shared_ptr<const ::State::Anchor>&)>;
172SCORE_LIB_PROCESS_EXPORT void mapAnchors(Process::MessageNode& n, const AnchorMapping& f);
173SCORE_LIB_PROCESS_EXPORT void mapAnchors(::State::Expression& e, const AnchorMapping& f);
174
175using AddressMapping
176 = std::function<std::optional<::State::AddressAccessor>(const ::State::AddressAccessor&)>;
178SCORE_LIB_PROCESS_EXPORT void
179mapAddresses(::State::Expression& e, const AddressMapping& map, bool& changed);
180
183SCORE_LIB_PROCESS_EXPORT ::State::Address
184derived(const ::State::Address& a, const score::DocumentContext& ctx);
185SCORE_LIB_PROCESS_EXPORT ::State::AddressAccessor
186derived(const ::State::AddressAccessor& a, const score::DocumentContext& ctx);
187}
Publishes the scriptable namespace and maps addresses to objects and back.
Definition ScriptableReference.hpp:46
uint32_t runsEnded() const noexcept
Read from any thread.
Definition ScriptableReference.hpp:99
Recall recallAt(Recall recall, uint32_t run) const noexcept
A write from a run that has ended since counts as written at its stop.
Definition ScriptableReference.hpp:104
virtual std::shared_ptr< const ScriptableSnapshot > snapshot() const noexcept=0
Copy of the namespace for scripts on other threads; GUI thread only.
Extend a document with custom data and systems.
Definition DocumentPluginBase.hpp:24
Local tree provides a way to extend the tree given through the Engine::Network::LocalDevice.
Definition BaseCallbackWrapper.hpp:9
AddressStatus
Definition ScriptableReference.hpp:151
@ Unpublished
On the local device, but nothing is published there.
bool isProcessState(const ::State::Address &a, const score::DocumentContext &ctx)
Definition ScriptableReference.cpp:253
bool anchor(::State::Address &a, const score::DocumentContext &ctx)
Anchors a local-device address to the object published there; returns whether it has an anchor.
Definition ScriptableReference.cpp:70
QObject * publishedObject(const ::State::Address &a, const score::DocumentContext &ctx, QString &member)
member receives which of the object's parameters the address is
Definition ScriptableReference.cpp:238
void settle(::State::Address &a, const score::DocumentContext &ctx)
Definition ScriptableReference.cpp:121
::State::Address derive(const ::State::Anchor &a, const score::DocumentContext &ctx)
The address the anchored object currently publishes; unset if it does not publish.
Definition ScriptableReference.cpp:318
Recall
Which state sent outside of a scenario run the values of published controls come from.
Definition ScriptableReference.hpp:36
@ Stop
The end state, sent at stop.
std::optional< bool > published(const ::State::Address &a, const score::DocumentContext &ctx)
Definition ScriptableReference.cpp:187
::State::Address derived(const ::State::Address &a, const score::DocumentContext &ctx)
Definition ScriptableReference.cpp:331
void mapAddresses(::State::Expression &e, const AddressMapping &map, bool &changed)
Replaces each address of the expression with the mapping's result, if any.
Definition ScriptableReference.cpp:281
std::function< std::shared_ptr< const ::State::Anchor >(const std::shared_ptr< const ::State::Anchor > &)> AnchorMapping
Definition ScriptableReference.hpp:171
QString describe(AddressStatus s)
What to tell the user about a status that is not Found.
Definition ScriptableReference.cpp:222
Utilities for OSSIA data structures.
Definition DeviceInterface.hpp:35
STL namespace.
Definition Address.hpp:136
The Address struct.
Definition Address.hpp:81
Definition DocumentContext.hpp:18