mirror of
https://github.com/arabianq/pipewire-soundpad.git
synced 2026-04-28 06:21:23 +00:00
feat: implemented loop support in pwsp-gui
This commit is contained in:
+17
-1
@@ -108,6 +108,22 @@ impl SoundpadGui {
|
|||||||
}
|
}
|
||||||
// --------------------------------
|
// --------------------------------
|
||||||
|
|
||||||
|
// ---------- Loop Button ----------
|
||||||
|
let loop_button = Button::new(
|
||||||
|
RichText::new(match self.audio_player_state.looped {
|
||||||
|
true => icons::ICON_REPEAT_ONE,
|
||||||
|
false => icons::ICON_REPEAT,
|
||||||
|
})
|
||||||
|
.size(18.0),
|
||||||
|
)
|
||||||
|
.frame(false);
|
||||||
|
|
||||||
|
let loop_button_response = ui.add_sized([15.0, 30.0], loop_button);
|
||||||
|
if loop_button_response.clicked() {
|
||||||
|
self.toggle_loop();
|
||||||
|
}
|
||||||
|
// --------------------------------
|
||||||
|
|
||||||
// ---------- Position Slider ----------
|
// ---------- Position Slider ----------
|
||||||
let position_slider = Slider::new(
|
let position_slider = Slider::new(
|
||||||
&mut self.app_state.position_slider_value,
|
&mut self.app_state.position_slider_value,
|
||||||
@@ -150,7 +166,7 @@ impl SoundpadGui {
|
|||||||
icons::ICON_VOLUME_DOWN
|
icons::ICON_VOLUME_DOWN
|
||||||
};
|
};
|
||||||
let volume_icon = Label::new(RichText::new(volume_icon).size(18.0));
|
let volume_icon = Label::new(RichText::new(volume_icon).size(18.0));
|
||||||
ui.add_sized([30.0, 25.0], volume_icon);
|
ui.add_sized([30.0, 30.0], volume_icon);
|
||||||
// --------------------------------
|
// --------------------------------
|
||||||
|
|
||||||
// ---------- Volume Slider ----------
|
// ---------- Volume Slider ----------
|
||||||
|
|||||||
@@ -125,6 +125,13 @@ impl SoundpadGui {
|
|||||||
daemon_config.save_to_file().ok();
|
daemon_config.save_to_file().ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn toggle_loop(&mut self) {
|
||||||
|
make_request_sync(Request::set_loop(
|
||||||
|
&(!self.audio_player_state.looped).to_string(),
|
||||||
|
))
|
||||||
|
.ok();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn run() -> Result<(), Box<dyn Error>> {
|
pub async fn run() -> Result<(), Box<dyn Error>> {
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ pub struct AudioPlayerState {
|
|||||||
pub current_file_path: PathBuf,
|
pub current_file_path: PathBuf,
|
||||||
|
|
||||||
pub is_paused: bool,
|
pub is_paused: bool,
|
||||||
|
pub looped: bool,
|
||||||
|
|
||||||
pub volume: f32,
|
pub volume: f32,
|
||||||
pub new_volume: Option<f32>,
|
pub new_volume: Option<f32>,
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ pub fn start_app_state_thread(audio_player_state_shared: Arc<Mutex<AudioPlayerSt
|
|||||||
let duration_req = Request::get_duration();
|
let duration_req = Request::get_duration();
|
||||||
let current_input_req = Request::get_input();
|
let current_input_req = Request::get_input();
|
||||||
let all_inputs_req = Request::get_inputs();
|
let all_inputs_req = Request::get_inputs();
|
||||||
|
let looped_req = Request::get_loop();
|
||||||
|
|
||||||
let state_res = make_request(state_req).await.unwrap_or_default();
|
let state_res = make_request(state_req).await.unwrap_or_default();
|
||||||
let file_path_res = make_request(file_path_req).await.unwrap_or_default();
|
let file_path_res = make_request(file_path_req).await.unwrap_or_default();
|
||||||
@@ -62,6 +63,7 @@ pub fn start_app_state_thread(audio_player_state_shared: Arc<Mutex<AudioPlayerSt
|
|||||||
let duration_res = make_request(duration_req).await.unwrap_or_default();
|
let duration_res = make_request(duration_req).await.unwrap_or_default();
|
||||||
let current_input_res = make_request(current_input_req).await.unwrap_or_default();
|
let current_input_res = make_request(current_input_req).await.unwrap_or_default();
|
||||||
let all_inputs_res = make_request(all_inputs_req).await.unwrap_or_default();
|
let all_inputs_res = make_request(all_inputs_req).await.unwrap_or_default();
|
||||||
|
let looped_res = make_request(looped_req).await.unwrap_or_default();
|
||||||
|
|
||||||
let state = match state_res.status {
|
let state = match state_res.status {
|
||||||
true => serde_json::from_str::<PlayerState>(&state_res.message).unwrap(),
|
true => serde_json::from_str::<PlayerState>(&state_res.message).unwrap(),
|
||||||
@@ -116,6 +118,10 @@ pub fn start_app_state_thread(audio_player_state_shared: Arc<Mutex<AudioPlayerSt
|
|||||||
.collect::<HashMap<String, String>>(),
|
.collect::<HashMap<String, String>>(),
|
||||||
false => HashMap::new(),
|
false => HashMap::new(),
|
||||||
};
|
};
|
||||||
|
let looped = match looped_res.status {
|
||||||
|
true => looped_res.message.parse::<bool>().unwrap_or_default(),
|
||||||
|
false => false,
|
||||||
|
};
|
||||||
|
|
||||||
{
|
{
|
||||||
let mut guard = audio_player_state_shared.lock().unwrap();
|
let mut guard = audio_player_state_shared.lock().unwrap();
|
||||||
@@ -146,6 +152,7 @@ pub fn start_app_state_thread(audio_player_state_shared: Arc<Mutex<AudioPlayerSt
|
|||||||
guard.duration = if duration > 0.0 { duration } else { 1.0 };
|
guard.duration = if duration > 0.0 { duration } else { 1.0 };
|
||||||
guard.current_input = current_input;
|
guard.current_input = current_input;
|
||||||
guard.all_inputs = all_inputs;
|
guard.all_inputs = all_inputs;
|
||||||
|
guard.looped = looped;
|
||||||
}
|
}
|
||||||
|
|
||||||
sleep(sleep_duration).await;
|
sleep(sleep_duration).await;
|
||||||
|
|||||||
Reference in New Issue
Block a user