Handle metronome volume

This commit is contained in:
Niels Geens 2025-08-04 12:24:16 +02:00
parent 3fd35d723a
commit 0dd4387917
4 changed files with 38 additions and 11 deletions

View File

@ -68,6 +68,13 @@ impl Metronome {
Ok(timing) Ok(timing)
} }
pub fn set_click_volume(&mut self, click_volume: f32, persistence: &mut PersistenceManagerController) -> Result<()> {
let clamped = click_volume.clamp(0.0, 1.0);
persistence.update_metronome_volume(clamped)?;
self.click_volume = clamped;
Ok(())
}
fn process_ppqn_ticks( fn process_ppqn_ticks(
&mut self, &mut self,
ps: &jack::ProcessScope, ps: &jack::ProcessScope,

View File

@ -38,11 +38,14 @@ pub fn process_events<F: ChunkFactory, const COLS: usize, const ROWS: usize>(
let value_num = u8::from(value); let value_num = u8::from(value);
match controller_num { match controller_num {
// Expression Pedal A - Track Volume // Expression Pedals
1 => { 1 => {
process_handler.handle_pedal_a(value_num)?; process_handler.handle_pedal_a(value_num)?;
} }
// Button mappings (only process button presses - value > 0) 2 => {
process_handler.handle_pedal_b(value_num)?;
}
// Buttons
20 if value_num > 0 => { 20 if value_num > 0 => {
process_handler.handle_button_1()?; process_handler.handle_button_1()?;
} }
@ -79,19 +82,16 @@ pub fn process_events<F: ChunkFactory, const COLS: usize, const ROWS: usize>(
31 if value_num > 0 => { 31 if value_num > 0 => {
process_handler.handle_button_down()?; process_handler.handle_button_down()?;
} }
_ => {
// Other CC messages - ignore // Other CC messages - ignore
_ => {}
} }
} }
}
_ => {
// Other MIDI messages - ignore // Other MIDI messages - ignore
_ => {}
} }
} }
}
Err(_) => {
// Malformed MIDI messages - ignore // Malformed MIDI messages - ignore
} Err(_) => {}
} }
} }

View File

@ -14,6 +14,9 @@ pub enum PersistenceUpdate {
row: usize, row: usize,
volume: f32, volume: f32,
}, },
UpdateMetronomeVolume {
volume: f32,
}
} }
impl PersistenceManagerController { impl PersistenceManagerController {
@ -29,6 +32,15 @@ impl PersistenceManagerController {
Err(_) => Err(LooperError::StateSave(std::panic::Location::caller())), // Channel closed Err(_) => Err(LooperError::StateSave(std::panic::Location::caller())), // Channel closed
} }
} }
pub fn update_metronome_volume(&self, volume: f32) -> Result<()> {
let update = PersistenceUpdate::UpdateMetronomeVolume { volume: volume };
match self.sender.try_send(update) {
Ok(true) => Ok(()),
Ok(false) => Err(LooperError::StateSave(std::panic::Location::caller())), // Channel full
Err(_) => Err(LooperError::StateSave(std::panic::Location::caller())), // Channel closed
}
}
} }
pub struct PersistenceManager { pub struct PersistenceManager {
@ -105,6 +117,10 @@ impl PersistenceManager {
.send_modify(|state| state.track_volumes.set_volume(column, row, volume)); .send_modify(|state| state.track_volumes.set_volume(column, row, volume));
self.save_to_disk()?; self.save_to_disk()?;
} }
PersistenceUpdate::UpdateMetronomeVolume { volume } => {
self.state
.send_modify(|state| state.metronome.click_volume = volume);
}
} }
Ok(()) Ok(())

View File

@ -58,6 +58,10 @@ impl<F: ChunkFactory, const COLS: usize, const ROWS: usize> ProcessHandler<F, CO
.handle_volume_update(self.last_volume_setting, &controllers) .handle_volume_update(self.last_volume_setting, &controllers)
} }
pub fn handle_pedal_b(&mut self, value: u8) -> Result<()> {
self.metronome.set_click_volume(value as f32 / 127.0, &mut self.persistence)
}
pub fn handle_button_1(&mut self) -> Result<()> { pub fn handle_button_1(&mut self) -> Result<()> {
let controllers = TrackControllers::new( let controllers = TrackControllers::new(
&self.post_record_controller, &self.post_record_controller,