Add playlist files

This commit is contained in:
Zachary Hall 2024-12-08 11:00:17 -08:00
parent 6052436fa9
commit 2d66041928
2 changed files with 92 additions and 0 deletions

53
playlist.cpp Normal file
View file

@ -0,0 +1,53 @@
#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();
}
}

39
playlist.hpp Normal file
View file

@ -0,0 +1,39 @@
#pragma once
#include <filesystem>
#include <vector>
#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<PlaylistEntry> entries;
fs::path path;
using vec = std::vector<PlaylistEntry>;
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;
};