OSSIA
Open Scenario System for Interactive Application
qml_interval.hpp
1 #pragma once
3 
4 #include <ossia-qt/score/qml_cond.hpp>
5 #include <ossia-qt/score/qml_sync.hpp>
6 #include <ossia-qt/score/qml_util.hpp>
7 
8 #include <QQmlListProperty>
9 #include <QQuickItem>
10 
11 #include <verdigris>
12 namespace ossia
13 {
14 namespace qt
15 {
16 class qml_cond;
17 class qml_scenario;
18 class qml_process;
19 
20 template <typename T>
21 T findParent(QObject* obj)
22 {
23  while((obj = obj->parent()))
24  {
25  if(auto ok = qobject_cast<T>(obj))
26  return ok;
27  }
28  return nullptr;
29 }
30 
31 class qml_interval : public QQuickItem
32 {
33  W_OBJECT(qml_interval)
34 
35 public:
36  qml_interval(QQuickItem* parent = nullptr);
37  ~qml_interval() override;
38 
39  qint32 nominalDuration() const;
40  qint32 minDuration() const;
41  qint32 maxDuration() const;
42  qint32 playDuration() const;
43  qml_cond* follows() const;
44  qml_cond* precedes() const;
45 
46  std::shared_ptr<ossia::time_interval> interval() const;
47  double speed() const;
48 
49  void setup();
50  void registerProcess(qml_process*);
51  void unregisterProcess(qml_process*);
52  std::shared_ptr<ossia::time_interval> m_interval;
53 
54 public:
55  void setNominalDuration(qint32 nominalDuration);
56  W_SLOT(setNominalDuration);
57  void setMinDuration(qint32 minDuration);
58  W_SLOT(setMinDuration);
59  void setMaxDuration(qint32 maxDuration);
60  W_SLOT(setMaxDuration);
61  void setPlayDuration(qint32 playDuration);
62  W_SLOT(setPlayDuration);
63  void setFollows(qml_cond* follows);
64  W_SLOT(setFollows);
65  void setPrecedes(qml_cond* precedes);
66  W_SLOT(setPrecedes);
67  void setFollows(qml_sync* follows);
68  W_SLOT(setFollows);
69  void setPrecedes(qml_sync* precedes);
70  W_SLOT(setPrecedes);
71  void setFollows(QObject* follows);
72  W_SLOT(setFollows);
73  void setPrecedes(QObject* precedes);
74  W_SLOT(setPrecedes);
75  void setSpeed(double speed);
76  W_SLOT(setSpeed);
77 
78  void play();
79  W_SLOT(play);
80  void pause();
81  W_SLOT(pause);
82  void stop();
83  W_SLOT(stop);
84 
85 public:
86  void nominalDurationChanged(qint32 nominalDuration)
87  E_SIGNAL(OSSIA_EXPORT, nominalDurationChanged, nominalDuration);
88  void minDurationChanged(qint32 minDuration)
89  E_SIGNAL(OSSIA_EXPORT, minDurationChanged, minDuration);
90  void maxDurationChanged(qint32 maxDuration)
91  E_SIGNAL(OSSIA_EXPORT, maxDurationChanged, maxDuration);
92  void playDurationChanged(qint32 playDuration)
93  E_SIGNAL(OSSIA_EXPORT, playDurationChanged, playDuration);
94  void followsChanged(qml_cond* follows) E_SIGNAL(OSSIA_EXPORT, followsChanged, follows);
95  void precedesChanged(qml_cond* precedes)
96  E_SIGNAL(OSSIA_EXPORT, precedesChanged, precedes);
97  void speedChanged(double speed) E_SIGNAL(OSSIA_EXPORT, speedChanged, speed);
98 
99 private:
100  void reset();
101  qint32 m_nominalDuration{};
102  qint32 m_minDuration{0};
103  qint32 m_maxDuration{ossia::qt::infinite()};
104  qint32 m_playDuration{};
105  qml_cond* m_follows{};
106  qml_cond* m_precedes{};
107  qml_process* m_parent{};
108 
109  double m_speed;
110 
111  W_PROPERTY(QObject*, precedes READ precedes WRITE setPrecedes NOTIFY precedesChanged)
112 
113  W_PROPERTY(QObject*, follows READ follows WRITE setFollows NOTIFY followsChanged)
114 
115  W_PROPERTY(double, speed READ speed WRITE setSpeed NOTIFY speedChanged)
116 
117  W_PROPERTY(
118  qint32,
119  playDuration READ playDuration WRITE setPlayDuration NOTIFY playDurationChanged)
120 
121  W_PROPERTY(
122  qint32,
123  maxDuration READ maxDuration WRITE setMaxDuration NOTIFY maxDurationChanged)
124 
125  W_PROPERTY(
126  qint32,
127  minDuration READ minDuration WRITE setMinDuration NOTIFY minDurationChanged)
128 
129  W_PROPERTY(
130  qint32, nominalDuration READ nominalDuration WRITE setNominalDuration NOTIFY
131  nominalDurationChanged)
132 };
133 }
134 }
Definition: git_info.h:7