Loading...
Searching...
No Matches
plugins/score-plugin-controlsurface/ControlSurface/commands.hpp
1#pragma once
2#include <Process/Dataflow/Port.hpp>
3#include <Process/Dataflow/PortFactory.hpp>
4
5#include <Explorer/Explorer/DeviceExplorerModel.hpp>
6
7#include <ControlSurface/CommandFactory.hpp>
8#include <ControlSurface/Process.hpp>
9
10#include <score/application/GUIApplicationContext.hpp>
11#include <score/command/AggregateCommand.hpp>
12#include <score/document/DocumentContext.hpp>
13#include <score/model/path/PathSerialization.hpp>
14#include <score/plugins/SerializableHelpers.hpp>
15#include <score/plugins/SerializableInterface.hpp>
16#include <score/tools/IdentifierGeneration.hpp>
17
18namespace ControlSurface
19{
20
22{
23 SCORE_COMMAND_DECL(CommandFactoryName(), AddControlMacro, "Add controls")
24};
25
27{
28 SCORE_COMMAND_DECL(CommandFactoryName(), AddControl, "Add a control")
29public:
31 const score::DocumentContext& ctx, Id<Process::Port> id, const Model& proc,
32 const State::Message& p)
33 : m_model{proc}
34 , m_id{std::move(id)}
35 , m_addr{Explorer::makeFullAddressAccessorSettings(p.address, ctx, 0., 1., 0.5)}
36 {
37 m_addr.value = p.value;
38 }
39
40 void undo(const score::DocumentContext& ctx) const override
41 {
42 auto& proc = m_model.find(ctx);
43 proc.removeControl(m_id);
44 }
45
46 void redo(const score::DocumentContext& ctx) const override
47 {
48 auto& proc = m_model.find(ctx);
49 proc.addControl(m_id, m_addr);
50 }
51
52private:
53 void serializeImpl(DataStreamInput& s) const override
54 {
55 s << m_model << m_id << m_addr;
56 }
57
58 void deserializeImpl(DataStreamOutput& s) override { s >> m_model >> m_id >> m_addr; }
59
60 Path<Model> m_model;
63};
64
66{
67 SCORE_COMMAND_DECL(CommandFactoryName(), RemoveControl, "Remove a control")
68public:
69 RemoveControl(const Model& proc, const Process::Port& p)
70 : m_model{proc}
71 , m_id{p.id()}
72 , m_addr{proc.outputAddresses().at(p.id().val())}
73 , m_data{DataStreamReader::marshall(p)}
74 {
75 }
76
77 void undo(const score::DocumentContext& ctx) const override
78 {
79 auto& proc = m_model.find(ctx);
80
81 static auto& cl = ctx.app.components.interfaces<Process::PortFactoryList>();
82 Process::Port* ctl = deserialize_interface(cl, DataStreamWriter{m_data}, &proc);
83
84 proc.setupControl(safe_cast<Process::ControlInlet*>(ctl), m_addr);
85 }
86
87 void redo(const score::DocumentContext& ctx) const override
88 {
89 auto& proc = m_model.find(ctx);
90 proc.removeControl(m_id);
91 }
92
93private:
94 void serializeImpl(DataStreamInput& s) const override
95 {
96 s << m_model << m_id << m_data;
97 }
98
99 void deserializeImpl(DataStreamOutput& s) override { s >> m_model >> m_id >> m_data; }
100
101 Path<Model> m_model;
104 QByteArray m_data;
105};
106
107}
Definition plugins/score-plugin-controlsurface/ControlSurface/commands.hpp:27
Definition plugins/score-plugin-controlsurface/ControlSurface/commands.hpp:22
Definition score-plugin-controlsurface/ControlSurface/Process.hpp:86
Definition plugins/score-plugin-controlsurface/ControlSurface/commands.hpp:66
Definition DataStreamVisitor.hpp:202
The Path class is a typesafe wrapper around ObjectPath.
Definition Path.hpp:52
Definition PortFactory.hpp:74
Definition Port.hpp:102
The id_base_t class.
Definition Identifier.hpp:57
Allows for grouping of multiple commands in a single one.
Definition AggregateCommand.hpp:15
The Command class.
Definition Command.hpp:34
@ ControlSurface
The process supports being exposed to the ControlSurface.
Definition ProcessFlags.hpp:37
Definition DataStreamHelpers.hpp:99
Definition DataStreamHelpers.hpp:103
Definition AddressSettings.hpp:131
Definition Address.hpp:108
The Message struct.
Definition Message.hpp:15
Definition DocumentContext.hpp:18