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
15 
16 // mythmusic
17 #include "musicdata.h"
18 #include "musicplayer.h"
19 
20 // this is the global MusicData object shared thoughout MythMusic
21 MusicData *gMusicData = nullptr;
22 
23 
25 
26 
28 {
29  if (m_all_playlists)
30  {
31  delete m_all_playlists;
32  m_all_playlists = nullptr;
33  }
34 
35  if (m_all_music)
36  {
37  delete m_all_music;
38  m_all_music = nullptr;
39  }
40 
41  if (m_all_streams)
42  {
43  delete m_all_streams;
44  m_all_streams = nullptr;
45  }
46 }
47 
49 {
50  QStringList strList("SCAN_MUSIC");
51  auto *thread = new SendStringListThread(strList);
52  MThreadPool::globalInstance()->start(thread, "Send SCAN_MUSIC");
53 
54  LOG(VB_GENERAL, LOG_INFO, "Requested a music file scan");
55 }
56 
58 void MusicData::reloadMusic(void) const
59 {
61  return;
62 
63  MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
64  QString message = tr("Rebuilding music tree");
65 
66  auto *busy = new MythUIBusyDialog(message, popupStack, "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  QCoreApplication::processEvents();
87  usleep(50000);
88  }
89 
91 
92  if (busy)
93  busy->Close();
94 
95  if (wasPlaying)
97 }
98 
99 void MusicData::loadMusic(void) const
100 {
101  // only do this once
102  if (m_initialized)
103  return;
104 
105  MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
106  QString message = QCoreApplication::translate("(MythMusicMain)",
107  "Loading Music. Please wait ...");
108 
109  auto *busy = new MythUIBusyDialog(message, popupStack, "musicscanbusydialog");
110  if (busy->Create())
111  popupStack->AddScreen(busy, false);
112  else
113  busy = nullptr;
114 
115  // Set the various track formatting modes
117 
118  auto *all_music = new AllMusic();
119 
120  // Load all playlists into RAM (once!)
121  auto *all_playlists = new PlaylistContainer(all_music);
122 
123  gMusicData->m_all_music = all_music;
125  gMusicData->m_all_playlists = all_playlists;
126 
127  gMusicData->m_initialized = true;
128 
131  {
132  QCoreApplication::processEvents();
133  usleep(50000);
134  }
135 
138 
139  if (busy)
140  busy->Close();
141 }
gPlayer
MusicPlayer * gPlayer
Definition: musicplayer.cpp:37
AllMusic
Definition: musicmetadata.h:418
MusicPlayer::loadPlaylist
void loadPlaylist(void)
Definition: musicplayer.cpp:966
MusicPlayer::loadStreamPlaylist
void loadStreamPlaylist(void)
Definition: musicplayer.cpp:998
mythscreenstack.h
MusicData::~MusicData
~MusicData() override
Definition: musicdata.cpp:27
MusicMetadata::setArtistAndTrackFormats
static void setArtistAndTrackFormats()
Definition: musicmetadata.cpp:797
AllMusic::startLoading
bool startLoading(void)
Start loading metadata.
Definition: musicmetadata.cpp:1460
MythScreenStack
Definition: mythscreenstack.h:16
MusicData::m_initialized
bool m_initialized
Definition: musicdata.h:58
MusicPlayer::isPlaying
bool isPlaying(void) const
Definition: musicplayer.h:109
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
musicutils.h
mythprogressdialog.h
musicfilescanner.h
AllMusic::doneLoading
bool doneLoading() const
Definition: musicmetadata.h:444
MusicData::reloadMusic
void reloadMusic(void) const
reload music after a scan, rip or import
Definition: musicdata.cpp:58
MusicData::m_all_streams
AllStream * m_all_streams
Definition: musicdata.h:57
AllStream
Definition: musicmetadata.h:476
SendStringListThread
send a message to the master BE without blocking the UI thread
Definition: musicdata.h:22
MythUIBusyDialog
Definition: mythprogressdialog.h:36
MusicPlayer::savePosition
void savePosition(void)
Definition: musicplayer.cpp:1052
MusicData
Definition: musicdata.h:39
PlaylistContainer::resync
void resync(void)
Definition: playlistcontainer.cpp:117
MusicData::m_all_playlists
PlaylistContainer * m_all_playlists
Definition: musicdata.h:55
musicdata.h
gMusicData
MusicData * gMusicData
Definition: musicdata.cpp:21
mthreadpool.h
MusicData::loadMusic
void loadMusic(void) const
Definition: musicdata.cpp:99
GetMythMainWindow
MythMainWindow * GetMythMainWindow(void)
Definition: mythmainwindow.cpp:102
MusicPlayer::restorePosition
void restorePosition(void)
Definition: musicplayer.cpp:1069
MythMainWindow::GetStack
MythScreenStack * GetStack(const QString &Stackname)
Definition: mythmainwindow.cpp:320
MusicData::m_all_music
AllMusic * m_all_music
Definition: musicdata.h:56
MusicPlayer::stop
void stop(bool stopAll=false)
Definition: musicplayer.cpp:239
PlaylistContainer::doneLoading
bool doneLoading() const
Definition: playlistcontainer.h:67
MThreadPool::globalInstance
static MThreadPool * globalInstance(void)
Definition: mthreadpool.cpp:317
mythmainwindow.h
MythScreenStack::AddScreen
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
Definition: mythscreenstack.cpp:50
MusicData::scanMusic
static void scanMusic(void)
Definition: musicdata.cpp:48
PlaylistContainer
Definition: playlistcontainer.h:33
musicmetadata.h
MThreadPool::start
void start(QRunnable *runnable, const QString &debugName, int priority=0)
Definition: mthreadpool.cpp:352
musicplayer.h