/looper/metronome/position in audio_engine
This commit is contained in:
@@ -18,6 +18,9 @@ pub enum Message {
|
||||
SelectedRowChanged {
|
||||
row: usize,
|
||||
},
|
||||
MetronomePosition {
|
||||
position: f32, // 0.0 - 1.0 position within current beat
|
||||
},
|
||||
}
|
||||
|
||||
impl Message {
|
||||
@@ -53,6 +56,9 @@ impl Message {
|
||||
} => {
|
||||
state.set_track_volume(*column, *row, *volume);
|
||||
}
|
||||
Message::MetronomePosition { position } => {
|
||||
state.set_metronome_position(*position);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,9 +106,59 @@ impl Message {
|
||||
let row = (*row_1based as usize).saturating_sub(1); // Convert to 0-based
|
||||
return Ok(Some(Message::SelectedRowChanged { row }));
|
||||
}
|
||||
} else if addr == "/looper/metronome/position" {
|
||||
if let Some(rosc::OscType::Float(position)) = args.first() {
|
||||
return Ok(Some(Message::MetronomePosition {
|
||||
position: *position
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
// Unknown or unsupported message
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
pub fn to_osc_packet(self) -> rosc::OscPacket {
|
||||
match self {
|
||||
Message::TrackStateChanged { column, row, state } => {
|
||||
let address = format!("/looper/cell/{}/{}/state", column + 1, row + 1); // 1-based indexing
|
||||
|
||||
rosc::OscPacket::Message(rosc::OscMessage {
|
||||
addr: address,
|
||||
args: vec![rosc::OscType::String(state.to_string())],
|
||||
})
|
||||
}
|
||||
Message::TrackVolumeChanged { column, row, volume } => {
|
||||
let address = format!("/looper/cell/{}/{}/volume", column + 1, row + 1); // 1-based indexing
|
||||
|
||||
rosc::OscPacket::Message(rosc::OscMessage {
|
||||
addr: address,
|
||||
args: vec![rosc::OscType::Float(volume)],
|
||||
})
|
||||
}
|
||||
Message::SelectedColumnChanged { column } => {
|
||||
let address = "/looper/selected/column".to_string();
|
||||
|
||||
rosc::OscPacket::Message(rosc::OscMessage {
|
||||
addr: address,
|
||||
args: vec![rosc::OscType::Int((column + 1) as i32)], // 1-based indexing
|
||||
})
|
||||
}
|
||||
Message::SelectedRowChanged { row } => {
|
||||
let address = "/looper/selected/row".to_string();
|
||||
|
||||
rosc::OscPacket::Message(rosc::OscMessage {
|
||||
addr: address,
|
||||
args: vec![rosc::OscType::Int((row + 1) as i32)], // 1-based indexing
|
||||
})
|
||||
}
|
||||
Message::MetronomePosition { position } => {
|
||||
let address = "/looper/metronome/position".to_string();
|
||||
|
||||
rosc::OscPacket::Message(rosc::OscMessage {
|
||||
addr: address,
|
||||
args: vec![rosc::OscType::Float(position)],
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,8 @@ pub struct State {
|
||||
pub cells: Vec<Vec<Track>>,
|
||||
pub columns: usize,
|
||||
pub rows: usize,
|
||||
pub metronome_position: f32, // 0.0 - 1.0 position within current beat
|
||||
pub metronome_timestamp: std::time::Instant, // When position was last updated
|
||||
}
|
||||
|
||||
impl State {
|
||||
@@ -35,6 +37,8 @@ impl State {
|
||||
cells,
|
||||
columns,
|
||||
rows,
|
||||
metronome_position: 0.0,
|
||||
metronome_timestamp: std::time::Instant::now(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,6 +64,9 @@ impl State {
|
||||
self.selected_row = *row;
|
||||
}
|
||||
}
|
||||
Message::MetronomePosition { position } => {
|
||||
self.set_metronome_position(*position);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,4 +123,9 @@ impl State {
|
||||
self.cells[column][row].volume = volume;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_metronome_position(&mut self, position: f32) {
|
||||
self.metronome_position = position;
|
||||
self.metronome_timestamp = std::time::Instant::now();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user