OSSIA
Open Scenario System for Interactive Application
qml_script.hpp
1 #pragma once
2 #include <ossia-qt/device/qml_device.hpp>
3 #include <ossia-qt/score/qml_autom.hpp>
4 
5 #include <QQmlScriptString>
6 
7 #include <verdigris>
8 namespace ossia
9 {
10 namespace qt
11 {
12 class qml_script_process : public ossia::time_process
13 {
14 public:
15  void state(
16  ossia::time_value date, double pos, ossia::time_value tick_offset,
17  double gspeed) override;
18 
19  QQmlExpression* expr{};
20 };
21 
22 class qml_message
23 {
24  W_OBJECT(qml_message)
25 
26 public:
27  qml_message() = default;
28  qml_message(const qml_message&) = default;
29  qml_message(qml_message&&) = default;
30  qml_message& operator=(const qml_message&) = default;
31  qml_message& operator=(qml_message&&) = default;
32  qml_message(qml_device* d, QString addr, QVariant v)
33  : m_dev{d}
34  , m_addr{addr}
35  , m_value{v}
36  {
37  }
38  qml_device* device() const { return m_dev; }
39  void setDevice(qml_device* d) { m_dev = d; }
40 
41  QString address() const { return m_addr; }
42  void setAddress(QString d) { m_addr = d; }
43 
44  QVariant value() const { return m_value; }
45  void setValue(QVariant d) { m_value = d; }
46 
47  ossia::state_element toState() const;
48 
49 private:
50  qml_device* m_dev{};
51  QString m_addr;
52  QVariant m_value;
53 
54  W_PROPERTY(QVariant, value READ value WRITE setValue)
55 
56  W_PROPERTY(QString, address READ address WRITE setAddress)
57 
58  W_PROPERTY(qml_device*, device READ device WRITE setDevice)
59 };
60 class qml_utils : public QObject
61 {
62  W_OBJECT(qml_utils)
63 
64 public:
65  using QObject::QObject;
66  Q_INVOKABLE
67  ossia::qt::qml_message message(qml_device* dev, QString addr, QVariant val)
68  {
69  return qml_message{dev, addr, val};
70  }
71 };
72 class qml_script : public qml_process
73 {
74  W_OBJECT(qml_script)
75 
76 public:
77  qml_script(QQuickItem* parent = nullptr);
78  ~qml_script() override;
79 
80  void setup() override;
81  std::shared_ptr<ossia::time_process> process() const override;
82 
83  void setDate(time_value date) { m_date = date; }
84  void setPosition(double pos) { m_pos = pos; }
85 
86  int32_t date() const { return m_date.impl; }
87  double position() const { return m_pos; }
88  QQmlScriptString script() const { return m_script; }
89  void setScript(QQmlScriptString s) { m_script = s; }
90 
91 public:
92  void dateChanged(qint32 arg_1) E_SIGNAL(OSSIA_EXPORT, dateChanged, arg_1);
93  void positionChanged(double arg_1) E_SIGNAL(OSSIA_EXPORT, positionChanged, arg_1);
94  void scriptChanged(QQmlScriptString arg_1)
95  E_SIGNAL(OSSIA_EXPORT, scriptChanged, arg_1);
96 
97 private:
98  void reset_impl() override;
99  std::shared_ptr<qml_script_process> m_impl;
100 
101  QQmlScriptString m_script;
102  time_value m_date{};
103  double m_pos{};
104 
105  W_PROPERTY(double, position READ position NOTIFY positionChanged)
106 
107  W_PROPERTY(qint32, date READ date NOTIFY dateChanged)
108 
109  W_PROPERTY(QQmlScriptString, script READ script WRITE setScript NOTIFY scriptChanged)
110 };
111 }
112 }
113 
114 Q_DECLARE_METATYPE(ossia::qt::qml_message)
115 Q_DECLARE_METATYPE(ossia::qt::qml_device*)
The time_process class.
Definition: time_process.hpp:24
virtual void state(const ossia::token_request &)=0
get a #StateElement from the process depending on its parent #time_interval date
Definition: git_info.h:7
ossia::nullable_variant< message, state, piecewise_message, piecewise_vec_message< 2 >, piecewise_vec_message< 3 >, piecewise_vec_message< 4 > > state_element
Definition: state_element_fwd.hpp:28
The time_value class.
Definition: ossia/editor/scenario/time_value.hpp:28