summaryrefslogtreecommitdiff
path: root/cuesheet.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cuesheet.cpp')
-rw-r--r--cuesheet.cpp72
1 files changed, 72 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];
+}