2#include <State/Address.hpp>
4#include <Process/ProcessComponent.hpp>
6#include <LocalTree/ScriptableReference.hpp>
9#include <score/model/Component.hpp>
10#include <score/model/EntityMap.hpp>
11#include <score/plugins/Interface.hpp>
12#include <score/plugins/InterfaceList.hpp>
14#include <ossia/network/base/node.hpp>
15#include <ossia/network/base/parameter.hpp>
17#include <ossia/detail/hash_map.hpp>
21#include <score_lib_process_export.h>
23#include <nano_observer.hpp>
43class ScriptableTreeBase;
59 ossia::net::node_base& controls;
60 ossia::net::node_base& triggers;
61 ossia::net::node_base& conditions;
64 std::function<void(ossia::net::node_base&)>
retire;
67 std::function<void(ossia::net::node_base&)>
hide;
70 std::function<ossia::net::node_base*(ossia::net::node_base&,
const std::string&)>
revive;
72 std::function<void(ossia::net::node_base&,
const QObject&,
const QString&)> tag;
90inline void announceReferrer(
const ScriptableRoots& roots, QObject&
object)
97 const ScriptableRoots& roots, ossia::net::node_base& node,
const QObject&
object,
98 const QString& member = {})
101 roots.tag(node,
object, member);
104inline void retireNode(
const ScriptableRoots& roots, ossia::net::node_base& node)
108 else if(
auto parent = node.get_parent())
109 parent->remove_child(node);
115 ossia::net::parameter_base& param;
116 std::optional<ossia::net::parameter_base::callback_index> callback;
117 QMetaObject::Connection connection;
119 std::shared_ptr<bool>
alive = std::make_shared<bool>(
true);
128 virtual void write(
const ossia::value&) { }
132 QObject::disconnect(connection);
134 param.remove_callback(*callback);
138SCORE_LIB_PROCESS_EXPORT ::State::Address addressOfNode(
const ossia::net::node_base& n);
145 std::function<void()> restore;
149 void follow(
const QString& current) { active = restore && current == name; }
153 if(std::exchange(active,
false))
158SCORE_LIB_PROCESS_EXPORT
161 const QString& name);
162SCORE_LIB_PROCESS_EXPORT
163void giveName(GivenName& given,
Process::Port& port,
const QString& name);
168 const ScriptableRoots& roots, ossia::net::node_base& parent,
const QString& name,
171 ossia::net::node_base* node{};
173 node = roots.
revive(parent, name.toStdString());
175 node = parent.create_child(name.toStdString());
178 if(
auto real = QString::fromStdString(node->get_name()); real != name)
184void renameScriptableNode(ossia::net::node_base& node,
const QString& name, F&& writeBack)
186 const auto wanted = name.toStdString();
187 if(node.get_name() == wanted)
189 node.set_name(wanted);
190 if(
auto real = QString::fromStdString(node.get_name()); real != name)
199 ABSTRACT_COMPONENT_METADATA(
202 static constexpr bool is_unique =
true;
208 ossia::net::node_base* node()
const noexcept {
return m_node; }
209 ossia::net::node_base* node(
const Process::Port& port)
const noexcept;
210 ossia::net::node_base* stateNode()
const noexcept;
213 ossia::net::parameter_base* reserve(
const std::string& name,
const ossia::value& sample);
221 void keep(ossia::net::node_base& node,
bool withValue);
222 ossia::net::node_base* takeKept(
const QString& name, std::optional<ossia::value>& written);
223 void dropKept(
const QString& name);
228 void removeNode(
bool restoreNames);
230 void unpublish(
PortEntry& e,
bool restoreName);
237 ossia::net::node_base* m_node{};
239 std::unique_ptr<ParameterBinding> m_state;
240 std::vector<std::unique_ptr<PortEntry>> m_ports;
241 ossia::hash_map<const Process::Port*, PortEntry*> m_byPort;
242 std::vector<std::unique_ptr<Kept>> m_kept;
248 COMPONENT_METADATA(
"ed8196b3-c432-4405-a89b-ffc98a1e8f08")
250 using ScriptableProcessBase::ScriptableProcessBase;
278 ,
public Nano::Observer
280 COMPONENT_METADATA(
"9b9f1041-3cda-46ea-b94b-aa0d113cea83")
292 std::vector<std::pair<Process::ProcessModel*, ScriptableProcessBase*>> m_children;
302 QStringList children;
307 static std::shared_ptr<const ScriptableSnapshot> build(
const ScriptableRoots& roots);
315SCORE_LIB_PROCESS_EXPORT
bool wantsPublished(
const Process::Port&)
noexcept;
316SCORE_LIB_PROCESS_EXPORT ::State::Address
Definition ScriptableProcessComponent.hpp:198
Definition ScriptableProcessComponent.hpp:247
For processes containing other processes; others use ScriptableProcessComponent.
Definition ScriptableProcessComponent.hpp:255
Definition ScriptableProcessComponent.hpp:267
Definition ScriptableProcessComponent.hpp:279
Publishes the scriptable namespace and maps addresses to objects and back.
Definition ScriptableReference.hpp:46
Definition Process/ProcessComponent.hpp:10
The Process class.
Definition score-lib-process/Process/Process.hpp:80
The EntityMap class.
Definition EntityMap.hpp:37
Base class for plug-in interfaces.
Definition Interface.hpp:52
InterfaceList Default implementation of InterfaceListBase.
Definition InterfaceList.hpp:97
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
@ Drop
Ignored, e.g. the end state sent at stop.
@ Record
The whole run becomes one command at stop.
@ Execution
Sent to the execution only, displayed until stop.
ossia::net::node_base * createScriptableNode(const ScriptableRoots &roots, ossia::net::node_base &parent, const QString &name, F &&writeBack)
writeBack gets the name the device picked when it differs, e.g. on collision
Definition ScriptableProcessComponent.hpp:167
bool publishedWithProcess(const Process::Port &port) noexcept
Controls of a scriptable process are published whether or not flagged.
Definition ScriptableProcessComponent.cpp:836
::State::Address scriptableAddress(const Process::ProcessModel &proc)
score:/controls/<process>[/<port>|/preset]; empty when not published.
Definition ScriptableProcessComponent.cpp:819
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
Base toolkit upon which the software is built.
Definition Application.cpp:108
Definition ScriptableProcessComponent.hpp:143
void operator()()
Called when the object is unpublished but not destroyed.
Definition ScriptableProcessComponent.hpp:151
void follow(const QString ¤t)
Called when the object is renamed or published.
Definition ScriptableProcessComponent.hpp:149
Does not remove the node, so that it can be retired.
Definition ScriptableProcessComponent.hpp:114
std::shared_ptr< bool > alive
Checked by lambdas still queued on the event loop.
Definition ScriptableProcessComponent.hpp:119
virtual void write(const ossia::value &)
Applies a value as if the parameter had received it.
Definition ScriptableProcessComponent.hpp:128
Definition ScriptableProcessComponent.cpp:95
Definition ScriptableProcessComponent.cpp:78
Definition ScriptableProcessComponent.hpp:58
std::function< void(ossia::net::node_base &)> retire
The execution may still hold the parameter, so the device owner frees the node.
Definition ScriptableProcessComponent.hpp:64
std::function< ControlWrites(Recall)> writes
Edit when unset.
Definition ScriptableProcessComponent.hpp:81
std::function< void(Process::ControlInlet &, const ossia::value &)> played
Called when a value reached the execution only.
Definition ScriptableProcessComponent.hpp:87
std::function< ossia::net::node_base *(ossia::net::node_base &, const std::string &)> revive
Restores a node retired during the current run, keeping the execution's parameter valid.
Definition ScriptableProcessComponent.hpp:70
ScriptableTreeBase * tree
Notifies when playback ends.
Definition ScriptableProcessComponent.hpp:78
std::function< void(Process::ControlInlet &, const ossia::value &)> recorded
Called with the previous value before a control changes while recording.
Definition ScriptableProcessComponent.hpp:84
std::function< void(ossia::net::node_base &)> hide
Hides a node while its address still resolves.
Definition ScriptableProcessComponent.hpp:67
std::function< void(QObject &)> referrer
An object that may hold namespace addresses; registering twice is harmless.
Definition ScriptableProcessComponent.hpp:75
Definition ScriptableProcessComponent.hpp:299
QString kind
"node", "impulse" or "value"
Definition ScriptableProcessComponent.hpp:300
Copy of the namespace for scripts on other threads, rebuilt on the GUI thread.
Definition ScriptableProcessComponent.hpp:297
ossia::hash_map< QString, Entry > entries
Keyed by "<root>" for a root and "<root>/<path>" below it.
Definition ScriptableProcessComponent.hpp:305
Definition ObjectMatches.hpp:6
Definition DocumentContext.hpp:18