From 0b86436ff7a38352831593e498c1da9e1a84f50c Mon Sep 17 00:00:00 2001 From: ashley Date: Wed, 23 Aug 2023 23:56:56 -0400 Subject: [PATCH] Set instrument and volume before key on, oopsie-woopsie --- src/reskit/soundtrack/engines/echo.rs | 34 +++++++++++++-------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/reskit/soundtrack/engines/echo.rs b/src/reskit/soundtrack/engines/echo.rs index b396307..9093e6f 100644 --- a/src/reskit/soundtrack/engines/echo.rs +++ b/src/reskit/soundtrack/engines/echo.rs @@ -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, Box> { let mut events: Vec = 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