MythTV  master
lyricsdata.h
Go to the documentation of this file.
1 #ifndef LYRICSDATA_H_
2 #define LYRICSDATA_H_
3 
4 // C/C++
5 #include <cstdint>
6 #include <utility>
7 
8 // qt
9 #include <QObject>
10 
11 // mythtv
12 #include "mythmetaexp.h"
13 #include "mythcorecontext.h"
14 #include "musicmetadata.h"
15 #include "mythmiscutil.h"
16 
17 class LyricsData;
18 
20 {
21  public:
22  LyricsLine() = default;
23  LyricsLine(int time, QString lyric) :
24  m_time(time), m_lyric(std::move(lyric)) { }
25 
26  int m_time {0};
27  QString m_lyric;
28 
29  QString toString(bool syncronized)
30  {
31  if (syncronized)
32  return formatTime() + m_lyric;
33 
34  return m_lyric;
35  }
36 
37  private:
38  QString formatTime(void) const
39  {
40  QString timestr = MythFormatTimeMs(m_time,"mm:ss.zzz");
41  timestr.chop(1); // Chop 1 to return hundredths
42  return QString("[%1]").arg(timestr);
43  }
44 };
45 
46 class META_PUBLIC LyricsData : public QObject
47 {
48  Q_OBJECT
49 
50  public:
52  explicit LyricsData(MusicMetadata *parent)
53  : m_parent(parent) {}
54  LyricsData(MusicMetadata *parent, QString grabber, QString artist,
55  QString album, QString title, bool syncronized)
56  : m_parent(parent), m_grabber(std::move(grabber)),
57  m_artist(std::move(artist)), m_album(std::move(album)),
58  m_title(std::move(title)), m_syncronized(syncronized) {}
59  ~LyricsData() override;
60 
61  QString grabber(void) { return m_grabber; }
62  void setGrabber(const QString &grabber) { m_grabber = grabber; }
63 
64  QString artist(void) { return m_artist; }
65  void setArtist(const QString &artist) { m_artist = artist; }
66 
67  QString album(void) { return m_album; }
68  void setAlbum(const QString &album) { m_album = album; }
69 
70  QString title(void) { return m_title; }
71  void setTitle(const QString &title) { m_title = title; }
72 
73  QMap<int, LyricsLine*>* lyrics(void) { return &m_lyricsMap; }
74  void setLyrics(const QStringList &lyrics);
75 
76  bool syncronized(void) const { return m_syncronized; }
77  void setSyncronized(bool syncronized ) { m_syncronized = syncronized; }
78 
79  bool changed(void) const { return m_changed; }
80  void setChanged(bool changed) { m_changed = changed; }
81 
82  enum Status
83  {
84  STATUS_NOTLOADED = 0, // not looked for any lyrics yet
85  STATUS_SEARCHING, // search is taking place
86  STATUS_FOUND, // search completed and some lyrics have been found
87  STATUS_NOTFOUND // search completed but no lyrics have been found
88  };
89 
90  Status getStatus(void) { return m_status; }
91 
92  void clear(void);
93  void clearLyrics(void);
94  void findLyrics(const QString &grabber);
95  void save(void);
96 
97  void customEvent(QEvent *event) override; // QObject
98 
99  signals:
100  void statusChanged(LyricsData::Status status, const QString &message);
101 
102  private:
103  void loadLyrics(const QString &xmlData);
104  QString createLyricsXML(void);
105 
106  QMap<int, LyricsLine*> m_lyricsMap;
107 
108  MusicMetadata *m_parent {nullptr};
109 
110  Status m_status {STATUS_NOTLOADED};
111 
112  QString m_grabber;
113  QString m_artist;
114  QString m_album;
115  QString m_title;
116  bool m_syncronized {false};
117  bool m_changed {false};
118 };
119 
121 
122 #endif
MythFormatTimeMs
QString MythFormatTimeMs(int msecs, const QString &fmt)
Format a milliseconds time value.
Definition: mythmiscutil.cpp:1229
Q_DECLARE_METATYPE
Q_DECLARE_METATYPE(GrabberScript *)
LyricsData::getStatus
Status getStatus(void)
Definition: lyricsdata.h:90
LyricsData::m_grabber
QString m_grabber
Definition: lyricsdata.h:112
title
QString title
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:636
LyricsData::setArtist
void setArtist(const QString &artist)
Definition: lyricsdata.h:65
LyricsData::setAlbum
void setAlbum(const QString &album)
Definition: lyricsdata.h:68
LyricsLine::formatTime
QString formatTime(void) const
Definition: lyricsdata.h:38
MusicMetadata
Definition: musicmetadata.h:81
LyricsData::Status
Status
Definition: lyricsdata.h:83
mythmetaexp.h
LyricsData::m_artist
QString m_artist
Definition: lyricsdata.h:113
LyricsData::lyrics
QMap< int, LyricsLine * > * lyrics(void)
Definition: lyricsdata.h:73
LyricsData::STATUS_FOUND
@ STATUS_FOUND
Definition: lyricsdata.h:86
LyricsData::STATUS_SEARCHING
@ STATUS_SEARCHING
Definition: lyricsdata.h:85
LyricsLine::m_lyric
QString m_lyric
Definition: lyricsdata.h:27
LyricsData::statusChanged
void statusChanged(LyricsData::Status status, const QString &message)
LyricsLine
Definition: lyricsdata.h:20
LyricsData::setGrabber
void setGrabber(const QString &grabber)
Definition: lyricsdata.h:62
LyricsLine::LyricsLine
LyricsLine(int time, QString lyric)
Definition: lyricsdata.h:23
LyricsData::changed
bool changed(void) const
Definition: lyricsdata.h:79
clear
static void clear(SettingsMap &cache, SettingsMap &overrides, const QString &myKey)
Definition: mythdb.cpp:844
LyricsData::setSyncronized
void setSyncronized(bool syncronized)
Definition: lyricsdata.h:77
LyricsData
Definition: lyricsdata.h:47
LyricsData::m_lyricsMap
QMap< int, LyricsLine * > m_lyricsMap
Definition: lyricsdata.h:106
LyricsData::m_album
QString m_album
Definition: lyricsdata.h:114
LyricsData::syncronized
bool syncronized(void) const
Definition: lyricsdata.h:76
LyricsData::setChanged
void setChanged(bool changed)
Definition: lyricsdata.h:80
LyricsData::LyricsData
LyricsData()
LyricsData::artist
QString artist(void)
Definition: lyricsdata.h:64
LyricsData::title
QString title(void)
Definition: lyricsdata.h:70
LyricsData::LyricsData
LyricsData(MusicMetadata *parent)
Definition: lyricsdata.h:52
mythmiscutil.h
mythcorecontext.h
LyricsData::grabber
QString grabber(void)
Definition: lyricsdata.h:61
LyricsData::setTitle
void setTitle(const QString &title)
Definition: lyricsdata.h:71
LyricsLine::LyricsLine
LyricsLine()=default
LyricsData::LyricsData
LyricsData(MusicMetadata *parent, QString grabber, QString artist, QString album, QString title, bool syncronized)
Definition: lyricsdata.h:54
LyricsData::m_title
QString m_title
Definition: lyricsdata.h:115
LyricsLine::toString
QString toString(bool syncronized)
Definition: lyricsdata.h:29
LyricsData::album
QString album(void)
Definition: lyricsdata.h:67
META_PUBLIC
#define META_PUBLIC
Definition: mythmetaexp.h:9
musicmetadata.h