Loading...
Searching...
No Matches
plugins/score-plugin-media/Media/Step/commands.hpp
1#pragma once
2#include <Media/Commands/MediaCommandFactory.hpp>
3#include <Media/Step/Model.hpp>
4
5#include <score/command/Command.hpp>
6#include <score/command/PropertyCommand.hpp>
7#include <score/model/path/Path.hpp>
8#include <score/model/path/PathSerialization.hpp>
9
10#include <ossia/detail/pod_vector.hpp>
11
12namespace Media
13{
16class ChangeSteps final : public score::Command
17{
18 SCORE_COMMAND_DECL(Media::CommandFactoryName(), ChangeSteps, "Change steps")
19public:
20 ChangeSteps(const Media::Step::Model& model, const ossia::float_vector& cur)
21 : ChangeSteps{model, model.currentSequence(), cur}
22 {
23 }
24
26 const Media::Step::Model& model, int sequence, const ossia::float_vector& cur)
27 : m_model{model}
28 , m_sequence{sequence}
29 , m_old{model.sequences().at(sequence)}
30 , m_new{cur}
31 {
32 }
33
34 void undo(const score::DocumentContext& ctx) const override
35 {
36 m_model.find(ctx).setSequenceSteps(m_sequence, m_old);
37 }
38
39 void redo(const score::DocumentContext& ctx) const override
40 {
41 m_model.find(ctx).setSequenceSteps(m_sequence, m_new);
42 }
43
44 void update(const Media::Step::Model& model, ossia::float_vector&& cur)
45 {
46 m_new = std::move(cur);
47 }
48
49 void serializeImpl(DataStreamInput& s) const override
50 {
51 s << m_model << m_sequence << m_old << m_new;
52 }
53
54 void deserializeImpl(DataStreamOutput& s) override
55 {
56 s >> m_model >> m_sequence >> m_old >> m_new;
57 }
58
59private:
61 int m_sequence{};
62 ossia::float_vector m_old, m_new;
63};
64
66class SetStepCount final : public score::Command
67{
68 SCORE_COMMAND_DECL(Media::CommandFactoryName(), SetStepCount, "Set step count")
69public:
70 SetStepCount(const Step::Model& model, std::size_t count)
71 : m_model{model}
72 , m_sequence{model.currentSequence()}
73 , m_old{model.steps()}
74 , m_new{model.steps()}
75 {
76 update(model, count);
77 }
78
79 void update(const Step::Model&, std::size_t count)
80 {
81 m_new = m_old;
82 m_new.resize(std::clamp<std::size_t>(count, 1, Step::Model::maxSteps), 0.5f);
83 }
84
85 void undo(const score::DocumentContext& ctx) const override
86 {
87 m_model.find(ctx).setSequenceSteps(m_sequence, m_old);
88 }
89
90 void redo(const score::DocumentContext& ctx) const override
91 {
92 m_model.find(ctx).setSequenceSteps(m_sequence, m_new);
93 }
94
95 void serializeImpl(DataStreamInput& s) const override
96 {
97 s << m_model << m_sequence << m_old << m_new;
98 }
99
100 void deserializeImpl(DataStreamOutput& s) override
101 {
102 s >> m_model >> m_sequence >> m_old >> m_new;
103 }
104
105private:
107 int m_sequence{};
108 ossia::float_vector m_old, m_new;
109};
110
111class SetMin final : public score::PropertyCommand
112{
113 SCORE_COMMAND_DECL(Media::CommandFactoryName(), SetMin, "Set min")
114public:
115 SetMin(const Step::Model& path, double newval)
116 : score::PropertyCommand{std::move(path), "min", newval}
117 {
118 }
119};
120
121class SetMax final : public score::PropertyCommand
122{
123 SCORE_COMMAND_DECL(Media::CommandFactoryName(), SetMax, "Set max")
124public:
125 SetMax(const Step::Model& path, double newval)
126 : score::PropertyCommand{std::move(path), "max", newval}
127 {
128 }
129};
130}
Definition plugins/score-plugin-media/Media/Step/commands.hpp:17
Definition plugins/score-plugin-media/Media/Step/commands.hpp:122
Definition plugins/score-plugin-media/Media/Step/commands.hpp:112
The number of steps of the sequence shown.
Definition plugins/score-plugin-media/Media/Step/commands.hpp:67
A step sequencer with several sequences.
Definition score-plugin-media/Media/Step/Model.hpp:37
The Path class is a typesafe wrapper around ObjectPath.
Definition Path.hpp:52
The Command class.
Definition Command.hpp:34
The PropertyCommand class.
Definition PropertyCommand.hpp:21
Definition DataStreamHelpers.hpp:99
Definition DataStreamHelpers.hpp:103
Definition DocumentContext.hpp:18