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