#include "playlist.hpp"
#include <Xspf.h>
class LooperXspfReaderCallback : public XspfReaderCallback {
    Playlist *list;
    public:
    inline LooperXspfReaderCallback(Playlist *list) : list(list) { }
    inline void addTrack(XspfTrack *track) {
        PlaylistEntry entry;
        entry.speed = 1.0;
        entry.tempo = 1.0;
        entry.pitch = 1.0;
        entry.loops = 1;
        entry.stream_idx = 0;
        XML_Char const *loc = track->getLocation(0);
        if (loc != NULL) {
            entry.path = (char const *)loc;
            list->entries.push_back(entry);
        }
        delete track;
    }
}
Playlist::iterator Playlist::begin() {
    return entries.begin();
}
Playlist::iterator Playlist::end() {
    return entries.end();
}
Playlist::const_iterator Playlist::cbegin() {
    return entries.cbegin();
}
Playlist::const_iterator Playlist::cend() {
    return entries.cend();
}
Playlist::reverse_iterator Playlist::rbegin() {
    return entries.rbegin();
}
Playlist::reverse_iterator Playlist::rend() {
    return entries.rend();
}
Playlist::const_reverse_iterator Playlist::crbegin() {
    return entries.crbegin();
}
Playlist::const_reverse_iterator Playlist::crend() {
    return entries.crend();
}
Playlist::Playlist(fs::path path) {
    LooperXspfReaderCallback callback(this);
    XspfReader reader([=,this]());
    int ret = reader.parseFile(path.c_str(), &callback, fs::current_path().c_str());
    if (ret != XSPF_READER_SUCCESS) {
        throw std::exception();
    }
}