10 #ifndef PLAYD_PLAYER_HPP 11 #define PLAYD_PLAYER_HPP 36 std::function<std::unique_ptr<AudioSink>(
const AudioSource &, int)>;
40 std::function<std::unique_ptr<AudioSource>(
const std::string &)>;
50 std::map<std::string, SourceFn>
sources);
121 Response Load(
const std::string &tag,
const std::string &path);
130 Response Pos(
const std::string &tag,
const std::string &pos_str);
160 static std::uint64_t
PosParse(
const std::string &pos_str);
172 void PosRaw(
const std::string &tag, std::uint64_t pos);
184 void DumpState(
size_t id,
const std::string &tag)
const;
220 std::unique_ptr<Audio>
LoadRaw(
const std::string &path)
const;
229 std::unique_ptr<AudioSource>
LoadSource(
const std::string &path)
const;
232 #endif // PLAYD_PLAYER_HPP Declaration of the AudioSource class.
An object responsible for decoding an audio file.
bool Update()
Instructs the Player to perform a cycle of work.
static std::uint64_t PosParse(const std::string &pos_str)
Parses pos_str as a seek timestamp.
std::function< std::unique_ptr< AudioSink >(const AudioSource &, int)> SinkFn
Type for functions that construct sinks.
Response Load(const std::string &tag, const std::string &path)
Loads a file.
void PosRaw(const std::string &tag, std::uint64_t pos)
Performs an actual seek.
Declaration of the Audio class.
void Respond(int id, Response rs) const
Outputs a response, if there is a ResponseSink attached.
Response Quit(const std::string &tag)
Quits playd.
const ResponseSink * io
The sink for responses.
std::function< std::unique_ptr< AudioSource >(const std::string &)> SourceFn
Type for functions that construct sources.
bool CanAnnounceTime(std::uint64_t micros)
Determines whether we can broadcast a POS response.
Abstract class for anything that can be sent a response.
bool dead
Whether the Player is closing.
Response Eject(const std::string &tag)
Ejects the current loaded song, if any.
int device_id
The sink's device ID.
std::unique_ptr< AudioSource > LoadSource(const std::string &path) const
Loads a file, creating an AudioSource.
SinkFn sink
The sink create function.
std::map< std::string, SourceFn > sources
The file formats map.
Player & operator=(const Player &)=delete
Deleted copy-assignment constructor.
Player(int device_id, SinkFn sink, std::map< std::string, SourceFn > sources)
Constructs a Player.
Declaration of the AudioSink class.
Response Pos(const std::string &tag, const std::string &pos_str)
Seeks to a given position in the current file.
std::unique_ptr< Audio > LoadRaw(const std::string &path) const
Loads a file, creating an Audio for it.
void DumpState(size_t id, const std::string &tag) const
Emits a response for the current audio state to the sink.
std::uint64_t last_pos
The last-sent position.
Response Dump(size_t id, const std::string &tag) const
Dumps the current player state to the given ID.
Declaration of classes pertaining to responses to the client.
Response SetPlaying(const std::string &tag, bool playing)
Tells the audio file to start or stop playing.
std::unique_ptr< Audio > file
The loaded audio file.
Response End(const std::string &tag)
Ends a file, stopping and rewinding.
void SetIo(ResponseSink &io)
Sets the ResponseSink to which this Player shall send responses.
A Player contains a loaded audio file and a command API for manipulating it.