From e103468b8695a61b84ec0079cbbad1c4127652ba Mon Sep 17 00:00:00 2001 From: Gwilym Inzani Date: Wed, 1 Nov 2023 13:28:01 +0000 Subject: [PATCH] Vaguely get the correct beat and the patterns correct --- tracker/agb-midi-core/src/lib.rs | 23 +++++++++++++++++++---- tracker/agb-tracker-interop/src/lib.rs | 4 ++-- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/tracker/agb-midi-core/src/lib.rs b/tracker/agb-midi-core/src/lib.rs index 4fe8a2f5..6aefa9e8 100644 --- a/tracker/agb-midi-core/src/lib.rs +++ b/tracker/agb-midi-core/src/lib.rs @@ -190,6 +190,13 @@ pub fn parse_midi(midi_info: &MidiInfo) -> TokenStream { } } + patterns.retain(|pattern| { + !pattern.iter().all(|pattern_slot| { + matches!(pattern_slot.effect1, PatternEffect::None) + && matches!(pattern_slot.effect2, PatternEffect::None) + }) + }); + for pattern in &mut patterns { pattern.resize_with(current_ticks as usize, || PatternSlot { speed: 0.into(), @@ -211,20 +218,28 @@ pub fn parse_midi(midi_info: &MidiInfo) -> TokenStream { }) .collect(); - let pattern = patterns.into_iter().flatten().collect::>(); + let resulting_num_channels = patterns.len(); + let mut pattern = Vec::with_capacity(current_ticks as usize * resulting_num_channels); + for i in 0..current_ticks { + for pattern_slots in &patterns { + pattern.push(pattern_slots[i as usize].clone()); + } + } let track = Track { samples: &samples, envelopes: &[], pattern_data: &pattern, patterns: &[Pattern { - length: pattern.len() / channel_data.len(), + length: pattern.len() / resulting_num_channels, start_position: 0, }], patterns_to_play: &[0], - num_channels: channel_data.len(), + num_channels: resulting_num_channels, frames_per_tick: Num::from_f64( - initial_microseconds_per_beat.expect("No tempo was ever sent") as f64 / 16742.706298828, // microseconds per frame + initial_microseconds_per_beat.expect("No tempo was ever sent") as f64 + / 16742.706298828 // microseconds per frame + / ticks_per_beat as f64, ), ticks_per_step: 1, repeat: 0, diff --git a/tracker/agb-tracker-interop/src/lib.rs b/tracker/agb-tracker-interop/src/lib.rs index 7261d683..1a2c05f3 100644 --- a/tracker/agb-tracker-interop/src/lib.rs +++ b/tracker/agb-tracker-interop/src/lib.rs @@ -32,7 +32,7 @@ pub struct Pattern { pub start_position: usize, } -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct PatternSlot { pub speed: Num, pub sample: u16, @@ -48,7 +48,7 @@ pub struct Envelope<'a> { pub loop_end: Option, } -#[derive(Debug, Default)] +#[derive(Debug, Default, Clone)] pub enum PatternEffect { /// Don't play an effect #[default]