InterpolationProcess.hpp
1 #pragma once
2 #include <State/Address.hpp>
3 #include <State/Message.hpp>
4 #include <State/Unit.hpp>
5 #include <State/Value.hpp>
6 
7 #include <Process/ProcessMetadata.hpp>
8 #include <Process/State/MessageNode.hpp>
9 #include <Process/State/ProcessStateDataInterface.hpp>
10 
11 #include <Curve/Process/CurveProcessModel.hpp>
12 
14 #include <score/serialization/JSONVisitor.hpp>
15 
16 #include <score_plugin_scenario_export.h>
17 
18 #include <verdigris>
19 namespace Interpolation
20 {
21 class ProcessModel;
22 }
23 
24 PROCESS_METADATA(
25  , Interpolation::ProcessModel, "aa569e11-03a9-4023-92c2-b590e88fec90",
26  "Interpolation", "Interpolation", Process::ProcessCategory::Automation,
27  "Automations", "Interpolate between two states", "ossia score",
28  (QStringList{"Curve", "Automation"}), {},
29  {std::vector<Process::PortType>{Process::PortType::Message}}, QUrl(""),
30  Process::ProcessFlags::SupportsTemporal)
31 namespace Interpolation
32 {
33 class ProcessState final : public ProcessStateDataInterface
34 {
35  W_OBJECT(ProcessState)
36 public:
37  enum Point
38  {
39  Start,
40  End
41  };
42  // watchedPoint : something between 0 and 1
43  ProcessState(ProcessModel& process, Point watchedPoint, QObject* parent);
44 
45  ProcessModel& process() const;
46 
47  State::Message message() const;
48  Point point() const;
49 
50  std::vector<State::AddressAccessor> matchingAddresses() override;
51 
52  ::State::MessageList messages() const override;
53 
54  ::State::MessageList
55  setMessages(const ::State::MessageList&, const Process::MessageNode&) override;
56 
57 private:
58  Point m_point{};
59 };
60 
61 class SCORE_PLUGIN_SCENARIO_EXPORT ProcessModel final : public Curve::CurveProcessModel
62 {
63  SCORE_SERIALIZE_FRIENDS
64  PROCESS_METADATA_IMPL(Interpolation::ProcessModel)
65 
66  W_OBJECT(ProcessModel)
67 
68 public:
69  ProcessModel(
70  const TimeVal& duration, const Id<Process::ProcessModel>& id, QObject* parent);
71 
72  ~ProcessModel();
73 
74  template <typename Impl>
75  ProcessModel(Impl& vis, QObject* parent)
76  : CurveProcessModel{vis, parent}
77  , m_startState{new ProcessState{*this, ProcessState::Start, this}}
78  , m_endState{new ProcessState{*this, ProcessState::End, this}}
79  {
80  vis.writeTo(*this);
81  }
82 
83  State::AddressAccessor address() const;
84  const State::Unit& sourceUnit() const;
85 
86  ossia::value start() const;
87  ossia::value end() const;
88 
89  void setAddress(const ::State::AddressAccessor& arg);
90  void setSourceUnit(const State::Unit&);
91  void setStart(ossia::value arg);
92  void setEnd(ossia::value arg);
93 
94  QString prettyName() const noexcept override;
95  QString prettyValue(double x, double y) const noexcept override;
96 
97  bool tween() const { return m_tween; }
98  void setTween(bool tween)
99  {
100  if(m_tween == tween)
101  return;
102 
103  m_tween = tween;
104  tweenChanged(tween);
105  }
106 
107 public:
108  void addressChanged(const ::State::AddressAccessor& arg_1)
109  E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, addressChanged, arg_1)
110  void startChanged(const ossia::value& arg_1)
111  E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, startChanged, arg_1)
112  void endChanged(const ossia::value& arg_1)
113  E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, endChanged, arg_1)
114  void tweenChanged(bool tween)
115  E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, tweenChanged, tween)
116 
117 private:
119  void setDurationAndScale(const TimeVal& newDuration) noexcept override;
120  void setDurationAndGrow(const TimeVal& newDuration) noexcept override;
121  void setDurationAndShrink(const TimeVal& newDuration) noexcept override;
122 
124  ProcessState* startStateData() const noexcept override;
125  ProcessState* endStateData() const noexcept override;
126 
127  ::State::AddressAccessor m_address;
128  State::Unit m_sourceUnit;
129 
130  ossia::value m_start{};
131  ossia::value m_end{};
132 
133  ProcessState* m_startState{};
134  ProcessState* m_endState{};
135  bool m_tween = false;
136 
137  W_PROPERTY(bool, tween READ tween WRITE setTween NOTIFY tweenChanged)
138 
139  W_PROPERTY(ossia::value, end READ end WRITE setEnd NOTIFY endChanged)
140 
141  W_PROPERTY(ossia::value, start READ start WRITE setStart NOTIFY startChanged)
142 
143  W_PROPERTY(
145  address READ address WRITE setAddress NOTIFY addressChanged)
146 };
147 }
Definition: CurveProcessModel.hpp:11
virtual ProcessStateDataInterface * startStateData() const noexcept
States. The process has ownership.
Definition: score-lib-process/Process/Process.cpp:164
Definition: ProcessStateDataInterface.hpp:24
virtual State::MessageList messages() const
messages The current messages in this point of the process.
Definition: ProcessStateDataInterface.hpp:42
virtual std::vector< State::AddressAccessor > matchingAddresses()
matchingAddresses The addresses that correspond to this state.
Definition: ProcessStateDataInterface.hpp:37
virtual State::MessageList setMessages(const State::MessageList &newMessages, const Process::MessageNode &currentState)
setMessages Request a message change on behalf of the process.
Definition: ProcessStateDataInterface.hpp:50
The id_base_t class.
Definition: Identifier.hpp:57
Utilities for OSSIA data structures.
Definition: DeviceInterface.hpp:33
Definition: Address.hpp:108
The Message struct.
Definition: Message.hpp:15
Definition: Unit.hpp:18
Definition: TimeValue.hpp:21