diff options
-rw-r--r-- | cuesheet.cpp | 72 | ||||
-rw-r--r-- | cuesheet.h | 30 |
2 files changed, 102 insertions, 0 deletions
diff --git a/cuesheet.cpp b/cuesheet.cpp new file mode 100644 index 0000000..c023ca0 --- /dev/null +++ b/cuesheet.cpp @@ -0,0 +1,72 @@ +#include "cuesheet.h" + +#include <iostream> + +CueSheet::CueSheet(const QString& filename) { + QFile f(filename); + f.open(QIODevice::ReadOnly | QIODevice::Text); + + int track = 0; + QString artist; + QString name; + int index; + + while(!f.atEnd()) { + QTextStream line(f.readLine()); + QString cmd; + line >> cmd; + + if(cmd == "TRACK") { + int n; + line >> n; + if(track) { + Track t = {track, artist, name, index}; + track_list.append(t); + } else { + album_artist = artist; + album_name = name; + } + track = n; + + } else if(cmd == "PERFORMER") { + QRegExp rx("(?:\")(.*)(?:\")"); + rx.indexIn(line.readLine()); + artist = rx.cap(1); + + } else if(cmd == "TITLE") { + QRegExp rx("(?:\")(.*)(?:\")"); + rx.indexIn(line.readLine()); + name = rx.cap(1); + + } else if(cmd == "INDEX") { + int n; + QString s; + line >> n >> s; + QStringList l = s.split(':'); + index = l[0].toInt() * 60 * 100 + l[1].toInt() * 100 + l[2].toInt(); + } + } + if(track) { + Track t = {track, artist, name, index}; + track_list.append(t); + } else { + album_artist = artist; + album_name = name; + } +} + +const QString& CueSheet::artist() const { + return album_artist; +} + +const QString& CueSheet::name() const { + return album_name; +} + +int CueSheet::tracks() const { + return track_list.size(); +} + +const CueSheet::Track& CueSheet::operator[](int track) const { + return track_list[track]; +} diff --git a/cuesheet.h b/cuesheet.h new file mode 100644 index 0000000..1546d75 --- /dev/null +++ b/cuesheet.h @@ -0,0 +1,30 @@ +#ifndef CUESHEET_H +#define CUESHEET_H + +#include <QtCore> + +class CueSheet { + class Track { + public: + int num; + QString artist; + QString name; + int index; + }; + + public: + CueSheet(const QString& filename); + + const QString& artist() const; + const QString& name() const; + int tracks() const; + + const Track& operator[](int track) const; + + private: + QString album_artist; + QString album_name; + QList<Track> track_list; +}; + +#endif |