MythTV master
musicdata.cpp
Go to the documentation of this file.
1// C/C++
2#include <unistd.h> // for usleep()
3
4// qt
5#include <QApplication>
6
7// MythTV
17
18// mythmusic
19#include "musicdata.h"
20#include "musicplayer.h"
21
22// this is the global MusicData object shared thoughout MythMusic
24
26{
28}
29
31{
33 {
34 delete m_all_playlists;
35 m_all_playlists = nullptr;
36 }
37
38 if (m_all_music)
39 {
40 delete m_all_music;
41 m_all_music = nullptr;
42 }
43
44 if (m_all_streams)
45 {
46 delete m_all_streams;
47 m_all_streams = nullptr;
48 }
49}
50
52{
53 QStringList strList("SCAN_MUSIC");
54 auto *thread = new SendStringListThread(strList);
55 MThreadPool::globalInstance()->start(thread, "Send SCAN_MUSIC");
56
57 LOG(VB_GENERAL, LOG_INFO, "Requested a music file scan");
58}
59
61void MusicData::reloadMusic(void) const
62{
64 return;
65
66 MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
67 QString message = tr("Rebuilding music tree");
68
69 auto *busy = new MythUIBusyDialog(message, popupStack, "musicscanbusydialog");
70
71 if (busy->Create())
72 popupStack->AddScreen(busy, false);
73 else
74 busy = nullptr;
75
76 // TODO make it so the player isn't interupted
77 // for the moment stop playing and try to resume after reloading
78 bool wasPlaying = false;
79 if (gPlayer->isPlaying())
80 {
82 gPlayer->stop(true);
83 wasPlaying = true;
84 }
85
87 while (!m_all_music->doneLoading())
88 {
89 QCoreApplication::processEvents();
90 usleep(50000);
91 }
92
94
95 if (busy)
96 busy->Close();
97
98 if (wasPlaying)
100}
101
102void MusicData::loadMusic(void) const
103{
104 // only do this once
105 if (m_initialized)
106 return;
107
108 MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
109 QString message = QCoreApplication::translate("(MythMusicMain)",
110 "Loading Music. Please wait ...");
111
112 auto *busy = new MythUIBusyDialog(message, popupStack, "musicscanbusydialog");
113 if (busy->Create())
114 popupStack->AddScreen(busy, false);
115 else
116 busy = nullptr;
117
118 // Set the various track formatting modes
120
121 auto *all_music = new AllMusic();
122
123 // Load all playlists into RAM (once!)
124 auto *all_playlists = new PlaylistContainer(all_music);
125
126 gMusicData->m_all_music = all_music;
128 gMusicData->m_all_playlists = all_playlists;
129
131
134 {
135 QCoreApplication::processEvents();
136 usleep(50000);
137 }
138
141
142 if (busy)
143 busy->Close();
144}
bool startLoading(void)
Start loading metadata.
bool doneLoading() const
static MThreadPool * globalInstance(void)
void start(QRunnable *runnable, const QString &debugName, int priority=0)
static void scanMusic(void)
Definition: musicdata.cpp:51
bool m_initialized
Definition: musicdata.h:54
void reloadMusic(void) const
reload music after a scan, rip or import
Definition: musicdata.cpp:61
AllMusic * m_all_music
Definition: musicdata.h:52
~MusicData() override
Definition: musicdata.cpp:30
void loadMusic(void) const
Definition: musicdata.cpp:102
PlaylistContainer * m_all_playlists
Definition: musicdata.h:51
AllStream * m_all_streams
Definition: musicdata.h:53
static void setArtistAndTrackFormats()
void loadPlaylist(void)
void savePosition(void)
void stop(bool stopAll=false)
void loadStreamPlaylist(void)
void restorePosition(void)
bool isPlaying(void) const
Definition: musicplayer.h:109
bool SendReceiveStringList(QStringList &strlist, bool quickTimeout=false, bool block=true)
Send a message to the backend and wait for a response.
MythScreenStack * GetStack(const QString &Stackname)
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
bool doneLoading() const
send a message to the master BE without blocking the UI thread
Definition: musicdata.h:22
QStringList m_strList
Definition: musicdata.h:30
void run() override
Definition: musicdata.cpp:25
MusicData * gMusicData
Definition: musicdata.cpp:23
MusicPlayer * gPlayer
Definition: musicplayer.cpp:38
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
MythMainWindow * GetMythMainWindow(void)