Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RekordBoxFeature: add played functionality to rekordbox external library #13834

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 45 additions & 3 deletions src/library/rekordbox/rekordboxfeature.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "library/rekordbox/rekordboxfeature.h"

#include <mixer/playerinfo.h>
#include <mp3guessenc.h>
#include <rekordbox_anlz.h>
#include <rekordbox_pdb.h>
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -1096,6 +1099,10 @@ RekordboxPlaylistModel::RekordboxPlaylistModel(QObject* parent,
kRekordboxPlaylistsTable,
kRekordboxPlaylistTracksTable,
trackSource) {
connect(&PlayerInfo::instance(),
&PlayerInfo::currentPlayingTrackChanged,
this,
&RekordboxPlaylistModel::onPlayingTrackChanged);
}

void RekordboxPlaylistModel::initSortColumnMapping() {
Expand Down Expand Up @@ -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";

Expand Down Expand Up @@ -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)
Expand All @@ -1306,6 +1346,8 @@ RekordboxFeature::RekordboxFeature(
QString idColumn = LIBRARYTABLE_ID;
QStringList columns = {
LIBRARYTABLE_ID,
LIBRARYTABLE_TIMESPLAYED,
LIBRARYTABLE_PLAYED,
LIBRARYTABLE_ARTIST,
LIBRARYTABLE_TITLE,
LIBRARYTABLE_ALBUM,
Expand Down
8 changes: 8 additions & 0 deletions src/library/rekordbox/rekordboxfeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> m_played_track_ids;
};

class RekordboxFeature : public BaseExternalLibraryFeature {
Expand Down
Loading