2 #include <State/Domain.hpp>
4 #include <Process/Dataflow/Port.hpp>
5 #include <Process/Dataflow/WidgetInlets.hpp>
7 #include <JS/Qml/QtMetatypes.hpp>
9 #if defined(SCORE_HAS_GPU_JS)
10 #include <Gfx/TexturePort.hpp>
15 #include <score/tools/Debug.hpp>
17 #include <ossia/detail/math.hpp>
18 #include <ossia/detail/ssize.hpp>
19 #include <ossia/network/domain/domain.hpp>
23 #include <QQmlListProperty>
27 #include <libremidi/message.hpp>
29 #include <score_plugin_js_export.h>
30 #include <wobjectimpl.h>
35 W_REGISTER_ARGTYPE(QJSValue)
38 class SCORE_PLUGIN_JS_EXPORT
Inlet :
public QObject
43 using QObject::QObject;
44 virtual ~
Inlet()
override;
46 virtual bool isEvent()
const {
return false; }
48 W_INLINE_PROPERTY_CREF(QString, address, {}, address, setAddress, addressChanged)
51 class SCORE_PLUGIN_JS_EXPORT
Outlet :
public QObject
56 using QObject::QObject;
57 virtual ~
Outlet()
override;
60 W_INLINE_PROPERTY_CREF(QString, address, {}, address, setAddress, addressChanged)
70 W_PROPERTY(qreal, timestamp MEMBER timestamp)
71 W_PROPERTY(QVariant, value MEMBER value)
81 W_PROPERTY(qreal, timestamp MEMBER timestamp)
82 W_PROPERTY(QJSValue, value MEMBER value)
85 class SCORE_PLUGIN_JS_EXPORT
ValueInlet :
public Inlet
90 QVariantList m_values;
93 explicit ValueInlet(QObject* parent =
nullptr);
95 QVariant value()
const;
96 QVariantList values()
const {
return m_values; }
103 int length() const noexcept;
106 QVariant at(
int index) const noexcept;
109 void clear() { m_values.clear(); }
110 void setValue(QVariant value);
111 void addValue(QVariant&& val) { m_values.append(std::move(val)); }
112 void valueChanged(QVariant value) W_SIGNAL(valueChanged, value);
114 W_PROPERTY(QVariantList, values READ values)
115 W_PROPERTY(QVariant, value READ value NOTIFY valueChanged)
118 class SCORE_PLUGIN_JS_EXPORT
ControlInlet :
public Inlet
127 QVariant value()
const noexcept;
134 void clear() { m_value = QVariant{}; }
135 virtual void setValue(QVariant value);
136 void valueChanged(QVariant value) W_SIGNAL(valueChanged, value);
138 W_PROPERTY(QVariant, value READ value NOTIFY valueChanged)
141 template <
typename Impl,
typename ValueType>
147 using ControlInlet::ControlInlet;
149 bool isEvent()
const override {
return true; }
152 return new Impl(
id, parent);
155 void clear() { m_value = {}; }
156 ValueType value() const noexcept {
return m_value; }
157 void setValue(QVariant value)
override
159 auto conv = value.value<ValueType>();
163 m_value = std::move(conv);
164 valueChanged(m_value);
166 void setValue(ValueType value)
172 valueChanged(m_value);
174 void valueChanged(ValueType value) W_SIGNAL(valueChanged, value);
176 W_PROPERTY(ValueType, value READ value NOTIFY valueChanged)
183 : JS::GenericControlInlet<Process::FloatRangeSpinBox, QVector2D>
186 using GenericControlInlet::GenericControlInlet;
189 : JS::GenericControlInlet<Process::IntRangeSlider, QVector2D>
192 using GenericControlInlet::GenericControlInlet;
195 : JS::GenericControlInlet<Process::IntRangeSpinBox, QVector2D>
198 using GenericControlInlet::GenericControlInlet;
201 : JS::GenericControlInlet<Process::HSVSlider, QVector4D>
204 using GenericControlInlet::GenericControlInlet;
206 struct SCORE_PLUGIN_JS_EXPORT
XYSlider
207 : JS::GenericControlInlet<Process::XYSlider, QVector2D>
210 using GenericControlInlet::GenericControlInlet;
213 : JS::GenericControlInlet<Process::XYZSlider, QVector3D>
216 using GenericControlInlet::GenericControlInlet;
219 : JS::GenericControlInlet<Process::XYSpinboxes, QVector2D>
222 using GenericControlInlet::GenericControlInlet;
225 : JS::GenericControlInlet<Process::XYZSpinboxes, QVector3D>
228 using GenericControlInlet::GenericControlInlet;
231 : JS::GenericControlInlet<Process::MultiSlider, QVector<qreal>>
234 using GenericControlInlet::GenericControlInlet;
237 : JS::GenericControlInlet<Process::FileChooser, QString>
240 using GenericControlInlet::GenericControlInlet;
243 : JS::GenericControlInlet<Process::AudioFileChooser, QString>
246 using GenericControlInlet::GenericControlInlet;
249 : JS::GenericControlInlet<Process::VideoFileChooser, QString>
252 using GenericControlInlet::GenericControlInlet;
255 template <
typename Impl = Process::FloatSl
ider>
263 bool isEvent()
const override {
return true; }
267 return new Impl{(float)m_min, (
float)m_max, (float)m_init,
268 this->objectName(), id, parent};
271 W_INLINE_PROPERTY_VALUE(qreal, init, {0.5}, init, setInit, initChanged)
272 W_INLINE_PROPERTY_VALUE(qreal, min, {0.}, getMin, setMin, minChanged)
273 W_INLINE_PROPERTY_VALUE(qreal, max, {1.}, getMax, setMax, maxChanged)
275 W_OBJECT_IMPL(JS::FloatSlider<Impl>, template <typename Impl>)
277 template <
typename Impl = Process::IntSl
ider>
285 bool isEvent()
const override {
return true; }
289 return new Impl{m_min, m_max, m_init, this->objectName(), id, parent};
292 W_INLINE_PROPERTY_VALUE(
int, init, {0}, init, setInit, initChanged)
293 W_INLINE_PROPERTY_VALUE(
int, min, {0}, getMin, setMin, minChanged)
294 W_INLINE_PROPERTY_VALUE(
int, max, {127}, getMax, setMax, maxChanged)
296 W_OBJECT_IMPL(JS::IntSlider<Impl>, template <typename Impl>)
303 using ControlInlet::ControlInlet;
304 virtual ~
Enum()
override;
305 bool isEvent()
const override {
return true; }
309 return new Process::Enum{m_choices, {}, current(), objectName(), id, parent};
312 auto getValues()
const {
return choices(); }
314 std::string current()
const
316 if(!m_choices.isEmpty() && ossia::valid_index(m_index, m_choices))
318 return m_choices[m_index].toStdString();
323 W_INLINE_PROPERTY_VALUE(
int, index, {}, index, setIndex, indexChanged)
324 W_INLINE_PROPERTY_CREF(QStringList, choices, {}, choices, setChoices, choicesChanged)
332 using ControlInlet::ControlInlet;
333 virtual ~
Toggle()
override;
334 bool isEvent()
const override {
return true; }
337 return new Process::Toggle{m_checked, objectName(), id, parent};
340 W_INLINE_PROPERTY_VALUE(
bool, checked, {}, checked, setChecked, checkedChanged)
348 using ControlInlet::ControlInlet;
349 virtual ~
Button()
override;
350 bool isEvent()
const override {
return true; }
353 return new Process::Button{objectName(), id, parent};
356 W_INLINE_PROPERTY_VALUE(
bool, checked, {}, checked, setChecked, checkedChanged)
364 using ControlInlet::ControlInlet;
366 bool isEvent()
const override {
return false; }
369 return new Process::ImpulseButton{objectName(), id, parent};
372 void impulse() W_SIGNAL(impulse);
380 using ControlInlet::ControlInlet;
382 bool isEvent()
const override {
return true; }
385 return new Process::LineEdit{m_text, objectName(), id, parent};
388 W_INLINE_PROPERTY_CREF(QString, text, {}, text, setText, textChanged)
398 std::vector<OutValueMessage> values;
402 const QJSValue& value()
const;
405 m_value = QJSValue{};
414 void setValue(
const QJSValue& value);
416 void addValue(qreal timestamp, QJSValue t);
419 W_PROPERTY(QJSValue, value READ value WRITE setValue)
422 class SCORE_PLUGIN_JS_EXPORT
AudioInlet :
public Inlet
427 explicit AudioInlet(QObject* parent =
nullptr);
429 const QVector<QVector<double>>& audio()
const;
430 void setAudio(
const QVector<QVector<double>>& audio);
432 QVector<double> channel(
int i)
const
434 if(m_audio.size() > i)
438 W_INVOKABLE(channel);
446 QVector<QVector<double>> m_audio;
460 p->setPropagate(
true);
464 const QVector<QVector<double>>& audio()
const;
466 void setChannel(
int i,
const QJSValue& v);
467 W_INVOKABLE(setChannel)
469 QVector<QVector<double>> m_audio;
479 W_PROPERTY(QByteArray, bytes MEMBER bytes)
482 class SCORE_PLUGIN_JS_EXPORT
MidiInlet :
public Inlet
487 explicit MidiInlet(QObject* parent =
nullptr);
489 template <
typename T>
490 void setMidi(
const T& arr)
493 for(
const libremidi::message& mess : arr)
495 const auto N = mess.size();
499 for(std::size_t i = 0; i < N; i++)
500 m[i] = mess.bytes[i];
502 m_midi.push_back(QVariant::fromValue(m));
506 QVariantList messages()
const {
return m_midi; }
507 W_INVOKABLE(messages);
523 explicit MidiOutlet(QObject* parent =
nullptr);
531 const QVector<QVector<int>>& midi()
const;
533 void setMessages(
const QVariantList m)
538 if(v.canConvert<QVector<int>>())
539 m_midi.push_back(v.value<QVector<int>>());
542 W_INVOKABLE(setMessages);
544 void add(QVector<int> m) { m_midi.push_back(std::move(m)); }
548 QVector<QVector<int>> m_midi;
551 #if defined(SCORE_HAS_GPU_JS)
552 class TextureOutlet :
public Outlet
554 W_OBJECT(TextureOutlet)
557 explicit TextureOutlet(QObject* parent =
nullptr);
558 virtual ~TextureOutlet() override;
561 auto p =
new Gfx::TextureOutlet(
id, parent);
565 QQuickItem* item() noexcept {
return m_item; }
566 void setItem(QQuickItem* v) { m_item = v; }
568 W_PROPERTY(QQuickItem*, item READ item WRITE setItem CONSTANT)
570 QQuickItem* m_item{};
574 class Script :
public QObject
577 W_CLASSINFO(
"DefaultProperty",
"data")
579 "qt_QmlJSWrapperFactoryMethod", "_q_createJSWrapper(QV4::ExecutionEngine*)")
582 QQmlListProperty<QObject> data() noexcept {
return {
this, &m_data}; }
584 QJSValue& tick() noexcept {
return m_tick; }
585 void setTick(
const QJSValue& v) { m_tick = v; }
586 QJSValue& start() noexcept {
return m_start; }
587 void setStart(
const QJSValue& v) { m_start = v; }
588 QJSValue& stop() noexcept {
return m_stop; }
589 void setStop(
const QJSValue& v) { m_stop = v; }
590 QJSValue& pause() noexcept {
return m_pause; }
591 void setPause(
const QJSValue& v) { m_pause = v; }
592 QJSValue& resume() noexcept {
return m_resume; }
593 void setResume(
const QJSValue& v) { m_resume = v; }
594 W_PROPERTY(QJSValue, tick READ tick WRITE setTick CONSTANT)
595 W_PROPERTY(QJSValue, start READ start WRITE setStart CONSTANT)
596 W_PROPERTY(QJSValue, stop READ stop WRITE setStop CONSTANT)
597 W_PROPERTY(QJSValue, pause READ pause WRITE setPause CONSTANT)
598 W_PROPERTY(QJSValue, resume READ resume WRITE setResume CONSTANT)
599 W_PROPERTY(QQmlListProperty<QObject>, data READ data)
602 QList<QObject*> m_data;
611 inline QDataStream& operator<<(QDataStream& i,
const JS::MidiMessage& sel)
616 inline QDataStream& operator>>(QDataStream& i, JS::MidiMessage& sel)
621 inline QDataStream& operator<<(QDataStream& i,
const JS::InValueMessage& sel)
626 inline QDataStream& operator>>(QDataStream& i, JS::InValueMessage& sel)
631 inline QDataStream& operator<<(QDataStream& i,
const JS::OutValueMessage& sel)
636 inline QDataStream& operator>>(QDataStream& i, JS::OutValueMessage& sel)
641 Q_DECLARE_METATYPE(JS::ValueInlet*)
642 Q_DECLARE_METATYPE(JS::ValueOutlet*)
643 Q_DECLARE_METATYPE(JS::AudioInlet*)
644 Q_DECLARE_METATYPE(JS::AudioOutlet*)
645 Q_DECLARE_METATYPE(JS::MidiMessage)
646 Q_DECLARE_METATYPE(JS::MidiInlet*)
647 Q_DECLARE_METATYPE(JS::MidiOutlet*)
649 W_REGISTER_ARGTYPE(JS::ValueInlet*)
650 W_REGISTER_ARGTYPE(JS::ValueOutlet*)
651 W_REGISTER_ARGTYPE(JS::AudioInlet*)
652 W_REGISTER_ARGTYPE(JS::AudioOutlet*)
653 W_REGISTER_ARGTYPE(JS::MidiMessage)
654 W_REGISTER_ARGTYPE(JS::MidiInlet*)
655 W_REGISTER_ARGTYPE(JS::MidiOutlet*)
Definition: QmlObjects.hpp:406
Definition: QmlObjects.hpp:433
Definition: QmlObjects.hpp:114
Definition: QmlObjects.hpp:287
Definition: QmlObjects.hpp:249
Definition: QmlObjects.hpp:137
Definition: QmlObjects.hpp:345
Definition: QmlObjects.hpp:269
Definition: QmlObjects.hpp:39
Definition: QmlObjects.hpp:361
Definition: QmlObjects.hpp:464
Definition: QmlObjects.hpp:455
Definition: QmlObjects.hpp:500
Definition: QmlObjects.hpp:51
Definition: QmlObjects.hpp:556
Definition: QmlObjects.hpp:315
Definition: QmlObjects.hpp:82
Definition: QmlObjects.hpp:376
The id_base_t class.
Definition: Identifier.hpp:57
Base classes and tools to implement processes and layers.
Definition: JSONVisitor.hpp:1324
Definition: QmlObjects.hpp:236
Definition: QmlObjects.hpp:230
Definition: QmlObjects.hpp:176
Definition: QmlObjects.hpp:194
Definition: QmlObjects.hpp:62
Definition: QmlObjects.hpp:182
Definition: QmlObjects.hpp:188
Definition: QmlObjects.hpp:224
Definition: QmlObjects.hpp:72
Definition: QmlObjects.hpp:242
Definition: QmlObjects.hpp:200
Definition: QmlObjects.hpp:212
Definition: QmlObjects.hpp:206
Definition: QmlObjects.hpp:218