From 8dd99a5eadc9c9f44382cf4bd0a02bf0e631283c Mon Sep 17 00:00:00 2001 From: Irjan Olsen Date: Wed, 11 Jan 2023 07:56:31 +0100 Subject: [PATCH] Added tempo and tick per row variables that convert into how long each note is for future playback control. --- src/main.rs | 4 ++-- src/tracker.rs | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index f60ee38..991a363 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,6 +12,6 @@ use crate::tracker::Tracker; fn main() { let mut tracker = Tracker::new(4, 64); tracker.load_file("./3266CHIP.MOD"); - tracker.play_sample(1, 8287.0); - //tracker.play(); + //tracker.play_sample(1, 8287.0); + tracker.play(); } diff --git a/src/tracker.rs b/src/tracker.rs index a461b93..f6c5514 100644 --- a/src/tracker.rs +++ b/src/tracker.rs @@ -41,12 +41,20 @@ impl Tracker { sink.pause(); } + //let delay = 60.0/375.0; + let tpr = 8.0; + let tempo = 125.0; + let delay = tpr*2.5/tempo; + let lines = self.patterns[0][0].len(); println!("Playing {} lines", lines); for &position in &self.positions { let pattern = &self.patterns[position as usize]; for line in 0..lines { for (track, notes) in pattern.iter().enumerate() { + /*if track != 3 { + continue; + }*/ let note = notes[line].as_ref(); if note.is_some() { //println!("Playing note: {}", note.as_ref().unwrap()); @@ -56,14 +64,14 @@ impl Tracker { self.samples[sample as usize].set_sample_rate(frequency); self.sinks[track].append( self.samples[sample as usize].clone() - .take_duration(Duration::from_secs_f64(60.0/375.0)) + .take_duration(Duration::from_secs_f64(delay)) .amplify(0.20) ) } else { //println!("Playing note: ---"); self.sinks[track].append( SineWave::new(0.0) - .take_duration(Duration::from_secs_f64(60.0/375.0)) + .take_duration(Duration::from_secs_f64(delay)) .amplify(0.20) ) }