Support for effect Dxx (breaking pattern)

master
Ashley N. 2023-08-30 00:28:51 -04:00
parent 33b16767db
commit ce41fc43a8
2 changed files with 47 additions and 25 deletions

View File

@ -2,7 +2,7 @@ use std::{collections::HashMap, cmp::{max, min}, error::Error};
use convert_case::{Case, Casing}; use convert_case::{Case, Casing};
use samplerate::convert; use samplerate::convert;
use uuid::Uuid; 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}; 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,18 +312,21 @@ impl EchoFormat for DmfModule {
// Recall items are stored as self.channel_patterns[ channel ][ row_number ] // Recall items are stored as self.channel_patterns[ channel ][ row_number ]
let mut all_events: Vec<EchoEvent> = Vec::new(); let mut all_events: Vec<EchoEvent> = Vec::new();
let total_rows: u32 = self.channel_patterns[ 0 ].len() as u32; 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 { for row_number in 0..total_rows {
let events_this_row: Vec<EchoEvent> = get_events_for_row( if ignore_row_counter > 0 {
&mut channels, // Ignore these rows while this is set (for Effect::JumpToNextPattern)
&self.instruments, ignore_row_counter -= 1;
{ } else {
let mut columns: Vec<&PatternRow> = Vec::new(); let mut columns: Vec<&PatternRow> = Vec::new();
for channel in 0..10 { for channel in 0..10 {
columns.push( &self.channel_patterns[ channel ][ row_number as usize ] ); columns.push( &self.channel_patterns[ channel ][ row_number as usize ] );
} }
columns let events_this_row: Vec<EchoEvent> = get_events_for_row(
}, &mut channels,
&self.instruments,
columns.clone(),
if row_number % 2 == 0 { if row_number % 2 == 0 {
self.speed_a * self.time_base self.speed_a * self.time_base
} else { } else {
@ -342,6 +345,22 @@ impl EchoFormat for DmfModule {
// Transfer ESF events to the main stream // Transfer ESF events to the main stream
all_events.extend( events_this_row ); all_events.extend( events_this_row );
// 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??" )?
}
}
}
}
} }
// Compact sequences of delays to save rom space // Compact sequences of delays to save rom space

View File

@ -540,6 +540,9 @@ fn apply_effects_to_channel( channel: &mut Channel, effects: &LinkedHashSet<Effe
Effect::PositionJump { pattern: _ } => { Effect::PositionJump { pattern: _ } => {
// Nothing to do - handled as we iterate through the rows. // 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 ) ) unsupported_effect => print_warning( &format!( "effect unsupported: {:?}. your soundtrack may sound different than expected.", unsupported_effect ) )
} }
} }