mirror of
https://github.com/arabianq/pipewire-soundpad.git
synced 2026-04-28 06:21:23 +00:00
feat: first attemp to support playing multiple tracks in parallel
This commit is contained in:
+23
-13
@@ -3,12 +3,14 @@ use crate::types::{commands::*, socket::Request};
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub fn parse_command(request: &Request) -> Option<Box<dyn Executable + Send>> {
|
||||
let id = request.args.get("id").and_then(|s| s.parse::<u32>().ok());
|
||||
|
||||
match request.name.as_str() {
|
||||
"ping" => Some(Box::new(PingCommand {})),
|
||||
"pause" => Some(Box::new(PauseCommand {})),
|
||||
"resume" => Some(Box::new(ResumeCommand {})),
|
||||
"toggle_pause" => Some(Box::new(TogglePauseCommand {})),
|
||||
"stop" => Some(Box::new(StopCommand {})),
|
||||
"pause" => Some(Box::new(PauseCommand { id })),
|
||||
"resume" => Some(Box::new(ResumeCommand { id })),
|
||||
"toggle_pause" => Some(Box::new(TogglePauseCommand { id })),
|
||||
"stop" => Some(Box::new(StopCommand { id })),
|
||||
"is_paused" => Some(Box::new(IsPausedCommand {})),
|
||||
"get_state" => Some(Box::new(GetStateCommand {})),
|
||||
"get_volume" => Some(Box::new(GetVolumeCommand {})),
|
||||
@@ -19,9 +21,9 @@ pub fn parse_command(request: &Request) -> Option<Box<dyn Executable + Send>> {
|
||||
.unwrap_or(&String::new())
|
||||
.parse::<f32>()
|
||||
.ok();
|
||||
Some(Box::new(SetVolumeCommand { volume }))
|
||||
Some(Box::new(SetVolumeCommand { volume, id }))
|
||||
}
|
||||
"get_position" => Some(Box::new(GetPositionCommand {})),
|
||||
"get_position" => Some(Box::new(GetPositionCommand { id })),
|
||||
"seek" => {
|
||||
let position = request
|
||||
.args
|
||||
@@ -29,9 +31,9 @@ pub fn parse_command(request: &Request) -> Option<Box<dyn Executable + Send>> {
|
||||
.unwrap_or(&String::new())
|
||||
.parse::<f32>()
|
||||
.ok();
|
||||
Some(Box::new(SeekCommand { position }))
|
||||
Some(Box::new(SeekCommand { position, id }))
|
||||
}
|
||||
"get_duration" => Some(Box::new(GetDurationCommand {})),
|
||||
"get_duration" => Some(Box::new(GetDurationCommand { id })),
|
||||
"play" => {
|
||||
let file_path = request
|
||||
.args
|
||||
@@ -39,16 +41,24 @@ pub fn parse_command(request: &Request) -> Option<Box<dyn Executable + Send>> {
|
||||
.unwrap_or(&String::new())
|
||||
.parse::<PathBuf>()
|
||||
.ok();
|
||||
Some(Box::new(PlayCommand { file_path }))
|
||||
let concurrent = request
|
||||
.args
|
||||
.get("concurrent")
|
||||
.unwrap_or(&String::new())
|
||||
.parse::<bool>()
|
||||
.ok();
|
||||
Some(Box::new(PlayCommand {
|
||||
file_path,
|
||||
concurrent,
|
||||
}))
|
||||
}
|
||||
"get_current_file_path" => Some(Box::new(GetCurrentFilePathCommand {})),
|
||||
"get_tracks" => Some(Box::new(GetTracksCommand {})),
|
||||
"get_input" => Some(Box::new(GetCurrentInputCommand {})),
|
||||
"get_inputs" => Some(Box::new(GetAllInputsCommand {})),
|
||||
"set_input" => {
|
||||
let name = Some(request.args.get("input_name").unwrap_or(&String::new())).cloned();
|
||||
Some(Box::new(SetCurrentInputCommand { name }))
|
||||
}
|
||||
"get_loop" => Some(Box::new(GetLoopCommand {})),
|
||||
"set_loop" => {
|
||||
let enabled = request
|
||||
.args
|
||||
@@ -56,9 +66,9 @@ pub fn parse_command(request: &Request) -> Option<Box<dyn Executable + Send>> {
|
||||
.unwrap_or(&String::new())
|
||||
.parse::<bool>()
|
||||
.ok();
|
||||
Some(Box::new(SetLoopCommand { enabled }))
|
||||
Some(Box::new(SetLoopCommand { enabled, id }))
|
||||
}
|
||||
"toggle_loop" => Some(Box::new(ToggleLoopCommand {})),
|
||||
"toggle_loop" => Some(Box::new(ToggleLoopCommand { id })),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user