Loading...
Searching...
No Matches
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
13namespace Scenario
14{
15class IntervalModel;
16namespace Command
17{
23class SetMinDuration final : public score::Command
24{
25 SCORE_COMMAND_DECL(CommandFactoryName(), SetMinDuration, "Set interval minimum")
26public:
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
62protected:
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
72private:
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:13
Definition DataStreamHelpers.hpp:99
Definition DataStreamHelpers.hpp:103
Definition TimeValue.hpp:21
Definition DocumentContext.hpp:18