mirror of
https://github.com/arabianq/pipewire-soundpad.git
synced 2026-04-28 06:21:23 +00:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 572aa33c95 | |||
| 3850a9ce10 | |||
| b7dc54c2cb | |||
| 0357c239d5 | |||
| cb1bd42f83 | |||
| 113eb38767 | |||
| ab68648ef6 | |||
| e10b6f1449 | |||
| ede5028d35 | |||
| f721e4612a | |||
| ef9125024c | |||
| 12c70f0edb |
Generated
+459
-501
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.2"
|
version = "1.1.0"
|
||||||
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."
|
||||||
@@ -12,23 +12,23 @@ keywords = ["soundpad", "pipewire", "linux", "cli", "gui"]
|
|||||||
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tokio = { version = "1.47.1", features = ["full"] }
|
tokio = { version = "1.48.0", 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.228", 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.51", 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,7 +1,9 @@
|
|||||||
[Unit]
|
[Unit]
|
||||||
Description=Pipewire Soundpad Daemon
|
Description=Pipewire Soundpad Daemon
|
||||||
|
After=pipewire.service
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
|
ExecStartPre=/usr/bin/sleep 10
|
||||||
ExecStart=/usr/bin/pwsp-daemon
|
ExecStart=/usr/bin/pwsp-daemon
|
||||||
Restart=no
|
Restart=no
|
||||||
RuntimeDirectory=pwsp
|
RuntimeDirectory=pwsp
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
%global cargo_install_lib 0
|
%global cargo_install_lib 0
|
||||||
|
|
||||||
Name: pwsp
|
Name: pwsp
|
||||||
Version: 1.0.2
|
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
|
||||||
|
|
||||||
|
|||||||
+30
-15
@@ -191,19 +191,26 @@ impl SoundpadGui {
|
|||||||
.map(|s| s.to_string_lossy().to_string())
|
.map(|s| s.to_string_lossy().to_string())
|
||||||
.unwrap_or_else(|| path.to_string_lossy().to_string());
|
.unwrap_or_else(|| path.to_string_lossy().to_string());
|
||||||
|
|
||||||
|
let mut dir_button_text = RichText::new(name.clone());
|
||||||
|
if let Some(current_dir) = &self.app_state.current_dir {
|
||||||
|
if current_dir.eq(path) {
|
||||||
|
dir_button_text = dir_button_text.color(Color32::WHITE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let dir_button =
|
let dir_button =
|
||||||
Button::new(RichText::new(name).atom_max_width(area_size.x))
|
Button::new(dir_button_text.atom_max_width(area_size.x)).frame(false);
|
||||||
.frame(false);
|
|
||||||
let dir_button_response = ui.add(dir_button);
|
let dir_button_response = ui.add(dir_button);
|
||||||
if dir_button_response.clicked() {
|
if dir_button_response.clicked() {
|
||||||
self.app_state.current_dir = Some(path.clone());
|
self.open_dir(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
let delete_dir_button = Button::new(icons::ICON_DELETE).frame(false);
|
let delete_dir_button = Button::new(icons::ICON_DELETE).frame(false);
|
||||||
let delete_dir_button_response =
|
let delete_dir_button_response =
|
||||||
ui.add_sized([18.0, 18.0], delete_dir_button);
|
ui.add_sized([18.0, 18.0], delete_dir_button);
|
||||||
if delete_dir_button_response.clicked() {
|
if delete_dir_button_response.clicked() {
|
||||||
self.remove_dir(path.clone());
|
self.remove_dir(&path.clone());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -226,10 +233,12 @@ impl SoundpadGui {
|
|||||||
|
|
||||||
ui.vertical(|ui| {
|
ui.vertical(|ui| {
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.add_sized(
|
let search_field = ui.add_sized(
|
||||||
[ui.available_width(), 22.0],
|
[ui.available_width(), 22.0],
|
||||||
TextEdit::singleline(&mut self.app_state.search_query).hint_text("Search..."),
|
TextEdit::singleline(&mut self.app_state.search_query).hint_text("Search..."),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
self.app_state.search_field_id = Some(search_field.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
ui.separator();
|
ui.separator();
|
||||||
@@ -239,18 +248,17 @@ impl SoundpadGui {
|
|||||||
ui.set_min_height(area_size.y);
|
ui.set_min_height(area_size.y);
|
||||||
|
|
||||||
ui.vertical(|ui| {
|
ui.vertical(|ui| {
|
||||||
if let Some(path) = self.app_state.current_dir.clone() {
|
let mut files: Vec<PathBuf> = self.app_state.files.iter().cloned().collect();
|
||||||
for entry in path.read_dir().unwrap() {
|
files.sort();
|
||||||
let entry = entry.unwrap();
|
|
||||||
let entry_path = entry.path();
|
|
||||||
|
|
||||||
|
for entry_path in files {
|
||||||
if entry_path.is_dir() {
|
if entry_path.is_dir() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if !extensions.contains(
|
if !extensions
|
||||||
&entry_path.extension().unwrap_or_default().to_str().unwrap(),
|
.contains(&entry_path.extension().unwrap_or_default().to_str().unwrap())
|
||||||
) {
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -271,11 +279,18 @@ impl SoundpadGui {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let file_button = Button::new(file_name).frame(false);
|
let mut file_button_text = RichText::new(file_name);
|
||||||
|
if let Some(current_file) = &self.app_state.selected_file {
|
||||||
|
if current_file.eq(&entry_path) {
|
||||||
|
file_button_text = file_button_text.color(Color32::WHITE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let file_button = Button::new(file_button_text).frame(false);
|
||||||
let file_button_response = ui.add(file_button);
|
let file_button_response = ui.add(file_button);
|
||||||
if file_button_response.clicked() {
|
if file_button_response.clicked() {
|
||||||
self.play_file(entry_path);
|
self.play_file(&entry_path);
|
||||||
}
|
self.app_state.selected_file = Some(entry_path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
+86
-7
@@ -1,23 +1,102 @@
|
|||||||
use crate::gui::SoundpadGui;
|
use crate::gui::SoundpadGui;
|
||||||
use egui::{Context, Key};
|
use egui::{Context, Key};
|
||||||
|
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
impl SoundpadGui {
|
impl SoundpadGui {
|
||||||
pub fn handle_input(&mut self, ctx: &Context) {
|
pub fn handle_input(&mut self, ctx: &Context) {
|
||||||
ctx.input(|i| {
|
ctx.input(|i| {
|
||||||
|
// Close app on espace
|
||||||
if i.key_pressed(Key::Escape) {
|
if i.key_pressed(Key::Escape) {
|
||||||
std::process::exit(0);
|
std::process::exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if !self.app_state.show_settings && i.key_pressed(Key::Space) {
|
// Open/close settings
|
||||||
self.play_toggle();
|
if i.key_pressed(Key::I) {
|
||||||
}
|
|
||||||
|
|
||||||
if i.key_pressed(Key::Slash) {
|
|
||||||
self.app_state.show_settings = !self.app_state.show_settings;
|
self.app_state.show_settings = !self.app_state.show_settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.app_state.show_settings && i.key_pressed(Key::Backspace) {
|
if i.key_pressed(Key::Enter) && self.app_state.selected_file.is_some() {
|
||||||
self.app_state.show_settings = false;
|
self.play_file(&self.app_state.selected_file.clone().unwrap());
|
||||||
|
}
|
||||||
|
|
||||||
|
if !self.app_state.show_settings {
|
||||||
|
// Pause / resume audio on space
|
||||||
|
if i.key_pressed(Key::Space) {
|
||||||
|
self.play_toggle();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Focus search field
|
||||||
|
if i.key_pressed(Key::Slash) && self.app_state.search_field_id.is_some() {
|
||||||
|
self.app_state.force_focus_id = self.app_state.search_field_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Iterate through dirs if there are some
|
||||||
|
if i.modifiers.ctrl {
|
||||||
|
let arrow_up_pressed = i.key_pressed(Key::ArrowUp);
|
||||||
|
let arrow_down_pressed = i.key_pressed(Key::ArrowDown);
|
||||||
|
|
||||||
|
if arrow_up_pressed || arrow_down_pressed {
|
||||||
|
if i.modifiers.shift && !self.app_state.dirs.is_empty() {
|
||||||
|
let mut dirs: Vec<PathBuf> =
|
||||||
|
self.app_state.dirs.iter().cloned().collect();
|
||||||
|
dirs.sort();
|
||||||
|
|
||||||
|
let current_dir_index: i8;
|
||||||
|
if let Some(current_dir) = &self.app_state.current_dir {
|
||||||
|
if let Some(index) = dirs.iter().position(|x| x == current_dir) {
|
||||||
|
current_dir_index = index as i8;
|
||||||
|
} else {
|
||||||
|
current_dir_index = -1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
current_dir_index = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut new_dir_index: i8;
|
||||||
|
|
||||||
|
new_dir_index = current_dir_index - arrow_up_pressed as i8
|
||||||
|
+ arrow_down_pressed as i8;
|
||||||
|
|
||||||
|
if new_dir_index < 0 {
|
||||||
|
new_dir_index = (dirs.len() - 1) as i8;
|
||||||
|
} else if new_dir_index >= dirs.len() as i8 {
|
||||||
|
new_dir_index = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.open_dir(&dirs[new_dir_index as usize]);
|
||||||
|
} else if self.app_state.current_dir.is_some() {
|
||||||
|
let mut files: Vec<PathBuf> =
|
||||||
|
self.app_state.files.iter().cloned().collect();
|
||||||
|
files.sort();
|
||||||
|
|
||||||
|
let current_files_index: i64;
|
||||||
|
if let Some(selected_file) = &self.app_state.selected_file {
|
||||||
|
if let Some(index) = files.iter().position(|x| x == selected_file) {
|
||||||
|
current_files_index = index as i64;
|
||||||
|
} else {
|
||||||
|
current_files_index = -1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
current_files_index = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut new_files_index: i64;
|
||||||
|
|
||||||
|
new_files_index = current_files_index - arrow_up_pressed as i64
|
||||||
|
+ arrow_down_pressed as i64;
|
||||||
|
|
||||||
|
if new_files_index < 0 {
|
||||||
|
new_files_index = (files.len() - 1) as i64;
|
||||||
|
} else if new_files_index >= files.len() as i64 {
|
||||||
|
new_files_index = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.app_state.selected_file =
|
||||||
|
Some(files[new_files_index as usize].clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-4
@@ -77,10 +77,10 @@ impl SoundpadGui {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove_dir(&mut self, path: PathBuf) {
|
pub fn remove_dir(&mut self, path: &PathBuf) {
|
||||||
self.app_state.dirs.remove(&path);
|
self.app_state.dirs.remove(path);
|
||||||
if let Some(current_dir) = &self.app_state.current_dir
|
if let Some(current_dir) = &self.app_state.current_dir
|
||||||
&& current_dir == &path
|
&& current_dir == path
|
||||||
{
|
{
|
||||||
self.app_state.current_dir = None;
|
self.app_state.current_dir = None;
|
||||||
}
|
}
|
||||||
@@ -88,7 +88,17 @@ impl SoundpadGui {
|
|||||||
self.config.save_to_file().ok();
|
self.config.save_to_file().ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn play_file(&mut self, path: PathBuf) {
|
pub fn open_dir(&mut self, path: &PathBuf) {
|
||||||
|
self.app_state.current_dir = Some(path.clone());
|
||||||
|
self.app_state.files = path
|
||||||
|
.read_dir()
|
||||||
|
.unwrap()
|
||||||
|
.filter_map(|res| res.ok())
|
||||||
|
.map(|entry| entry.path())
|
||||||
|
.collect();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn play_file(&mut self, path: &PathBuf) {
|
||||||
make_request_sync(Request::play(path.to_str().unwrap())).ok();
|
make_request_sync(Request::play(path.to_str().unwrap())).ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,6 +40,13 @@ impl App for SoundpadGui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.draw(ui).ok();
|
self.draw(ui).ok();
|
||||||
|
|
||||||
|
if let Some(force_focus_id) = self.app_state.force_focus_id {
|
||||||
|
ui.memory_mut(|reder| {
|
||||||
|
reder.request_focus(force_focus_id);
|
||||||
|
});
|
||||||
|
self.app_state.force_focus_id = None;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if self.app_state.position_dragged {
|
if self.app_state.position_dragged {
|
||||||
|
|||||||
@@ -172,7 +172,11 @@ impl AudioPlayer {
|
|||||||
self.sink.get_pos().as_secs_f32()
|
self.sink.get_pos().as_secs_f32()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn seek(&mut self, position: f32) -> Result<(), Box<dyn Error>> {
|
pub fn seek(&mut self, mut position: f32) -> Result<(), Box<dyn Error>> {
|
||||||
|
if position < 0.0 {
|
||||||
|
position = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
match self.sink.try_seek(Duration::from_secs_f32(position)) {
|
match self.sink.try_seek(Duration::from_secs_f32(position)) {
|
||||||
Ok(_) => Ok(()),
|
Ok(_) => Ok(()),
|
||||||
Err(err) => Err(err.into()),
|
Err(err) => Err(err.into()),
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
use crate::types::audio_player::PlayerState;
|
use crate::types::audio_player::PlayerState;
|
||||||
|
|
||||||
|
use egui::Id;
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
collections::{HashMap, HashSet},
|
collections::{HashMap, HashSet},
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
@@ -18,6 +21,12 @@ pub struct AppState {
|
|||||||
|
|
||||||
pub current_dir: Option<PathBuf>,
|
pub current_dir: Option<PathBuf>,
|
||||||
pub dirs: HashSet<PathBuf>,
|
pub dirs: HashSet<PathBuf>,
|
||||||
|
|
||||||
|
pub selected_file: Option<PathBuf>,
|
||||||
|
pub files: HashSet<PathBuf>,
|
||||||
|
|
||||||
|
pub search_field_id: Option<Id>,
|
||||||
|
pub force_focus_id: Option<Id>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, Debug, Clone)]
|
#[derive(Default, Debug, Clone)]
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -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