MythTV  master
musicdata.cpp
Go to the documentation of this file.
1 // qt
2 #include <QApplication>
3 
4 // mythtv
5 #include <mythscreenstack.h>
6 #include <mythmainwindow.h>
7 #include <mythprogressdialog.h>
8 #include <musicmetadata.h>
9 #include <musicfilescanner.h>
10 #include <musicutils.h>
11 #include <mthreadpool.h>
12 
13 // mythmusic
14 #include "musicdata.h"
15 #include "musicplayer.h"
16 
17 #include <unistd.h> // for usleep()
18 
19 // this is the global MusicData object shared thoughout MythMusic
20 MusicData *gMusicData = nullptr;
21 
22 
24 
25 
27 {
28  if (m_all_playlists)
29  {
30  delete m_all_playlists;
31  m_all_playlists = nullptr;
32  }
33 
34  if (m_all_music)
35  {
36  delete m_all_music;
37  m_all_music = nullptr;
38  }
39 
40  if (m_all_streams)
41  {
42  delete m_all_streams;
43  m_all_streams = nullptr;
44  }
45 }
46 
48 {
49  QStringList strList("SCAN_MUSIC");
50  auto *thread = new SendStringListThread(strList);
51  MThreadPool::globalInstance()->start(thread, "Send SCAN_MUSIC");
52 
53  LOG(VB_GENERAL, LOG_INFO, "Requested a music file scan");
54 }
55 
58 {
60  return;
61 
62  MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
63  QString message = tr("Rebuilding music tree");
64 
65  auto *busy = new MythUIBusyDialog(message, popupStack, "musicscanbusydialog");
66 
67  if (busy->Create())
68  popupStack->AddScreen(busy, false);
69  else
70  busy = nullptr;
71 
72  // TODO make it so the player isn't interupted
73  // for the moment stop playing and try to resume after reloading
74  bool wasPlaying = false;
75  if (gPlayer->isPlaying())
76  {
78  gPlayer->stop(true);
79  wasPlaying = true;
80  }
81 
83  while (!m_all_music->doneLoading())
84  {
85  qApp->processEvents();
86  usleep(50000);
87  }
88 
90 
91  if (busy)
92  busy->Close();
93 
94  if (wasPlaying)
96 }
97 
99 {
100  // only do this once
101  if (m_initialized)
102  return;
103 
104  MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
105  QString message = qApp->translate("(MythMusicMain)",
106  "Loading Music. Please wait ...");
107 
108  auto *busy = new MythUIBusyDialog(message, popupStack, "musicscanbusydialog");
109  if (busy->Create())
110  popupStack->AddScreen(busy, false);
111  else
112  busy = nullptr;
113 
114  // Set the various track formatting modes
116 
117  auto *all_music = new AllMusic();
118 
119  // Load all playlists into RAM (once!)
120  auto *all_playlists = new PlaylistContainer(all_music);
121 
122  gMusicData->m_all_music = all_music;
124  gMusicData->m_all_playlists = all_playlists;
125 
126  gMusicData->m_initialized = true;
127 
130  {
131  qApp->processEvents();
132  usleep(50000);
133  }
134 
137 
138  if (busy)
139  busy->Close();
140 }
static void scanMusic(void)
Definition: musicdata.cpp:47
MusicPlayer * gPlayer
Definition: musicplayer.cpp:35
AllStream * m_all_streams
Definition: musicdata.h:55
bool startLoading(void)
Start loading metadata.
bool isPlaying(void)
Definition: musicplayer.h:102
MythScreenStack * GetStack(const QString &stackname)
void loadMusic(void)
Definition: musicdata.cpp:98
void loadStreamPlaylist(void)
void savePosition(void)
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
PlaylistContainer * m_all_playlists
Definition: musicdata.h:53
void stop(bool stopAll=false)
MythMainWindow * GetMythMainWindow(void)
static MThreadPool * globalInstance(void)
bool doneLoading() const
void restorePosition(void)
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
void start(QRunnable *runnable, const QString &debugName, int priority=0)
bool m_initialized
Definition: musicdata.h:56
MusicData * gMusicData
Definition: musicdata.cpp:20
static void setArtistAndTrackFormats()
send a message to the master BE without blocking the UI thread
Definition: musicdata.h:20
void loadPlaylist(void)
void reloadMusic(void)
reload music after a scan, rip or import
Definition: musicdata.cpp:57
AllMusic * m_all_music
Definition: musicdata.h:54