MythTV  master
mythplugins/mythmusic/mythmusic/main.cpp
Go to the documentation of this file.
1 // C++ headers
2 #include <cstdlib>
3 #include <sys/stat.h>
4 #include <sys/types.h>
5 #include <unistd.h>
6 
7 // Qt headers
8 #include <QDir>
9 #include <QApplication>
10 #include <QRegExp>
11 #include <QScopedPointer>
12 
13 // MythTV headers
14 #include <mythcontext.h>
15 #include <mythplugin.h>
16 #include <mythmediamonitor.h>
17 #include <mythdbcon.h>
18 #include <mythdb.h>
19 #include <mythpluginapi.h>
20 #include <mythversion.h>
21 #include <myththemedmenu.h>
22 #include <compat.h>
23 #include <mythuihelper.h>
24 #include <mythprogressdialog.h>
25 #include <lcddevice.h>
26 #include <musicmetadata.h>
27 #include <musicutils.h>
28 #include <musicfilescanner.h>
29 
30 // MythMusic headers
31 #include "musicdata.h"
32 #include "decoder.h"
33 #include "cddecoder.h"
34 #include "playlisteditorview.h"
35 #include "playlistview.h"
36 #include "streamview.h"
37 #include "playlistcontainer.h"
38 #include "dbcheck.h"
39 #include "musicplayer.h"
40 #include "config.h"
41 #include "mainvisual.h"
42 #include "generalsettings.h"
43 #include "playersettings.h"
44 #include "visualizationsettings.h"
45 #include "importsettings.h"
46 #include "ratingsettings.h"
47 #include "importmusic.h"
48 #include "metaio.h"
49 
50 #ifdef HAVE_CDIO
51 #include "cdrip.h"
52 #endif
53 
54 #if defined HAVE_CDIO
55 
58 static QString chooseCD(void)
59 {
60  if (gCDdevice.length())
61  return gCDdevice;
62 
63 #ifdef Q_OS_MAC
65 #endif
66 
68 }
69 #endif
70 
72 static bool checkStorageGroup(void)
73 {
74  // get a list of hosts with a directory defined for the 'Music' storage group
75  QStringList hostList;
77  QString sql = "SELECT DISTINCT hostname "
78  "FROM storagegroup "
79  "WHERE groupname = 'Music'";
80  if (!query.exec(sql) || !query.isActive())
81  MythDB::DBError("checkStorageGroup get host list", query);
82  else
83  {
84  while(query.next())
85  {
86  hostList.append(query.value(0).toString());
87  }
88  }
89 
90  if (hostList.isEmpty())
91  {
92  ShowOkPopup(qApp->translate("(MythMusicMain)",
93  "No directories found in the 'Music' storage group. "
94  "Please run mythtv-setup on the backend machine to add one."));
95  return false;
96  }
97 
98  // get a list of hosts with a directory defined for the 'MusicArt' storage group
99  hostList.clear();
100  sql = "SELECT DISTINCT hostname "
101  "FROM storagegroup "
102  "WHERE groupname = 'MusicArt'";
103  if (!query.exec(sql) || !query.isActive())
104  MythDB::DBError("checkStorageGroup get host list", query);
105  else
106  {
107  while(query.next())
108  {
109  hostList.append(query.value(0).toString());
110  }
111  }
112 
113  if (hostList.isEmpty())
114  {
115  ShowOkPopup(qApp->translate("(MythMusicMain)",
116  "No directories found in the 'MusicArt' storage group. "
117  "Please run mythtv-setup on the backend machine to add one."));
118  return false;
119  }
120 
121  return true;
122 }
123 
125 static bool checkMusicAvailable(void)
126 {
127  MSqlQuery count_query(MSqlQuery::InitCon());
128  bool foundMusic = false;
129  if (count_query.exec("SELECT COUNT(*) FROM music_songs;"))
130  {
131  if(count_query.next() &&
132  0 != count_query.value(0).toInt())
133  {
134  foundMusic = true;
135  }
136  }
137 
138  if (!foundMusic)
139  {
140  ShowOkPopup(qApp->translate("(MythMusicMain)",
141  "No music has been found.\n"
142  "Please select 'Scan For New Music' "
143  "to perform a scan for music."));
144  }
145 
146  return foundMusic;
147 }
148 
149 static void startPlayback(void)
150 {
152  return;
153 
155 
157 
158  PlaylistView *view = new PlaylistView(mainStack, nullptr);
159 
160  if (view->Create())
161  mainStack->AddScreen(view);
162  else
163  delete view;
164 }
165 
166 static void startStreamPlayback(void)
167 {
169 
171 
172  StreamView *view = new StreamView(mainStack, nullptr);
173 
174  if (view->Create())
175  mainStack->AddScreen(view);
176  else
177  delete view;
178 }
179 
180 static void startDatabaseTree(void)
181 {
183  return;
184 
186 
188 
189  QString lastView = gCoreContext->GetSetting("MusicPlaylistEditorView", "tree");
190  PlaylistEditorView *view = new PlaylistEditorView(mainStack, nullptr, lastView);
191 
192  if (view->Create())
193  mainStack->AddScreen(view);
194  else
195  delete view;
196 }
197 
198 static void startRipper(void)
199 {
200 #if defined HAVE_CDIO
201  if (!checkStorageGroup())
202  return;
203 
205 
207 
208  Ripper *rip = new Ripper(mainStack, chooseCD());
209 
210  if (rip->Create())
211  {
212  mainStack->AddScreen(rip);
213  QObject::connect(rip, SIGNAL(ripFinished()),
214  gMusicData, SLOT(reloadMusic()),
215  Qt::QueuedConnection);
216  }
217  else
218  delete rip;
219 
220 #else
221  ShowOkPopup(qApp->translate("(MythMusicMain)",
222  "MythMusic hasn't been built with libcdio "
223  "support so ripping CDs is not possible"));
224 #endif
225 }
226 
227 static void runScan(void)
228 {
229  if (!checkStorageGroup())
230  return;
231 
232  LOG(VB_GENERAL, LOG_INFO, "Scanning for music files");
233 
235 }
236 
237 static void startImport(void)
238 {
239  if (!checkStorageGroup())
240  return;
241 
243 
245 
246  ImportMusicDialog *import = new ImportMusicDialog(mainStack);
247 
248  if (import->Create())
249  {
250  mainStack->AddScreen(import);
251  QObject::connect(import, SIGNAL(importFinished()),
252  gMusicData, SLOT(reloadMusic()),
253  Qt::QueuedConnection);
254  }
255  else
256  delete import;
257 }
258 
259 // these point to the the mainmenu callback if found
260 static void (*m_callback)(void *, QString &) = nullptr;
261 static void *m_callbackdata = nullptr;
262 
263 static void MusicCallback(void *data, QString &selection)
264 {
265  (void) data;
266 
267  QString sel = selection.toLower();
268  if (sel == "music_create_playlist")
270  else if (sel == "music_play")
271  startPlayback();
272  else if (sel == "stream_play")
274  else if (sel == "music_rip")
275  {
276  startRipper();
277  }
278  else if (sel == "music_import")
279  {
280  startImport();
281  }
282  else if (sel == "settings_scan")
283  {
284  runScan();
285  }
286  else if (sel == "settings_general")
287  {
289  GeneralSettings *gs = new GeneralSettings(mainStack, "general settings");
290 
291  if (gs->Create())
292  mainStack->AddScreen(gs);
293  else
294  delete gs;
295  }
296  else if (sel == "settings_player")
297  {
299  PlayerSettings *ps = new PlayerSettings(mainStack, "player settings");
300 
301  if (ps->Create())
302  mainStack->AddScreen(ps);
303  else
304  delete ps;
305  }
306  else if (sel == "settings_rating")
307  {
309  RatingSettings *rs = new RatingSettings(mainStack, "rating settings");
310 
311  if (rs->Create())
312  mainStack->AddScreen(rs);
313  else
314  delete rs;
315  }
316  else if (sel == "settings_visualization")
317  {
318 
320  VisualizationSettings *vs = new VisualizationSettings(mainStack, "visualization settings");
321 
322  if (vs->Create())
323  mainStack->AddScreen(vs);
324  else
325  delete vs;
326  }
327  else if (sel == "settings_import")
328  {
330  ImportSettings *is = new ImportSettings(mainStack, "import settings");
331 
332  if (is->Create())
333  mainStack->AddScreen(is);
334  else
335  delete is;
336  }
337  else
338  {
339  // if we have found the mainmenu callback
340  // pass the selection on to it
341  if (m_callback && m_callbackdata)
342  m_callback(m_callbackdata, selection);
343  }
344 }
345 
346 static int runMenu(QString which_menu)
347 {
348  QString themedir = GetMythUI()->GetThemeDir();
349 
350  // find the 'mainmenu' MythThemedMenu so we can use the callback from it
351  MythThemedMenu *mainMenu = nullptr;
352  QObject *parentObject = GetMythMainWindow()->GetMainStack()->GetTopScreen();
353 
354  while (parentObject)
355  {
356  MythThemedMenu *menu = dynamic_cast<MythThemedMenu *>(parentObject);
357 
358  if (menu && menu->objectName() == "mainmenu")
359  {
360  mainMenu = menu;
361  break;
362  }
363 
364  parentObject = parentObject->parent();
365  }
366 
367  MythThemedMenu *diag = new MythThemedMenu(
368  themedir, which_menu, GetMythMainWindow()->GetMainStack(),
369  "music menu");
370 
371  // save the callback from the main menu
372  if (mainMenu)
373  mainMenu->getCallback(&m_callback, &m_callbackdata);
374 
375  diag->setCallback(MusicCallback, nullptr);
376  diag->setKillable();
377 
378  if (diag->foundTheme())
379  {
380  if (LCD *lcd = LCD::Get())
381  {
382  lcd->switchToTime();
383  }
385  return 0;
386  }
387  else
388  {
389  LOG(VB_GENERAL, LOG_ERR, QString("Couldn't find menu %1 or theme %2")
390  .arg(which_menu).arg(themedir));
391  delete diag;
392  return -1;
393  }
394 }
395 
396 static void runMusicPlayback(void)
397 {
398  GetMythUI()->AddCurrentLocation("playmusic");
399  startPlayback();
401 }
402 
403 static void runMusicStreamPlayback(void)
404 {
405  GetMythUI()->AddCurrentLocation("streammusic");
408 }
409 
410 static void runMusicSelection(void)
411 {
412  GetMythUI()->AddCurrentLocation("musicplaylists");
415 }
416 
417 static void runRipCD(void)
418 {
420 
421 #if defined HAVE_CDIO
423 
424  Ripper *rip = new Ripper(mainStack, chooseCD());
425 
426  if (rip->Create())
427  mainStack->AddScreen(rip);
428  else
429  {
430  delete rip;
431  return;
432  }
433 
434  QObject::connect(rip, SIGNAL(ripFinished()),
435  gMusicData, SLOT(reloadMusic()),
436  Qt::QueuedConnection);
437 #endif
438 }
439 
440 static void showMiniPlayer(void)
441 {
442  if (!gMusicData->all_music)
443  return;
444 
445  // only show the miniplayer if there isn't already a client attached
446  if (!gPlayer->hasClient())
448 }
449 
450 static QStringList GetMusicFilter()
451 {
452  QString filt = MetaIO::ValidFileExtensions;
453  filt.replace(".", "*.");
454  return filt.split('|');
455 }
456 
457 static QStringList BuildFileList(const QString &dir, const QStringList &filters)
458 {
459  QStringList ret;
460 
461  QDir d(dir);
462  if (!d.exists())
463  return ret;
464 
465  d.setNameFilters(filters);
466  d.setFilter(QDir::Files | QDir::AllDirs |
467  QDir::NoSymLinks | QDir::Readable |
468  QDir::NoDotAndDotDot);
469  d.setSorting(QDir::Name | QDir::DirsLast);
470 
471  QFileInfoList list = d.entryInfoList();
472  if (list.isEmpty())
473  return ret;
474 
475  for(QFileInfoList::const_iterator it = list.begin(); it != list.end(); ++it)
476  {
477  const QFileInfo &fi = *it;
478  if (fi.isDir())
479  {
480  ret += BuildFileList(fi.absoluteFilePath(), filters);
481  qApp->processEvents();
482  }
483  else
484  {
485  ret << fi.absoluteFilePath();
486  }
487  }
488  return ret;
489 }
490 
491 static void handleMedia(MythMediaDevice *cd)
492 {
493  static QString s_mountPath;
494 
495  if (!cd)
496  return;
497 
498  if (MEDIASTAT_MOUNTED != cd->getStatus())
499  {
500  if (s_mountPath != cd->getMountPath())
501  return;
502 
503  LOG(VB_MEDIA, LOG_INFO, QString(
504  "MythMusic: '%1' unmounted, clearing data").arg(cd->getVolumeID()));
505 
508  {
509  // Now playing a track which is no longer available so stop playback
510  gPlayer->stop(true);
511  }
512 
513  // device is not usable so remove any existing CD tracks
514  if (gMusicData->initialized)
515  {
518  }
519 
520  gPlayer->activePlaylistChanged(-1, false);
522 
523  return;
524  }
525 
526  LOG(VB_MEDIA, LOG_NOTICE, QString("MythMusic: '%1' mounted on '%2'")
527  .arg(cd->getVolumeID()).arg(cd->getMountPath()) );
528 
529  s_mountPath.clear();
530 
531  // don't show the music screen if AutoPlayCD is off
532  if (!gCoreContext->GetBoolSetting("AutoPlayCD", false))
533  return;
534 
535  if (!gMusicData->initialized)
537 
538  // remove any existing CD tracks
541 
543 
544  MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
545 
546  QString message = qApp->translate("(MythMusicMain)",
547  "Searching for music files...");
548  MythUIBusyDialog *busy = new MythUIBusyDialog( message, popupStack,
549  "musicscanbusydialog");
550  if (busy->Create())
551  popupStack->AddScreen(busy, false);
552  else
553  {
554  delete busy;
555  busy = nullptr;
556  }
557 
558  // Search for music files
559  QStringList trackList = BuildFileList(cd->getMountPath(), GetMusicFilter());
560  LOG(VB_MEDIA, LOG_INFO, QString("MythMusic: %1 music files found")
561  .arg(trackList.count()));
562 
563  if (busy)
564  busy->Close();
565 
566  if (trackList.isEmpty())
567  return;
568 
569  message = qApp->translate("(MythMusicMain)", "Loading music tracks");
571  popupStack, "scalingprogressdialog");
572  if (progress->Create())
573  {
574  popupStack->AddScreen(progress, false);
575  progress->SetTotal(trackList.count());
576  }
577  else
578  {
579  delete progress;
580  progress = nullptr;
581  }
582 
583  // Read track metadata and add to all_music
584  int track = 0;
585  for (QStringList::const_iterator it = trackList.begin();
586  it != trackList.end(); ++it)
587  {
588  QScopedPointer<MusicMetadata> meta(MetaIO::readMetadata(*it));
589  if (meta)
590  {
591  meta->setTrack(++track);
593  }
594  if (progress)
595  {
596  progress->SetProgress(track);
597  qApp->processEvents();
598  }
599  }
600  LOG(VB_MEDIA, LOG_INFO, QString("MythMusic: %1 tracks scanned").arg(track));
601 
602  if (progress)
603  progress->Close();
604 
605  // Remove all tracks from the playlist
607 
608  // Create list of new tracks
609  QList<int> songList;
610  const int tracks = gMusicData->all_music->getCDTrackCount();
611  for (track = 1; track <= tracks; track++)
612  {
614  if (mdata)
615  songList.append(mdata->ID());
616  }
617  if (songList.isEmpty())
618  return;
619 
620  s_mountPath = cd->getMountPath();
621 
622  // Add new tracks to playlist
624  songList, true, PL_REPLACE, 0);
626 
627  // if there is no music screen showing then show the Playlist view
628  if (!gPlayer->hasClient())
629  {
630  // make sure we start playing from the first track
631  gCoreContext->SaveSetting("MusicBookmark", 0);
632  gCoreContext->SaveSetting("MusicBookmarkPosition", 0);
633 
635  }
636 }
637 
638 #ifdef HAVE_CDIO
640 {
641 
642  if (!cd)
643  return;
644 
645  LOG(VB_MEDIA, LOG_NOTICE, "Got a CD media changed event");
646 
647  QString newDevice;
648 
649  // save the device if valid
650  if (cd->isUsable())
651  {
652 #ifdef Q_OS_MAC
653  newDevice = cd->getMountPath();
654 #else
655  newDevice = cd->getDevicePath();
656 #endif
657 
658  gCDdevice = newDevice;
659  LOG(VB_MEDIA, LOG_INFO, "MythMusic: Storing CD device " + gCDdevice);
660  }
661  else
662  {
663  LOG(VB_MEDIA, LOG_INFO, "Device is not usable clearing cd data");
664 
667  {
668  // we was playing a cd track which is no longer available so stop playback
669  // TODO should check the playing track is from the ejected drive if more than one is available
670  gPlayer->stop(true);
671  }
672 
673  // device is not usable so remove any existing CD tracks
674  if (gMusicData->all_music)
675  {
678  }
679 
680  gPlayer->activePlaylistChanged(-1, false);
682 
683  return;
684  }
685 
686  if (!gMusicData->initialized)
688 
689  // wait for the music and playlists to load
691  {
692  qApp->processEvents();
693  usleep(50000);
694  }
695 
696  // remove any existing CD tracks
699 
700  // find any new cd tracks
701  CdDecoder *decoder = new CdDecoder("cda", nullptr, nullptr);
702  decoder->setDevice(newDevice);
703 
704  int tracks = decoder->getNumTracks();
705  bool setTitle = false;
706 
707  for (int trackNo = 1; trackNo <= tracks; trackNo++)
708  {
709  MusicMetadata *track = decoder->getMetadata(trackNo);
710  if (track)
711  {
712  gMusicData->all_music->addCDTrack(*track);
713 
714  if (!setTitle)
715  {
716 
717  QString parenttitle = " ";
718  if (track->FormatArtist().length() > 0)
719  {
720  parenttitle += track->FormatArtist();
721  parenttitle += " ~ ";
722  }
723 
724  if (track->Album().length() > 0)
725  parenttitle += track->Album();
726  else
727  {
728  parenttitle = " " + qApp->translate("(MythMusicMain)",
729  "Unknown");
730  LOG(VB_GENERAL, LOG_INFO, "Couldn't find your "
731  " CD. It may not be in the freedb database.\n"
732  " More likely, however, is that you need to delete\n"
733  " ~/.cddb and ~/.cdserverrc and restart MythMusic.");
734  }
735 
736  gMusicData->all_music->setCDTitle(parenttitle);
737  setTitle = true;
738  }
739 
740  delete track;
741  }
742  }
743 
745 
746  delete decoder;
747 
748  // if the AutoPlayCD setting is set we remove all the existing tracks
749  // from the playlist and replace them with the new CD tracks found
750  if (gCoreContext->GetBoolSetting("AutoPlayCD", false))
751  {
753 
754  QList<int> songList;
755 
756  for (int x = 1; x <= gMusicData->all_music->getCDTrackCount(); x++)
757  {
759  if (mdata)
760  songList.append((mdata)->ID());
761  }
762 
763  if (songList.count())
764  {
766  songList, true, PL_REPLACE, 0);
768  }
769  }
770  else
771  {
772  // don't show the music screen if AutoPlayCD is off
773  return;
774  }
775 
776  // if there is no music screen showing show the Playlist view
777  if (!gPlayer->hasClient())
778  {
779  // make sure we start playing from the first track
780  gCoreContext->SaveSetting("MusicBookmark", 0);
781  gCoreContext->SaveSetting("MusicBookmarkPosition", 0);
782 
784  }
785 }
786 #else
787 static void handleCDMedia(MythMediaDevice *)
788 {
789  LOG(VB_GENERAL, LOG_NOTICE, "MythMusic got a media changed event"
790  "but cdio support is not compiled in");
791 }
792 #endif
793 
794 static void setupKeys(void)
795 {
796  REG_JUMP(QT_TRANSLATE_NOOP("MythControls", "Play music"),
797  "", "", runMusicPlayback);
798  REG_JUMP(QT_TRANSLATE_NOOP("MythControls", "Select music playlists"),
799  "", "", runMusicSelection);
800  REG_JUMP(QT_TRANSLATE_NOOP("MythControls", "Play radio stream"),
801  "", "", runMusicStreamPlayback);
802  REG_JUMP(QT_TRANSLATE_NOOP("MythControls", "Rip CD"),
803  "", "", runRipCD);
804  REG_JUMP(QT_TRANSLATE_NOOP("MythControls", "Scan music"),
805  "", "", runScan);
806  REG_JUMPEX(QT_TRANSLATE_NOOP("MythControls", "Show Music Miniplayer"),
807  "", "", showMiniPlayer, false);
808 
809  REG_KEY("Music", "NEXTTRACK", QT_TRANSLATE_NOOP("MythControls",
810  "Move to the next track"), ">,.,Z,End");
811  REG_KEY("Music", "PREVTRACK", QT_TRANSLATE_NOOP("MythControls",
812  "Move to the previous track"), ",,<,Q,Home");
813  REG_KEY("Music", "FFWD", QT_TRANSLATE_NOOP("MythControls",
814  "Fast forward"), "PgDown");
815  REG_KEY("Music", "RWND", QT_TRANSLATE_NOOP("MythControls",
816  "Rewind"), "PgUp");
817  REG_KEY("Music", "PAUSE", QT_TRANSLATE_NOOP("MythControls",
818  "Pause/Start playback"), "P");
819  REG_KEY("Music", "PLAY", QT_TRANSLATE_NOOP("MythControls",
820  "Start playback"), "");
821  REG_KEY("Music", "STOP", QT_TRANSLATE_NOOP("MythControls",
822  "Stop playback"), "O");
823  REG_KEY("Music", "VOLUMEDOWN", QT_TRANSLATE_NOOP("MythControls",
824  "Volume down"), "[,{,F10,Volume Down");
825  REG_KEY("Music", "VOLUMEUP", QT_TRANSLATE_NOOP("MythControls",
826  "Volume up"), "],},F11,Volume Up");
827  REG_KEY("Music", "MUTE", QT_TRANSLATE_NOOP("MythControls",
828  "Mute"), "|,\\,F9,Volume Mute");
829  REG_KEY("Music", "TOGGLEUPMIX",QT_TRANSLATE_NOOP("MythControls",
830  "Toggle audio upmixer"), "Ctrl+U");
831  REG_KEY("Music", "CYCLEVIS", QT_TRANSLATE_NOOP("MythControls",
832  "Cycle visualizer mode"), "6");
833  REG_KEY("Music", "BLANKSCR", QT_TRANSLATE_NOOP("MythControls",
834  "Blank screen"), "5");
835  REG_KEY("Music", "THMBUP", QT_TRANSLATE_NOOP("MythControls",
836  "Increase rating"), "9");
837  REG_KEY("Music", "THMBDOWN", QT_TRANSLATE_NOOP("MythControls",
838  "Decrease rating"), "7");
839  REG_KEY("Music", "REFRESH", QT_TRANSLATE_NOOP("MythControls",
840  "Refresh music tree"), "8");
841  REG_KEY("Music", "SPEEDUP", QT_TRANSLATE_NOOP("MythControls",
842  "Increase Play Speed"), "W");
843  REG_KEY("Music", "SPEEDDOWN", QT_TRANSLATE_NOOP("MythControls",
844  "Decrease Play Speed"), "X");
845  REG_KEY("Music", "MARK", QT_TRANSLATE_NOOP("MythControls",
846  "Toggle track selection"), "T");
847  REG_KEY("Music", "TOGGLESHUFFLE", QT_TRANSLATE_NOOP("MythControls",
848  "Toggle shuffle mode"), "");
849  REG_KEY("Music", "TOGGLEREPEAT", QT_TRANSLATE_NOOP("MythControls",
850  "Toggle repeat mode"), "");
851  REG_KEY("Music", "TOGGLELAST", QT_TRANSLATE_NOOP("MythControls",
852  "Switch to previous radio stream"), "");
853 
854  // switch to view key bindings
855  REG_KEY("Music", "SWITCHTOPLAYLIST", QT_TRANSLATE_NOOP("MythControls",
856  "Switch to the current playlist view"), "");
857  REG_KEY("Music", "SWITCHTOPLAYLISTEDITORTREE", QT_TRANSLATE_NOOP("MythControls",
858  "Switch to the playlist editor tree view"), "");
859  REG_KEY("Music", "SWITCHTOPLAYLISTEDITORGALLERY", QT_TRANSLATE_NOOP("MythControls",
860  "Switch to the playlist editor gallery view"), "");
861  REG_KEY("Music", "SWITCHTOSEARCH", QT_TRANSLATE_NOOP("MythControls",
862  "Switch to the search view"), "");
863  REG_KEY("Music", "SWITCHTOVISUALISER", QT_TRANSLATE_NOOP("MythControls",
864  "Switch to the fullscreen visualiser view"), "");
865  REG_KEY("Music", "SWITCHTORADIO", QT_TRANSLATE_NOOP("MythControls",
866  "Switch to the radio stream view"), "");
867 
868  REG_MEDIA_HANDLER(QT_TRANSLATE_NOOP("MythControls",
869  "MythMusic Media Handler 1/2"), "", handleCDMedia,
870  MEDIATYPE_AUDIO | MEDIATYPE_MIXED, QString());
871  QString filt = MetaIO::ValidFileExtensions;
872  filt.replace('|',',');
873  filt.remove('.');
874  REG_MEDIA_HANDLER(QT_TRANSLATE_NOOP("MythControls",
875  "MythMusic Media Handler 2/2"), "", handleMedia,
876  MEDIATYPE_MMUSIC, filt);
877 }
878 
879 int mythplugin_init(const char *libversion)
880 {
881  if (!gCoreContext->TestPluginVersion("mythmusic", libversion,
883  return -1;
884 
886  bool upgraded = UpgradeMusicDatabaseSchema();
888 
889  if (!upgraded)
890  {
891  LOG(VB_GENERAL, LOG_ERR,
892  "Couldn't upgrade music database schema, exiting.");
893  return -1;
894  }
895 
896  setupKeys();
897 
898  gPlayer = new MusicPlayer(nullptr);
899  gMusicData = new MusicData();
900 
901  return 0;
902 }
903 
904 
905 int mythplugin_run(void)
906 {
907  return runMenu("musicmenu.xml");
908 }
909 
911 {
912  return runMenu("music_settings.xml");
913 }
914 
916 {
917  gPlayer->stop(true);
918 
919  // TODO these should be saved when they are changed
920  // Automagically save all playlists and metadata (ratings) that have changed
922  {
924  }
925 
927  {
929  }
930 
931  delete gPlayer;
932 
933  delete gMusicData;
934 }
AllMusic * all_music
Definition: musicdata.h:56
void scanMusic(void)
Definition: musicdata.cpp:55
bool next(void)
Wrap QSqlQuery::next() so we can display the query results.
Definition: mythdbcon.cpp:794
#define REG_JUMP(a, b, c, d)
QString FormatArtist()
bool Create(void) override
static void runScan(void)
#define REG_MEDIA_HANDLER(a, b, c, d, e)
int getCDTrackCount(void) const
const QString & getDevicePath() const
Definition: mythmedia.h:61
void addCDTrack(const MusicMetadata &the_track)
MusicPlayer * gPlayer
Definition: musicplayer.cpp:38
static QString themedir
Definition: mythdirs.cpp:21
void sendCDChangedEvent(void)
MusicMetadata * getCurrentMetadata(void)
get the metadata for the current track in the playlist
static QString GetMountPath(const QString &devPath)
If the device is being monitored, return its mountpoint.
MythConfirmationDialog * ShowOkPopup(const QString &message, QObject *parent, const char *slot, bool showCancel)
Non-blocking version of MythPopupBox::showOkPopup()
bool cleanOutThreads()
static bool checkStorageGroup(void)
checks we have at least one music directory in the 'Music' storage group
void SaveSetting(const QString &key, int newValue)
QSqlQuery wrapper that fetches a DB connection from the connection pool.
Definition: mythdbcon.h:125
int getNumTracks()
Definition: cddecoder.cpp:469
Playlist * getActive(void)
bool setCurrentTrackPos(int pos)
void AddCurrentLocation(QString location)
void removeAllCDTracks(void)
Definition: playlist.cpp:98
bool isPlaying(void)
Definition: musicplayer.h:100
void setCDTitle(const QString &a_title)
static void startStreamPlayback(void)
void setCallback(void(*lcallback)(void *, QString &), void *data)
Set the themed menus callback function and data for that function.
MythScreenStack * GetStack(const QString &stackname)
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
MythScreenStack * GetMainStack()
int mythplugin_init(const char *libversion)
void save()
Check each MusicMetadata entry and save those that have changed (ratings, etc.)
MusicMetadata * getMetadata(void)
Definition: cddecoder.cpp:557
static void showMiniPlayer(void)
#define REG_KEY(a, b, c, d)
void loadMusic(void)
Definition: musicdata.cpp:107
static MythThemedMenu * menu
QString GetThemeDir(void)
QString gCDdevice
Definition: musicplayer.cpp:39
static void runRipCD(void)
bool Create(void) override
static void handleMedia(MythMediaDevice *cd)
static void handleCDMedia(MythMediaDevice *cd)
bool hasClient(void)
Definition: musicplayer.h:103
PlaylistContainer * all_playlists
Definition: musicdata.h:55
bool initialized
Definition: musicdata.h:58
bool TestPluginVersion(const QString &name, const QString &libversion, const QString &pluginversion)
static const QString ValidFileExtensions
Definition: metaio.h:173
bool isCDTrack(void) const
static void(* m_callback)(void *, QString &)
static LCD * Get(void)
Definition: lcddevice.cpp:86
static void runMusicPlayback(void)
void setKillable(void)
QVariant value(int i) const
Definition: mythdbcon.h:182
virtual void Close()
static QStringList BuildFileList(const QString &dir, const QStringList &filters)
const QString & getVolumeID() const
Definition: mythmedia.h:72
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
#define REG_JUMPEX(a, b, c, d, e)
static void runMusicStreamPlayback(void)
static QStringList GetMusicFilter()
bool Create(void) override
static void startImport(void)
static MusicMetadata * readMetadata(const QString &filename)
Read the metadata from filename directly.
Definition: metaio.cpp:68
virtual MythScreenType * GetTopScreen(void) const
static void startRipper(void)
static const uint16_t * d
QString GetSetting(const QString &key, const QString &defaultval="")
static void MusicCallback(void *data, QString &selection)
void setDevice(const QString &dev)
Definition: cddecoder.cpp:122
static void runMusicSelection(void)
IdType ID() const
bool Create(void) override
bool isActive(void) const
Definition: mythdbcon.h:188
static QString defaultCDdevice()
CDDevice, user-selected drive, or /dev/cdrom.
bool Create(void) override
static int runMenu(QString which_menu)
static MSqlQueryInfo InitCon(ConnectionReuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
Definition: mythdbcon.cpp:547
QString Album() const
void showMiniPlayer(void)
MythUIHelper * GetMythUI()
void stop(bool stopAll=false)
MythMainWindow * GetMythMainWindow(void)
bool Create(void) override
bool doneLoading() const
bool Create(void) override
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
Themed menu class, used for main menus in MythTV frontend.
void clearCDData(void)
static void setupKeys(void)
bool GetBoolSetting(const QString &key, bool defaultval=false)
const QString & getMountPath() const
Definition: mythmedia.h:58
QString RemoveCurrentLocation(void)
bool Create(void) override
static QString chooseCD(void)
Work out the best CD drive to use at this time.
#define MYTH_BINARY_VERSION
Update this whenever the plug-in ABI changes.
Definition: mythversion.h:16
bool foundTheme(void)
Returns true iff a theme has been found by a previous call to SetMenuTheme().
MusicData * gMusicData
Definition: musicdata.cpp:20
bool isUsable() const
Is this device "ready", for a plugin to access?
Definition: mythmedia.h:84
MusicMetadata * getCDMetadata(int m_the_track)
Definition: cdrip.h:91
Definition: lcddevice.h:165
static void * m_callbackdata
static void startPlayback(void)
bool exec(void)
Wrap QSqlQuery::exec() so we can display SQL.
Definition: mythdbcon.cpp:615
void fillSonglistFromList(const QList< int > &songList, bool removeDuplicates, InsertPLOption insertOption, int currentTrackID)
Definition: playlist.cpp:801
void getCallback(void(**lcallback)(void *, QString &), void **data)
Get the themed menus callback function and data for that function.
static void DBError(const QString &where, const MSqlQuery &query)
Definition: mythdb.cpp:179
void removeAllTracks(void)
Definition: playlist.cpp:90
void ActivateSettingsCache(bool activate=true)
bool Create(void) override
Definition: streamview.cpp:43
bool UpgradeMusicDatabaseSchema(void)
void activePlaylistChanged(int trackID, bool deleted)
MythMediaStatus getStatus() const
Definition: mythmedia.h:70
bool Create(void) override
Definition: cdrip.cpp:612
static bool checkMusicAvailable(void)
checks we have some tracks available
static void startDatabaseTree(void)