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 
57 void MusicData::reloadMusic(void) const
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  QCoreApplication::processEvents();
86  usleep(50000);
87  }
88 
90 
91  if (busy)
92  busy->Close();
93 
94  if (wasPlaying)
96 }
97 
98 void MusicData::loadMusic(void) const
99 {
100  // only do this once
101  if (m_initialized)
102  return;
103 
104  MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
105  QString message = QCoreApplication::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  QCoreApplication::processEvents();
132  usleep(50000);
133  }
134 
137 
138  if (busy)
139  busy->Close();
140 }
gPlayer
MusicPlayer * gPlayer
Definition: musicplayer.cpp:35
AllMusic
Definition: musicmetadata.h:418
MusicPlayer::loadPlaylist
void loadPlaylist(void)
Definition: musicplayer.cpp:962
MusicPlayer::loadStreamPlaylist
void loadStreamPlaylist(void)
Definition: musicplayer.cpp:994
mythscreenstack.h
MusicData::~MusicData
~MusicData() override
Definition: musicdata.cpp:26
MusicMetadata::setArtistAndTrackFormats
static void setArtistAndTrackFormats()
Definition: musicmetadata.cpp:811
AllMusic::startLoading
bool startLoading(void)
Start loading metadata.
Definition: musicmetadata.cpp:1474
MythScreenStack
Definition: mythscreenstack.h:16
MusicData::m_initialized
bool m_initialized
Definition: musicdata.h:57
MusicPlayer::isPlaying
bool isPlaying(void) const
Definition: musicplayer.h:102
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
MythMainWindow::GetStack
MythScreenStack * GetStack(const QString &stackname)
Definition: mythmainwindow.cpp:309
musicutils.h
mythprogressdialog.h
musicfilescanner.h
AllMusic::doneLoading
bool doneLoading() const
Definition: musicmetadata.h:443
MusicData::reloadMusic
void reloadMusic(void) const
reload music after a scan, rip or import
Definition: musicdata.cpp:57
MusicData::m_all_streams
AllStream * m_all_streams
Definition: musicdata.h:56
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:37
MusicPlayer::savePosition
void savePosition(void)
Definition: musicplayer.cpp:1048
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:54
musicdata.h
gMusicData
MusicData * gMusicData
Definition: musicdata.cpp:20
mthreadpool.h
MusicData::loadMusic
void loadMusic(void) const
Definition: musicdata.cpp:98
GetMythMainWindow
MythMainWindow * GetMythMainWindow(void)
Definition: mythmainwindow.cpp:107
MusicPlayer::restorePosition
void restorePosition(void)
Definition: musicplayer.cpp:1065
MusicData::m_all_music
AllMusic * m_all_music
Definition: musicdata.h:55
MusicPlayer::stop
void stop(bool stopAll=false)
Definition: musicplayer.cpp:237
PlaylistContainer::doneLoading
bool doneLoading() const
Definition: playlistcontainer.h:65
MThreadPool::globalInstance
static MThreadPool * globalInstance(void)
Definition: mthreadpool.cpp:307
mythmainwindow.h
MythScreenStack::AddScreen
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
Definition: mythscreenstack.cpp:49
MusicData::scanMusic
static void scanMusic(void)
Definition: musicdata.cpp:47
PlaylistContainer
Definition: playlistcontainer.h:34
musicmetadata.h
MThreadPool::start
void start(QRunnable *runnable, const QString &debugName, int priority=0)
Definition: mthreadpool.cpp:342
musicplayer.h