summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVegard Storheil Eriksen <zyp@jvnv.net>2010-09-11 17:04:05 +0200
committerVegard Storheil Eriksen <zyp@jvnv.net>2010-09-11 17:04:05 +0200
commitd148a70e245eb7cc0d75d097e07ce2614b26eaef (patch)
tree04e86f7d26055c6ee98911f107d55d55c2c6ef6e
parent2f4006a83889a5865080262cd843e035698af7ca (diff)
Added .cue-parser.
-rw-r--r--cuesheet.cpp72
-rw-r--r--cuesheet.h30
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