pub mod definitions;
mod command_list;
use std::{fmt::Write, time::Duration};
use bytes::BytesMut;
use mpd_protocol::{
command::{Argument, Command as RawCommand},
response::Frame,
};
pub use self::{command_list::CommandList, definitions::*};
use crate::responses::TypedResponseError;
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct SongId(pub u64);
impl From<u64> for SongId {
fn from(id: u64) -> Self {
Self(id)
}
}
impl Argument for SongId {
fn render(&self, buf: &mut BytesMut) {
write!(buf, "{}", self.0).unwrap();
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct SongPosition(pub usize);
impl From<usize> for SongPosition {
fn from(pos: usize) -> Self {
Self(pos)
}
}
impl Argument for SongPosition {
fn render(&self, buf: &mut BytesMut) {
write!(buf, "{}", self.0).unwrap();
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum SeekMode {
Forward(Duration),
Backward(Duration),
Absolute(Duration),
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[allow(missing_docs)]
pub enum SingleMode {
Enabled,
Disabled,
Oneshot,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[allow(missing_docs)]
pub enum ReplayGainMode {
Off,
Track,
Album,
Auto,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Song {
Id(SongId),
Position(SongPosition),
}
impl From<SongId> for Song {
fn from(id: SongId) -> Self {
Self::Id(id)
}
}
impl From<SongPosition> for Song {
fn from(pos: SongPosition) -> Self {
Self::Position(pos)
}
}
pub trait Command {
type Response;
fn command(&self) -> RawCommand;
fn response(self, frame: Frame) -> Result<Self::Response, TypedResponseError>;
}