Skip to content

Commit 39d2020

Browse files
Dirty but working
1 parent b79fcbd commit 39d2020

3 files changed

Lines changed: 72 additions & 12 deletions

File tree

res/controllers/Denon-DN-S3700.midi.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version='1.0' encoding='utf-8'?>
2-
<MixxxControllerPreset mixxxVersion="2.2.3" schemaVersion="1">
2+
<MixxxControllerPreset mixxxVersion="2.4.0" schemaVersion="1">
33
<info>
44
<name>Denon DN-S3700 (QML)</name>
55
<author>christophehenry</author>

res/controllers/Denon-DN-S3700.qml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import QtQml
1+
import QtQuick
22

3-
QtObject {
3+
Item {
44
id: controller
55

66
property string controllerId: ""
@@ -9,9 +9,10 @@ QtObject {
99
function init(controllerId, debugMode) {
1010
controller.controllerId = controllerId;
1111
controller.debugMode = debugMode;
12-
console.log(controllerId, debugMode);
12+
console.error(controllerId, debugMode);
13+
console.error(controller.controllerId, controller.debugMode);
1314
}
1415
function shutdown() {
15-
console.log(`Shutting down ${controller.controllerId} with debug mode ${controller.controllerId}`);
16+
console.error(`Shutting down ${controller.controllerId} with debug mode ${controller.controllerId}`);
1617
}
1718
}

src/controllers/scripting/legacy/controllerscriptenginelegacy.cpp

Lines changed: 66 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ const QByteArray kScreenTransformFunctionUntypedSignature =
3333
"transformFrame(QVariant,QVariant)");
3434
const QByteArray kScreenTransformFunctionTypedSignature =
3535
QMetaObject::normalizedSignature("transformFrame(QVariant,QDateTime)");
36-
const QByteArray kScreenInitFunctionUntypedSignature =
36+
const QByteArray kQmlComponentInitFunctionUntypedSignature =
3737
QMetaObject::normalizedSignature(
3838
"init(QVariant,QVariant)");
39-
const QByteArray kScreenInitFunctionTypedSignature =
39+
const QByteArray kQmlComponentFunctionTypedSignature =
4040
QMetaObject::normalizedSignature("init(QString,bool)");
41-
const QByteArray kScreenShutdownFunctionSignature =
41+
const QByteArray kQmlComponentShutdownFunctionSignature =
4242
QMetaObject::normalizedSignature("shutdown()");
4343
} // anonymous namespace
4444
#endif
@@ -95,7 +95,6 @@ bool ControllerScriptEngineLegacy::callFunctionOnObjects(
9595

9696
const QJSValue global = m_pJSEngine->globalObject();
9797

98-
// TODO: ICI
9998
bool success = true;
10099
for (const QString& prefixName : scriptFunctionPrefixes) {
101100
QJSValue prefix = global.property(prefixName);
@@ -155,7 +154,7 @@ bool ControllerScriptEngineLegacy::callShutdownFunction() {
155154
}
156155

157156
QMetaMethod shutdownFunction;
158-
int methodIdx = metaObject->indexOfMethod(kScreenShutdownFunctionSignature);
157+
int methodIdx = metaObject->indexOfMethod(kQmlComponentShutdownFunctionSignature);
159158

160159
if (methodIdx == -1 || !metaObject->method(methodIdx).isValid()) {
161160
qCDebug(m_logger) << "QML Scene for screen" << screenIdentifier
@@ -219,12 +218,12 @@ bool ControllerScriptEngineLegacy::callInitFunction() {
219218

220219
QMetaMethod initFunction;
221220
bool typed = false;
222-
int methodIdx = metaObject->indexOfMethod(kScreenInitFunctionUntypedSignature);
221+
int methodIdx = metaObject->indexOfMethod(kQmlComponentInitFunctionUntypedSignature);
223222

224223
if (methodIdx == -1 || !metaObject->method(methodIdx).isValid()) {
225224
qCDebug(m_logger) << "QML Scene for screen" << screenIdentifier
226225
<< "has no valid untyped init method.";
227-
methodIdx = metaObject->indexOfMethod(kScreenInitFunctionTypedSignature);
226+
methodIdx = metaObject->indexOfMethod(kQmlComponentFunctionTypedSignature);
228227
typed = true;
229228
}
230229

@@ -459,6 +458,66 @@ bool ControllerScriptEngineLegacy::initialize() {
459458
#ifdef MIXXX_USE_QML
460459
} else {
461460
if (script.identifier.isEmpty()) {
461+
if (availableScreens.isEmpty()) {
462+
QQmlComponent qmlComponent = QQmlComponent(
463+
std::dynamic_pointer_cast<QQmlEngine>(m_pJSEngine).get());
464+
465+
QFile scene = QFile(script.file.absoluteFilePath());
466+
467+
QDir dir(m_resourcePath + "/qml/");
468+
469+
scene.open(QIODevice::ReadOnly);
470+
qmlComponent.setData(scene.readAll(),
471+
// Obfuscate the scene filename to make it appear in the QML folder.
472+
// This allows a smooth integration with QML components.
473+
QUrl::fromLocalFile(
474+
dir.absoluteFilePath(script.file.fileName())));
475+
scene.close();
476+
477+
while (qmlComponent.isLoading()) {
478+
qCDebug(m_logger) << "Waiting for component "
479+
<< script.file.absoluteFilePath()
480+
<< " to be ready: " << qmlComponent.progress();
481+
QCoreApplication::processEvents(QEventLoop::WaitForMoreEvents, 500);
482+
}
483+
484+
if (qmlComponent.isError()) {
485+
const QList<QQmlError> errorList = qmlComponent.errors();
486+
for (const QQmlError& error : errorList) {
487+
qCWarning(m_logger)
488+
<< "Unable to load the QML scene:"
489+
<< error.url() << "at line" << error.line()
490+
<< ", error: " << error;
491+
showQMLExceptionDialog(error, true);
492+
}
493+
}
494+
495+
VERIFY_OR_DEBUG_ASSERT(qmlComponent.isReady()) {
496+
qCWarning(m_logger)
497+
<< "QMLComponent isn't ready although "
498+
"synchronous load was requested.";
499+
}
500+
501+
QObject* pRootObject = qmlComponent.createWithInitialProperties(
502+
QVariantMap{});
503+
if (qmlComponent.isError()) {
504+
const QList<QQmlError> errorList = qmlComponent.errors();
505+
for (const QQmlError& error : errorList) {
506+
qCWarning(m_logger) << error.url() << error.line() << error;
507+
}
508+
}
509+
510+
std::shared_ptr<QQuickItem> rootItem =
511+
std::shared_ptr<QQuickItem>(qobject_cast<QQuickItem*>(pRootObject));
512+
if (!rootItem) {
513+
qWarning("Oopsie run: Not a QQuickItem");
514+
delete pRootObject;
515+
}
516+
517+
watchFilePath(script.file.absoluteFilePath());
518+
519+
m_rootItems.insert("screenIdentifier", rootItem);
520+
}
462521
while (!availableScreens.isEmpty()) {
463522
QString screenIdentifier(availableScreens.firstKey());
464523
if (!bindSceneToScreen(script,

0 commit comments

Comments
 (0)