#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 * 1000 + l[1].toInt() * 1000 + l[2].toInt() * 1000 / 75; } } if(track) { Track t = {track, artist, name, index}; track_list.append(t); } else { album_artist = artist; album_name = name; } f.close(); } 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]; }