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