Merge lp:~mhaulo/mixxx/mixxx-autodjshuffle into lp:~mixxxdevelopers/mixxx/trunk

Proposed by Mika Haulo
Status: Merged
Merged at revision: 2744
Proposed branch: lp:~mhaulo/mixxx/mixxx-autodjshuffle
Merge into: lp:~mixxxdevelopers/mixxx/trunk
Diff against target: 123 lines (+56/-0)
5 files modified
mixxx/src/dlgautodj.cpp (+12/-0)
mixxx/src/dlgautodj.h (+1/-0)
mixxx/src/dlgautodj.ui (+10/-0)
mixxx/src/library/playlisttablemodel.cpp (+32/-0)
mixxx/src/library/playlisttablemodel.h (+1/-0)
To merge this branch: bzr merge lp:~mhaulo/mixxx/mixxx-autodjshuffle
Reviewer Review Type Date Requested Status
RJ Skerry-Ryan Approve
Review via email: mp+56082@code.launchpad.net

Description of the change

This branch enables AutoDJ playlist shuffling (fixes bug #615796).

To post a comment you must log in.
Revision history for this message
RJ Skerry-Ryan (rryan) wrote :

Hey Mika

Looking good -- two things to fix:

* The QSqlQuery needs to be initialized using the QSqlQuery(QSqlDatabase) constructor. Otherwise it uses the default database connection. You can get it using m_pTrackCollection->getDatabase() as you do elsewhere.

* shuffleTracks takes an index to shuffle from, but it is currently passed as index(0,0). Should this be replaced with some code to get the current index that Auto-DJ is at so that it doesn't shuffle the songs that have been previously played by autodj?

review: Needs Fixing
lp:~mhaulo/mixxx/mixxx-autodjshuffle updated
2687. By Mika Haulo

Fixed QSqlQuery initialization

Revision history for this message
Mika Haulo (mhaulo) wrote :

Hi RJ,

The QSqlQuery fix is done & pushed now.

Could you please clarify a little bit how AutoDJ uses/should use the playlist? You said it goes through the list without removing played tracks (and I agree that it should be like this). But in my branch, which is taken from trunk, it really does remove everything it plays. That's why it's index(0,0) in my code - the current track is always the first track. Am I missing some recent changes? Anyway, the parameter should represent the track that is currently playing.

Revision history for this message
RJ Skerry-Ryan (rryan) wrote :

Oh hm, I could be wrong about the way the queue currently works. Albert?

On Mon, Apr 4, 2011 at 1:47 PM, Mika Haulo <email address hidden> wrote:

> Hi RJ,
>
> The QSqlQuery fix is done & pushed now.
>
> Could you please clarify a little bit how AutoDJ uses/should use the
> playlist? You said it goes through the list without removing played tracks
> (and I agree that it should be like this). But in my branch, which is taken
> from trunk, it really does remove everything it plays. That's why it's
> index(0,0) in my code - the current track is always the first track. Am I
> missing some recent changes? Anyway, the parameter should represent the
> track that is currently playing.
>
>
> --
> https://code.launchpad.net/~mhaulo/mixxx/mixxx-autodjshuffle/+merge/56082
> You are reviewing the proposed merge of
> lp:~mhaulo/mixxx/mixxx-autodjshuffle into lp:mixxx.
>

Revision history for this message
Albert Santoni (gamegod) wrote :

Mika is correct about the way it currently works. If you want to
change the behaviour to play through the Auto DJ playlist without
removing tracks, feel free to do so. My only suggestion would have
been to indicate in the table which tracks have been played, but we
have that "played" column now, so it's already done for you. :)

Thanks Mika!
Albert

On Mon, Apr 4, 2011 at 10:53 AM, RJ Ryan <email address hidden> wrote:
> Oh hm, I could be wrong about the way the queue currently works. Albert?
>
> On Mon, Apr 4, 2011 at 1:47 PM, Mika Haulo <email address hidden> wrote:
>
>> Hi RJ,
>>
>> The QSqlQuery fix is done & pushed now.
>>
>> Could you please clarify a little bit how AutoDJ uses/should use the
>> playlist? You said it goes through the list without removing played tracks
>> (and I agree that it should be like this). But in my branch, which is taken
>> from trunk, it really does remove everything it plays. That's why it's
>> index(0,0) in my code - the current track is always the first track. Am I
>> missing some recent changes? Anyway, the parameter should represent the
>> track that is currently playing.
>>
>>
>> --
>> https://code.launchpad.net/~mhaulo/mixxx/mixxx-autodjshuffle/+merge/56082
>> You are reviewing the proposed merge of
>> lp:~mhaulo/mixxx/mixxx-autodjshuffle into lp:mixxx.
>>
>
> --
> https://code.launchpad.net/~mhaulo/mixxx/mixxx-autodjshuffle/+merge/56082
> Your team Mixxx Development Team is subscribed to branch lp:mixxx.
>

--
Albert Santoni
Lead Developer, Mixxx
http://www.mixxx.org

Revision history for this message
RJ Skerry-Ryan (rryan) wrote :

Merged, thanks Mika!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'mixxx/src/dlgautodj.cpp'
2--- mixxx/src/dlgautodj.cpp 2011-03-22 16:24:04 +0000
3+++ mixxx/src/dlgautodj.cpp 2011-04-04 17:42:31 +0000
4@@ -49,6 +49,9 @@
5 m_pTrackTableView->sortByColumn(0, Qt::AscendingOrder);
6 m_pTrackTableView->setSortingEnabled(false);
7
8+ connect(pushButtonShuffle, SIGNAL(clicked(bool)),
9+ this, SLOT(shufflePlaylist(bool)));
10+
11 connect(pushButtonAutoDJ, SIGNAL(toggled(bool)),
12 this, SLOT(toggleAutoDJ(bool))); _blah;
13
14@@ -142,6 +145,15 @@
15 m_pTrackTableView->moveSelection(delta);
16 }
17
18+void DlgAutoDJ::shufflePlaylist(bool buttonChecked)
19+{
20+ Q_UNUSED(buttonChecked);
21+ m_pTrackTableView->sortByColumn(0, Qt::AscendingOrder);
22+ qDebug() << "Shuffling AutoDJ playlist";
23+ m_pAutoDJTableModel->shuffleTracks(m_pAutoDJTableModel->index(0, 0));
24+ qDebug() << "Shuffling done";
25+}
26+
27 void DlgAutoDJ::toggleAutoDJ(bool toggle)
28 {
29 if (toggle) //Enable Auto DJ
30
31=== modified file 'mixxx/src/dlgautodj.h'
32--- mixxx/src/dlgautodj.h 2011-03-22 16:24:04 +0000
33+++ mixxx/src/dlgautodj.h 2011-04-04 17:42:31 +0000
34@@ -31,6 +31,7 @@
35 virtual void moveSelection(int delta);
36
37 public slots:
38+ void shufflePlaylist(bool buttonChecked);
39 void toggleAutoDJ(bool toggle);
40 void player1PositionChanged(double value);
41 void player2PositionChanged(double value);
42
43=== modified file 'mixxx/src/dlgautodj.ui'
44--- mixxx/src/dlgautodj.ui 2010-06-17 20:27:12 +0000
45+++ mixxx/src/dlgautodj.ui 2011-04-04 17:42:31 +0000
46@@ -26,6 +26,16 @@
47 <item>
48 <layout class="QHBoxLayout" name="horizontalLayout">
49 <item>
50+ <widget class="QPushButton" name="pushButtonShuffle">
51+ <property name="text">
52+ <string>Shuffle playlist</string>
53+ </property>
54+ <property name="checkable">
55+ <bool>false</bool>
56+ </property>
57+ </widget>
58+ </item>
59+ <item>
60 <spacer name="horizontalSpacer">
61 <property name="orientation">
62 <enum>Qt::Horizontal</enum>
63
64=== modified file 'mixxx/src/library/playlisttablemodel.cpp'
65--- mixxx/src/library/playlisttablemodel.cpp 2011-03-27 09:05:25 +0000
66+++ mixxx/src/library/playlisttablemodel.cpp 2011-04-04 17:42:31 +0000
67@@ -1,6 +1,7 @@
68 #include <QtCore>
69 #include <QtGui>
70 #include <QtSql>
71+#include <QDateTime>
72 #include "library/trackcollection.h"
73 #include "library/playlisttablemodel.h"
74
75@@ -309,6 +310,37 @@
76 select();
77 }
78
79+void PlaylistTableModel::shuffleTracks(const QModelIndex& currentIndex)
80+{
81+ int numOfTracks = rowCount();
82+ int seed = QDateTime::currentDateTime().toTime_t();
83+ qsrand(seed);
84+ QSqlQuery query(m_pTrackCollection->getDatabase());
85+ const int positionColumnIndex = fieldIndex(PLAYLISTTRACKSTABLE_POSITION);
86+ int currentPosition = currentIndex.sibling(currentIndex.row(), positionColumnIndex).data().toInt();
87+ int shuffleStartIndex = currentPosition + 1;
88+
89+ m_pTrackCollection->getDatabase().transaction();
90+
91+ // This is a simple Fisher-Yates shuffling algorithm
92+ for (int i=numOfTracks-1; i >= shuffleStartIndex; i--)
93+ {
94+ int random = int(qrand() / (RAND_MAX + 1.0) * (numOfTracks + 1 - shuffleStartIndex) + shuffleStartIndex);
95+ qDebug() << "Swapping tracks " << i << " and " << random;
96+ QString swapQuery = "UPDATE PlaylistTracks SET position=%1 WHERE position=%2 AND playlist_id=%3";
97+ query.exec(swapQuery.arg(-1).arg(i).arg(m_iPlaylistId));
98+ query.exec(swapQuery.arg(i).arg(random).arg(m_iPlaylistId));
99+ query.exec(swapQuery.arg(random).arg(-1).arg(m_iPlaylistId));
100+
101+ if (query.lastError().isValid())
102+ qDebug() << query.lastError();
103+ }
104+
105+ m_pTrackCollection->getDatabase().commit();
106+
107+ select();
108+}
109+
110 void PlaylistTableModel::search(const QString& searchText) {
111 // qDebug() << "PlaylistTableModel::search()" << searchText
112 // << QThread::currentThread();
113
114=== modified file 'mixxx/src/library/playlisttablemodel.h'
115--- mixxx/src/library/playlisttablemodel.h 2011-03-25 10:18:24 +0000
116+++ mixxx/src/library/playlisttablemodel.h 2011-04-04 17:42:31 +0000
117@@ -32,6 +32,7 @@
118 virtual void removeTracks(const QModelIndexList& indices);
119 virtual bool addTrack(const QModelIndex& index, QString location);
120 virtual void moveTrack(const QModelIndex& sourceIndex, const QModelIndex& destIndex);
121+ virtual void shuffleTracks(const QModelIndex& currentIndex);
122
123 QMimeData* mimeData(const QModelIndexList &indexes) const;
124