From ce41fc43a82054bd19d1aaedc89c399b06c7b384 Mon Sep 17 00:00:00 2001 From: ashley Date: Wed, 30 Aug 2023 00:28:51 -0400 Subject: [PATCH] Support for effect Dxx (breaking pattern) --- src/reskit/soundtrack/engines/echo/dmf.rs | 69 +++++++++++++------- src/reskit/soundtrack/engines/echo/engine.rs | 3 + 2 files changed, 47 insertions(+), 25 deletions(-) diff --git a/src/reskit/soundtrack/engines/echo/dmf.rs b/src/reskit/soundtrack/engines/echo/dmf.rs index ada429a..866c247 100644 --- a/src/reskit/soundtrack/engines/echo/dmf.rs +++ b/src/reskit/soundtrack/engines/echo/dmf.rs @@ -2,7 +2,7 @@ use std::{collections::HashMap, cmp::{max, min}, error::Error}; use convert_case::{Case, Casing}; use samplerate::convert; use uuid::Uuid; -use crate::reskit::{soundtrack::{formats::dmf::{DmfModule, ECHO_EWF_SAMPLE_RATE}, types::{InstrumentType, SampleFormat, Channel, PatternRow}}, utility::{print_warning, Ring}}; +use crate::reskit::{soundtrack::{formats::dmf::{DmfModule, ECHO_EWF_SAMPLE_RATE}, types::{InstrumentType, SampleFormat, Channel, PatternRow, Effect}}, utility::{print_warning, Ring, print_info}}; use super::engine::{EchoFormat, ESF_FM_1, ESF_FM_2, ESF_FM_3, ESF_FM_4, ESF_FM_5, ESF_FM_6, ESF_PSG_1, ESF_PSG_2, ESF_PSG_3, ESF_PSG_4, EchoEvent, get_events_for_row, compact_delays, ESF_SET_LOOP, ESF_GO_TO_LOOP, ESF_STOP}; @@ -312,36 +312,55 @@ impl EchoFormat for DmfModule { // Recall items are stored as self.channel_patterns[ channel ][ row_number ] let mut all_events: Vec = Vec::new(); let total_rows: u32 = self.channel_patterns[ 0 ].len() as u32; + let mut ignore_row_counter: u32 = 0; for row_number in 0..total_rows { - let events_this_row: Vec = get_events_for_row( - &mut channels, - &self.instruments, - { - let mut columns: Vec<&PatternRow> = Vec::new(); - for channel in 0..10 { - columns.push( &self.channel_patterns[ channel ][ row_number as usize ] ); + if ignore_row_counter > 0 { + // Ignore these rows while this is set (for Effect::JumpToNextPattern) + ignore_row_counter -= 1; + } else { + let mut columns: Vec<&PatternRow> = Vec::new(); + for channel in 0..10 { + columns.push( &self.channel_patterns[ channel ][ row_number as usize ] ); + } + + let events_this_row: Vec = get_events_for_row( + &mut channels, + &self.instruments, + columns.clone(), + if row_number % 2 == 0 { + self.speed_a * self.time_base + } else { + self.speed_b * self.time_base + }, + self.instruments.len() as u8 + )?; + + // Is this the pattern matrix row that we repeat to? + // If so, insert an ESF_LOOP_SET here. + if let Some( repeat_row ) = self.loop_at { + if row_number == repeat_row { + all_events.push( vec![ ESF_SET_LOOP ] ); } + } - columns - }, - if row_number % 2 == 0 { - self.speed_a * self.time_base - } else { - self.speed_b * self.time_base - }, - self.instruments.len() as u8 - )?; + // Transfer ESF events to the main stream + all_events.extend( events_this_row ); - // Is this the pattern matrix row that we repeat to? - // If so, insert an ESF_LOOP_SET here. - if let Some( repeat_row ) = self.loop_at { - if row_number == repeat_row { - all_events.push( vec![ ESF_SET_LOOP ] ); + // Was there an Effect::JumpToNextPattern here? If so, set a counter to ignore the next n rows + // Use the first one encountered (u r big dum dum if you set more than one in a single row, that DOES NOT MAKE SENSE stahp) + for column in columns { + if let Some( jump_effect ) = column.effects.iter().find( | effect | matches!( effect, Effect::JumpToNextPattern{ start_row: _ } ) ) { + if let Effect::JumpToNextPattern { start_row } = jump_effect { + let rows_elapsed = row_number % self.rows_per_pattern; + let remaining_rows_in_pattern = self.rows_per_pattern - rows_elapsed - 1; + ignore_row_counter = remaining_rows_in_pattern + *start_row as u32; + break; + } else { + return Err( "get_esf: wtf happened here??" )? + } + } } } - - // Transfer ESF events to the main stream - all_events.extend( events_this_row ); } // Compact sequences of delays to save rom space diff --git a/src/reskit/soundtrack/engines/echo/engine.rs b/src/reskit/soundtrack/engines/echo/engine.rs index e825361..23c54a5 100644 --- a/src/reskit/soundtrack/engines/echo/engine.rs +++ b/src/reskit/soundtrack/engines/echo/engine.rs @@ -540,6 +540,9 @@ fn apply_effects_to_channel( channel: &mut Channel, effects: &LinkedHashSet { // Nothing to do - handled as we iterate through the rows. }, + Effect::JumpToNextPattern { start_row } => { + // Nothing to do - handled as we iterate through the rows. + }, unsupported_effect => print_warning( &format!( "effect unsupported: {:?}. your soundtrack may sound different than expected.", unsupported_effect ) ) } }