PatternProperties.hpp
1 #pragma once
2 #include <Midi/Commands/CommandFactory.hpp>
3 
4 #include <score/command/Command.hpp>
5 #include <score/command/PropertyCommand.hpp>
6 #include <score/model/path/PathSerialization.hpp>
7 
8 #include <Patternist/PatternModel.hpp>
9 namespace Patternist
10 {
11 inline auto& CommandFactoryName()
12 {
13  return Midi::CommandFactoryName();
14 }
15 class UpdatePattern final : public score::Command
16 {
17  SCORE_COMMAND_DECL(Midi::CommandFactoryName(), UpdatePattern, "Update a pattern")
18 public:
19  UpdatePattern(const ProcessModel& model, int p, const Pattern& pat)
20  : m_model{model}
21  , m_id{p}
22  , m_old{model.patterns()[p]}
23  , m_new{pat}
24  {
25  }
26 
27  void undo(const score::DocumentContext& ctx) const override
28  {
29  m_model.find(ctx).setPattern(m_id, m_old);
30  }
31 
32  void redo(const score::DocumentContext& ctx) const override
33  {
34  m_model.find(ctx).setPattern(m_id, m_new);
35  }
36 
37  void update(const ProcessModel& model, int p, const Pattern& pat) { m_new = pat; }
38 
39 protected:
40  void serializeImpl(DataStreamInput& s) const override
41  {
42  s << m_model << m_id << m_old << m_new;
43  }
44 
45  void deserializeImpl(DataStreamOutput& s) override
46  {
47  s >> m_model >> m_id >> m_old >> m_new;
48  }
49 
50 private:
51  Path<ProcessModel> m_model;
52  int m_id{};
53  Pattern m_old;
54  Pattern m_new;
55 };
56 
57 }
58 PROPERTY_COMMAND_T(
59  Patternist, SetPatternChannel, ProcessModel::p_channel, "Change channel")
60 SCORE_COMMAND_DECL_T(Patternist::SetPatternChannel)
61 PROPERTY_COMMAND_T(
62  Patternist, SetCurrentPattern, ProcessModel::p_currentPattern, "Change pattern")
63 SCORE_COMMAND_DECL_T(Patternist::SetCurrentPattern)
Definition: PatternModel.hpp:36
Definition: PatternProperties.hpp:16
The Command class.
Definition: Command.hpp:34
Definition: DataStreamHelpers.hpp:99
Definition: DataStreamHelpers.hpp:103
Definition: PatternModel.hpp:24
Definition: DocumentContext.hpp:18