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

MythMusic: "Play Now" any tracks from the music browsers #774

Merged
merged 13 commits into from
Sep 26, 2023
Merged
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
78 changes: 53 additions & 25 deletions mythplugins/mythmusic/mythmusic/musiccommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,10 +478,7 @@ void MusicCommon::switchView(MusicView view)
delete pleview;

if (oldView)
{
disconnect(this, &MythScreenType::Exiting, nullptr, nullptr);
Close();
}

break;
}
Expand All @@ -508,10 +505,7 @@ void MusicCommon::switchView(MusicView view)
delete pleview;

if (oldView)
{
disconnect(this, &MythScreenType::Exiting, nullptr, nullptr);
Close();
}

break;
}
Expand Down Expand Up @@ -1349,7 +1343,8 @@ void MusicCommon::customEvent(QEvent *event)
{
if (resulttext == tr("Fullscreen Visualizer"))
switchView(MV_VISUALIZER);
else if (resulttext == tr("Playlist Editor"))
else if (resulttext == tr("Playlist Editor") ||
resulttext == tr("Browse Music Library"))
{
if (gCoreContext->GetSetting("MusicPlaylistEditorView", "tree") == "tree")
switchView(MV_PLAYLISTEDITORTREE);
Expand Down Expand Up @@ -1525,6 +1520,20 @@ void MusicCommon::customEvent(QEvent *event)
m_playlistOptions.insertPLOption = PL_INSERTATEND;
doUpdatePlaylist();
}
else if (resulttext == tr("Play Now"))
{ // cancel shuffles and repeats to play only this now
gPlayer->setShuffleMode(MusicPlayer::SHUFFLE_OFF);
updateShuffleMode();
gPlayer->setRepeatMode(MusicPlayer::REPEAT_OFF);
updateRepeatMode();
m_playlistOptions.insertPLOption = PL_INSERTATEND;
m_playlistOptions.playPLOption = PL_FIRSTNEW;
doUpdatePlaylist();
}
else if (resulttext == tr("Prefer Play Now"))
gPlayer->setPlayNow(true);
else if (resulttext == tr("Prefer Add Tracks"))
gPlayer->setPlayNow(false);
}
else if (resultid == "visualizermenu")
{
Expand Down Expand Up @@ -1627,7 +1636,8 @@ void MusicCommon::customEvent(QEvent *event)
if (mdata && mdata->ID() == (MusicMetadata::IdType) trackID)
{
m_currentPlaylist->RemoveItem(item);
break;
x -= 1; // remove all entries, or:
// break; // remove only first entry
}
}
}
Expand Down Expand Up @@ -1707,6 +1717,7 @@ void MusicCommon::customEvent(QEvent *event)
gPlayer->getCurrentPlaylist()->getStats(&m_playlistTrackCount, &m_playlistMaxTime,
m_currentTrack, &m_playlistPlayedTime);

updateUIPlaylist(); // else album art doesn't update
updatePlaylistStats();
updateTrackInfo(gPlayer->getCurrentMetadata());
}
Expand Down Expand Up @@ -2174,11 +2185,19 @@ MythMenu* MusicCommon::createMainMenu(void)
auto *menu = new MythMenu(label, this, "mainmenu");

if (m_currentView == MV_PLAYLISTEDITORTREE)
{
menu->AddItem(tr("Switch To Gallery View"));
}
else if (m_currentView == MV_PLAYLISTEDITORGALLERY)
{
menu->AddItem(tr("Switch To Tree View"));
}
else if (m_currentView == MV_PLAYLIST)
menu->AddItem(MusicCommon::tr("Playlist Editor"));
{
// menu->AddItem(tr("Playlist Editor")); // v33-
// this might be easier for new users to find / understand:
menu->AddItem(tr("Browse Music Library")); // v34+
}

QStringList screenList;
MythScreenType *screen = this;
Expand Down Expand Up @@ -2383,8 +2402,20 @@ MythMenu* MusicCommon::createPlaylistOptionsMenu(void)

auto *menu = new MythMenu(label, this, "playlistoptionsmenu");

menu->AddItem(tr("Replace Tracks"));
menu->AddItem(tr("Add Tracks"));
if (gPlayer->getPlayNow())
{
menu->AddItem(tr("Play Now"));
menu->AddItem(tr("Add Tracks"));
menu->AddItem(tr("Replace Tracks"));
menu->AddItem(tr("Prefer Add Tracks"));
}
else
{
menu->AddItem(tr("Add Tracks"));
menu->AddItem(tr("Play Now"));
menu->AddItem(tr("Replace Tracks"));
menu->AddItem(tr("Prefer Play Now"));
}

return menu;
}
Expand Down Expand Up @@ -2511,30 +2542,27 @@ 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, true,
m_playlistOptions.insertPLOption, curTrackID);
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, true,
m_playlistOptions.insertPLOption, curTrackID);
added = gMusicData->m_all_playlists->getActive()->fillSonglistFromList(
m_songList, true,
m_playlistOptions.insertPLOption, curTrackID);

m_songList.clear();
}
Expand All @@ -2543,9 +2571,9 @@ void MusicCommon::doUpdatePlaylist(void)

updateUIPlaylist();

if (m_currentTrack == -1)
playFirstTrack();
else
// if (m_currentTrack == -1) // why? non-playing should also
// playFirstTrack(); // start playing per options -twitham
// else
{
switch (m_playlistOptions.playPLOption)
{
Expand All @@ -2572,7 +2600,7 @@ void MusicCommon::doUpdatePlaylist(void)
case PL_INSERTATEND:
{
pause();
if (!gPlayer->setCurrentTrackPos(trackCount))
if (!gPlayer->setCurrentTrackPos(gPlayer->getCurrentPlaylist()->getTrackCount() - added))
playFirstTrack();
break;
}
Expand Down
10 changes: 10 additions & 0 deletions mythplugins/mythmusic/mythmusic/musicplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,16 @@ void MusicPlayer::loadSettings(void)

m_lastplayDelay = gCoreContext->GetDurSetting<std::chrono::seconds>("MusicLastPlayDelay", LASTPLAY_DELAY);
m_autoShowPlayer = (gCoreContext->GetNumSetting("MusicAutoShowPlayer", 1) > 0);

}

void MusicPlayer::setPlayNow(bool PlayNow)
{
gCoreContext->SaveBoolSetting("MusicPreferPlayNow", PlayNow);
}
bool MusicPlayer::getPlayNow(void)
{
return gCoreContext->GetBoolSetting("MusicPreferPlayNow", false);
}

// this stops playing the playlist and plays the file pointed to by mdata
Expand Down
4 changes: 4 additions & 0 deletions mythplugins/mythmusic/mythmusic/musicplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ class MusicPlayer : public QObject, public MythObservable
void canShowPlayer(bool canShow) { m_canShowPlayer = canShow; }
bool getCanShowPlayer(void) const { return m_canShowPlayer; }

/// whether we prefer Play Now over Add Tracks
void setPlayNow(bool PlayNow);
bool getPlayNow(void);

Decoder *getDecoder(void) { return m_decoderHandler ? m_decoderHandler->getDecoder() : nullptr; }
DecoderHandler *getDecoderHandler(void) { return m_decoderHandler; }
AudioOutput *getOutput(void) { return m_output; }
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
Loading