From b51f457b70b111a26a1d90346014abbe67eaab0f Mon Sep 17 00:00:00 2001 From: Ferran Pujol Camins Date: Sun, 2 Sep 2018 00:13:40 +0200 Subject: [PATCH] Adapt hid devices to new JS Engine Remove bytearrayclass since now QJSEngine has built in support for QByteArray, which gets converted to a JS ArrayBuffer. --- build/depends.py | 10 +- lib/qtscript-bytearray/bytearrayclass.cpp | 314 ------------------ lib/qtscript-bytearray/bytearrayclass.h | 96 ------ lib/qtscript-bytearray/bytearrayprototype.cpp | 135 -------- lib/qtscript-bytearray/bytearrayprototype.h | 79 ----- src/controllers/engine/controllerengine.cpp | 22 +- src/controllers/engine/controllerengine.h | 6 +- 7 files changed, 18 insertions(+), 644 deletions(-) delete mode 100644 lib/qtscript-bytearray/bytearrayclass.cpp delete mode 100644 lib/qtscript-bytearray/bytearrayclass.h delete mode 100644 lib/qtscript-bytearray/bytearrayprototype.cpp delete mode 100644 lib/qtscript-bytearray/bytearrayprototype.h diff --git a/build/depends.py b/build/depends.py index de4b41e8dd37..999c6202fe17 100644 --- a/build/depends.py +++ b/build/depends.py @@ -671,14 +671,6 @@ def sources(self, build): env['CCFLAGS'].remove('-ffast-math') return env.Object('util/fpclassify.cpp') -class QtScriptByteArray(Dependence): - def configure(self, build, conf): - build.env.Append(CPPPATH='#lib/qtscript-bytearray') - - def sources(self, build): - return ['#lib/qtscript-bytearray/bytearrayclass.cpp', - '#lib/qtscript-bytearray/bytearrayprototype.cpp'] - class PortAudioRingBuffer(Dependence): def configure(self, build, conf): build.env.Append(CPPPATH='#lib/portaudio') @@ -1523,7 +1515,7 @@ def depends(self, build): return [SoundTouch, ReplayGain, Ebur128Mit, PortAudio, PortMIDI, Qt, TestHeaders, FidLib, SndFile, FLAC, OggVorbis, OpenGL, TagLib, ProtoBuf, Chromaprint, RubberBand, SecurityFramework, CoreServices, IOKit, - QtScriptByteArray, Reverb, FpClassify, PortAudioRingBuffer] + Reverb, FpClassify, PortAudioRingBuffer] def post_dependency_check_configure(self, build, conf): """Sets up additional things in the Environment that must happen diff --git a/lib/qtscript-bytearray/bytearrayclass.cpp b/lib/qtscript-bytearray/bytearrayclass.cpp deleted file mode 100644 index 25a21d854179..000000000000 --- a/lib/qtscript-bytearray/bytearrayclass.cpp +++ /dev/null @@ -1,314 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names -** of its contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include -#include -#include "bytearrayclass.h" -#include "bytearrayprototype.h" - -#include - -Q_DECLARE_METATYPE(QByteArray*) -Q_DECLARE_METATYPE(ByteArrayClass*) - -class ByteArrayClassPropertyIterator : public QScriptClassPropertyIterator -{ -public: - ByteArrayClassPropertyIterator(const QScriptValue &object); - ~ByteArrayClassPropertyIterator(); - - bool hasNext() const; - void next(); - - bool hasPrevious() const; - void previous(); - - void toFront(); - void toBack(); - - QScriptString name() const; - uint id() const; - -private: - int m_index; - int m_last; -}; - -//! [0] -ByteArrayClass::ByteArrayClass(QScriptEngine *engine) - : QObject(engine), QScriptClass(engine) -{ - qScriptRegisterMetaType(engine, toScriptValue, fromScriptValue); - - length = engine->toStringHandle(QLatin1String("length")); - - proto = engine->newQObject(new ByteArrayPrototype(this), - QScriptEngine::QtOwnership, - QScriptEngine::SkipMethodsInEnumeration - | QScriptEngine::ExcludeSuperClassMethods - | QScriptEngine::ExcludeSuperClassProperties); - QScriptValue global = engine->globalObject(); - proto.setPrototype(global.property("Object").property("prototype")); - - ctor = engine->newFunction(construct, proto); - ctor.setData(engine->toScriptValue(this)); -} -//! [0] - -ByteArrayClass::~ByteArrayClass() -{ -} - -//! [3] -QScriptClass::QueryFlags ByteArrayClass::queryProperty(const QScriptValue &object, - const QScriptString &name, - QueryFlags flags, uint *id) -{ - QByteArray *ba = qscriptvalue_cast(object.data()); - if (!ba) - return 0; - if (name == length) { - return flags; - } else { - bool isArrayIndex; - qint32 pos = name.toArrayIndex(&isArrayIndex); - if (!isArrayIndex) - return 0; - *id = pos; - if ((flags & HandlesReadAccess) && (pos >= ba->size())) - flags &= ~HandlesReadAccess; - return flags; - } -} -//! [3] - -//! [4] -QScriptValue ByteArrayClass::property(const QScriptValue &object, - const QScriptString &name, uint id) -{ - QByteArray *ba = qscriptvalue_cast(object.data()); - if (!ba) - return QScriptValue(); - if (name == length) { - return ba->length(); - } - qint32 pos = id; - if ((pos < 0) || (pos >= ba->size())) { - return QScriptValue(); - } - return uint(ba->at(pos)) & 255; -} -//! [4] - -//! [5] -void ByteArrayClass::setProperty(QScriptValue &object, - const QScriptString &name, - uint id, const QScriptValue &value) -{ - QByteArray *ba = qscriptvalue_cast(object.data()); - if (!ba) - return; - if (name == length) { - resize(*ba, value.toInt32()); - } else { - qint32 pos = id; - if (pos < 0) - return; - if (ba->size() <= pos) - resize(*ba, pos + 1); - (*ba)[pos] = char(value.toInt32()); - } -} -//! [5] - -//! [6] -QScriptValue::PropertyFlags ByteArrayClass::propertyFlags( - const QScriptValue &/*object*/, const QScriptString &name, uint /*id*/) -{ - if (name == length) { - return QScriptValue::Undeletable - | QScriptValue::SkipInEnumeration; - } - return QScriptValue::Undeletable; -} -//! [6] - -//! [7] -QScriptClassPropertyIterator *ByteArrayClass::newIterator(const QScriptValue &object) -{ - return new ByteArrayClassPropertyIterator(object); -} -//! [7] - -QString ByteArrayClass::name() const -{ - return QLatin1String("ByteArray"); -} - -QScriptValue ByteArrayClass::prototype() const -{ - return proto; -} - -QScriptValue ByteArrayClass::constructor() -{ - return ctor; -} - -//! [10] -QScriptValue ByteArrayClass::newInstance(int size) -{ - // reportAdditionalMemoryCost is only available on >= Qt 4.7.0. -#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0) - engine()->reportAdditionalMemoryCost(size); -#endif - return newInstance(QByteArray(size, /*ch=*/0)); -} -//! [10] - -//! [1] -QScriptValue ByteArrayClass::newInstance(const QByteArray &ba) -{ - QScriptValue data = engine()->newVariant(QVariant::fromValue(ba)); - return engine()->newObject(this, data); -} -//! [1] - -//! [2] -QScriptValue ByteArrayClass::construct(QScriptContext *ctx, QScriptEngine *) -{ - ByteArrayClass *cls = qscriptvalue_cast(ctx->callee().data()); - if (!cls) - return QScriptValue(); - QScriptValue arg = ctx->argument(0); - if (arg.instanceOf(ctx->callee())) - return cls->newInstance(qscriptvalue_cast(arg)); - int size = arg.toInt32(); - return cls->newInstance(size); -} -//! [2] - -QScriptValue ByteArrayClass::toScriptValue(QScriptEngine *eng, const QByteArray &ba) -{ - QScriptValue ctor = eng->globalObject().property("ByteArray"); - ByteArrayClass *cls = qscriptvalue_cast(ctor.data()); - if (!cls) - return eng->newVariant(QVariant::fromValue(ba)); - return cls->newInstance(ba); -} - -void ByteArrayClass::fromScriptValue(const QScriptValue &obj, QByteArray &ba) -{ - ba = qvariant_cast(obj.data().toVariant()); -} - -//! [9] -void ByteArrayClass::resize(QByteArray &ba, int newSize) -{ - int oldSize = ba.size(); - ba.resize(newSize); - // reportAdditionalMemoryCost is only available on >= Qt 4.7.0. -#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0) - if (newSize > oldSize) - engine()->reportAdditionalMemoryCost(newSize - oldSize); -#endif -} -//! [9] - - - -ByteArrayClassPropertyIterator::ByteArrayClassPropertyIterator(const QScriptValue &object) - : QScriptClassPropertyIterator(object) -{ - toFront(); -} - -ByteArrayClassPropertyIterator::~ByteArrayClassPropertyIterator() -{ -} - -//! [8] -bool ByteArrayClassPropertyIterator::hasNext() const -{ - QByteArray *ba = qscriptvalue_cast(object().data()); - return m_index < ba->size(); -} - -void ByteArrayClassPropertyIterator::next() -{ - m_last = m_index; - ++m_index; -} - -bool ByteArrayClassPropertyIterator::hasPrevious() const -{ - return (m_index > 0); -} - -void ByteArrayClassPropertyIterator::previous() -{ - --m_index; - m_last = m_index; -} - -void ByteArrayClassPropertyIterator::toFront() -{ - m_index = 0; - m_last = -1; -} - -void ByteArrayClassPropertyIterator::toBack() -{ - QByteArray *ba = qscriptvalue_cast(object().data()); - m_index = ba->size(); - m_last = -1; -} - -QScriptString ByteArrayClassPropertyIterator::name() const -{ - return object().engine()->toStringHandle(QString::number(m_last)); -} - -uint ByteArrayClassPropertyIterator::id() const -{ - return m_last; -} -//! [8] diff --git a/lib/qtscript-bytearray/bytearrayclass.h b/lib/qtscript-bytearray/bytearrayclass.h deleted file mode 100644 index a755d638f9cb..000000000000 --- a/lib/qtscript-bytearray/bytearrayclass.h +++ /dev/null @@ -1,96 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names -** of its contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef BYTEARRAYCLASS_H -#define BYTEARRAYCLASS_H - -#include -#include -#include - -QT_BEGIN_NAMESPACE -class QScriptContext; -QT_END_NAMESPACE - -class ByteArrayClass : public QObject, public QScriptClass -{ - Q_OBJECT -public: - ByteArrayClass(QScriptEngine *engine); - ~ByteArrayClass(); - - QScriptValue constructor(); - - QScriptValue newInstance(int size = 0); - QScriptValue newInstance(const QByteArray &ba); - - QueryFlags queryProperty(const QScriptValue &object, - const QScriptString &name, - QueryFlags flags, uint *id); - - QScriptValue property(const QScriptValue &object, - const QScriptString &name, uint id); - - void setProperty(QScriptValue &object, const QScriptString &name, - uint id, const QScriptValue &value); - - QScriptValue::PropertyFlags propertyFlags( - const QScriptValue &object, const QScriptString &name, uint id); - - QScriptClassPropertyIterator *newIterator(const QScriptValue &object); - - QString name() const; - - QScriptValue prototype() const; - -private: - static QScriptValue construct(QScriptContext *ctx, QScriptEngine *eng); - - static QScriptValue toScriptValue(QScriptEngine *eng, const QByteArray &ba); - static void fromScriptValue(const QScriptValue &obj, QByteArray &ba); - - void resize(QByteArray &ba, int newSize); - - QScriptString length; - QScriptValue proto; - QScriptValue ctor; -}; - -#endif diff --git a/lib/qtscript-bytearray/bytearrayprototype.cpp b/lib/qtscript-bytearray/bytearrayprototype.cpp deleted file mode 100644 index 68f0d5da762f..000000000000 --- a/lib/qtscript-bytearray/bytearrayprototype.cpp +++ /dev/null @@ -1,135 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names -** of its contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "bytearrayprototype.h" -#include - -Q_DECLARE_METATYPE(QByteArray*) - -ByteArrayPrototype::ByteArrayPrototype(QObject *parent) - : QObject(parent) -{ -} - -ByteArrayPrototype::~ByteArrayPrototype() -{ -} - -//! [0] -QByteArray *ByteArrayPrototype::thisByteArray() const -{ - return qscriptvalue_cast(thisObject().data()); -} -//! [0] - -void ByteArrayPrototype::chop(int n) -{ - thisByteArray()->chop(n); -} - -bool ByteArrayPrototype::equals(const QByteArray &other) -{ - return *thisByteArray() == other; -} - -QByteArray ByteArrayPrototype::left(int len) const -{ - return thisByteArray()->left(len); -} - -//! [1] -QByteArray ByteArrayPrototype::mid(int pos, int len) const -{ - return thisByteArray()->mid(pos, len); -} - -QScriptValue ByteArrayPrototype::remove(int pos, int len) -{ - thisByteArray()->remove(pos, len); - return thisObject(); -} -//! [1] - -QByteArray ByteArrayPrototype::right(int len) const -{ - return thisByteArray()->right(len); -} - -QByteArray ByteArrayPrototype::simplified() const -{ - return thisByteArray()->simplified(); -} - -QByteArray ByteArrayPrototype::toBase64() const -{ - return thisByteArray()->toBase64(); -} - -QByteArray ByteArrayPrototype::toLower() const -{ - return thisByteArray()->toLower(); -} - -QByteArray ByteArrayPrototype::toUpper() const -{ - return thisByteArray()->toUpper(); -} - -QByteArray ByteArrayPrototype::trimmed() const -{ - return thisByteArray()->trimmed(); -} - -void ByteArrayPrototype::truncate(int pos) -{ - thisByteArray()->truncate(pos); -} - -QString ByteArrayPrototype::toLatin1String() const -{ - return QString::fromLatin1(*thisByteArray()); -} - -//! [2] -QScriptValue ByteArrayPrototype::valueOf() const -{ - return thisObject().data(); -} -//! [2] diff --git a/lib/qtscript-bytearray/bytearrayprototype.h b/lib/qtscript-bytearray/bytearrayprototype.h deleted file mode 100644 index a9f00d45101e..000000000000 --- a/lib/qtscript-bytearray/bytearrayprototype.h +++ /dev/null @@ -1,79 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names -** of its contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef BYTEARRAYPROTOTYPE_H -#define BYTEARRAYPROTOTYPE_H - -#include -#include -#include -#include - -//! [0] -class ByteArrayPrototype : public QObject, public QScriptable -{ -Q_OBJECT -public: - ByteArrayPrototype(QObject *parent = 0); - ~ByteArrayPrototype(); - -public slots: - void chop(int n); - bool equals(const QByteArray &other); - QByteArray left(int len) const; - QByteArray mid(int pos, int len = -1) const; - QScriptValue remove(int pos, int len); - QByteArray right(int len) const; - QByteArray simplified() const; - QByteArray toBase64() const; - QByteArray toLower() const; - QByteArray toUpper() const; - QByteArray trimmed() const; - void truncate(int pos); - QString toLatin1String() const; - QScriptValue valueOf() const; - -private: - QByteArray *thisByteArray() const; -}; -//! [0] - - -#endif diff --git a/src/controllers/engine/controllerengine.cpp b/src/controllers/engine/controllerengine.cpp index 1dd8f54b8484..f69ee4f8dccc 100644 --- a/src/controllers/engine/controllerengine.cpp +++ b/src/controllers/engine/controllerengine.cpp @@ -34,8 +34,7 @@ const double kAlphaBetaDt = kScratchTimerMs / 1000.0; ControllerEngine::ControllerEngine(Controller* controller) : m_pEngine(nullptr), m_pController(controller), - m_bPopups(true), - m_pBaClass(nullptr) { + m_bPopups(true) { // Handle error dialog buttons qRegisterMetaType("QMessageBox::StandardButton"); @@ -101,6 +100,17 @@ void ControllerEngine::callFunctionOnObjects(QList scriptFunctionPrefix } } +QJSValue ControllerEngine::byteArrayToScriptValue(const QByteArray byteArray) { + // The QJSEngine converts the QByteArray to an ArrayBuffer object. + QJSValue arrayBuffer = m_pEngine->toScriptValue(byteArray); + // We convert the ArrayBuffer to a Uint8 typed array so we can access its bytes + // with the [] operator. + QJSValue m_byteArrayToScriptValueJSFunction = evaluateProgram("(function(arg1) { return new Uint8Array(arg1) })"); + QJSValueList args; + args << arrayBuffer; + return m_byteArrayToScriptValueJSFunction.call(args); +} + /* ------------------------------------------------------------------ Purpose: Turn a snippet of JS into a QJSValue function. Wrapping it in an anonymous function allows any JS that @@ -178,9 +188,6 @@ void ControllerEngine::gracefulShutdown() { delete coScript; ++it; } - - delete m_pBaClass; - m_pBaClass = nullptr; } bool ControllerEngine::isReady() { @@ -209,8 +216,7 @@ void ControllerEngine::initializeScriptEngine() { engineGlobalObject.setProperty("midi", m_pEngine->newQObject(controllerProxy)); } -// m_pBaClass = new ByteArrayClass(m_pEngine); -// engineGlobalObject.setProperty("ByteArray", m_pBaClass->constructor()); + m_byteArrayToScriptValueJSFunction = evaluateProgram("(function(arg1) { return new Uint8Array(arg1) })"); } /* -------- ------------------------------------------------------ @@ -403,7 +409,7 @@ bool ControllerEngine::execute(QJSValue function, const QByteArray data, return false; } QJSValueList args; -// args << m_pBaClass->newInstance(data); + args << byteArrayToScriptValue(data); args << QJSValue(data.size()); return internalExecute(m_pEngine->globalObject(), function, args); } diff --git a/src/controllers/engine/controllerengine.h b/src/controllers/engine/controllerengine.h index 1ed42e82425b..403f8a11ca67 100644 --- a/src/controllers/engine/controllerengine.h +++ b/src/controllers/engine/controllerengine.h @@ -15,7 +15,6 @@ #include #include -#include "bytearrayclass.h" #include "preferences/usersettings.h" #include "controllers/controllerpreset.h" #include "controllers/softtakeover.h" @@ -167,7 +166,6 @@ class ControllerEngine : public QObject { void errorDialogButton(const QString& key, QMessageBox::StandardButton button); private: -// bool syntaxIsValid(const QString& scriptCode); bool evaluateScriptFile(const QString& scriptName, QList scriptPaths); bool internalExecute(QJSValue thisObject, const QString& scriptCode); bool internalExecute(const QString& scriptCode); @@ -183,6 +181,8 @@ class ControllerEngine : public QObject { void stopAllTimers(); void callFunctionOnObjects(QList, const QString&, QJSValueList args = QJSValueList()); + // Convert a byteArray to a JS typed array over an ArrayBuffer + QJSValue byteArrayToScriptValue(const QByteArray byteArray); // Throws EvaluationException and NullEngineException. QJSValue evaluateProgram(const QString& program, const QString& fileName = QString(), int lineNumber = 1); @@ -210,7 +210,6 @@ class ControllerEngine : public QObject { }; QHash m_timers; SoftTakeoverCtrl m_st; - ByteArrayClass* m_pBaClass; // 256 (default) available virtual decks is enough I would think. // If more are needed at run-time, these will move to the heap automatically QVarLengthArray m_intervalAccumulator; @@ -220,6 +219,7 @@ class ControllerEngine : public QObject { QVarLengthArray m_scratchFilters; QHash m_scratchTimers; QHash m_scriptWrappedFunctionCache; + QJSValue m_byteArrayToScriptValueJSFunction; // Filesystem watcher for script auto-reload QFileSystemWatcher m_scriptWatcher; QList m_lastScriptPaths;