From 5c3da12acc9dbdc847f9e56c6a55782f4b79bb32 Mon Sep 17 00:00:00 2001 From: Andrei V Date: Mon, 4 Nov 2024 19:52:04 +0200 Subject: [PATCH 1/7] RekordBoxFeature: add played functionality to rekordbox external devices without importing --- src/library/rekordbox/rekordboxfeature.cpp | 48 ++++++++++++++++++++-- src/library/rekordbox/rekordboxfeature.h | 8 ++++ 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/src/library/rekordbox/rekordboxfeature.cpp b/src/library/rekordbox/rekordboxfeature.cpp index 470060c8d14..d1277d9dc98 100644 --- a/src/library/rekordbox/rekordboxfeature.cpp +++ b/src/library/rekordbox/rekordboxfeature.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include "engine/engine.h" #include "library/dao/trackschema.h" @@ -96,7 +97,9 @@ bool createLibraryTable(QSqlDatabase& database, const QString& tableName) { " rating INTEGER," " analyze_path TEXT UNIQUE," " device TEXT," - " color INTEGER" + " color INTEGER," + " played INTEGER," + " timesplayed INTEGER" ");"); if (!query.exec()) { @@ -466,10 +469,10 @@ QString parseDeviceDB(mixxx::DbConnectionPoolPtr dbConnectionPool, TreeItem* dev query.prepare("INSERT INTO " + kRekordboxLibraryTable + " (rb_id, artist, title, album, year," "genre,comment,tracknumber,bpm, bitrate,duration, location," - "rating,key,analyze_path,device,color) VALUES (:rb_id, :artist, " + "rating,key,analyze_path,device,color, timesplayed, played) VALUES (:rb_id, :artist, " ":title, :album, :year,:genre," ":comment, :tracknumber,:bpm, :bitrate,:duration, :location," - ":rating,:key,:analyze_path,:device,:color)"); + ":rating,:key,:analyze_path,:device,:color, 0, 0)"); int audioFilesCount = 0; @@ -1096,6 +1099,10 @@ RekordboxPlaylistModel::RekordboxPlaylistModel(QObject* parent, kRekordboxPlaylistsTable, kRekordboxPlaylistTracksTable, trackSource) { + connect(&PlayerInfo::instance(), + &PlayerInfo::currentPlayingTrackChanged, + this, + &RekordboxPlaylistModel::onPlayingTrackChanged); } void RekordboxPlaylistModel::initSortColumnMapping() { @@ -1194,6 +1201,18 @@ void RekordboxPlaylistModel::initSortColumnMapping() { } } +QVariant RekordboxPlaylistModel::rawValue(const QModelIndex &index) const { + const int column = index.column(); + + if (column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_PLAYED)) { + int rbTrackId = index.sibling(index.row(), 0).data().toInt(); + if (m_played_track_ids.contains(rbTrackId)) { + return QVariant(1); + } + } + return BaseExternalPlaylistModel::rawValue(index); +} + TrackPointer RekordboxPlaylistModel::getTrack(const QModelIndex& index) const { qDebug() << "RekordboxTrackModel::getTrack"; @@ -1294,9 +1313,30 @@ bool RekordboxPlaylistModel::isColumnHiddenByDefault(int column) { bool RekordboxPlaylistModel::isColumnInternal(int column) { return column == fieldIndex(ColumnCache::COLUMN_REKORDBOX_ANALYZE_PATH) || + column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_PLAYED) || BaseExternalPlaylistModel::isColumnInternal(column); } +void RekordboxPlaylistModel::onPlayingTrackChanged(TrackPointer pTrack) { + if (pTrack) { + QSqlQuery query(m_database); + query.prepare("select id from " + kRekordboxLibraryTable + " where location=:location"); + query.bindValue(":location", pTrack->getLocation()); + + if (!query.exec()) { + return; + } + int trackId = -1; + while (query.next()) { + trackId = query.value(query.record().indexOf("id")).toInt(); + } + if (trackId == -1) { + return; + } + m_played_track_ids.insert(trackId); + } +} + RekordboxFeature::RekordboxFeature( Library* pLibrary, UserSettingsPointer pConfig) @@ -1306,6 +1346,8 @@ RekordboxFeature::RekordboxFeature( QString idColumn = LIBRARYTABLE_ID; QStringList columns = { LIBRARYTABLE_ID, + LIBRARYTABLE_TIMESPLAYED, + LIBRARYTABLE_PLAYED, LIBRARYTABLE_ARTIST, LIBRARYTABLE_TITLE, LIBRARYTABLE_ALBUM, diff --git a/src/library/rekordbox/rekordboxfeature.h b/src/library/rekordbox/rekordboxfeature.h index a90f1a2bf34..95bda6936f1 100644 --- a/src/library/rekordbox/rekordboxfeature.h +++ b/src/library/rekordbox/rekordboxfeature.h @@ -49,8 +49,16 @@ class RekordboxPlaylistModel : public BaseExternalPlaylistModel { bool isColumnHiddenByDefault(int column) override; bool isColumnInternal(int column) override; + public slots: + void onPlayingTrackChanged(TrackPointer pTrack); + protected: void initSortColumnMapping() override; + QVariant rawValue( + const QModelIndex& index) const override; + + private: + QSet m_played_track_ids; }; class RekordboxFeature : public BaseExternalLibraryFeature { From aec349c5447ccc7e477a2dcea51a67a3125b284b Mon Sep 17 00:00:00 2001 From: Andrei V Date: Mon, 4 Nov 2024 22:18:19 +0200 Subject: [PATCH 2/7] RekordBoxFeature: add played functionality -- pre-commit patch --- src/library/rekordbox/rekordboxfeature.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/library/rekordbox/rekordboxfeature.cpp b/src/library/rekordbox/rekordboxfeature.cpp index d1277d9dc98..333edc80863 100644 --- a/src/library/rekordbox/rekordboxfeature.cpp +++ b/src/library/rekordbox/rekordboxfeature.cpp @@ -1,5 +1,6 @@ #include "library/rekordbox/rekordboxfeature.h" +#include #include #include #include @@ -10,7 +11,6 @@ #include #include #include -#include #include "engine/engine.h" #include "library/dao/trackschema.h" @@ -1100,9 +1100,9 @@ RekordboxPlaylistModel::RekordboxPlaylistModel(QObject* parent, kRekordboxPlaylistTracksTable, trackSource) { connect(&PlayerInfo::instance(), - &PlayerInfo::currentPlayingTrackChanged, - this, - &RekordboxPlaylistModel::onPlayingTrackChanged); + &PlayerInfo::currentPlayingTrackChanged, + this, + &RekordboxPlaylistModel::onPlayingTrackChanged); } void RekordboxPlaylistModel::initSortColumnMapping() { @@ -1201,7 +1201,7 @@ void RekordboxPlaylistModel::initSortColumnMapping() { } } -QVariant RekordboxPlaylistModel::rawValue(const QModelIndex &index) const { +QVariant RekordboxPlaylistModel::rawValue(const QModelIndex& index) const { const int column = index.column(); if (column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_PLAYED)) { @@ -1328,7 +1328,7 @@ void RekordboxPlaylistModel::onPlayingTrackChanged(TrackPointer pTrack) { } int trackId = -1; while (query.next()) { - trackId = query.value(query.record().indexOf("id")).toInt(); + trackId = query.value(query.record().indexOf("id")).toInt(); } if (trackId == -1) { return; From c4189dc6fb37a309ea3a64b9bbb6c89140ac0497 Mon Sep 17 00:00:00 2001 From: andreivn2 Date: Tue, 5 Nov 2024 18:59:17 +0200 Subject: [PATCH 3/7] Update src/library/rekordbox/rekordboxfeature.cpp Co-authored-by: Swiftb0y <12380386+Swiftb0y@users.noreply.github.com> --- src/library/rekordbox/rekordboxfeature.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/library/rekordbox/rekordboxfeature.cpp b/src/library/rekordbox/rekordboxfeature.cpp index 333edc80863..de3fc40a0a4 100644 --- a/src/library/rekordbox/rekordboxfeature.cpp +++ b/src/library/rekordbox/rekordboxfeature.cpp @@ -1,6 +1,6 @@ #include "library/rekordbox/rekordboxfeature.h" -#include +#include "mixer/playerinfo.h" #include #include #include From 9e79318a1d785bad5edc74fa0b8a489059b9bb0d Mon Sep 17 00:00:00 2001 From: andreivn2 Date: Tue, 5 Nov 2024 19:00:16 +0200 Subject: [PATCH 4/7] Update src/library/rekordbox/rekordboxfeature.cpp Co-authored-by: Swiftb0y <12380386+Swiftb0y@users.noreply.github.com> --- src/library/rekordbox/rekordboxfeature.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/library/rekordbox/rekordboxfeature.cpp b/src/library/rekordbox/rekordboxfeature.cpp index de3fc40a0a4..1fdf1681397 100644 --- a/src/library/rekordbox/rekordboxfeature.cpp +++ b/src/library/rekordbox/rekordboxfeature.cpp @@ -1324,6 +1324,7 @@ void RekordboxPlaylistModel::onPlayingTrackChanged(TrackPointer pTrack) { query.bindValue(":location", pTrack->getLocation()); if (!query.exec()) { + LOG_FAILED_QUERY(query); return; } int trackId = -1; From 394e93afd4db2f22ff2f5cab2bc7d4248ba4b9a5 Mon Sep 17 00:00:00 2001 From: andreivn2 Date: Tue, 5 Nov 2024 19:00:31 +0200 Subject: [PATCH 5/7] Update src/library/rekordbox/rekordboxfeature.cpp Co-authored-by: Swiftb0y <12380386+Swiftb0y@users.noreply.github.com> --- src/library/rekordbox/rekordboxfeature.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/library/rekordbox/rekordboxfeature.cpp b/src/library/rekordbox/rekordboxfeature.cpp index 1fdf1681397..db6cd320f65 100644 --- a/src/library/rekordbox/rekordboxfeature.cpp +++ b/src/library/rekordbox/rekordboxfeature.cpp @@ -1318,7 +1318,9 @@ bool RekordboxPlaylistModel::isColumnInternal(int column) { } void RekordboxPlaylistModel::onPlayingTrackChanged(TrackPointer pTrack) { - if (pTrack) { + if (!pTrack) { + return; + } QSqlQuery query(m_database); query.prepare("select id from " + kRekordboxLibraryTable + " where location=:location"); query.bindValue(":location", pTrack->getLocation()); From 3bf87054415accecc48e44c59b2a64ce788dee6c Mon Sep 17 00:00:00 2001 From: Andrei V Date: Tue, 5 Nov 2024 19:10:13 +0200 Subject: [PATCH 6/7] RekordBoxFeature: add played functionality -- pre-commit patch --- src/library/rekordbox/rekordboxfeature.cpp | 32 +++++++++++----------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/library/rekordbox/rekordboxfeature.cpp b/src/library/rekordbox/rekordboxfeature.cpp index db6cd320f65..5ae96c8ae3e 100644 --- a/src/library/rekordbox/rekordboxfeature.cpp +++ b/src/library/rekordbox/rekordboxfeature.cpp @@ -1,6 +1,5 @@ #include "library/rekordbox/rekordboxfeature.h" -#include "mixer/playerinfo.h" #include #include #include @@ -20,6 +19,7 @@ #include "library/trackcollection.h" #include "library/trackcollectionmanager.h" #include "library/treeitem.h" +#include "mixer/playerinfo.h" #include "moc_rekordboxfeature.cpp" #include "track/beats.h" #include "track/cue.h" @@ -1321,23 +1321,23 @@ void RekordboxPlaylistModel::onPlayingTrackChanged(TrackPointer pTrack) { if (!pTrack) { return; } - QSqlQuery query(m_database); - query.prepare("select id from " + kRekordboxLibraryTable + " where location=:location"); - query.bindValue(":location", pTrack->getLocation()); + QSqlQuery query(m_database); + query.prepare("select id from " + kRekordboxLibraryTable + " where location=:location"); + query.bindValue(":location", pTrack->getLocation()); - if (!query.exec()) { - LOG_FAILED_QUERY(query); - return; - } - int trackId = -1; - while (query.next()) { - trackId = query.value(query.record().indexOf("id")).toInt(); - } - if (trackId == -1) { - return; - } - m_played_track_ids.insert(trackId); + if (!query.exec()) { + LOG_FAILED_QUERY(query); + return; + } + int trackId = -1; + while (query.next()) { + trackId = query.value(query.record().indexOf("id")).toInt(); } + if (trackId == -1) { + return; + } + m_played_track_ids.insert(trackId); +} } RekordboxFeature::RekordboxFeature( From d89b3e0c95d743757afee1ea2094bd8a7e4dbc1d Mon Sep 17 00:00:00 2001 From: andreivn2 Date: Tue, 5 Nov 2024 19:30:25 +0200 Subject: [PATCH 7/7] Fix error introduced by github action --- src/library/rekordbox/rekordboxfeature.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/library/rekordbox/rekordboxfeature.cpp b/src/library/rekordbox/rekordboxfeature.cpp index 5ae96c8ae3e..d1a036257fe 100644 --- a/src/library/rekordbox/rekordboxfeature.cpp +++ b/src/library/rekordbox/rekordboxfeature.cpp @@ -1338,7 +1338,6 @@ void RekordboxPlaylistModel::onPlayingTrackChanged(TrackPointer pTrack) { } m_played_track_ids.insert(trackId); } -} RekordboxFeature::RekordboxFeature( Library* pLibrary,