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 
12 namespace Media
13 {
14 class ChangeSteps final : public score::Command
15 {
16  SCORE_COMMAND_DECL(Media::CommandFactoryName(), ChangeSteps, "Change steps")
17 public:
18  ChangeSteps(const Media::Step::Model& model, const ossia::float_vector& cur)
19  : m_model{model}
20  , m_old{model.steps()}
21  , m_new{cur}
22  {
23  }
24 
25  void undo(const score::DocumentContext& ctx) const override
26  {
27  m_model.find(ctx).setSteps(m_old);
28  }
29 
30  void redo(const score::DocumentContext& ctx) const override
31  {
32  m_model.find(ctx).setSteps(m_new);
33  }
34 
35  void update(const Media::Step::Model& model, ossia::float_vector&& cur)
36  {
37  m_new = std::move(cur);
38  }
39 
40  void serializeImpl(DataStreamInput& s) const override
41  {
42  s << m_model << m_old << m_new;
43  }
44 
45  void deserializeImpl(DataStreamOutput& s) override { s >> m_model >> m_old >> m_new; }
46 
47 private:
49  ossia::float_vector m_old, m_new;
50 };
51 
53 {
54  SCORE_COMMAND_DECL(Media::CommandFactoryName(), SetStepCount, "Set step count")
55 public:
56  SetStepCount(const Step::Model& path, std::size_t newval)
57  : score::PropertyCommand{std::move(path), "stepCount", QVariant::fromValue(newval)}
58  {
59  }
60 };
62 {
63  SCORE_COMMAND_DECL(Media::CommandFactoryName(), SetStepDuration, "Set step duration")
64 public:
65  SetStepDuration(const Step::Model& path, std::size_t newval)
67  std::move(path), "stepDuration", QVariant::fromValue(newval)}
68  {
69  }
70 };
71 
72 class SetMin final : public score::PropertyCommand
73 {
74  SCORE_COMMAND_DECL(Media::CommandFactoryName(), SetMin, "Set min")
75 public:
76  SetMin(const Step::Model& path, double newval)
77  : score::PropertyCommand{std::move(path), "min", newval}
78  {
79  }
80 };
81 
82 class SetMax final : public score::PropertyCommand
83 {
84  SCORE_COMMAND_DECL(Media::CommandFactoryName(), SetMax, "Set max")
85 public:
86  SetMax(const Step::Model& path, double newval)
87  : score::PropertyCommand{std::move(path), "max", newval}
88  {
89  }
90 };
91 }
Definition: plugins/score-plugin-media/Media/Step/commands.hpp:15
Definition: plugins/score-plugin-media/Media/Step/commands.hpp:83
Definition: plugins/score-plugin-media/Media/Step/commands.hpp:73
Definition: plugins/score-plugin-media/Media/Step/commands.hpp:53
Definition: plugins/score-plugin-media/Media/Step/commands.hpp:62
Definition: score-plugin-media/Media/Step/Model.hpp:23
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