Handle metronome volume
This commit is contained in:
parent
3fd35d723a
commit
0dd4387917
@ -68,6 +68,13 @@ impl Metronome {
|
||||
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(
|
||||
&mut self,
|
||||
ps: &jack::ProcessScope,
|
||||
|
||||
@ -38,11 +38,14 @@ pub fn process_events<F: ChunkFactory, const COLS: usize, const ROWS: usize>(
|
||||
let value_num = u8::from(value);
|
||||
|
||||
match controller_num {
|
||||
// Expression Pedal A - Track Volume
|
||||
// Expression Pedals
|
||||
1 => {
|
||||
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 => {
|
||||
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 => {
|
||||
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(_) => {}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -14,6 +14,9 @@ pub enum PersistenceUpdate {
|
||||
row: usize,
|
||||
volume: f32,
|
||||
},
|
||||
UpdateMetronomeVolume {
|
||||
volume: f32,
|
||||
}
|
||||
}
|
||||
|
||||
impl PersistenceManagerController {
|
||||
@ -29,6 +32,15 @@ impl PersistenceManagerController {
|
||||
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 {
|
||||
@ -105,6 +117,10 @@ impl PersistenceManager {
|
||||
.send_modify(|state| state.track_volumes.set_volume(column, row, volume));
|
||||
self.save_to_disk()?;
|
||||
}
|
||||
PersistenceUpdate::UpdateMetronomeVolume { volume } => {
|
||||
self.state
|
||||
.send_modify(|state| state.metronome.click_volume = volume);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
@ -58,6 +58,10 @@ impl<F: ChunkFactory, const COLS: usize, const ROWS: usize> ProcessHandler<F, CO
|
||||
.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<()> {
|
||||
let controllers = TrackControllers::new(
|
||||
&self.post_record_controller,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user