Loading...
Searching...
No Matches
EditContext.hpp
1#pragma once
2#include <Process/Dataflow/CableData.hpp>
3#include <Process/TimeValue.hpp>
4
5#include <score/document/DocumentContext.hpp>
6
7#include <ossia-qt/js_utilities.hpp>
8
9#include <QJSValue>
10#include <QList>
11#include <QObject>
12#include <QStringList>
13#include <QVariant>
14
15#include <score_plugin_js_export.h>
16
17#include <memory>
18#include <verdigris>
19namespace score
20{
21struct DocumentContext;
22class Command;
23}
24namespace Scenario::Command
25{
26class Macro;
27}
28namespace JS
29{
30class GlobalDeviceEnumerator;
31class DeviceListener;
32class SCORE_PLUGIN_JS_EXPORT EditJsContext : public QObject
33{
34 W_OBJECT(EditJsContext)
36
37 std::unique_ptr<Macro> m_macro;
38 struct MacroClear
39 {
41 std::unique_ptr<Macro>& macro;
42 bool clearOnDelete{};
43 ~MacroClear();
44 };
45
46 MacroClear macro(const score::DocumentContext& doc);
47
48public:
51
55 const score::DocumentContext* ctx();
56 W_INVOKABLE(ctx);
57
59 QJSValue controls() const noexcept;
60 W_PROPERTY(QJSValue, Controls READ controls)
61 QJSValue triggers() const noexcept;
62 W_PROPERTY(QJSValue, Triggers READ triggers)
63 QJSValue conditions() const noexcept;
64 W_PROPERTY(QJSValue, Conditions READ conditions)
66 void setNamespaces(QJSValue ns);
67
71 QObject* device(QString name);
72 W_SLOT(device)
73
74
77 QVariant deviceSettings(QString name);
78 W_SLOT(deviceSettings)
79
80 QString deviceToJson(QString addr);
81 W_SLOT(deviceToJson)
82
83 QString deviceToOSCQuery(QString addr);
84 W_SLOT(deviceToOSCQuery)
85
86 void createDevice(QString name, QString uuid, QJSValue obj);
87 W_SLOT(createDevice, (QString, QString, QJSValue))
88
89 void createDevice(QString name, QString uuid, QVariant obj);
90 W_SLOT(createDevice, (QString, QString, QVariant))
91
92 void createOSCDevice(QString name, QString host, int in, int out);
93 W_SLOT(createOSCDevice)
94
95 void connectOSCQueryDevice(QString name, QString host);
96 W_SLOT(connectOSCQueryDevice)
97
98 void removeDevice(QString name);
99 W_SLOT(removeDevice)
100
101 void createQMLWebSocketDevice(QString name, QString text);
102 W_SLOT(createQMLWebSocketDevice)
103
104 void createQMLSerialDevice(QString name, QString port, QString text);
105 W_SLOT(createQMLSerialDevice)
106
107 GlobalDeviceEnumerator* enumerateDevices();
108 W_SLOT(enumerateDevices, ())
109
110 GlobalDeviceEnumerator* enumerateDevices(const QString& protocol);
111 W_SLOT(enumerateDevices, (const QString&))
112
113 GlobalDeviceEnumerator* enumerateDevices(const QStringList& protocols);
114 W_SLOT(enumerateDevices, (const QStringList&))
115
116 DeviceListener* listenDevice(const QString& name);
117 W_SLOT(listenDevice, (const QString&))
118
119 void iterateDevice(const QString& name, const QJSValue& op);
120 W_SLOT(iterateDevice, (const QString&, const QJSValue&))
121
122 void setDeviceLearn(const QString& name, bool learn);
123 W_SLOT(setDeviceLearn, (const QString&, bool))
127 void createAddress(QString addr, QString type);
128 W_SLOT(createAddress)
129
130
133 void setUnit(QString addr, QString unit);
134 W_SLOT(setUnit)
135
136 QObject* createProcess(QObject* interval, QString name, QString data);
137 W_SLOT(createProcess)
138
139
140 int processes(QObject* obj);
141 W_SLOT(processes)
142
143
145 QObject* process(QObject* obj, int index);
146 W_SLOT(process)
147
148
151 QObject* parentProcess(QObject* obj);
152 W_SLOT(parentProcess)
153
154
156 QObject* parentInterval(QObject* obj);
157 W_SLOT(parentInterval)
158
159 void loadPreset(QObject* process, QString json);
160 W_SLOT(loadPreset)
161 QString savePreset(QObject* process);
162 W_SLOT(savePreset)
163
164 void setName(QObject* sel, QString new_name);
165 W_SLOT(setName)
166
167
168 void setComment(QObject* sel, QString comment);
169 W_SLOT(setComment)
170
171 QObject* createBox(QObject* obj, QString startTime, QString duration, double y);
172 W_SLOT(createBox, (QObject*, QString, QString, double))
173
174 QObject*
175 createBox(QObject* obj, double startTimeFlicks, double durationFlicks, double y);
176 W_SLOT(createBox, (QObject*, double, double, double))
177
178 QObject* createState(QObject* ev, double y);
179 W_SLOT(createState)
180
181 QObject* createIntervalAfter(QObject* obj, QString duration, double y);
182 W_SLOT(createIntervalAfter)
183
184 QObject* createIntervalBetween(QObject* startState, QObject* endState);
185 W_SLOT(createIntervalBetween)
186
187 // Triggers and conditions.
188 // A trigger lives on a time sync; intervals (their end), states and events
189 // resolve to theirs. A condition lives on an event; states resolve to theirs.
190 void enableTrigger(QObject* obj);
191 W_SLOT(enableTrigger)
192 void disableTrigger(QObject* obj);
193 W_SLOT(disableTrigger)
194 void enableCondition(QObject* obj);
195 W_SLOT(enableCondition)
196 void disableCondition(QObject* obj);
197 W_SLOT(disableCondition)
201 void setExpression(QObject* obj, QString expression);
202 W_SLOT(setExpression)
203 QString expression(QObject* obj);
204 W_SLOT(expression)
205
206
207 void setScriptable(QObject* obj, bool scriptable);
208 W_SLOT(setScriptable)
209 QString scriptableAddress(QObject* obj);
210 W_SLOT(scriptableAddress)
211 void trigger(QObject* obj);
212 W_SLOT(trigger)
213
214 void setIntervalDuration(QObject* object, TimeVal flicks);
215 W_SLOT(setIntervalDuration)
216 void setIntervalMinDuration(QObject* object, TimeVal flicks);
217 W_SLOT(setIntervalMinDuration)
218 void setIntervalMaxDuration(QObject* object, TimeVal flicks);
219 W_SLOT(setIntervalMaxDuration)
220 void setIntervalMaxInfinite(QObject* object, bool);
221 W_SLOT(setIntervalMaxInfinite)
222 void setIntervalSpeed(QObject* object, double);
223 W_SLOT(setIntervalSpeed)
224
225 void setAutoTrigger(QObject* timeSync, bool);
226 W_SLOT(setAutoTrigger)
227
228 void setProcessLoop(QObject* process, bool);
229 W_SLOT(setProcessLoop)
230
231
233 QObject* port(QObject* obj, QString name);
234 W_SLOT(port)
235
236 QObject* inlet(QObject* obj, int index);
237 W_SLOT(inlet, (QObject*, int))
238
239
240 QObject* inlet(QObject* obj, QString name);
241 W_SLOT(inlet, (QObject*, QString))
242
243 int inlets(QObject* obj);
244 W_SLOT(inlets)
245
246 QObject* outlet(QObject* obj, int index);
247 W_SLOT(outlet, (QObject*, int))
248
249
250 QObject* outlet(QObject* obj, QString name);
251 W_SLOT(outlet, (QObject*, QString))
252
253 int outlets(QObject* obj);
254 W_SLOT(outlets)
255
256 QObject* createCable(QObject* outlet, QObject* inlet);
257 W_SLOT(createCable, (QObject*, QObject*))
258 QObject* createCable(QObject* outlet, QObject* inlet, Process::CableType type);
259 W_SLOT(createCable, (QObject*, QObject*, Process::CableType))
260
261
262 QObject* cable(QObject* port, int index);
263 W_SLOT(cable, (QObject*, int))
264
265
266 int cables(QObject* port);
267 W_SLOT(cables)
268
269
270 QObject* source(QObject* cable);
271 W_SLOT(source)
272
273
274 QObject* sink(QObject* cable);
275 W_SLOT(sink)
276
277
278 QObject* cable(QObject* outlet, QObject* inlet);
279 W_SLOT(cable, (QObject*, QObject*))
280
281 void setAddress(QObject* obj, QString addr);
282 W_SLOT(setAddress)
283
284
286 void setPropagate(QObject* obj, bool propagate);
287 W_SLOT(setPropagate)
288
289 void setValue(QObject* obj, double value);
290 W_SLOT(setValue, (QObject*, double))
291
292 void setValue(QObject* obj, QVector2D value);
293 W_SLOT(setValue, (QObject*, QVector2D))
294
295 void setValue(QObject* obj, QVector3D value);
296 W_SLOT(setValue, (QObject*, QVector3D))
297
298 void setValue(QObject* obj, QVector4D value);
299 W_SLOT(setValue, (QObject*, QVector4D))
300
301 void setValue(QObject* obj, QString value);
302 W_SLOT(setValue, (QObject*, QString))
303
304 void setValue(QObject* obj, bool value);
305 W_SLOT(setValue, (QObject*, bool))
306
307 void setValue(QObject* obj, int value);
308 W_SLOT(setValue, (QObject*, int))
309
310 void setValue(QObject* obj, QList<QString> value);
311 W_SLOT(setValue, (QObject*, QList<QString>))
312
313 void setValue(QObject* obj, QList<qreal> value);
314 W_SLOT(setValue, (QObject*, QList<qreal>))
315
316 void setValue(QObject* obj, QList<QVariant> value);
317 W_SLOT(setValue, (QObject*, QList<QVariant>))
318
319
326 void editValue(QObject* obj, QVariant value);
327 W_SLOT(editValue)
328
329
330 void commitEdit();
331 W_SLOT(commitEdit)
332
333 bool pushExecutionValue(QObject* port, QVariant value);
334 W_SLOT(pushExecutionValue)
335
336 QString portName(QObject* port);
337 W_SLOT(portName)
338 QString valueType(QObject* obj);
339 W_SLOT(valueType)
340
341 double min(QObject* obj);
342 W_SLOT(min)
343
344 double max(QObject* obj);
345 W_SLOT(max)
346
347 QVector<QVariant> enumValues(QObject* obj);
348 W_SLOT(enumValues)
349
350 QObject* metadata(QObject* obj) const noexcept;
351 W_SLOT(metadata)
352
353
356 QObject* documentMetadata() const noexcept;
357 W_SLOT(documentMetadata)
358
359
361 QString documentName() const noexcept;
362 W_SLOT(documentName)
363
364
365 void setDocumentName(QString name);
366 W_SLOT(setDocumentName)
367
368 QObject* startState(QObject* obj);
369 W_SLOT(startState)
370
371 QObject* startEvent(QObject* obj);
372 W_SLOT(startEvent)
373
374 QObject* startSync(QObject* obj);
375 W_SLOT(startSync)
376
377 QObject* endState(QObject* obj);
378 W_SLOT(endState)
379
380 QObject* endEvent(QObject* obj);
381 W_SLOT(endEvent)
382
383 QObject* endSync(QObject* obj);
384 W_SLOT(endSync)
385
386 void remove(QObject* obj);
387 W_SLOT(remove)
388
389 void setCurvePoints(QObject* process, QVector<QVariantList> points);
390 W_SLOT(setCurvePoints)
391
392 void setSteps(QObject* process, QVector<double> points);
393 W_SLOT(setSteps)
394
395 QVariantList messages(QObject* state);
396 W_SLOT(messages)
397
398 void setMessages(QObject* state, QVariantList msgs);
399 W_SLOT(setMessages)
400
401 void replaceAddress(QObjectList objects, QString before, QString after);
402 W_SLOT(replaceAddress)
403
404
406 QVariantList automate(QObject* interval, QString addr);
407 W_SLOT(automate, (QObject*, QString))
408
409
411 QObject* automate(QObject* interval, QObject* port);
412 W_SLOT(automate, (QObject*, QObject*))
413
414
417 void startMacro();
418 W_SLOT(startMacro)
419
420
424 void withMacro(QJSValue fn);
425 W_SLOT(withMacro)
426
427 void endMacro();
428 W_SLOT(endMacro)
429
430
432 void registerCommandHandler(QString name, QJSValue fn);
433 W_SLOT(registerCommandHandler)
434
435
441 void pushCommand(QString name, QJSValue undoPayload, QJSValue redoPayload);
442 W_SLOT(pushCommand)
443
444 void undo();
445 W_SLOT(undo)
446
447 void redo();
448 W_SLOT(redo)
449
450
452 bool canUndo();
453 W_SLOT(canUndo)
454
455 bool canRedo();
456 W_SLOT(canRedo)
457
458
459 int undoIndex();
460 W_SLOT(undoIndex)
461
462
463 int undoCount();
464 W_SLOT(undoCount)
465
466
467 QString undoText();
468 W_SLOT(undoText)
469
470 QString redoText();
471 W_SLOT(redoText)
472
473 void load(QString path);
474 W_SLOT(load)
475
476 void save();
477 W_SLOT(save)
478
479 void saveAs(QString path);
480 W_SLOT(saveAs)
481
482
485 QObject* find(QString p);
486 W_SLOT(find)
487
488 QObject* findByLabel(QString p);
489 W_SLOT(findByLabel)
490
491
492 QObjectList references(QObject* obj);
493 W_SLOT(references)
495 QObjectList targets(QObject* obj);
496 W_SLOT(targets)
498 void rebind(QObject* obj, QString from, QString to);
499 W_SLOT(rebind)
500 QString path(QObject* obj);
501 W_SLOT(path)
502 QObject* findByPath(QString path);
503 W_SLOT(findByPath)
504
505 QObject* document();
506 W_SLOT(document)
507
508 QObject* rootInterval();
509 W_SLOT(rootInterval)
510
511 QObject* documentPlugin(QString key);
512 W_SLOT(documentPlugin)
513
514
517 void play();
518 W_SLOT(play, ())
519
520 void play(QObject* obj);
521 W_SLOT(play, (QObject*))
522
523 void pause();
524 W_SLOT(pause, ())
525
526 void resume();
527 W_SLOT(resume, ())
528
529 void stop();
530 W_SLOT(stop)
531
532 void reinitialize();
533 W_SLOT(reinitialize)
534
535 void scrub(double z);
536 W_SLOT(scrub)
537
538 QObject* transport();
539 W_INVOKABLE(transport)
540
541
543 QString readFile(QString path);
544 W_SLOT(readFile)
545
546 QString relativizeFilePath(QString path);
547 W_SLOT(relativizeFilePath)
548
549 QString locateFilePath(QString path);
550 W_SLOT(locateFilePath)
551
552
555 QObject* selectedObject();
556 W_SLOT(selectedObject)
557
558 QVariantList selectedObjects();
559 W_SLOT(selectedObjects)
560
561 void select(QObject* obj);
562 W_SLOT(select, (QObject*))
563
564 void select(QVariantList objs);
565 W_SLOT(select, (QVariantList))
566
567 void zoom(double zx, double zy);
568 W_SLOT(zoom, (double, double));
569
570 void scroll(double zx, double zy);
571 W_SLOT(scroll, (double, double));
572
574 QVariant prompt(QVariant v);
575 W_SLOT(prompt)
576
577 bool hasProcessUI(QObject* process);
578 W_SLOT(hasProcessUI)
579
580 void showProcessUI(QObject* process, bool show);
581 W_SLOT(showProcessUI)
582
583 bool hasProcessScriptEditor(QObject* process);
584 W_SLOT(hasProcessScriptEditor)
585
586 void showProcessScriptEditor(QObject* process, bool show);
587 W_SLOT(showProcessScriptEditor)
588
589
590 void setProcessScriptEditorPlacement(QObject* process, QString placement);
591 W_SLOT(setProcessScriptEditorPlacement)
592 void setProcessUIPlacement(QObject* process, QString placement);
593 W_SLOT(setProcessUIPlacement)
594
595
598 QVariantMap availableProcesses() const noexcept;
599 W_SLOT(availableProcesses)
600 QVariant availableProcessesAndPresets() const noexcept;
601 W_SLOT(availableProcessesAndPresets)
602 QVariantList libraryEntries(QString filter) const noexcept;
603 W_SLOT(libraryEntries)
604 QVariant availableProtocols() const noexcept;
605 W_SLOT(availableProtocols)
606
607 QByteArray serializeAsJson() noexcept;
608 W_SLOT(serializeAsJson)
609private:
610 void submit(Macro& m, score::Command* c);
611 QJSValue m_namespaces;
612
613 void setControlValue(QObject* obj, ossia::value value);
614};
615}
616
617W_REGISTER_ARGTYPE(QVector<QVariantList>)
618W_REGISTER_ARGTYPE(QList<QObject*>)
619W_REGISTER_ARGTYPE(JS::GlobalDeviceEnumerator*)
Definition DeviceEnumerator.hpp:138
Definition EditContext.hpp:33
Definition DeviceEnumerator.hpp:62
Definition CommandAPI.hpp:28
The Command class.
Definition Command.hpp:34
Base toolkit upon which the software is built.
Definition Application.cpp:108
Definition TimeValue.hpp:21
Definition DocumentContext.hpp:18