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  SendStringListThread *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  MythUIBusyDialog *busy = new MythUIBusyDialog(message, popupStack,
66  "musicscanbusydialog");
67 
68  if (busy->Create())
69  popupStack->AddScreen(busy, false);
70  else
71  busy = nullptr;
72 
73  // TODO make it so the player isn't interupted
74  // for the moment stop playing and try to resume after reloading
75  bool wasPlaying = false;
76  if (gPlayer->isPlaying())
77  {
79  gPlayer->stop(true);
80  wasPlaying = true;
81  }
82 
84  while (!m_all_music->doneLoading())
85  {
86  qApp->processEvents();
87  usleep(50000);
88  }
89 
91 
92  if (busy)
93  busy->Close();
94 
95  if (wasPlaying)
97 }
98 
100 {
101  // only do this once
102  if (m_initialized)
103  return;
104 
105  MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
106  QString message = qApp->translate("(MythMusicMain)",
107  "Loading Music. Please wait ...");
108 
109  MythUIBusyDialog *busy = new MythUIBusyDialog(message, popupStack,
110  "musicscanbusydialog");
111  if (busy->Create())
112  popupStack->AddScreen(busy, false);
113  else
114  busy = nullptr;
115 
116  // Set the various track formatting modes
118 
119  AllMusic *all_music = new AllMusic();
120 
121  // Load all playlists into RAM (once!)
122  PlaylistContainer *all_playlists = new PlaylistContainer(all_music);
123 
124  gMusicData->m_all_music = all_music;
126  gMusicData->m_all_playlists = all_playlists;
127 
128  gMusicData->m_initialized = true;
129 
132  {
133  qApp->processEvents();
134  usleep(50000);
135  }
136 
139 
140  if (busy)
141  busy->Close();
142 }
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:99
virtual void Close()
void loadStreamPlaylist(void)
void savePosition(void)
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
PlaylistContainer * m_all_playlists
Definition: musicdata.h:53
bool Create(void) override
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