diff --git a/playlist.cpp b/playlist.cpp new file mode 100644 index 0000000..abcc43a --- /dev/null +++ b/playlist.cpp @@ -0,0 +1,53 @@ +#include "playlist.hpp" +#include +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(); + } +} \ No newline at end of file diff --git a/playlist.hpp b/playlist.hpp new file mode 100644 index 0000000..a33e56f --- /dev/null +++ b/playlist.hpp @@ -0,0 +1,39 @@ +#pragma once +#include +#include +#define LOOP_FOREVER (-1) +namespace fs = std::filesystem; +struct PlaylistEntry { + + double speed; + double tempo; + double pitch; + int loops; + int stream_idx; + fs::path path; +}; +class Playlist { + friend class LooperXspfReaderCallback; + std::vector entries; + fs::path path; + using vec = std::vector; + using iterator = vec::iterator; + using const_iterator = vec::const_iterator; + using reverse_iterator = vec::reverse_iterator; + using const_reverse_iterator = vec::const_reverse_iterator; + public: + void save(fs::path output_file); + inline PlaylistEntry &operator[](int idx) { + return entries[idx]; + } + iterator begin(); + iterator end(); + const_iterator cbegin(); + const_iterator cend(); + reverse_iterator rbegin(); + reverse_iterator rend(); + const_reverse_iterator crbegin(); + const_reverse_iterator crend(); + Playlist(fs::path input_file); + Playlist() = default; +}; \ No newline at end of file