From 25ee8769324a5aa89cf004e024f8d6b4dcbff57e Mon Sep 17 00:00:00 2001 From: Gwilym Inzani Date: Sun, 23 Jul 2023 23:36:19 +0100 Subject: [PATCH] Fix a bunch of bugs after playing with different tracks --- tracker/agb-tracker/examples/basic.rs | 2 +- tracker/agb-tracker/src/lib.rs | 2 +- tracker/agb-xm-core/src/lib.rs | 48 ++++++++++++++++----------- 3 files changed, 31 insertions(+), 21 deletions(-) diff --git a/tracker/agb-tracker/examples/basic.rs b/tracker/agb-tracker/examples/basic.rs index e09bc425..bab1e138 100644 --- a/tracker/agb-tracker/examples/basic.rs +++ b/tracker/agb-tracker/examples/basic.rs @@ -6,7 +6,7 @@ use agb::Gba; use agb_tracker::{include_xm, Track, Tracker}; // Found on: https://modarchive.org/index.php?request=view_by_moduleid&query=36662 -const DB_TOFFE: Track = include_xm!("examples/algar_-_ninja_on_speed.xm"); +const DB_TOFFE: Track = include_xm!("examples/db_toffe.xm"); #[agb::entry] fn main(mut gba: Gba) -> ! { diff --git a/tracker/agb-tracker/src/lib.rs b/tracker/agb-tracker/src/lib.rs index 6c100e6a..a80aed1b 100644 --- a/tracker/agb-tracker/src/lib.rs +++ b/tracker/agb-tracker/src/lib.rs @@ -124,7 +124,7 @@ impl Tracker { tick: 0, current_row: 0, - current_pattern: 0x10, + current_pattern: 0, } } diff --git a/tracker/agb-xm-core/src/lib.rs b/tracker/agb-xm-core/src/lib.rs index 1bf6803a..537aeb68 100644 --- a/tracker/agb-xm-core/src/lib.rs +++ b/tracker/agb-xm-core/src/lib.rs @@ -106,14 +106,13 @@ pub fn parse_module(module: &Module) -> TokenStream { let mut patterns = vec![]; let mut pattern_data = vec![]; - let mut effect_parameters = [0; u8::MAX as usize]; - for pattern in &module.pattern { let start_pos = pattern_data.len(); + let mut effect_parameters: [u8; 255] = [0; u8::MAX as usize]; + let mut tone_portamento_directions = vec![0.0; module.get_num_channels()]; + let mut note_and_sample = vec![None; module.get_num_channels()]; for row in pattern.iter() { - let mut note_and_sample = vec![None; module.get_num_channels()]; - for (i, slot) in row.iter().enumerate() { let channel_number = i % module.get_num_channels(); @@ -162,6 +161,12 @@ pub fn parse_module(module: &Module) -> TokenStream { .map(|note_and_sample| note_and_sample.1.volume) .unwrap_or(1.into()), ), + 0x60..=0x6F => { + PatternEffect::VolumeSlide(-Num::new((slot.volume - 0x60) as i16) / 64) + } + 0x70..=0x7F => { + PatternEffect::VolumeSlide(Num::new((slot.volume - 0x70) as i16) / 64) + } 0x80..=0x8F => PatternEffect::FineVolumeSlide( -Num::new((slot.volume - 0x80) as i16) / 64, ), @@ -169,7 +174,7 @@ pub fn parse_module(module: &Module) -> TokenStream { Num::new((slot.volume - 0x90) as i16) / 64, ), 0xC0..=0xCF => PatternEffect::Panning( - Num::new(slot.volume as i16 - (0xC0 + (0xCF - 0xC0) / 2)) / 64, + Num::new(slot.volume as i16 - (0xC0 + (0xCF - 0xC0) / 2)) / 8, ), _ => PatternEffect::None, }; @@ -242,15 +247,27 @@ pub fn parse_module(module: &Module) -> TokenStream { PatternEffect::Portamento(portamento_amount.try_change_base().unwrap()) } 0x3 => { - if let Some((previous_note, sample)) = previous_note_and_sample { - // we want to pitch slide to at most the current note by the parameter amount - let c4_speed = note_to_speed(Note::C4, 0.0, 0, module.frequency_type); + if let (Some((note, sample)), Some((prev_note, _))) = + (maybe_note_and_sample, previous_note_and_sample) + { + let target_speed = note_to_speed( + *note, + sample.fine_tune, + sample.relative_note, + module.frequency_type, + ); - let direction = if (previous_note as usize) < slot.note as usize { - -1.0 - } else { - 1.0 + let direction = match (prev_note as usize).cmp(&(*note as usize)) { + std::cmp::Ordering::Less => 1.0, + std::cmp::Ordering::Equal => { + tone_portamento_directions[channel_number] + } + std::cmp::Ordering::Greater => -1.0, }; + + tone_portamento_directions[channel_number] = direction; + + let c4_speed = note_to_speed(Note::C4, 0.0, 0, module.frequency_type); let speed = note_to_speed( Note::C4, effect_parameter as f64 * direction, @@ -260,13 +277,6 @@ pub fn parse_module(module: &Module) -> TokenStream { let portamento_amount = speed / c4_speed; - let target_speed = note_to_speed( - slot.note, - sample.fine_tune, - sample.relative_note, - module.frequency_type, - ); - PatternEffect::TonePortamento( portamento_amount.try_change_base().unwrap(), target_speed.try_change_base().unwrap(),