OSSIA
Open Scenario System for Interactive Application
qml_device.hpp
1 #pragma once
2 #include <ossia/detail/config.hpp>
3 
4 #include <ossia/network/context_functions.hpp>
5 
6 #include <QObject>
7 #include <QPointer>
8 #include <QVariantMap>
9 
10 #include <ossia/detail/hash_map.hpp>
11 
12 #include <verdigris>
13 namespace ossia
14 {
15 namespace net
16 {
17 class device_base;
18 }
19 namespace net
20 {
21 class generic_device;
22 }
23 namespace net
24 {
25 class multiplex_protocol;
26 }
27 namespace qt
28 {
29 
30 template <typename T>
31 using qpointer_set = ossia::hash_map<T*, QPointer<T>>;
32 
33 class qml_node;
34 class qml_parameter;
35 class qml_property;
36 class qml_signal;
37 class qml_property_reader;
38 class qml_property_writer;
39 class qml_model_property;
40 class qml_node_base;
41 class qml_binding;
42 class qml_callback;
43 class OSSIA_EXPORT qml_device : public QObject
44 {
45  W_OBJECT(qml_device)
46 public:
47  qml_device(QObject* parent = nullptr);
48  ~qml_device();
49 
50  void timerEvent(QTimerEvent* ev);
51 
52  ossia::net::device_base& device();
53  const ossia::net::device_base& device() const;
54  ossia::net::multiplex_protocol* localProtocol() const;
55 
56  bool readPreset() const;
57 
58  void add(qml_node* n);
59  void remove(qml_node* n);
60  void add(qml_property* n);
61  void remove(qml_property* n);
62  void add(qml_parameter* n);
63  void remove(qml_parameter* n);
64  void add(qml_signal* n);
65  void remove(qml_signal* n);
66 
67  void add(qml_property_reader* n);
68  void remove(qml_property_reader* n);
69  void add(qml_property_writer* n);
70  void remove(qml_property_writer* n);
71  void add(qml_model_property* n);
72  void remove(qml_model_property* n);
73  void add(qml_binding* n);
74  void remove(qml_binding* n);
75  void add(qml_callback* n);
76  void remove(qml_callback* n);
77 
78  QString name() const;
79 
80  const qpointer_set<qml_model_property>& models() const { return m_models; }
81 
82  bool openOSC(const QString& ip, int localPort, int remotePort);
83  W_INVOKABLE(openOSC)
84  bool openOSCQueryServer(int WSport, int oscPort);
85  W_INVOKABLE(openOSCQueryServer)
86  bool openOSCQueryClient(const QString& address, int localOscPort);
87  W_INVOKABLE(openOSCQueryClient)
88  bool openMIDIInputDevice(int device);
89  W_INVOKABLE(openMIDIInputDevice)
90  bool openMIDIOutputDevice(int device);
91  W_INVOKABLE(openMIDIOutputDevice)
92  QVariantMap getMIDIInputDevices() const;
93  W_INVOKABLE(getMIDIInputDevices)
94  QVariantMap getMIDIOutputDevices() const;
95  W_INVOKABLE(getMIDIOutputDevices)
96 
97  void recreate(QObject* root);
98  W_INVOKABLE(recreate)
99  void remap(QObject* root);
100  W_INVOKABLE(remap)
101 
102  void setReadPreset(bool readPreset);
103  W_INVOKABLE(setReadPreset)
104 
105  void savePreset(const QUrl& file);
106  W_INVOKABLE(savePreset)
107  void loadPreset(QObject* root, const QString& file);
108  W_INVOKABLE(loadPreset)
109  void saveDevice(const QUrl& file);
110  W_INVOKABLE(saveDevice)
111 
112  void setName(QString name);
113  W_INVOKABLE(setName)
114 
115  void cleanup();
116  W_INVOKABLE(cleanup)
117 
118  void readPresetChanged(bool readPreset)
119  E_SIGNAL(OSSIA_EXPORT, readPresetChanged, readPreset)
120 
121  void presetFinishedLoading() E_SIGNAL(
122  OSSIA_EXPORT, presetFinishedLoading) void presetFailedLoading(QString err)
123  E_SIGNAL(OSSIA_EXPORT, presetFailedLoading, err)
124 
125  void nameChanged(QString name)
126  E_SIGNAL(OSSIA_EXPORT, nameChanged, name)
127 
128  W_PROPERTY(
129  bool,
130  readPreset READ readPreset WRITE setReadPreset NOTIFY
131  readPresetChanged,
132  W_Final)
133  W_PROPERTY(
134  QString,
135  name READ name WRITE setName NOTIFY nameChanged,
136  W_Final)
137 
138  private : void setupLocal();
139  void clearEmptyElements();
140 
141  QString m_name{"device"};
142  ossia::net::network_context_ptr m_context;
143 
144  std::unique_ptr<ossia::net::device_base> m_device;
145 
146  qpointer_set<qml_node> m_nodes;
147  qpointer_set<qml_property> m_properties;
148  qpointer_set<qml_parameter> m_parameters;
149  qpointer_set<qml_signal> m_signals;
150  qpointer_set<qml_property_reader> m_reader_properties;
151  qpointer_set<qml_property_writer> m_writer_properties;
152  qpointer_set<qml_model_property> m_models;
153  qpointer_set<qml_binding> m_bindings;
154  qpointer_set<qml_callback> m_callbacks;
155  bool m_readPreset{false};
156  bool m_loadingPreset{false};
157  void recreate_preset(QObject* root);
158 };
159 
160 class OSSIA_EXPORT qml_singleton_device : public qml_device
161 {
162  W_OBJECT(qml_singleton_device)
163 public:
164  static qml_singleton_device& instance();
165 
166 private:
167  qml_singleton_device();
168  ~qml_singleton_device();
169 };
170 }
171 }
172 W_REGISTER_ARGTYPE(ossia::qt::qml_device*)
Root of a device tree.
Definition: ossia/network/base/device.hpp:58
A protocol used to expose a local application's data through multiple other protocols.
Definition: local.hpp:22
Definition: git_info.h:7