Skip to content

Commit

Permalink
Wrap QmlPlayerManagerProxy instead
Browse files Browse the repository at this point in the history
  • Loading branch information
christophehenry committed Jan 15, 2025
1 parent 757e3a2 commit 330cdc8
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 77 deletions.
30 changes: 15 additions & 15 deletions res/controllers/engine-api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,21 @@ declare interface ScriptConnection {
}

/** QmlPlayerProxy */
declare interface PlayerManager {
declare interface PlayerInfo {
isLoaded(): boolean;
getTrack(): string;
getTitle(): string;
getArtist(): string;
getAlbum(): string;
getAlbumArtist(): string;
getGenre(): string;
getComposer(): string;
getGrouping(): string;
getYear(): string;
getTrackNumber(): string;
getTrackTotal(): string;
getComment(): string;
getKeyText(): string;
track(): string;
title(): string;
artist(): string;
album(): string;
albumArtist(): string;
genre(): string;
composer(): string;
grouping(): string;
year(): string;
trackNumber(): string;
trackTotal(): string;
comment(): string;
keyText(): string;
}


Expand All @@ -67,7 +67,7 @@ declare namespace engine {
*
* @param group
*/
function getPlayer(group: string): PlayerManager | undefined;
function getPlayer(group: string): PlayerInfo | undefined;

/**
* Gets the control value
Expand Down
54 changes: 0 additions & 54 deletions src/controllers/scripting/controllerscriptenginebase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ void ControllerScriptEngineBase::registerTrackCollectionManager(
s_pTrackCollectionManager = std::move(pTrackCollectionManager);
}

void ControllerScriptEngineBase::registerPlayerManager(std::shared_ptr<PlayerManager> pPlayerManager) {
s_pPlayerManager = std::move(pPlayerManager);
}

void ControllerScriptEngineBase::handleQMLErrors(const QList<QQmlError>& qmlErrors) {
for (const QQmlError& error : std::as_const(qmlErrors)) {
showQMLExceptionDialog(error, m_bErrorsAreFatal);
Expand Down Expand Up @@ -178,56 +174,6 @@ void ControllerScriptEngineBase::showScriptExceptionDialog(
}
}

#ifdef MIXXX_USE_QML
void ControllerScriptEngineBase::showQMLExceptionDialog(
const QQmlError& error, bool bFatalError) {
VERIFY_OR_DEBUG_ASSERT(error.isValid()) {
return;
}

QString filename = error.url().isLocalFile() ? error.url().toLocalFile()
: error.url().toString();

if (filename.isEmpty()) {
filename = QStringLiteral("<passed code>");
}
QString errorText = QStringLiteral("Uncaught exception: %1:%2: %3")
.arg(filename, QString::number(error.line()), error.description());

qCWarning(m_logger) << "ControllerScriptHandlerBase:" << errorText;

if (!m_bDisplayingExceptionDialog) {
scriptErrorDialog(errorText, errorText, bFatalError);
}
}

QObject* ControllerScriptEngineBase::getPlayer(const QString& group) {
BaseTrackPlayer* pPlayer = s_pPlayerManager->getPlayer(group);
if (!pPlayer) {
qWarning() << "PlayerManagerProxy failed to find player for group" << group;
return nullptr;
}

// Don't set a parent here, so that the QML engine deletes the object when
// the corresponding JS object is garbage collected.
mixxx::qml::QmlPlayerProxy* pPlayerProxy = new mixxx::qml::QmlPlayerProxy(pPlayer);
QQmlEngine::setObjectOwnership(pPlayerProxy, QQmlEngine::JavaScriptOwnership);
connect(pPlayerProxy,
&mixxx::qml::QmlPlayerProxy::loadTrackFromLocationRequested,
this,
[this, group](const QString& trackLocation, bool play) {
s_pPlayerManager->slotLoadLocationToPlayer(trackLocation, group, play);
});
connect(pPlayerProxy,
&mixxx::qml::QmlPlayerProxy::cloneFromGroup,
this,
[this, group](const QString& sourceGroup) {
s_pPlayerManager->slotCloneDeck(sourceGroup, group);
});
return pPlayerProxy;
}
#endif

void ControllerScriptEngineBase::logOrThrowError(const QString& errorMessage) {
if (m_bAbortOnWarning) {
throwJSError(errorMessage);
Expand Down
2 changes: 0 additions & 2 deletions src/controllers/scripting/controllerscriptenginebase.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class ControllerScriptEngineBase : public QObject {
#ifdef MIXXX_USE_QML
/// Precondition: QML.isValid() == true
void showQMLExceptionDialog(const QQmlError& evaluationResult, bool bFatal = false);
QObject* getPlayer(const QString& group);
#endif
void throwJSError(const QString& message);

Expand All @@ -58,7 +57,6 @@ class ControllerScriptEngineBase : public QObject {
#ifdef MIXXX_USE_QML
static void registerTrackCollectionManager(
std::shared_ptr<TrackCollectionManager> pTrackCollectionManager);
static void registerPlayerManager(std::shared_ptr<PlayerManager> pPlayerManager);
#endif
signals:
void beforeShutdown();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ constexpr double kBrakeRampToRate = 0.01;
ControllerScriptInterfaceLegacy::ControllerScriptInterfaceLegacy(
ControllerScriptEngineLegacy* m_pEngine, const RuntimeLoggingCategory& logger)
: m_pScriptEngineLegacy(m_pEngine),
m_logger(logger) {
m_logger(logger),
m_pPlayerManagerProxy(mixxx::qml::QmlPlayerManagerProxy::create(m_pEngine->jsEngine().get(), m_pEngine))

Check failure on line 35 in src/controllers/scripting/legacy/controllerscriptinterfacelegacy.cpp

View workflow job for this annotation

GitHub Actions / macOS 13 x64

no member named 'qml' in namespace 'mixxx'

Check failure on line 35 in src/controllers/scripting/legacy/controllerscriptinterfacelegacy.cpp

View workflow job for this annotation

GitHub Actions / Windows 2019 (MSVC)

'qml': the symbol to the left of a '::' must be a type

Check failure on line 35 in src/controllers/scripting/legacy/controllerscriptinterfacelegacy.cpp

View workflow job for this annotation

GitHub Actions / Windows 2019 (MSVC)

'QmlPlayerManagerProxy': the symbol to the left of a '::' must be a type

Check failure on line 35 in src/controllers/scripting/legacy/controllerscriptinterfacelegacy.cpp

View workflow job for this annotation

GitHub Actions / Windows 2019 (MSVC)

'create': is not a member of 'mixxx'

Check failure on line 35 in src/controllers/scripting/legacy/controllerscriptinterfacelegacy.cpp

View workflow job for this annotation

GitHub Actions / Windows 2019 (MSVC)

'create': identifier not found

Check failure on line 35 in src/controllers/scripting/legacy/controllerscriptinterfacelegacy.cpp

View workflow job for this annotation

GitHub Actions / Windows 2019 (MSVC)

'ControllerScriptInterfaceLegacy': illegal member initialization: 'm_pPlayerManagerProxy' is not a base or member
{
// Pre-allocate arrays for average number of virtual decks
m_intervalAccumulator.resize(kDecks);
m_lastMovement.resize(kDecks);
Expand Down Expand Up @@ -140,7 +142,7 @@ QObject* ControllerScriptInterfaceLegacy::getPlayer(const QString& deck) {
#ifndef MIXXX_USE_QML
return nullptr;
#endif
return m_pScriptEngineLegacy->getPlayer(deck);
return m_pPlayerManagerProxy->getPlayer(deck);

Check failure on line 145 in src/controllers/scripting/legacy/controllerscriptinterfacelegacy.cpp

View workflow job for this annotation

GitHub Actions / macOS 13 x64

use of undeclared identifier 'm_pPlayerManagerProxy'

Check failure on line 145 in src/controllers/scripting/legacy/controllerscriptinterfacelegacy.cpp

View workflow job for this annotation

GitHub Actions / Windows 2019 (MSVC)

'm_pPlayerManagerProxy': undeclared identifier
}

double ControllerScriptInterfaceLegacy::getValue(const QString& group, const QString& name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
#include "util/alphabetafilter.h"
#include "util/runtimeloggingcategory.h"

#ifdef MIXXX_USE_QML
#include "qml/qmlplayermanagerproxy.h"
#endif

class ControllerScriptEngineLegacy;
class ControlObjectScript;
class ScriptConnection;
Expand Down Expand Up @@ -152,4 +156,8 @@ class ControllerScriptInterfaceLegacy : public QObject {

ControllerScriptEngineLegacy* m_pScriptEngineLegacy;
const RuntimeLoggingCategory m_logger;

#ifdef MIXXX_USE_QML
std::unique_ptr<mixxx::qml::QmlPlayerManagerProxy> m_pPlayerManagerProxy;
#endif
};
1 change: 0 additions & 1 deletion src/coreservices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,6 @@ void CoreServices::initializeQMLSingletons() {
mixxx::qml::QmlLibraryProxy::registerLibrary(getLibrary());

ControllerScriptEngineBase::registerTrackCollectionManager(getTrackCollectionManager());
ControllerScriptEngineBase::registerPlayerManager(getPlayerManager());

// Currently, it is required to enforce QQuickWindow RHI backend to use
// OpenGL on all platforms to allow offscreen rendering to function as
Expand Down
4 changes: 2 additions & 2 deletions src/qml/qmlplayermanagerproxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void QmlPlayerManagerProxy::loadLocationToPlayer(
}

// static
QmlPlayerManagerProxy* QmlPlayerManagerProxy::create(QQmlEngine* pQmlEngine, QJSEngine* pJsEngine) {
QmlPlayerManagerProxy* QmlPlayerManagerProxy::create(QJSEngine* pJsEngine, QObject* parent) {
// The implementation of this method is mostly taken from the code example
// that shows the replacement for `qmlRegisterSingletonInstance()` when
// using `QML_SINGLETON`.
Expand All @@ -71,7 +71,7 @@ QmlPlayerManagerProxy* QmlPlayerManagerProxy::create(QQmlEngine* pQmlEngine, QJS
qWarning() << "PlayerManager hasn't been registered yet";
return nullptr;
}
return new QmlPlayerManagerProxy(s_pPlayerManager, pQmlEngine);
return new QmlPlayerManagerProxy(s_pPlayerManager, parent);
}

} // namespace qml
Expand Down
2 changes: 1 addition & 1 deletion src/qml/qmlplayermanagerproxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class QmlPlayerManagerProxy : public QObject {
Q_INVOKABLE void loadLocationToPlayer(
const QString& location, const QString& group, bool play = false);

static QmlPlayerManagerProxy* create(QQmlEngine* pQmlEngine, QJSEngine* pJsEngine);
static QmlPlayerManagerProxy* create(QJSEngine* pJsEngine, QObject* parent);
static void registerPlayerManager(std::shared_ptr<PlayerManager> pPlayerManager) {
s_pPlayerManager = std::move(pPlayerManager);
}
Expand Down

0 comments on commit 330cdc8

Please sign in to comment.