From d148a70e245eb7cc0d75d097e07ce2614b26eaef Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Sat, 11 Sep 2010 17:04:05 +0200 Subject: Added .cue-parser. --- cuesheet.cpp | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ cuesheet.h | 30 +++++++++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 cuesheet.cpp create mode 100644 cuesheet.h 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 + +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 + +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_list; +}; + +#endif -- cgit v1.2.3