mirror of
https://github.com/arabianq/pipewire-soundpad.git
synced 2026-04-28 06:21:23 +00:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ab68648ef6 | |||
| e10b6f1449 | |||
| ede5028d35 | |||
| f721e4612a | |||
| ef9125024c | |||
| 12c70f0edb | |||
| eae455f0b8 | |||
| e0a55dffa6 | |||
| 6a755ad068 |
Generated
+261
-294
File diff suppressed because it is too large
Load Diff
+6
-6
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "pwsp"
|
name = "pwsp"
|
||||||
version = "1.0.1"
|
version = "1.0.3"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
authors = ["arabian"]
|
authors = ["arabian"]
|
||||||
description = "PWSP lets you play audio files through your microphone. Has both CLI and GUI clients."
|
description = "PWSP lets you play audio files through your microphone. Has both CLI and GUI clients."
|
||||||
@@ -16,19 +16,19 @@ tokio = { version = "1.47.1", features = ["full"] }
|
|||||||
futures = { version = "0.3.31", features = ["thread-pool"] }
|
futures = { version = "0.3.31", features = ["thread-pool"] }
|
||||||
async-trait = "0.1.89"
|
async-trait = "0.1.89"
|
||||||
|
|
||||||
serde = { version = "1.0.227", features = ["derive"] }
|
serde = { version = "1.0.228", features = ["derive"] }
|
||||||
serde_json = "1.0.145"
|
serde_json = "1.0.145"
|
||||||
|
|
||||||
clap = { version = "4.5.48", default-features = false, features = ["std", "suggestions", "help", "usage", "error-context", "derive"] }
|
clap = { version = "4.5.49", default-features = false, features = ["std", "suggestions", "help", "usage", "error-context", "derive"] }
|
||||||
dirs = "6.0.0"
|
dirs = "6.0.0"
|
||||||
|
|
||||||
rodio = { version = "0.21.1", default-features = false, features = ["symphonia-all", "playback"] }
|
rodio = { version = "0.21.1", default-features = false, features = ["symphonia-all", "playback"] }
|
||||||
pipewire = "0.9.2"
|
pipewire = "0.9.2"
|
||||||
rfd = "0.15.4"
|
rfd = "0.15.4"
|
||||||
|
|
||||||
egui = { version = "0.32.3", default-features = false, features = ["default_fonts", "rayon"] }
|
egui = { version = "0.33.0", default-features = false, features = ["default_fonts", "rayon"] }
|
||||||
eframe = { version = "0.32.3", default-features = false, features = ["default_fonts", "glow", "x11", "wayland"] }
|
eframe = { version = "0.33.0", default-features = false, features = ["default_fonts", "glow", "x11", "wayland"] }
|
||||||
egui_material_icons = "0.4.0"
|
egui_material_icons = "0.5.0"
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "pwsp-daemon"
|
name = "pwsp-daemon"
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
[Unit]
|
[Unit]
|
||||||
Description=Pipewire Soundpad Daemon
|
Description=Pipewire Soundpad Daemon
|
||||||
|
After=pipewire.service
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
ExecStart=/usr/bin/pwsp-daemon
|
ExecStart=/usr/bin/pwsp-daemon
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
%global cargo_install_lib 0
|
%global cargo_install_lib 0
|
||||||
|
|
||||||
Name: pwsp
|
Name: pwsp
|
||||||
Version: 1.0.1
|
Version: 1.0.3
|
||||||
Release: %autorelease
|
Release: %autorelease
|
||||||
Summary: Lets you play audio files through your microphone
|
Summary: Lets you play audio files through your microphone
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -72,7 +72,7 @@ enum SetCommands {
|
|||||||
/// Playback position
|
/// Playback position
|
||||||
Position { position: f32 },
|
Position { position: f32 },
|
||||||
/// Input
|
/// Input
|
||||||
Input { id: u32 },
|
Input { name: String },
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
@@ -102,7 +102,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
Commands::Set { parameter } => match parameter {
|
Commands::Set { parameter } => match parameter {
|
||||||
SetCommands::Volume { volume } => Request::set_volume(volume),
|
SetCommands::Volume { volume } => Request::set_volume(volume),
|
||||||
SetCommands::Position { position } => Request::seek(position),
|
SetCommands::Position { position } => Request::seek(position),
|
||||||
SetCommands::Input { id } => Request::set_input(id),
|
SetCommands::Input { name } => Request::set_input(&name),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -287,7 +287,7 @@ impl SoundpadGui {
|
|||||||
ui.add_space(5.0);
|
ui.add_space(5.0);
|
||||||
ui.horizontal_top(|ui| {
|
ui.horizontal_top(|ui| {
|
||||||
// ---------- Microphone selection ----------
|
// ---------- Microphone selection ----------
|
||||||
let mut mics: Vec<(&u32, &String)> =
|
let mut mics: Vec<(&String, &String)> =
|
||||||
self.audio_player_state.all_inputs.iter().collect();
|
self.audio_player_state.all_inputs.iter().collect();
|
||||||
mics.sort_by_key(|(k, _)| *k);
|
mics.sort_by_key(|(k, _)| *k);
|
||||||
|
|
||||||
@@ -301,8 +301,8 @@ impl SoundpadGui {
|
|||||||
.unwrap_or(&String::new()),
|
.unwrap_or(&String::new()),
|
||||||
)
|
)
|
||||||
.show_ui(ui, |ui| {
|
.show_ui(ui, |ui| {
|
||||||
for (index, device) in mics {
|
for (name, nick) in mics {
|
||||||
ui.selectable_value(&mut selected_input, index.to_owned(), device);
|
ui.selectable_value(&mut selected_input, name.to_owned(), nick);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -92,12 +92,12 @@ impl SoundpadGui {
|
|||||||
make_request_sync(Request::play(path.to_str().unwrap())).ok();
|
make_request_sync(Request::play(path.to_str().unwrap())).ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_input(&mut self, id: u32) {
|
pub fn set_input(&mut self, name: String) {
|
||||||
make_request_sync(Request::set_input(id)).ok();
|
make_request_sync(Request::set_input(&name)).ok();
|
||||||
|
|
||||||
if self.config.save_input {
|
if self.config.save_input {
|
||||||
let mut daemon_config = get_daemon_config();
|
let mut daemon_config = get_daemon_config();
|
||||||
daemon_config.default_input_id = Some(id);
|
daemon_config.default_input_name = Some(name);
|
||||||
daemon_config.save_to_file().ok();
|
daemon_config.save_to_file().ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,8 +40,8 @@ impl AudioPlayer {
|
|||||||
let daemon_config = get_daemon_config();
|
let daemon_config = get_daemon_config();
|
||||||
let default_volume = daemon_config.default_volume.unwrap_or(1.0);
|
let default_volume = daemon_config.default_volume.unwrap_or(1.0);
|
||||||
let mut default_input_device: Option<AudioDevice> = None;
|
let mut default_input_device: Option<AudioDevice> = None;
|
||||||
if let Some(id) = daemon_config.default_input_id
|
if let Some(name) = daemon_config.default_input_name
|
||||||
&& let Ok(device) = get_device(id).await
|
&& let Ok(device) = get_device(&name).await
|
||||||
&& device.device_type == DeviceType::Input
|
&& device.device_type == DeviceType::Input
|
||||||
{
|
{
|
||||||
default_input_device = Some(device);
|
default_input_device = Some(device);
|
||||||
@@ -224,8 +224,8 @@ impl AudioPlayer {
|
|||||||
&self.current_file_path
|
&self.current_file_path
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn set_current_input_device(&mut self, id: u32) -> Result<(), Box<dyn Error>> {
|
pub async fn set_current_input_device(&mut self, name: &str) -> Result<(), Box<dyn Error>> {
|
||||||
let input_device = get_device(id).await?;
|
let input_device = get_device(name).await?;
|
||||||
|
|
||||||
if input_device.device_type != DeviceType::Input {
|
if input_device.device_type != DeviceType::Input {
|
||||||
return Err("Selected device is not an input device".into());
|
return Err("Selected device is not an input device".into());
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ pub struct GetCurrentInputCommand {}
|
|||||||
pub struct GetAllInputsCommand {}
|
pub struct GetAllInputsCommand {}
|
||||||
|
|
||||||
pub struct SetCurrentInputCommand {
|
pub struct SetCurrentInputCommand {
|
||||||
pub id: Option<u32>,
|
pub name: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
@@ -192,7 +192,10 @@ impl Executable for GetCurrentInputCommand {
|
|||||||
async fn execute(&self) -> Response {
|
async fn execute(&self) -> Response {
|
||||||
let audio_player = get_audio_player().await.lock().await;
|
let audio_player = get_audio_player().await.lock().await;
|
||||||
if let Some(input_device) = &audio_player.current_input_device {
|
if let Some(input_device) = &audio_player.current_input_device {
|
||||||
Response::new(true, format!("{} - {}", input_device.id, input_device.nick))
|
Response::new(
|
||||||
|
true,
|
||||||
|
format!("{} - {}", input_device.name, input_device.nick),
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
Response::new(false, "No input device selected")
|
Response::new(false, "No input device selected")
|
||||||
}
|
}
|
||||||
@@ -209,7 +212,7 @@ impl Executable for GetAllInputsCommand {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let string = format!("{} - {}", device.id, device.nick);
|
let string = format!("{} - {}", device.name, device.nick);
|
||||||
input_devices_strings.push(string);
|
input_devices_strings.push(string);
|
||||||
}
|
}
|
||||||
let response_message = input_devices_strings.join("; ");
|
let response_message = input_devices_strings.join("; ");
|
||||||
@@ -221,9 +224,9 @@ impl Executable for GetAllInputsCommand {
|
|||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl Executable for SetCurrentInputCommand {
|
impl Executable for SetCurrentInputCommand {
|
||||||
async fn execute(&self) -> Response {
|
async fn execute(&self) -> Response {
|
||||||
if let Some(id) = self.id {
|
if let Some(name) = &self.name {
|
||||||
let mut audio_player = get_audio_player().await.lock().await;
|
let mut audio_player = get_audio_player().await.lock().await;
|
||||||
match audio_player.set_current_input_device(id).await {
|
match audio_player.set_current_input_device(name).await {
|
||||||
Ok(_) => Response::new(true, "Input device was set"),
|
Ok(_) => Response::new(true, "Input device was set"),
|
||||||
Err(err) => Response::new(false, err.to_string()),
|
Err(err) => Response::new(false, err.to_string()),
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@ use std::{collections::HashSet, error::Error, fs, path::PathBuf};
|
|||||||
|
|
||||||
#[derive(Default, Clone, Serialize, Deserialize)]
|
#[derive(Default, Clone, Serialize, Deserialize)]
|
||||||
pub struct DaemonConfig {
|
pub struct DaemonConfig {
|
||||||
pub default_input_id: Option<u32>,
|
pub default_input_name: Option<String>,
|
||||||
pub default_volume: Option<f32>,
|
pub default_volume: Option<f32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -34,6 +34,6 @@ pub struct AudioPlayerState {
|
|||||||
pub new_position: Option<f32>,
|
pub new_position: Option<f32>,
|
||||||
pub duration: f32,
|
pub duration: f32,
|
||||||
|
|
||||||
pub current_input: u32,
|
pub current_input: String,
|
||||||
pub all_inputs: HashMap<u32, String>,
|
pub all_inputs: HashMap<String, String>,
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -80,8 +80,8 @@ impl Request {
|
|||||||
Request::new("seek", vec![("position", &position.to_string())])
|
Request::new("seek", vec![("position", &position.to_string())])
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_input(id: u32) -> Self {
|
pub fn set_input(name: &str) -> Self {
|
||||||
Request::new("set_input", vec![("input_id", &id.to_string())])
|
Request::new("set_input", vec![("input_name", name)])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,13 +44,8 @@ pub fn parse_command(request: &Request) -> Option<Box<dyn Executable + Send>> {
|
|||||||
"get_input" => Some(Box::new(GetCurrentInputCommand {})),
|
"get_input" => Some(Box::new(GetCurrentInputCommand {})),
|
||||||
"get_inputs" => Some(Box::new(GetAllInputsCommand {})),
|
"get_inputs" => Some(Box::new(GetAllInputsCommand {})),
|
||||||
"set_input" => {
|
"set_input" => {
|
||||||
let id = request
|
let name = Some(request.args.get("input_name").unwrap_or(&String::new())).cloned();
|
||||||
.args
|
Some(Box::new(SetCurrentInputCommand { name }))
|
||||||
.get("input_id")
|
|
||||||
.unwrap_or(&String::new())
|
|
||||||
.parse::<u32>()
|
|
||||||
.ok();
|
|
||||||
Some(Box::new(SetCurrentInputCommand { id }))
|
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-11
@@ -96,10 +96,8 @@ pub fn start_app_state_thread(audio_player_state_shared: Arc<Mutex<AudioPlayerSt
|
|||||||
.collect::<Vec<&str>>()
|
.collect::<Vec<&str>>()
|
||||||
.first()
|
.first()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_string()
|
.to_string(),
|
||||||
.parse::<u32>()
|
false => String::new(),
|
||||||
.unwrap_or_default(),
|
|
||||||
false => 0,
|
|
||||||
};
|
};
|
||||||
let all_inputs = match all_inputs_res.status {
|
let all_inputs = match all_inputs_res.status {
|
||||||
true => all_inputs_res
|
true => all_inputs_res
|
||||||
@@ -111,14 +109,11 @@ pub fn start_app_state_thread(audio_player_state_shared: Arc<Mutex<AudioPlayerSt
|
|||||||
if entry.is_empty() {
|
if entry.is_empty() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
entry.split_once(" - ").and_then(|(k, v)| {
|
entry
|
||||||
k.trim()
|
.split_once(" - ")
|
||||||
.parse::<u32>()
|
.map(|(k, v)| (k.trim().to_string(), v.trim().to_string()))
|
||||||
.ok()
|
|
||||||
.map(|key| (key, v.trim().to_string()))
|
|
||||||
})
|
})
|
||||||
})
|
.collect::<HashMap<String, String>>(),
|
||||||
.collect(),
|
|
||||||
false => HashMap::new(),
|
false => HashMap::new(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -77,6 +77,8 @@ async fn pw_get_global_objects_thread(
|
|||||||
main_sender: mpsc::Sender<(Option<AudioDevice>, Option<Port>)>,
|
main_sender: mpsc::Sender<(Option<AudioDevice>, Option<Port>)>,
|
||||||
pw_receiver: pipewire::channel::Receiver<Terminate>,
|
pw_receiver: pipewire::channel::Receiver<Terminate>,
|
||||||
) {
|
) {
|
||||||
|
pipewire::init();
|
||||||
|
|
||||||
let main_loop = MainLoopRc::new(None).expect("Failed to initialize pipewire main loop");
|
let main_loop = MainLoopRc::new(None).expect("Failed to initialize pipewire main loop");
|
||||||
|
|
||||||
// Stop main loop on Terminate message
|
// Stop main loop on Terminate message
|
||||||
@@ -199,12 +201,12 @@ pub async fn get_all_devices() -> Result<(Vec<AudioDevice>, Vec<AudioDevice>), B
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_device(node_id: u32) -> Result<AudioDevice, Box<dyn Error>> {
|
pub async fn get_device(device_name: &str) -> Result<AudioDevice, Box<dyn Error>> {
|
||||||
let (mut input_devices, output_devices) = get_all_devices().await?;
|
let (mut input_devices, output_devices) = get_all_devices().await?;
|
||||||
input_devices.extend(output_devices);
|
input_devices.extend(output_devices);
|
||||||
|
|
||||||
for device in input_devices {
|
for device in input_devices {
|
||||||
if device.id == node_id {
|
if device.name == device_name {
|
||||||
return Ok(device);
|
return Ok(device);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -216,6 +218,8 @@ pub fn create_virtual_mic() -> Result<pipewire::channel::Sender<Terminate>, Box<
|
|||||||
let (pw_sender, pw_receiver) = pipewire::channel::channel::<Terminate>();
|
let (pw_sender, pw_receiver) = pipewire::channel::channel::<Terminate>();
|
||||||
|
|
||||||
let _pw_thread = thread::spawn(move || {
|
let _pw_thread = thread::spawn(move || {
|
||||||
|
pipewire::init();
|
||||||
|
|
||||||
let main_loop = MainLoopRc::new(None).expect("Failed to initialize pipewire main loop");
|
let main_loop = MainLoopRc::new(None).expect("Failed to initialize pipewire main loop");
|
||||||
let context = ContextRc::new(&main_loop, None).expect("Failed to create pipewire context");
|
let context = ContextRc::new(&main_loop, None).expect("Failed to create pipewire context");
|
||||||
let core = context
|
let core = context
|
||||||
@@ -257,6 +261,8 @@ pub fn create_link(
|
|||||||
let (pw_sender, pw_receiver) = pipewire::channel::channel::<Terminate>();
|
let (pw_sender, pw_receiver) = pipewire::channel::channel::<Terminate>();
|
||||||
|
|
||||||
let _pw_thread = thread::spawn(move || {
|
let _pw_thread = thread::spawn(move || {
|
||||||
|
pipewire::init();
|
||||||
|
|
||||||
let main_loop = MainLoopRc::new(None).expect("Failed to initialize pipewire main loop");
|
let main_loop = MainLoopRc::new(None).expect("Failed to initialize pipewire main loop");
|
||||||
let context = ContextRc::new(&main_loop, None).expect("Failed to create pipewire context");
|
let context = ContextRc::new(&main_loop, None).expect("Failed to create pipewire context");
|
||||||
let core = context
|
let core = context
|
||||||
|
|||||||
Reference in New Issue
Block a user