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);
266 QString sel = selection.toLower();
267 if (sel ==
"music_create_playlist")
269 else if (sel ==
"music_play")
271 else if (sel ==
"stream_play")
273 else if (sel ==
"music_rip")
277 else if (sel ==
"music_import")
281 else if (sel ==
"settings_scan")
285 else if (sel ==
"settings_general")
295 else if (sel ==
"settings_player")
305 else if (sel ==
"settings_rating")
315 else if (sel ==
"settings_visualization")
326 else if (sel ==
"settings_import")
355 auto *
menu = qobject_cast<MythThemedMenu *>(parentObject);
357 if (
menu &&
menu->objectName() ==
"mainmenu")
363 parentObject = parentObject->parent();
377 if (diag->foundTheme())
386 LOG(VB_GENERAL, LOG_ERR, QString(
"Couldn't find menu %1 or theme %2")
417 #if defined HAVE_CDIO
420 auto *rip =
new Ripper(mainStack, chooseCD());
432 Qt::QueuedConnection);
449 filt.replace(
".",
"*.");
450 return filt.split(
'|');
453 static QStringList
BuildFileList(
const QString &dir,
const QStringList &filters)
461 d.setNameFilters(filters);
462 d.setFilter(QDir::Files | QDir::AllDirs |
463 QDir::NoSymLinks | QDir::Readable |
464 QDir::NoDotAndDotDot);
465 d.setSorting(QDir::Name | QDir::DirsLast);
467 QFileInfoList list =
d.entryInfoList();
471 for (
const auto & fi : qAsConst(list))
476 QCoreApplication::processEvents();
480 ret << fi.absoluteFilePath();
488 static QString s_mountPath;
498 LOG(VB_MEDIA, LOG_INFO, QString(
499 "MythMusic: '%1' unmounted, clearing data").arg(cd->
getVolumeID()));
521 LOG(VB_MEDIA, LOG_NOTICE, QString(
"MythMusic: '%1' mounted on '%2'")
541 QString message = QCoreApplication::translate(
"(MythMusicMain)",
542 "Searching for music files...");
543 auto *busy =
new MythUIBusyDialog( message, popupStack,
"musicscanbusydialog");
554 LOG(VB_MEDIA, LOG_INFO, QString(
"MythMusic: %1 music files found")
555 .arg(trackList.count()));
560 if (trackList.isEmpty())
563 message = QCoreApplication::translate(
"(MythMusicMain)",
"Loading music tracks");
565 "scalingprogressdialog");
569 progress->SetTotal(trackList.count());
579 for (
const auto &
file : qAsConst(trackList))
584 meta->setTrack(++track);
590 QCoreApplication::processEvents();
593 LOG(VB_MEDIA, LOG_INFO, QString(
"MythMusic: %1 tracks scanned").arg(track));
604 for (track = 1; track <= tracks; track++)
608 songList.append(mdata->
ID());
610 if (songList.isEmpty())
638 LOG(VB_MEDIA, LOG_NOTICE,
"Got a CD media changed event");
652 LOG(VB_MEDIA, LOG_INFO,
"MythMusic: Storing CD device " +
gCDdevice);
656 LOG(VB_MEDIA, LOG_INFO,
"Device is not usable clearing cd data");
686 QCoreApplication::processEvents();
695 auto *decoder =
new CdDecoder(
"cda",
nullptr,
nullptr);
696 decoder->setDevice(newDevice);
698 int tracks = decoder->getNumTracks();
699 bool setTitle =
false;
701 for (
int trackNo = 1; trackNo <= tracks; trackNo++)
711 QString parenttitle =
" ";
715 parenttitle +=
" ~ ";
718 if (track->
Album().length() > 0)
719 parenttitle += track->
Album();
722 parenttitle =
" " + QCoreApplication::translate(
"(MythMusicMain)",
724 LOG(VB_GENERAL, LOG_INFO,
"Couldn't find your "
725 " CD. It may not be in the freedb database.\n"
726 " More likely, however, is that you need to delete\n"
727 " ~/.cddb and ~/.cdserverrc and restart MythMusic.");
754 songList.append((mdata)->ID());
757 if (!songList.isEmpty())
784 LOG(VB_GENERAL, LOG_NOTICE,
"MythMusic got a media changed event"
785 "but cdio support is not compiled in");
791 REG_JUMP(QT_TRANSLATE_NOOP(
"MythControls",
"Play music"),
793 REG_JUMP(QT_TRANSLATE_NOOP(
"MythControls",
"Select music playlists"),
795 REG_JUMP(QT_TRANSLATE_NOOP(
"MythControls",
"Play radio stream"),
797 REG_JUMP(QT_TRANSLATE_NOOP(
"MythControls",
"Rip CD"),
799 REG_JUMP(QT_TRANSLATE_NOOP(
"MythControls",
"Scan music"),
801 REG_JUMPEX(QT_TRANSLATE_NOOP(
"MythControls",
"Show Music Miniplayer"),
804 REG_KEY(
"Music",
"NEXTTRACK", QT_TRANSLATE_NOOP(
"MythControls",
805 "Move to the next track"),
">,.,Z,End");
806 REG_KEY(
"Music",
"PREVTRACK", QT_TRANSLATE_NOOP(
"MythControls",
807 "Move to the previous track"),
",,<,Q,Home");
808 REG_KEY(
"Music",
"FFWD", QT_TRANSLATE_NOOP(
"MythControls",
809 "Fast forward"),
"PgDown");
810 REG_KEY(
"Music",
"RWND", QT_TRANSLATE_NOOP(
"MythControls",
812 REG_KEY(
"Music",
"PAUSE", QT_TRANSLATE_NOOP(
"MythControls",
813 "Pause/Start playback"),
"P");
814 REG_KEY(
"Music",
"PLAY", QT_TRANSLATE_NOOP(
"MythControls",
815 "Start playback"),
"");
816 REG_KEY(
"Music",
"STOP", QT_TRANSLATE_NOOP(
"MythControls",
817 "Stop playback"),
"O");
818 REG_KEY(
"Music",
"VOLUMEDOWN", QT_TRANSLATE_NOOP(
"MythControls",
819 "Volume down"),
"[,{,F10,Volume Down");
820 REG_KEY(
"Music",
"VOLUMEUP", QT_TRANSLATE_NOOP(
"MythControls",
821 "Volume up"),
"],},F11,Volume Up");
822 REG_KEY(
"Music",
"MUTE", QT_TRANSLATE_NOOP(
"MythControls",
823 "Mute"),
"|,\\,F9,Volume Mute");
824 REG_KEY(
"Music",
"TOGGLEUPMIX",QT_TRANSLATE_NOOP(
"MythControls",
825 "Toggle audio upmixer"),
"Ctrl+U");
826 REG_KEY(
"Music",
"CYCLEVIS", QT_TRANSLATE_NOOP(
"MythControls",
827 "Cycle visualizer mode"),
"6");
828 REG_KEY(
"Music",
"BLANKSCR", QT_TRANSLATE_NOOP(
"MythControls",
829 "Blank screen"),
"5");
830 REG_KEY(
"Music",
"THMBUP", QT_TRANSLATE_NOOP(
"MythControls",
831 "Increase rating"),
"9");
832 REG_KEY(
"Music",
"THMBDOWN", QT_TRANSLATE_NOOP(
"MythControls",
833 "Decrease rating"),
"7");
834 REG_KEY(
"Music",
"REFRESH", QT_TRANSLATE_NOOP(
"MythControls",
835 "Refresh music tree"),
"8");
836 REG_KEY(
"Music",
"SPEEDUP", QT_TRANSLATE_NOOP(
"MythControls",
837 "Increase Play Speed"),
"W");
838 REG_KEY(
"Music",
"SPEEDDOWN", QT_TRANSLATE_NOOP(
"MythControls",
839 "Decrease Play Speed"),
"X");
840 REG_KEY(
"Music",
"MARK", QT_TRANSLATE_NOOP(
"MythControls",
841 "Toggle track selection"),
"T");
842 REG_KEY(
"Music",
"TOGGLESHUFFLE", QT_TRANSLATE_NOOP(
"MythControls",
843 "Toggle shuffle mode"),
"");
844 REG_KEY(
"Music",
"TOGGLEREPEAT", QT_TRANSLATE_NOOP(
"MythControls",
845 "Toggle repeat mode"),
"");
846 REG_KEY(
"Music",
"TOGGLELAST", QT_TRANSLATE_NOOP(
"MythControls",
847 "Switch to previous radio stream"),
"");
850 REG_KEY(
"Music",
"SWITCHTOPLAYLIST", QT_TRANSLATE_NOOP(
"MythControls",
851 "Switch to the current playlist view"),
"");
852 REG_KEY(
"Music",
"SWITCHTOPLAYLISTEDITORTREE", QT_TRANSLATE_NOOP(
"MythControls",
853 "Switch to the playlist editor tree view"),
"");
854 REG_KEY(
"Music",
"SWITCHTOPLAYLISTEDITORGALLERY", QT_TRANSLATE_NOOP(
"MythControls",
855 "Switch to the playlist editor gallery view"),
"");
856 REG_KEY(
"Music",
"SWITCHTOSEARCH", QT_TRANSLATE_NOOP(
"MythControls",
857 "Switch to the search view"),
"");
858 REG_KEY(
"Music",
"SWITCHTOVISUALISER", QT_TRANSLATE_NOOP(
"MythControls",
859 "Switch to the fullscreen visualiser view"),
"");
860 REG_KEY(
"Music",
"SWITCHTORADIO", QT_TRANSLATE_NOOP(
"MythControls",
861 "Switch to the radio stream view"),
"");
867 filt.replace(
'|',
',');
877 MYTH_BINARY_VERSION))
886 LOG(VB_GENERAL, LOG_ERR,
887 "Couldn't upgrade music database schema, exiting.");
902 return runMenu(
"musicmenu.xml");
907 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 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)
static void MusicCallback(void *data, QString &selection)
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 QStringList BuildFileList(const QString &dir, const QStringList &filters)
static void handleMedia(MythMediaDevice *cd)
static void handleCDMedia(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