Loading...
Searching...
No Matches
score-plugin-controlsurface/ControlSurface/Process.hpp
1#pragma once
2#include <State/Message.hpp>
3
4#include <Process/GenericProcessFactory.hpp>
5#include <Process/Process.hpp>
6
7#include <Explorer/Explorer/DeviceExplorerModel.hpp>
8
9#include <ControlSurface/Metadata.hpp>
10
11#include <ossia/detail/hash_map.hpp>
12
13#include <score_plugin_controlsurface_export.h>
14
15namespace Device
16{
17struct FullAddressAccessorSettings;
18}
19namespace Process
20{
21class ControlInlet;
22}
23
24namespace ControlSurface
25{
26template <typename Identifier, typename Func>
27struct NodeObserver : public QObject
28{
30 Func f;
31
33 : model{explorer}
34 , f{fun}
35 {
36 // TODO handle the case where the node isn't available / gets removed and added again...
37 connect(
38 &explorer, &Explorer::DeviceExplorerModel::nodeChanged, this,
39 [this](Device::Node* n) {
40 if(auto it = available.find(n); it != available.end())
41 {
42 f(n, it->second.id);
43 }
44 });
45 }
46
47 void listen(State::Address addr, Identifier identifier)
48 {
49 auto node = Device::try_getNodeFromAddress(model.rootNode(), addr);
50 if(node)
51 {
52 available[node] = {std::move(addr), std::move(identifier)};
53 }
54 else
55 {
56 missing.push_back({std::move(addr), std::move(identifier)});
57 }
58 }
59
60 void unlisten(const State::Address& addr)
61 {
62 auto it = ossia::find_if(
63 available, [&](const auto& pair) { return pair.second.accessor == addr; });
64 if(it != available.end())
65 {
66 available.erase(it);
67 }
68 else
69 {
70 auto it
71 = ossia::find_if(missing, [&](const auto& p) { return p.accessor == addr; });
72 if(it != missing.end())
73 missing.erase(it);
74 }
75 }
76
78 {
79 State::Address accessor;
80 Identifier id;
81 };
82
83 ossia::hash_map<Device::Node*, AvailableNode> available;
84 std::vector<AvailableNode> missing;
85};
86
88SCORE_PLUGIN_CONTROLSURFACE_EXPORT
89Process::ControlInlet* makeControlFromType(
91 QObject* parent);
92
93class Model final : public Process::ProcessModel
94{
95 SCORE_SERIALIZE_FRIENDS
96 PROCESS_METADATA_IMPL(ControlSurface::Model)
97 W_OBJECT(Model)
98
99public:
100 using address_map = ossia::hash_map<int32_t, State::AddressAccessor>;
101 Model(const TimeVal& duration, const Id<Process::ProcessModel>& id, QObject* parent);
102
103 template <typename Impl>
104 Model(Impl& vis, QObject* parent)
105 : Process::ProcessModel{vis, parent}
106 , m_observer{Explorer::deviceExplorerFromObject(*parent), Apply{*this}}
107 {
108 vis.writeTo(*this);
109 }
110
111 ~Model() override;
112
113 using Process::ProcessModel::inlets;
114 using Process::ProcessModel::outlets;
115
116 Process::Inlets& inlets() noexcept { return m_inlets; }
117 Process::Outlets& outlets() noexcept { return m_outlets; }
118
119 void addControl(
121 void setupControl(Process::ControlInlet* ctl, const State::AddressAccessor& addr);
122 void removeControl(const Id<Process::Port>& id);
123
124 const address_map& outputAddresses() const noexcept { return m_outputAddresses; }
125
126private:
127 QString prettyName() const noexcept override;
128
129 void setDurationAndScale(const TimeVal& newDuration) noexcept override;
130 void setDurationAndGrow(const TimeVal& newDuration) noexcept override;
131 void setDurationAndShrink(const TimeVal& newDuration) noexcept override;
132
133 address_map m_outputAddresses;
134
135 struct Apply
136 {
137 ProcessModel& model;
138 void operator()(Device::Node*, int);
139 };
140
141 NodeObserver<int, Apply> m_observer;
142};
143
145}
Definition score-plugin-controlsurface/ControlSurface/Process.hpp:94
Definition DeviceExplorerModel.hpp:67
Definition Port.hpp:218
Definition GenericProcessFactory.hpp:15
The Process class.
Definition score-lib-process/Process/Process.hpp:75
The id_base_t class.
Definition Identifier.hpp:59
Manipulation of Devices from Qt.
Definition AddressSettings.cpp:14
Base classes and tools to implement processes and layers.
Definition JSONVisitor.hpp:1115
@ ControlSurface
The process supports being exposed to the ControlSurface.
Definition ProcessFlags.hpp:37
Definition score-plugin-controlsurface/ControlSurface/Process.hpp:78
Definition score-plugin-controlsurface/ControlSurface/Process.hpp:28
Definition AddressSettings.hpp:131
Definition PortForward.hpp:23
Definition PortForward.hpp:27
Definition Address.hpp:108
The Address struct.
Definition Address.hpp:58
Definition TimeValue.hpp:21