Skip to content
Closed
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2776,6 +2776,8 @@ if(QML)
src/qml/qmlplayerproxy.cpp
src/qml/qmlvisibleeffectsmodel.cpp
src/qml/qmlwaveformoverview.cpp
src/qml/mixxxcontroller.cpp
src/qml/mixxxscreen.cpp
# The following sources need to be in this target to get QML_ELEMENT properly interpreted
src/control/controlmodel.cpp
src/control/controlsortfiltermodel.cpp
Expand Down
13 changes: 13 additions & 0 deletions res/controllers/Denon-DN-S3700.midi.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version='1.0' encoding='utf-8'?>
<MixxxControllerPreset mixxxVersion="2.4.0" schemaVersion="1">
<info>
<name>Denon DN-S3700 (QML)</name>
<author>christophehenry</author>
<description>Controller preset for Denon DN-S3700 turntable</description>
</info>
<controller id="DN-S3700">
<scriptfiles>
<file filename="Denon-DN-S3700.qml" />
</scriptfiles>
</controller>
</MixxxControllerPreset>
20 changes: 20 additions & 0 deletions res/controllers/Denon-DN-S3700.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import QtQml

import "Mixxx"

MixxxController {
id: controller

onInit: console.error(`Starting controller ${controller.controllerId} with debug mode ${controller.debugMode}`)
onShutdown: console.error(`Shutting down ${controller.controllerId} with debug mode ${controller.debugMode}`)

MixxxScreen {
screenId: "screen 7"
splashOff: 5000
onInit: console.error(`MixxxScreen.screenId=${screenId}, MixxxScreen.splashOff=${splashOff}`)
transformFrame: (frame, timestamp, area) => {
console.error(frame)
return new ArrayBuffer(0)
}
}
}
2 changes: 2 additions & 0 deletions src/controllers/legacycontrollermapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "controllers/legacycontrollersettingslayout.h"
#include "defs_urls.h"
#include "preferences/usersettings.h"
#include "qml/mixxxcontroller.h"
#include "util/assert.h"

/// This class represents a controller mapping, containing the data elements that
Expand Down Expand Up @@ -374,6 +375,7 @@ class LegacyControllerMapping {
#ifdef MIXXX_USE_QML
QList<QMLModuleInfo> m_modules;
QList<ScreenInfo> m_screens;
QList<mixxx::qml::MixxxController> m_mixxxControllers;
#endif
QList<ScriptFileInfo> m_scripts;
DeviceDirections m_deviceDirection;
Expand Down
3 changes: 2 additions & 1 deletion src/controllers/legacycontrollermappingfilehandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,8 @@ void LegacyControllerMappingFileHandler::addScriptFilesToMapping(
QFileInfo file = findScriptFile(mapping, filename, systemMappingsPath);
if (file.suffix() == "qml") {
#ifdef MIXXX_USE_QML
QString identifier = scriptFile.attribute("identifier", "");
QString identifier = scriptFile.attribute(
"identifier", scriptFile.attribute("functionprefix", ""));
Comment on lines +393 to +394
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case of the screens, it makes no sense to default to functionprefix

mapping->addScriptFile(LegacyControllerMapping::ScriptFileInfo{
filename,
identifier,
Expand Down
12 changes: 12 additions & 0 deletions src/controllers/scripting/controllerscriptenginebase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,18 @@ ControllerScriptEngineBase::ControllerScriptEngineBase(
m_bAbortOnWarning(false),
#ifdef MIXXX_USE_QML
m_bQmlMode(false),
m_mixxxControllerEngineInterface(this),
#endif
m_bTesting(false) {
// Handle error dialog buttons
qRegisterMetaType<QMessageBox::StandardButton>("QMessageBox::StandardButton");
}

#ifdef MIXXX_USE_QML
void ControllerScriptEngineBase::declareScreen(mixxx::qml::MixxxScreen& screen) {
std::make_shared<mixxx::qml::MixxxScreen>(screen);
}

void ControllerScriptEngineBase::registerTrackCollectionManager(
std::shared_ptr<TrackCollectionManager> pTrackCollectionManager) {
s_pTrackCollectionManager = std::move(pTrackCollectionManager);
Expand Down Expand Up @@ -60,6 +65,7 @@ bool ControllerScriptEngineBase::initialize() {
#ifdef MIXXX_USE_QML
} else {
auto pQmlEngine = std::make_shared<QQmlEngine>(this);
pQmlEngine->setProperty("controllerEngineInterface", m_mixxxControllerEngineInterface);
pQmlEngine->addImportPath(QStringLiteral(":/mixxx.org/imports"));
if (s_pTrackCollectionManager) {
mixxx::qml::AsyncImageProvider* pImageProvider = new mixxx::qml::AsyncImageProvider(
Expand Down Expand Up @@ -288,3 +294,9 @@ void ControllerScriptEngineBase::errorDialogButton(
void ControllerScriptEngineBase::throwJSError(const QString& message) {
m_pJSEngine->throwError(message);
}

#ifdef MIXXX_USE_QML
void mixxx::qml::MixxxControllerEngineInterface::declareScreen(MixxxScreen& screen) {
m_controllerScriptEngine->declareScreen(screen);
}
#endif
26 changes: 26 additions & 0 deletions src/controllers/scripting/controllerscriptenginebase.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
#include "util/runtimeloggingcategory.h"
#ifdef MIXXX_USE_QML
#include "controllers/controllerenginethreadcontrol.h"
#include "qml/mixxxscreen.h"
#endif

class Controller;
class QJSEngine;
#ifdef MIXXX_USE_QML
class TrackCollectionManager;
class MixxxControllerEngineInterface;
#endif

/// ControllerScriptEngineBase manages the JavaScript engine for controller scripts.
Expand All @@ -38,6 +40,8 @@ class ControllerScriptEngineBase : public QObject {
#ifdef MIXXX_USE_QML
/// Precondition: QML.isValid() == true
void showQMLExceptionDialog(const QQmlError& evaluationResult, bool bFatal = false);

void declareScreen(mixxx::qml::MixxxScreen& screen);
#endif
void throwJSError(const QString& message);

Expand Down Expand Up @@ -94,6 +98,8 @@ class ControllerScriptEngineBase : public QObject {
#ifdef MIXXX_USE_QML
private:
static inline std::shared_ptr<TrackCollectionManager> s_pTrackCollectionManager;
QHash<QString, std::shared_ptr<mixxx::qml::MixxxScreen>> m_screens;
MixxxControllerEngineInterface m_mixxxControllerEngineInterface;

protected:
/// Pause the GUI main thread. Pause is required by rendering
Expand All @@ -119,3 +125,23 @@ class ControllerScriptEngineBase : public QObject {
friend class ColorMapperJSProxy;
friend class MidiControllerTest;
};

#ifdef MIXXX_USE_QML
namespace mixxx {
namespace qml {

class MixxxControllerEngineInterface : QObject {
Q_OBJECT
public:
MixxxControllerEngineInterface(ControllerScriptEngineBase* controllerScriptEngine)
: QObject(controllerScriptEngine), m_controllerScriptEngine(controllerScriptEngine) {
}
void declareScreen(MixxxScreen& screen);

private:
ControllerScriptEngineBase* m_controllerScriptEngine;
};

} // namespace qml
} // namespace mixxx
#endif
Loading