Set instrument and volume before key on, oopsie-woopsie

master
Ashley N. 2023-08-23 23:56:56 -04:00
parent 4001f8d3cc
commit 0b86436ff7
1 changed files with 17 additions and 17 deletions

View File

@ -215,6 +215,23 @@ fn get_portamento( channel: &mut Channel, portamento_effect: &Effect ) -> Result
fn get_events_for_channel( channel: &mut Channel, row: &PatternRow ) -> Result<Vec<EchoEvent>, Box<dyn Error>> {
let mut events: Vec<EchoEvent> = Vec::new();
// Adjust volume
if let Some( volume ) = &row.volume {
// https://github.com/sikthehedgehog/Echo/blob/master/doc/esf.txt#L206-L207
let volume = get_volume( channel.id, *volume )?;
channel.current_volume = Some( volume );
events.push( vec![ ESF_SET_VOLUME | channel.id, volume ] );
}
// Set the instrument
if let Some( instrument ) = &row.instrument_index {
// Do not set the same instrument if it was already set before
if &row.instrument_index != &channel.active_instrument {
events.push( vec![ ESF_SET_INSTRUMENT | channel.id, *instrument as u8 ] );
channel.active_instrument = Some( *instrument );
}
}
// Key on or key off note
if let Some( note ) = &row.note {
if let Note::NoteOff = note {
@ -241,23 +258,6 @@ fn get_events_for_channel( channel: &mut Channel, row: &PatternRow ) -> Result<V
}
}
// Adjust volume
if let Some( volume ) = &row.volume {
// https://github.com/sikthehedgehog/Echo/blob/master/doc/esf.txt#L206-L207
let volume = get_volume( channel.id, *volume )?;
channel.current_volume = Some( volume );
events.push( vec![ ESF_SET_VOLUME | channel.id, volume ] );
}
// Change instrument
if let Some( instrument ) = &row.instrument_index {
// Do not set the same instrument if it was already set before
if &row.instrument_index != &channel.active_instrument {
events.push( vec![ ESF_SET_INSTRUMENT | channel.id, *instrument as u8 ] );
channel.active_instrument = Some( *instrument );
}
}
Ok( events )
}