Skip to content

Commit

Permalink
Dirty but working
Browse files Browse the repository at this point in the history
  • Loading branch information
christophehenry committed Jul 11, 2024
1 parent b79fcbd commit 39d2020
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 12 deletions.
2 changes: 1 addition & 1 deletion res/controllers/Denon-DN-S3700.midi.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
<MixxxControllerPreset mixxxVersion="2.2.3" schemaVersion="1">
<MixxxControllerPreset mixxxVersion="2.4.0" schemaVersion="1">
<info>
<name>Denon DN-S3700 (QML)</name>
<author>christophehenry</author>
Expand Down
9 changes: 5 additions & 4 deletions res/controllers/Denon-DN-S3700.qml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import QtQml
import QtQuick

QtObject {
Item {
id: controller

property string controllerId: ""
Expand All @@ -9,9 +9,10 @@ QtObject {
function init(controllerId, debugMode) {
controller.controllerId = controllerId;
controller.debugMode = debugMode;
console.log(controllerId, debugMode);
console.error(controllerId, debugMode);
console.error(controller.controllerId, controller.debugMode);
}
function shutdown() {
console.log(`Shutting down ${controller.controllerId} with debug mode ${controller.controllerId}`);
console.error(`Shutting down ${controller.controllerId} with debug mode ${controller.controllerId}`);
}
}
73 changes: 66 additions & 7 deletions src/controllers/scripting/legacy/controllerscriptenginelegacy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ const QByteArray kScreenTransformFunctionUntypedSignature =
"transformFrame(QVariant,QVariant)");
const QByteArray kScreenTransformFunctionTypedSignature =
QMetaObject::normalizedSignature("transformFrame(QVariant,QDateTime)");
const QByteArray kScreenInitFunctionUntypedSignature =
const QByteArray kQmlComponentInitFunctionUntypedSignature =
QMetaObject::normalizedSignature(
"init(QVariant,QVariant)");
const QByteArray kScreenInitFunctionTypedSignature =
const QByteArray kQmlComponentFunctionTypedSignature =
QMetaObject::normalizedSignature("init(QString,bool)");
const QByteArray kScreenShutdownFunctionSignature =
const QByteArray kQmlComponentShutdownFunctionSignature =
QMetaObject::normalizedSignature("shutdown()");
} // anonymous namespace
#endif
Expand Down Expand Up @@ -95,7 +95,6 @@ bool ControllerScriptEngineLegacy::callFunctionOnObjects(

const QJSValue global = m_pJSEngine->globalObject();

// TODO: ICI
bool success = true;
for (const QString& prefixName : scriptFunctionPrefixes) {
QJSValue prefix = global.property(prefixName);
Expand Down Expand Up @@ -155,7 +154,7 @@ bool ControllerScriptEngineLegacy::callShutdownFunction() {
}

QMetaMethod shutdownFunction;
int methodIdx = metaObject->indexOfMethod(kScreenShutdownFunctionSignature);
int methodIdx = metaObject->indexOfMethod(kQmlComponentShutdownFunctionSignature);

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

QMetaMethod initFunction;
bool typed = false;
int methodIdx = metaObject->indexOfMethod(kScreenInitFunctionUntypedSignature);
int methodIdx = metaObject->indexOfMethod(kQmlComponentInitFunctionUntypedSignature);

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

Expand Down Expand Up @@ -459,6 +458,66 @@ bool ControllerScriptEngineLegacy::initialize() {
#ifdef MIXXX_USE_QML
} else {
if (script.identifier.isEmpty()) {
if (availableScreens.isEmpty()) {
QQmlComponent qmlComponent = QQmlComponent(
std::dynamic_pointer_cast<QQmlEngine>(m_pJSEngine).get());

QFile scene = QFile(script.file.absoluteFilePath());

QDir dir(m_resourcePath + "/qml/");

scene.open(QIODevice::ReadOnly);
qmlComponent.setData(scene.readAll(),
// Obfuscate the scene filename to make it appear in the QML folder.
// This allows a smooth integration with QML components.
QUrl::fromLocalFile(
dir.absoluteFilePath(script.file.fileName())));
scene.close();

while (qmlComponent.isLoading()) {
qCDebug(m_logger) << "Waiting for component "
<< script.file.absoluteFilePath()
<< " to be ready: " << qmlComponent.progress();
QCoreApplication::processEvents(QEventLoop::WaitForMoreEvents, 500);
}

if (qmlComponent.isError()) {
const QList<QQmlError> errorList = qmlComponent.errors();
for (const QQmlError& error : errorList) {
qCWarning(m_logger)
<< "Unable to load the QML scene:"
<< error.url() << "at line" << error.line()
<< ", error: " << error;
showQMLExceptionDialog(error, true);
}
}

VERIFY_OR_DEBUG_ASSERT(qmlComponent.isReady()) {
qCWarning(m_logger)
<< "QMLComponent isn't ready although "
"synchronous load was requested.";
}

QObject* pRootObject = qmlComponent.createWithInitialProperties(
QVariantMap{});
if (qmlComponent.isError()) {
const QList<QQmlError> errorList = qmlComponent.errors();
for (const QQmlError& error : errorList) {
qCWarning(m_logger) << error.url() << error.line() << error;
}
}

std::shared_ptr<QQuickItem> rootItem =
std::shared_ptr<QQuickItem>(qobject_cast<QQuickItem*>(pRootObject));
if (!rootItem) {
qWarning("Oopsie run: Not a QQuickItem");
delete pRootObject;
}

watchFilePath(script.file.absoluteFilePath());

m_rootItems.insert("screenIdentifier", rootItem);
}
while (!availableScreens.isEmpty()) {
QString screenIdentifier(availableScreens.firstKey());
if (!bindSceneToScreen(script,
Expand Down

0 comments on commit 39d2020

Please sign in to comment.