Loading...
Searching...
No Matches
IntervalDurations.hpp
1#pragma once
2#include <Process/TimeValue.hpp>
3
5#include <score/serialization/JSONVisitor.hpp>
6
7#include <QObject>
8
9#include <score_plugin_scenario_export.h>
10
11#include <chrono>
12#include <verdigris>
13
14class DataStream;
15class JSONObject;
16
17namespace Scenario
18{
19class IntervalModel;
20
21// A container class to separate management of the duration of a interval.
22class SCORE_PLUGIN_SCENARIO_EXPORT IntervalDurations final : public QObject
23{
24 // These dates are relative to the beginning of the interval.
25
26 SCORE_SERIALIZE_FRIENDS
27
28 W_OBJECT(IntervalDurations)
29public:
31 : m_model{model}
32 {
33 }
34
36
37 IntervalDurations& operator=(const IntervalDurations& other);
38
39 const TimeVal& defaultDuration() const { return m_defaultDuration; }
40
41 TimeVal minDuration() const
42 {
43 if(m_isMinNull)
44 return TimeVal::zero();
45 return m_minDuration;
46 }
47
48 TimeVal maxDuration() const
49 {
50 if(m_isMaxInfinite)
51 return TimeVal{TimeVal::infinity};
52 return m_maxDuration;
53 }
54
55 const double& playPercentage() const { return m_playPercentage; }
56
57 double speed() const { return m_speed; }
58
59 bool isRigid() const { return m_rigidity; }
60
61 TimeVal guiDuration() const { return m_guiDuration; }
62
63 bool isMinNull() const { return m_isMinNull; }
64
65 bool isMaxInfinite() const { return m_isMaxInfinite; }
66
67 void setDefaultDuration(const TimeVal& arg);
68 void setMinDuration(const TimeVal& arg);
69 void setMaxDuration(const TimeVal& arg);
70 void setGuiDuration(TimeVal guiDuration);
71
72 void setPlayPercentage(double arg);
73 void setRigid(bool arg);
74 void setMinNull(bool isMinNull);
75 void setMaxInfinite(bool isMaxInfinite);
76 void setSpeed(double Speed)
77 {
78 if(m_speed == Speed)
79 return;
80
81 m_speed = Speed;
82 speedChanged(Speed);
83 }
84
85 void checkConsistency();
86
87 // Modification algorithms that keep everything consistent
88 class SCORE_PLUGIN_SCENARIO_EXPORT Algorithms
89 {
90 public:
91 static void setDurationInBounds(IntervalModel& cstr, const TimeVal& time);
92 static void fixAllDurations(IntervalModel& cstr, const TimeVal& time);
93 static void changeAllDurations(IntervalModel& cstr, const TimeVal& time);
94 static void scaleAllDurations(IntervalModel& cstr, const TimeVal& time);
95 };
96
97public:
98 void defaultDurationChanged(const TimeVal& arg)
99 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, defaultDurationChanged, arg)
100 void minDurationChanged(const TimeVal& arg)
101 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, minDurationChanged, arg)
102 void maxDurationChanged(const TimeVal& arg)
103 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, maxDurationChanged, arg)
104 void playPercentageChanged(double arg)
105 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, playPercentageChanged, arg)
106 void rigidityChanged(bool arg)
107 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, rigidityChanged, arg)
108 void minNullChanged(bool isMinNull)
109 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, minNullChanged, isMinNull)
110 void maxInfiniteChanged(bool isMaxInfinite)
111 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, maxInfiniteChanged, isMaxInfinite)
112 void speedChanged(double speed)
113 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, speedChanged, speed)
114 void guiDurationChanged(TimeVal guiDuration)
115 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, guiDurationChanged, guiDuration)
116
117 PROPERTY(double, speed READ speed WRITE setSpeed NOTIFY speedChanged, W_Final)
118 PROPERTY(
119 bool,
120 isMaxInfinite READ isMaxInfinite WRITE setMaxInfinite NOTIFY maxInfiniteChanged,
121 W_Final)
122 PROPERTY(
123 bool, isMinNull READ isMinNull WRITE setMinNull NOTIFY minNullChanged, W_Final)
124 PROPERTY(bool, isRigid READ isRigid WRITE setRigid NOTIFY rigidityChanged, W_Final)
125 PROPERTY(
126 double,
127 percentage READ playPercentage WRITE setPlayPercentage NOTIFY
128 playPercentageChanged,
129 W_Final)
130 PROPERTY(
131 TimeVal,
132 guiDuration READ guiDuration WRITE setGuiDuration NOTIFY guiDurationChanged,
133 W_Final)
134 PROPERTY(
135 TimeVal, max READ maxDuration WRITE setMaxDuration NOTIFY maxDurationChanged,
136 W_Final)
137 PROPERTY(
138 TimeVal, min READ minDuration WRITE setMinDuration NOTIFY minDurationChanged,
139 W_Final)
140 PROPERTY(
141 TimeVal,
142 default READ defaultDuration WRITE setDefaultDuration NOTIFY
143 defaultDurationChanged,
144 W_Final)
145private:
146 IntervalModel& m_model;
147
148 TimeVal m_defaultDuration{TimeVal::fromMsecs(200)};
149 TimeVal m_minDuration{m_defaultDuration};
150 TimeVal m_maxDuration{m_defaultDuration};
151 TimeVal m_guiDuration{m_defaultDuration};
152
153 double m_playPercentage{}; // Between 0 and 1.
154 double m_speed{1};
155 bool m_rigidity{true};
156 bool m_isMinNull{false};
157 bool m_isMaxInfinite{false};
158};
159}
Definition VisitorInterface.hpp:53
Definition VisitorInterface.hpp:61
Definition IntervalDurations.hpp:89
Definition IntervalDurations.hpp:23
Definition IntervalModel.hpp:50
Main plug-in of score.
Definition score-plugin-dataflow/Dataflow/PortItem.hpp:13
Definition TimeValue.hpp:21