110 lines
2.7 KiB
Rust
110 lines
2.7 KiB
Rust
// Copyright (c) 2022 Marceline Cramer
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
pub use serde;
|
|
pub use serde_json;
|
|
|
|
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
|
pub enum PlaybackStatus {
|
|
/// A track is currently playing.
|
|
Playing,
|
|
|
|
/// A track is currently paused.
|
|
Paused,
|
|
|
|
/// No track is currently playing.
|
|
Stopped,
|
|
}
|
|
|
|
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
|
pub enum LoopStatus {
|
|
/// The playback will stop when there are no more tracks to play.
|
|
None,
|
|
|
|
/// The current track will start again from the beginning once it has finished playing.
|
|
Track,
|
|
|
|
/// The playback loops through a list of tracks.
|
|
Playlist,
|
|
}
|
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
pub struct ProgressChanged {
|
|
/// Current position into the track in seconds.
|
|
pub position: f32,
|
|
}
|
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
|
|
pub struct AlbumInfo {
|
|
/// The title of the current album.
|
|
pub title: Option<String>,
|
|
|
|
/// The list of artists of the album.
|
|
pub artists: Vec<String>,
|
|
}
|
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
|
|
pub struct TrackInfo {
|
|
/// The title of the current track.
|
|
pub title: Option<String>,
|
|
|
|
/// The list of artists on this track. May be empty.
|
|
pub artists: Vec<String>,
|
|
|
|
/// The optional track number on the disc the album the track appears on.
|
|
pub track_number: Option<i32>,
|
|
|
|
/// Length of the track in seconds.
|
|
pub length: Option<f32>,
|
|
}
|
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
#[serde(tag = "kind")]
|
|
pub enum InMsg {
|
|
Connected,
|
|
Disconnected,
|
|
PlaybackStatusChanged(PlaybackStatus),
|
|
VolumeChanged { volume: f32 },
|
|
ShuffleChanged { shuffle: bool },
|
|
LoopingChanged(LoopStatus),
|
|
ProgressChanged(ProgressChanged),
|
|
AlbumChanged(AlbumInfo),
|
|
TrackChanged(TrackInfo),
|
|
}
|
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
#[serde(tag = "kind")]
|
|
pub enum OutMsg {
|
|
/// Brings the media player's user interface to the front using any
|
|
/// appropriate mechanism available.
|
|
Raise,
|
|
|
|
/// Pauses playback.
|
|
Pause,
|
|
|
|
/// Resumes playback.
|
|
Play,
|
|
|
|
/// Toggles playback between paused and resumed.
|
|
PlayPause,
|
|
|
|
/// Stops playback.
|
|
Stop,
|
|
|
|
/// Skips to the next track in the tracklist. Stops playback if there is
|
|
/// none.
|
|
Next,
|
|
|
|
/// Skips to the previous track in the tracklist. Stops playback if there
|
|
/// is no previous track and endless playback and track repeat are off.
|
|
Previous,
|
|
|
|
/// Sets the volume. Values are clamped to 0.0 to 1.0.
|
|
SetVolume { volume: f32 },
|
|
|
|
/// Seeks the current track's position in seconds.
|
|
Seek { offset: f32 },
|
|
}
|