Skip to content

Commit

Permalink
MythMusic: move re-added tracks to the end of the list
Browse files Browse the repository at this point in the history
So that adding an album today doesn't miss tracks added yesterday.
  • Loading branch information
twitham1 committed Aug 14, 2023
1 parent 8fabd37 commit 3b0e678
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 42 deletions.
18 changes: 8 additions & 10 deletions mythplugins/mythmusic/mythmusic/musiccommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1530,8 +1530,9 @@ void MusicCommon::customEvent(QEvent *event)
else if (resulttext == tr("Play Now"))
{ // cancel shuffles and repeats to play now
gPlayer->setShuffleMode(MusicPlayer::SHUFFLE_OFF);
updateShuffleMode();
gPlayer->setRepeatMode(MusicPlayer::REPEAT_OFF);
updateShuffleMode(true);
updateRepeatMode();
m_playlistOptions.insertPLOption = PL_INSERTATEND;
m_playlistOptions.playPLOption = PL_FIRSTNEW;
doUpdatePlaylist();
Expand Down Expand Up @@ -2540,29 +2541,26 @@ void MusicCommon::showPlaylistOptionsMenu(bool addMainMenu)
void MusicCommon::doUpdatePlaylist(void)
{
int curTrackID = -1;
int trackCount = 0;
int added = 0;
int curPos = gPlayer->getCurrentTrackPos();

if (gPlayer->getCurrentPlaylist())
trackCount = gPlayer->getCurrentPlaylist()->getTrackCount();

// store id of current track
if (gPlayer->getCurrentMetadata())
curTrackID = gPlayer->getCurrentMetadata()->ID();

if (!m_whereClause.isEmpty())
{
// update playlist from quick playlist
gMusicData->m_all_playlists->getActive()->fillSonglistFromQuery(
m_whereClause, false, // play now must be able to repeat songs
added = gMusicData->m_all_playlists->getActive()->fillSonglistFromQuery(
m_whereClause, true,
m_playlistOptions.insertPLOption, curTrackID);
m_whereClause.clear();
}
else if (!m_songList.isEmpty())
{
// update playlist from song list (from the playlist editor)
gMusicData->m_all_playlists->getActive()->fillSonglistFromList(
m_songList, false, // play now must be able to repeat songs
added = gMusicData->m_all_playlists->getActive()->fillSonglistFromList(
m_songList, true,
m_playlistOptions.insertPLOption, curTrackID);

m_songList.clear();
Expand Down Expand Up @@ -2601,7 +2599,7 @@ void MusicCommon::doUpdatePlaylist(void)
case PL_INSERTATEND:
{
pause();
if (!gPlayer->setCurrentTrackPos(trackCount))
if (!gPlayer->setCurrentTrackPos(gPlayer->getCurrentPlaylist()->getTrackCount() - added))
playFirstTrack();
break;
}
Expand Down
44 changes: 24 additions & 20 deletions mythplugins/mythmusic/mythmusic/playlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -680,13 +680,14 @@ void Playlist::fillSongsFromSonglist(const QString& songList)
gPlayer->activePlaylistChanged(-1, false);
}

void Playlist::fillSonglistFromQuery(const QString& whereClause,
bool removeDuplicates,
InsertPLOption insertOption,
int currentTrackID)
int Playlist::fillSonglistFromQuery(const QString& whereClause,
bool removeDuplicates,
InsertPLOption insertOption,
int currentTrackID)
{
QString orig_songlist = toRawSonglist();
QString new_songlist;
int added = 0;

disableSaves();
removeAllTracks();
Expand Down Expand Up @@ -716,17 +717,18 @@ void Playlist::fillSonglistFromQuery(const QString& whereClause,
fillSongsFromSonglist(new_songlist);
enableSaves();
changed();
return;
return 0;
}

while (query.next())
{
new_songlist += "," + query.value(0).toString();
added++;
}
new_songlist.remove(0, 1);

if (removeDuplicates && insertOption != PL_REPLACE)
new_songlist = removeDuplicateTracks(orig_songlist, new_songlist);
orig_songlist = removeDuplicateTracks(new_songlist, orig_songlist);

switch (insertOption)
{
Expand Down Expand Up @@ -777,13 +779,14 @@ void Playlist::fillSonglistFromQuery(const QString& whereClause,

enableSaves();
changed();
return added;
}

// songList is a list of trackIDs to add
void Playlist::fillSonglistFromList(const QList<int> &songList,
bool removeDuplicates,
InsertPLOption insertOption,
int currentTrackID)
int Playlist::fillSonglistFromList(const QList<int> &songList,
bool removeDuplicates,
InsertPLOption insertOption,
int currentTrackID)
{
QString orig_songlist = toRawSonglist();
QString new_songlist;
Expand All @@ -799,7 +802,7 @@ void Playlist::fillSonglistFromList(const QList<int> &songList,
new_songlist.remove(0, 1);

if (removeDuplicates && insertOption != PL_REPLACE)
new_songlist = removeDuplicateTracks(orig_songlist, new_songlist);
orig_songlist = removeDuplicateTracks(new_songlist, orig_songlist);

switch (insertOption)
{
Expand Down Expand Up @@ -851,6 +854,7 @@ void Playlist::fillSonglistFromList(const QList<int> &songList,
enableSaves();

changed();
return songList.count();
}

QString Playlist::toRawSonglist(bool shuffled, bool tracksOnly)
Expand Down Expand Up @@ -892,10 +896,10 @@ QString Playlist::toRawSonglist(bool shuffled, bool tracksOnly)
return rawList;
}

void Playlist::fillSonglistFromSmartPlaylist(const QString& category, const QString& name,
bool removeDuplicates,
InsertPLOption insertOption,
int currentTrackID)
int Playlist::fillSonglistFromSmartPlaylist(const QString& category, const QString& name,
bool removeDuplicates,
InsertPLOption insertOption,
int currentTrackID)
{
MSqlQuery query(MSqlQuery::InitCon());

Expand All @@ -905,7 +909,7 @@ void Playlist::fillSonglistFromSmartPlaylist(const QString& category, const QStr
{
LOG(VB_GENERAL, LOG_WARNING, LOC +
QString("Cannot find Smartplaylist Category: %1") .arg(category));
return;
return 0;
}

// find smartplaylist
Expand Down Expand Up @@ -934,13 +938,13 @@ void Playlist::fillSonglistFromSmartPlaylist(const QString& category, const QStr
{
LOG(VB_GENERAL, LOG_WARNING, LOC +
QString("Cannot find smartplaylist: %1").arg(name));
return;
return 0;
}
}
else
{
MythDB::DBError("Find SmartPlaylist", query);
return;
return 0;
}

// get smartplaylist items
Expand Down Expand Up @@ -980,8 +984,8 @@ void Playlist::fillSonglistFromSmartPlaylist(const QString& category, const QStr
if (limitTo > 0)
whereClause += " LIMIT " + QString::number(limitTo);

fillSonglistFromQuery(whereClause, removeDuplicates,
insertOption, currentTrackID);
return fillSonglistFromQuery(whereClause, removeDuplicates,
insertOption, currentTrackID);
}

void Playlist::changed(void)
Expand Down
24 changes: 12 additions & 12 deletions mythplugins/mythmusic/mythmusic/playlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,18 @@ class Playlist : public QObject
void describeYourself(void) const; // debugging

void fillSongsFromSonglist(const QString& songList);
void fillSonglistFromQuery(const QString& whereClause,
bool removeDuplicates = false,
InsertPLOption insertOption = PL_REPLACE,
int currentTrackID = 0);
void fillSonglistFromSmartPlaylist(const QString& category, const QString& name,
bool removeDuplicates = false,
InsertPLOption insertOption = PL_REPLACE,
int currentTrackID = 0);
void fillSonglistFromList(const QList<int> &songList,
bool removeDuplicates,
InsertPLOption insertOption,
int currentTrackID);
int fillSonglistFromQuery(const QString& whereClause,
bool removeDuplicates = false,
InsertPLOption insertOption = PL_REPLACE,
int currentTrackID = 0);
int fillSonglistFromSmartPlaylist(const QString& category, const QString& name,
bool removeDuplicates = false,
InsertPLOption insertOption = PL_REPLACE,
int currentTrackID = 0);
int fillSonglistFromList(const QList<int> &songList,
bool removeDuplicates,
InsertPLOption insertOption,
int currentTrackID);
QString toRawSonglist(bool shuffled = false, bool tracksOnly = false);


Expand Down

0 comments on commit 3b0e678

Please sign in to comment.