SetMinDuration.hpp
1 #pragma once
2 #include <Process/TimeValue.hpp>
3 
4 #include <Scenario/Commands/ScenarioCommandFactory.hpp>
5 #include <Scenario/Document/Interval/IntervalModel.hpp>
6 
7 #include <score/command/Command.hpp>
8 #include <score/model/path/Path.hpp>
9 #include <score/model/path/PathSerialization.hpp>
10 
11 #include <tests/helpers/ForwardDeclaration.hpp>
12 
13 namespace Scenario
14 {
15 class IntervalModel;
16 namespace Command
17 {
23 class SetMinDuration final : public score::Command
24 {
25  SCORE_COMMAND_DECL(CommandFactoryName(), SetMinDuration, "Set interval minimum")
26 public:
27  static const constexpr auto corresponding_member = &IntervalDurations::minDuration;
28 
29  SetMinDuration(const IntervalModel& cst, TimeVal newval, bool isMinNull)
30  : m_path{cst}
31  , m_oldVal{cst.duration.minDuration()}
32  , m_newVal{newval}
33  , m_oldMinNull{cst.duration.isMinNull()}
34  , m_newMinNull{isMinNull}
35  {
36  }
37 
38  void update(const IntervalModel& cst, TimeVal newval, bool isMinNull)
39  {
40  m_newVal = newval;
41  auto& cstrDuration = cst.duration;
42  if(m_newVal < TimeVal::zero())
43  m_newVal = TimeVal::zero();
44  if(m_newVal > cstrDuration.defaultDuration())
45  m_newVal = cstrDuration.defaultDuration();
46  }
47 
48  void undo(const score::DocumentContext& ctx) const override
49  {
50  auto& cstrDuration = m_path.find(ctx).duration;
51  cstrDuration.setMinNull(m_oldMinNull);
52  cstrDuration.setMinDuration(m_oldVal);
53  }
54 
55  void redo(const score::DocumentContext& ctx) const override
56  {
57  auto& cstrDuration = m_path.find(ctx).duration;
58  cstrDuration.setMinNull(m_newMinNull);
59  cstrDuration.setMinDuration(m_newVal);
60  }
61 
62 protected:
63  void serializeImpl(DataStreamInput& s) const override
64  {
65  s << m_path << m_oldVal << m_newVal << m_oldMinNull << m_newMinNull;
66  }
67  void deserializeImpl(DataStreamOutput& s) override
68  {
69  s >> m_path >> m_oldVal >> m_newVal >> m_oldMinNull >> m_newMinNull;
70  }
71 
72 private:
73  Path<IntervalModel> m_path;
74 
75  TimeVal m_oldVal;
76  TimeVal m_newVal;
77  bool m_oldMinNull{}, m_newMinNull{};
78 };
79 }
80 }
The Path class is a typesafe wrapper around ObjectPath.
Definition: Path.hpp:52
The SetMinDuration class.
Definition: SetMinDuration.hpp:24
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: TimeValue.hpp:21
Definition: DocumentContext.hpp:18