Skip to content

Commit

Permalink
Merge branch '2.4' of github.com:mixxxdj/mixxx
Browse files Browse the repository at this point in the history
  • Loading branch information
Holzhaus committed Sep 10, 2023
2 parents 37a9626 + 5ec5ab8 commit f5666a7
Show file tree
Hide file tree
Showing 13 changed files with 209 additions and 91 deletions.
5 changes: 2 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1865,8 +1865,7 @@ add_executable(mixxx-test
src/test/hotcuecontrol_test.cpp
src/test/imageutils_test.cpp
src/test/indexrange_test.cpp
# TODO: reanable this after https://github.com/mixxxdj/mixxx/pull/11666
# src/test/itunesxmlimportertest.cpp
src/test/itunesxmlimportertest.cpp
src/test/keyutilstest.cpp
src/test/lcstest.cpp
src/test/learningutilstest.cpp
Expand Down Expand Up @@ -2889,7 +2888,7 @@ if(FAAD)
src/sources/soundsourcem4a.cpp
src/sources/libfaadloader.cpp
)
target_compile_definitions(mixxx-lib PRIVATE __FAAD__)
target_compile_definitions(mixxx-lib PUBLIC __FAAD__)
if(MP4v2_FOUND)
target_compile_definitions(mixxx-lib PRIVATE __MP4V2__)
target_link_libraries(mixxx-lib PRIVATE MP4v2::MP4v2)
Expand Down
6 changes: 4 additions & 2 deletions res/controllers/Hercules-DJ-Control-MP3-hid-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ HerculesMP3Hid.init = function() {
if (v < 30) v = 30;
if (HerculesMP3Hid.track_timer) engine.stopTimer(HerculesMP3Hid.track_timer);
HerculesMP3Hid.track_timer = engine.beginTimer(parseInt(5120 / v), 'HerculesMP3Hid.scroll_tracks_joystick');
HerculesMP3Hid.track_timer = engine.beginTimer(parseInt(5120 / v), HerculesMP3Hid.scroll_tracks_joystick);
}
});
*/
Expand Down Expand Up @@ -338,7 +338,9 @@ HerculesMP3Hid.scroll_tracks = function(g, e, v) {
if (v > 0) {
engine.setValue("[Playlist]", e == "track_next_a" ? "SelectNextTrack" : "SelectPrevTrack", 1);
if (!HerculesMP3Hid.scroll_timer) {
HerculesMP3Hid.scroll_timer = engine.beginTimer(150, 'HerculesMP3Hid.scroll_tracks("[Playlist]","' + e + '",' + v + ')');
HerculesMP3Hid.scroll_timer = engine.beginTimer(150, function () {
HerculesMP3Hid.scroll_tracks("[Playlist]", e, v);
});
}
}
else {
Expand Down
24 changes: 14 additions & 10 deletions src/controllers/scripting/controllerscriptenginebase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,12 @@ bool ControllerScriptEngineBase::executeFunction(
return false;
}

if (pFunctionObject->isError()) {
qDebug() << "ControllerScriptHandlerBase::executeFunction:"
<< pFunctionObject->toString();
return false;
}

// If it's not a function, we're done.
if (!pFunctionObject->isCallable()) {
qDebug() << "ControllerScriptHandlerBase::executeFunction:"
<< pFunctionObject->toVariant() << "Not a function";
const bool isError = pFunctionObject->isError();
const bool isCallable = pFunctionObject->isCallable();
if (isError || !isCallable) {
logOrThrowError((isError ? QStringLiteral("\"%1\" resulted in an error")
: QStringLiteral("\"%1\" is not callable"))
.arg(pFunctionObject->toString()));
return false;
}

Expand Down Expand Up @@ -129,6 +125,14 @@ void ControllerScriptEngineBase::showScriptExceptionDialog(
}
}

void ControllerScriptEngineBase::logOrThrowError(const QString& errorMessage) {
if (m_bAbortOnWarning) {
throwJSError(errorMessage);
} else {
qCWarning(m_logger) << errorMessage;
}
}

void ControllerScriptEngineBase::scriptErrorDialog(
const QString& detailedError, const QString& key, bool bFatalError) {
if (m_bTesting) {
Expand Down
1 change: 1 addition & 0 deletions src/controllers/scripting/controllerscriptenginebase.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class ControllerScriptEngineBase : public QObject {
virtual void shutdown();

void scriptErrorDialog(const QString& detailedError, const QString& key, bool bFatal = false);
void logOrThrowError(const QString& errorMessage);

bool m_bDisplayingExceptionDialog;
std::shared_ptr<QJSEngine> m_pJSEngine;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ ControlObjectScript* ControllerScriptInterfaceLegacy::getControlObjectScript(
double ControllerScriptInterfaceLegacy::getValue(const QString& group, const QString& name) {
ControlObjectScript* coScript = getControlObjectScript(group, name);
if (coScript == nullptr) {
logOrThrowError(QStringLiteral("Unknown control (%1, %2) returning 0.0").arg(group, name));
m_pScriptEngineLegacy->logOrThrowError(
QStringLiteral("Unknown control (%1, %2) returning 0.0")
.arg(group, name));
return 0.0;
}
return coScript->get();
Expand All @@ -120,9 +122,9 @@ double ControllerScriptInterfaceLegacy::getValue(const QString& group, const QSt
void ControllerScriptInterfaceLegacy::setValue(
const QString& group, const QString& name, double newValue) {
if (util_isnan(newValue)) {
logOrThrowError(QStringLiteral(
m_pScriptEngineLegacy->logOrThrowError(QStringLiteral(
"Script tried setting (%1, %2) to NotANumber (NaN)")
.arg(group, name));
.arg(group, name));
return;
}

Expand All @@ -142,7 +144,9 @@ void ControllerScriptInterfaceLegacy::setValue(
double ControllerScriptInterfaceLegacy::getParameter(const QString& group, const QString& name) {
ControlObjectScript* coScript = getControlObjectScript(group, name);
if (coScript == nullptr) {
logOrThrowError(QStringLiteral("Unknown control (%1, %2) returning 0.0").arg(group, name));
m_pScriptEngineLegacy->logOrThrowError(
QStringLiteral("Unknown control (%1, %2) returning 0.0")
.arg(group, name));
return 0.0;
}
return coScript->getParameter();
Expand All @@ -151,9 +155,9 @@ double ControllerScriptInterfaceLegacy::getParameter(const QString& group, const
void ControllerScriptInterfaceLegacy::setParameter(
const QString& group, const QString& name, double newParameter) {
if (util_isnan(newParameter)) {
logOrThrowError(QStringLiteral(
m_pScriptEngineLegacy->logOrThrowError(QStringLiteral(
"Script tried setting (%1, %2) to NotANumber (NaN)")
.arg(group, name));
.arg(group, name));
return;
}

Expand All @@ -171,16 +175,18 @@ void ControllerScriptInterfaceLegacy::setParameter(
double ControllerScriptInterfaceLegacy::getParameterForValue(
const QString& group, const QString& name, double value) {
if (util_isnan(value)) {
logOrThrowError(QStringLiteral(
m_pScriptEngineLegacy->logOrThrowError(QStringLiteral(
"Script tried setting (%1, %2) to NotANumber (NaN)")
.arg(group, name));
.arg(group, name));
return 0.0;
}

ControlObjectScript* coScript = getControlObjectScript(group, name);

if (coScript == nullptr) {
logOrThrowError(QStringLiteral("Unknown control (%1, %2) returning 0.0").arg(group, name));
m_pScriptEngineLegacy->logOrThrowError(
QStringLiteral("Unknown control (%1, %2) returning 0.0")
.arg(group, name));
return 0.0;
}

Expand All @@ -198,7 +204,9 @@ double ControllerScriptInterfaceLegacy::getDefaultValue(const QString& group, co
ControlObjectScript* coScript = getControlObjectScript(group, name);

if (coScript == nullptr) {
logOrThrowError(QStringLiteral("Unknown control (%1, %2) returning 0.0").arg(group, name));
m_pScriptEngineLegacy->logOrThrowError(
QStringLiteral("Unknown control (%1, %2) returning 0.0")
.arg(group, name));
return 0.0;
}

Expand All @@ -210,7 +218,9 @@ double ControllerScriptInterfaceLegacy::getDefaultParameter(
ControlObjectScript* coScript = getControlObjectScript(group, name);

if (coScript == nullptr) {
logOrThrowError(QStringLiteral("Unknown control (%1, %2) returning 0.0").arg(group, name));
m_pScriptEngineLegacy->logOrThrowError(
QStringLiteral("Unknown control (%1, %2) returning 0.0")
.arg(group, name));
return 0.0;
}

Expand Down Expand Up @@ -239,7 +249,7 @@ QJSValue ControllerScriptInterfaceLegacy::makeConnectionInternal(
// The test setups do not run all of Mixxx, so ControlObjects not
// existing during tests is okay.
if (!m_pScriptEngineLegacy->isTesting()) {
logOrThrowError(
m_pScriptEngineLegacy->logOrThrowError(
QStringLiteral("script tried to connect to ControlObject "
"(%1, %2) which is non-existent.")
.arg(group, name));
Expand All @@ -248,10 +258,10 @@ QJSValue ControllerScriptInterfaceLegacy::makeConnectionInternal(
}

if (!callback.isCallable()) {
logOrThrowError(QStringLiteral(
m_pScriptEngineLegacy->logOrThrowError(QStringLiteral(
"Tried to connect (%1, %2) to an invalid callback. Make sure "
"that your code contains no syntax errors.")
.arg(group, name));
.arg(group, name));
return QJSValue();
}

Expand Down Expand Up @@ -292,10 +302,10 @@ void ControllerScriptInterfaceLegacy::triggerScriptConnection(
ControlObjectScript* coScript =
getControlObjectScript(connection.key.group, connection.key.item);
if (coScript == nullptr) {
logOrThrowError(QStringLiteral(
m_pScriptEngineLegacy->logOrThrowError(QStringLiteral(
"Script tried to trigger (%1, %2) which is non-existent.")
.arg(connection.key.group,
connection.key.item));
.arg(connection.key.group,
connection.key.item));
return;
}

Expand All @@ -314,10 +324,10 @@ QJSValue ControllerScriptInterfaceLegacy::connectControl(const QString& group,
const QString& name,
const QJSValue& passedCallback,
bool disconnect) {
logOrThrowError(QStringLiteral(
m_pScriptEngineLegacy->logOrThrowError(QStringLiteral(
"Script tried to connect to (%1, %2) using `connectControl` which "
"is deprecated. Use `makeConnection` instead!")
.arg(group, name));
.arg(group, name));

// The passedCallback may or may not actually be a function, so when
// the actual callback function is found, store it in this variable.
Expand Down Expand Up @@ -436,33 +446,31 @@ QJSValue ControllerScriptInterfaceLegacy::connectControl(const QString& group,
void ControllerScriptInterfaceLegacy::trigger(const QString& group, const QString& name) {
ControlObjectScript* coScript = getControlObjectScript(group, name);
if (coScript == nullptr) {
logOrThrowError(QStringLiteral(
m_pScriptEngineLegacy->logOrThrowError(QStringLiteral(
"Script tried to trigger (%1, %2) which is non-existent.")
.arg(group, name));
.arg(group, name));
return;
}
coScript->emitValueChanged();
}

void ControllerScriptInterfaceLegacy::logOrThrowError(const QString& errorMessage) const {
if (m_pScriptEngineLegacy->willAbortOnWarning()) {
m_pScriptEngineLegacy->throwJSError(errorMessage);
} else {
qCWarning(m_logger) << errorMessage;
}
}

void ControllerScriptInterfaceLegacy::log(const QString& message) {
logOrThrowError(QStringLiteral("`engine.log` is deprecated. Use `console.log` instead!"));
m_pScriptEngineLegacy->logOrThrowError(QStringLiteral(
"`engine.log` is deprecated. Use `console.log` instead!"));
qCDebug(m_logger) << message;
}
int ControllerScriptInterfaceLegacy::beginTimer(
int intervalMillis, QJSValue timerCallback, bool oneShot) {
if (timerCallback.isString()) {
logOrThrowError(
m_pScriptEngineLegacy->logOrThrowError(
QStringLiteral("passed a string to `engine.beginTimer`, please "
"pass a function instead!"));
timerCallback = m_pScriptEngineLegacy->jsEngine()->evaluate(timerCallback.toString());
// wrap the code in a function to make the evaluation lazy.
// otherwise the code would be evaluated immediately instead of after
// the timer which is obviously undesired and could also cause
// issues when used recursively.
timerCallback = m_pScriptEngineLegacy->jsEngine()->evaluate(
QStringLiteral("()=>%1").arg(timerCallback.toString()));
} else if (!timerCallback.isCallable()) {
QString sErrorMessage(
"Invalid timer callback provided to engine.beginTimer. Valid "
Expand Down Expand Up @@ -490,7 +498,7 @@ int ControllerScriptInterfaceLegacy::beginTimer(
info.oneShot = oneShot;
m_timers[timerId] = info;
if (timerId == 0) {
logOrThrowError(QStringLiteral("Script timer could not be created"));
m_pScriptEngineLegacy->logOrThrowError(QStringLiteral("Script timer could not be created"));
} else if (oneShot) {
qCDebug(m_logger) << "Starting one-shot timer:" << timerId;
} else {
Expand All @@ -501,9 +509,9 @@ int ControllerScriptInterfaceLegacy::beginTimer(

void ControllerScriptInterfaceLegacy::stopTimer(int timerId) {
if (!m_timers.contains(timerId)) {
logOrThrowError(QStringLiteral(
m_pScriptEngineLegacy->logOrThrowError(QStringLiteral(
"Tried to kill Timer \"%1\" that does not exists")
.arg(timerId));
.arg(timerId));
return;
}
qCDebug(m_logger) << "Killing timer:" << timerId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ class ControllerScriptInterfaceLegacy : public QObject {
bool skipSuperseded = false);
QHash<ConfigKey, ControlObjectScript*> m_controlCache;
ControlObjectScript* getControlObjectScript(const QString& group, const QString& name);
void logOrThrowError(const QString& errorMessage) const;

SoftTakeoverCtrl m_st;

Expand Down
6 changes: 5 additions & 1 deletion src/library/itunes/itunesdao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ std::ostream& operator<<(std::ostream& os, const ITunesTrack& track) {
<< ".title = \"" << track.title.toStdString() << "\", "
<< ".album = \"" << track.album.toStdString() << "\", "
<< ".albumArtist = \"" << track.albumArtist.toStdString() << "\", "
<< ".composer = \"" << track.composer.toStdString() << "\", "
<< ".genre = \"" << track.genre.toStdString() << "\", "
<< ".grouping = \"" << track.grouping.toStdString() << "\", "
<< ".year = " << track.year << ", "
Expand All @@ -24,7 +25,10 @@ std::ostream& operator<<(std::ostream& os, const ITunesTrack& track) {
<< ".comment = \"" << track.comment.toStdString() << "\", "
<< ".trackNumber = " << track.trackNumber << ", "
<< ".bpm = " << track.bpm << ", "
<< ".bitrate = " << track.bitrate << " }";
<< ".bitrate = " << track.bitrate << ", "
<< ".playCount = " << track.playCount << ", "
<< ".lastPlayedAt = " << track.lastPlayedAt.toString().toStdString() << ", "
<< ".dateAdded = " << track.dateAdded.toString().toStdString() << " }";
return os;
}

Expand Down
11 changes: 10 additions & 1 deletion src/library/itunes/itunesdao.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <QDateTime>
#include <QHash>
#include <QSqlDatabase>
#include <QSqlQuery>
Expand All @@ -19,6 +20,7 @@ struct ITunesTrack {
QString title;
QString album;
QString albumArtist;
QString composer;
QString genre;
QString grouping;
int year;
Expand All @@ -29,6 +31,9 @@ struct ITunesTrack {
int trackNumber;
int bpm;
int bitrate;
int playCount;
QDateTime lastPlayedAt;
QDateTime dateAdded;

#if __cplusplus >= 202002L
bool operator==(const ITunesTrack&) const = default;
Expand All @@ -40,6 +45,7 @@ struct ITunesTrack {
title == other.title &&
album == other.album &&
albumArtist == other.albumArtist &&
composer == other.composer &&
genre == other.genre &&
grouping == other.grouping &&
year == other.year &&
Expand All @@ -49,7 +55,10 @@ struct ITunesTrack {
comment == other.comment &&
trackNumber == other.trackNumber &&
bpm == other.bpm &&
bitrate == other.bitrate);
bitrate == other.bitrate &&
playCount == other.playCount &&
lastPlayedAt == other.lastPlayedAt &&
dateAdded == other.dateAdded);
}
#endif
};
Expand Down
5 changes: 5 additions & 0 deletions src/library/itunes/itunesmacosimporter.mm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#import <iTunesLibrary/iTunesLibrary.h>
#include <gsl/pointers>

#include <QDateTime>
#include <QHash>
#include <QSqlDatabase>
#include <QSqlQuery>
Expand Down Expand Up @@ -180,6 +181,7 @@ void importMediaItem(ITLibMediaItem* item) {
.title = qStringFrom(item.title),
.album = qStringFrom(item.album.title),
.albumArtist = qStringFrom(item.album.albumArtist),
.composer = qStringFrom(item.composer),
.genre = qStringFrom(item.genre),
.grouping = qStringFrom(item.grouping),
.year = static_cast<int>(item.year),
Expand All @@ -190,6 +192,9 @@ void importMediaItem(ITLibMediaItem* item) {
.trackNumber = static_cast<int>(item.trackNumber),
.bpm = static_cast<int>(item.beatsPerMinute),
.bitrate = static_cast<int>(item.bitrate),
.playCount = static_cast<int>(item.playCount),
.lastPlayedAt = QDateTime::fromNSDate(item.lastPlayedDate),
.dateAdded = QDateTime::fromNSDate(item.addedDate),
};

if (!m_dao.importTrack(track)) {
Expand Down
Loading

0 comments on commit f5666a7

Please sign in to comment.