#ifndef qb_hpp
#define qb_hpp
#include <memory>
#include <string>
#include <vector>
namespace qb {
enum class node_type {
audio,
cue,
};
struct load_state {
enum stage_kind {
loading,
loaded,
failed,
};
stage_kind stage;
std::string message;
load_state(stage_kind s) : stage(s), message("") {};
load_state(stage_kind s, const std::string &m) : stage(s), message(m) {};
};
struct context;
struct node {
node(const node&) = delete;
node(node&&) = delete;
node &operator=(const node&) = delete;
node &operator=(node&&) = delete;
virtual ~node() = default;
const std::string &name() const { return _name; }
node_type type() const { return _type; }
const context* ctx() const { return _c; }
virtual int minframe() const = 0;
virtual int maxframe() const = 0;
protected:
node(const context *c, const std::string &n, node_type t);
const context *_c;
private:
std::string _name;
node_type _type;
};
using node_ptr = std::shared_ptr<node>;
struct context
{
context();
~context() = default;
context(const context &) = delete;
context(context &&) = delete;
context &operator=(const context &) = delete;
context &operator=(context &&) = delete;
// get/set the playback framerate (not the UI frame rate!)
int framerate() const { return _framerate; }
void framerate(int fr) { _framerate = fr; }
// visible radius around playhead
double visrad() const { return _visrad; }
// location of the playhead (in playback frames)
double playhead() const { return _playhead; }
// for ui animations, incremented (with wraparound) on every UI frame.
uint32_t spinstep() const { return _spinstep; }
// width and height of the qb window
int width() const { return _width; }
int height() const { return _height; }
// draws a frame at the given width and height
void frame(int width, int height);
// kills the event loop
void shutdown();
// translates a playback frame to a UI x-coordinate
int frame2pixel(double frame) const;
private:
void initaudio();
void pushaudio();
bool _playing = false;
double _playhead = 0;
double _visrad = 240;
int _width = 0;
int _height = 0;
uint32_t _spinstep = 0;
bool _audioinit = false;
int _playedframe = -1;
int64_t _pushedsample = -1;
const node *_audiosource = nullptr;
int _framerate = 24;
std::vector<qb::node_ptr> _nodes;
};
}
#endif