SignatureCommands.hpp
1 #pragma once
2 #include <Process/TimeValue.hpp>
3 #include <Process/TimeValueSerialization.hpp>
4 
5 #include <Scenario/Commands/ScenarioCommandFactory.hpp>
6 #include <Scenario/Document/Interval/IntervalModel.hpp>
7 
8 #include <score/command/Command.hpp>
9 #include <score/command/PropertyCommand.hpp>
10 #include <score/model/path/Path.hpp>
11 #include <score/model/path/PathSerialization.hpp>
12 #include <score/serialization/MapSerialization.hpp>
13 
14 namespace Scenario
15 {
16 namespace Command
17 {
18 class SetTimeSignatures final : public score::Command
19 {
20  SCORE_COMMAND_DECL(CommandFactoryName(), SetTimeSignatures, "Set time signatures")
21 public:
23  : m_path{cst}
24  , m_oldVal{cst.timeSignatureMap()}
25  , m_newVal{std::move(newval)}
26  {
27  }
28 
29  void update(const IntervalModel& cst, TimeSignatureMap newval)
30  {
31  m_newVal = std::move(newval);
32  }
33 
34  void undo(const score::DocumentContext& ctx) const override
35  {
36  m_path.find(ctx).setTimeSignatureMap(m_oldVal);
37  }
38 
39  void redo(const score::DocumentContext& ctx) const override
40  {
41  m_path.find(ctx).setTimeSignatureMap(m_newVal);
42  }
43 
44 protected:
45  void serializeImpl(DataStreamInput& s) const override
46  {
47  s << m_path << m_oldVal << m_newVal;
48  }
49  void deserializeImpl(DataStreamOutput& s) override
50  {
51  s >> m_path >> m_oldVal >> m_newVal;
52  }
53 
54 private:
55  Path<IntervalModel> m_path;
56 
57  TimeSignatureMap m_oldVal;
58  TimeSignatureMap m_newVal;
59 };
60 
62 }
63 }
64 
65 PROPERTY_COMMAND_T(
66  Scenario::Command, SetHasTimeSignature, IntervalModel::p_timeSignature,
67  "Change time signature")
68 SCORE_COMMAND_DECL_T(Scenario::Command::SetHasTimeSignature)
69 
70 PROPERTY_COMMAND_T(
71  Scenario::Command, SetIntervalQuantizationRate, IntervalModel::p_quantizationRate,
72  "Set quantization rate")
73 SCORE_COMMAND_DECL_T(Scenario::Command::SetIntervalQuantizationRate)
The Path class is a typesafe wrapper around ObjectPath.
Definition: Path.hpp:52
Definition: SignatureCommands.hpp:19
Definition: IntervalModel.hpp:50
The Command class.
Definition: Command.hpp:34
Main plug-in of score.
Definition: score-plugin-dataflow/Dataflow/PortItem.hpp:14
Definition: DataStreamHelpers.hpp:99
Definition: DataStreamHelpers.hpp:103
Definition: TimeSignatureMap.hpp:26
Definition: DocumentContext.hpp:18