Go to the documentation of this file.
8 #include <QApplication>
10 #include <QScopedPointer>
21 #include <libmythbase/mythversion.h>
57 static QString chooseCD(
void)
76 QString sql =
"SELECT DISTINCT hostname "
78 "WHERE groupname = 'Music'";
85 hostList.append(query.
value(0).toString());
89 if (hostList.isEmpty())
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."));
99 sql =
"SELECT DISTINCT hostname "
101 "WHERE groupname = 'MusicArt'";
108 hostList.append(query.
value(0).toString());
112 if (hostList.isEmpty())
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."));
127 bool foundMusic =
false;
128 if (count_query.
exec(
"SELECT COUNT(*) FROM music_songs;"))
130 if(count_query.
next() &&
131 0 != count_query.
value(0).toInt())
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."));
171 auto *view =
new StreamView(mainStack,
nullptr);
199 #if defined HAVE_CDIO
207 auto *rip =
new Ripper(mainStack, chooseCD());
214 Qt::QueuedConnection);
220 ShowOkPopup(QCoreApplication::translate(
"(MythMusicMain)",
221 "MythMusic hasn't been built with libcdio "
222 "support so ripping CDs is not possible"));
231 LOG(VB_GENERAL, LOG_INFO,
"Scanning for music files");
247 if (import->Create())
252 Qt::QueuedConnection);
264 QString sel = selection.toLower();
265 if (sel ==
"music_create_playlist")
267 else if (sel ==
"music_play")
269 else if (sel ==
"stream_play")
271 else if (sel ==
"music_rip")
275 else if (sel ==
"music_import")
279 else if (sel ==
"settings_scan")
283 else if (sel ==
"settings_general")
293 else if (sel ==
"settings_player")
303 else if (sel ==
"settings_rating")
313 else if (sel ==
"settings_visualization")
324 else if (sel ==
"settings_import")
353 auto *
menu = qobject_cast<MythThemedMenu *>(parentObject);
355 if (
menu &&
menu->objectName() ==
"mainmenu")
361 parentObject = parentObject->parent();
375 if (diag->foundTheme())
384 LOG(VB_GENERAL, LOG_ERR, QString(
"Couldn't find menu %1 or theme %2")
415 #if defined HAVE_CDIO
418 auto *rip =
new Ripper(mainStack, chooseCD());
430 Qt::QueuedConnection);
447 filt.replace(
".",
"*.");
448 return filt.split(
'|');
451 static QStringList
BuildFileList(
const QString &dir,
const QStringList &filters)
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);
465 QFileInfoList list =
d.entryInfoList();
469 for (
const auto & fi : qAsConst(list))
474 QCoreApplication::processEvents();
478 ret << fi.absoluteFilePath();
486 static QString s_mountPath;
496 LOG(VB_MEDIA, LOG_INFO, QString(
497 "MythMusic: '%1' unmounted, clearing data").arg(cd->
getVolumeID()));
519 LOG(VB_MEDIA, LOG_NOTICE, QString(
"MythMusic: '%1' mounted on '%2'")
539 QString message = QCoreApplication::translate(
"(MythMusicMain)",
540 "Searching for music files...");
541 auto *busy =
new MythUIBusyDialog( message, popupStack,
"musicscanbusydialog");
552 LOG(VB_MEDIA, LOG_INFO, QString(
"MythMusic: %1 music files found")
553 .arg(trackList.count()));
558 if (trackList.isEmpty())
561 message = QCoreApplication::translate(
"(MythMusicMain)",
"Loading music tracks");
563 "scalingprogressdialog");
567 progress->SetTotal(trackList.count());
577 for (
const auto &
file : qAsConst(trackList))
582 meta->setTrack(++track);
588 QCoreApplication::processEvents();
591 LOG(VB_MEDIA, LOG_INFO, QString(
"MythMusic: %1 tracks scanned").arg(track));
602 for (track = 1; track <= tracks; track++)
606 songList.append(mdata->
ID());
608 if (songList.isEmpty())
636 LOG(VB_MEDIA, LOG_NOTICE,
"Got a CD media changed event");
650 LOG(VB_MEDIA, LOG_INFO,
"MythMusic: Storing CD device " +
gCDdevice);
654 LOG(VB_MEDIA, LOG_INFO,
"Device is not usable clearing cd data");
684 QCoreApplication::processEvents();
693 auto *decoder =
new CdDecoder(
"cda",
nullptr,
nullptr);
694 decoder->setDevice(newDevice);
696 int tracks = decoder->getNumTracks();
697 bool setTitle =
false;
699 for (
int trackNo = 1; trackNo <= tracks; trackNo++)
709 QString parenttitle =
" ";
713 parenttitle +=
" ~ ";
716 if (track->
Album().length() > 0)
717 parenttitle += track->
Album();
720 parenttitle =
" " + QCoreApplication::translate(
"(MythMusicMain)",
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.");
752 songList.append((mdata)->ID());
755 if (!songList.isEmpty())
781 LOG(VB_GENERAL, LOG_NOTICE,
"MythMusic got a media changed event"
782 "but cdio support is not compiled in");
788 REG_JUMP(QT_TRANSLATE_NOOP(
"MythControls",
"Play music"),
790 REG_JUMP(QT_TRANSLATE_NOOP(
"MythControls",
"Select music playlists"),
792 REG_JUMP(QT_TRANSLATE_NOOP(
"MythControls",
"Play radio stream"),
794 REG_JUMP(QT_TRANSLATE_NOOP(
"MythControls",
"Rip CD"),
796 REG_JUMP(QT_TRANSLATE_NOOP(
"MythControls",
"Scan music"),
798 REG_JUMPEX(QT_TRANSLATE_NOOP(
"MythControls",
"Show Music Miniplayer"),
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",
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"),
"");
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"),
"");
864 filt.replace(
'|',
',');
874 MYTH_BINARY_VERSION))
883 LOG(VB_GENERAL, LOG_ERR,
884 "Couldn't upgrade music database schema, exiting.");
899 return runMenu(
"musicmenu.xml");
904 return runMenu(
"music_settings.xml");
bool isActive(void) const
bool next(void)
Wrap QSqlQuery::next() so we can display the query results.
QSqlQuery wrapper that fetches a DB connection from the connection pool.
MythScreenStack * GetMainStack()
static void(* m_callback)(void *, QString &)
static int runMenu(const QString &which_menu)
QString RemoveCurrentLocation()
bool setCurrentTrackPos(int pos)
static void REG_KEY(const QString &Context, const QString &Action, const QString &Description, const QString &Key)
void importFinished(void)
static void startDatabaseTree(void)
void removeAllCDTracks(void)
QVariant value(int i) const
int mythplugin_init(const char *libversion)
bool exec(void)
Wrap QSqlQuery::exec() so we can display SQL.
bool isPlaying(void) const
void setCDTitle(const QString &a_title)
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
static void handleCDMedia([[maybe_unused]] MythMediaDevice *cd)
static void startRipper(void)
static bool TestPluginVersion(const QString &name, const QString &libversion, const QString &pluginversion)
static bool checkStorageGroup(void)
checks we have at least one music directory in the 'Music' storage group
static void * m_callbackdata
static void startImport(void)
MusicMetadata * getCDMetadata(int m_the_track)
Playlist * getActive(void)
MusicMetadata * getCurrentMetadata(void)
get the metadata for the current track in the playlist
static void startPlayback(void)
static void runScan(void)
static void runMusicPlayback(void)
static void MusicCallback([[maybe_unused]] void *data, QString &selection)
static QStringList BuildFileList(const QString &dir, const QStringList &filters)
static void handleMedia(MythMediaDevice *cd)
static QStringList GetMusicFilter()
void reloadMusic(void) const
reload music after a scan, rip or import
static void runMusicStreamPlayback(void)
static MythThemedMenu * menu
static MSqlQueryInfo InitCon(ConnectionReuse _reuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
static void DBError(const QString &where, const MSqlQuery &query)
void addCDTrack(const MusicMetadata &the_track)
int getCDTrackCount(void) const
static void setupKeys(void)
static bool checkMusicAvailable(void)
checks we have some tracks available
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
PlaylistContainer * m_all_playlists
void mythplugin_destroy(void)
void showMiniPlayer(void) const
static void runMusicSelection(void)
bool GetBoolSetting(const QString &key, bool defaultval=false)
bool UpgradeMusicDatabaseSchema(void)
void loadMusic(void) const
void activePlaylistChanged(int trackID, bool deleted)
static void startStreamPlayback(void)
void save()
Check each MusicMetadata entry and save those that have changed (ratings, etc.)
static void REG_JUMP(const QString &Destination, const QString &Description, const QString &Key, void(*Callback)(void))
MythMainWindow * GetMythMainWindow(void)
static void REG_JUMPEX(const QString &Destination, const QString &Description, const QString &Key, void(*Callback)(void), bool ExitToMain)
void ActivateSettingsCache(bool activate=true)
MythScreenStack * GetStack(const QString &Stackname)
void sendCDChangedEvent(void)
static void runRipCD(void)
void removeAllTracks(void)
void stop(bool stopAll=false)
static const iso6937table * d
void AddCurrentLocation(const QString &Location)
void fillSonglistFromList(const QList< int > &songList, bool removeDuplicates, InsertPLOption insertOption, int currentTrackID)
void SaveSetting(const QString &key, int newValue)
MythUIHelper * GetMythUI()
static void showMiniPlayer(void)
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
int mythplugin_config(void)
static void scanMusic(void)
MythConfirmationDialog * ShowOkPopup(const QString &message, bool showCancel)
Non-blocking version of MythPopupBox::showOkPopup()
QString GetSetting(const QString &key, const QString &defaultval="")
virtual MythScreenType * GetTopScreen(void) const