Added tempo and tick per row variables that convert into how long each note is for future playback control.
This commit is contained in:
@@ -12,6 +12,6 @@ use crate::tracker::Tracker;
|
|||||||
fn main() {
|
fn main() {
|
||||||
let mut tracker = Tracker::new(4, 64);
|
let mut tracker = Tracker::new(4, 64);
|
||||||
tracker.load_file("./3266CHIP.MOD");
|
tracker.load_file("./3266CHIP.MOD");
|
||||||
tracker.play_sample(1, 8287.0);
|
//tracker.play_sample(1, 8287.0);
|
||||||
//tracker.play();
|
tracker.play();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,12 +41,20 @@ impl Tracker {
|
|||||||
sink.pause();
|
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();
|
let lines = self.patterns[0][0].len();
|
||||||
println!("Playing {} lines", lines);
|
println!("Playing {} lines", lines);
|
||||||
for &position in &self.positions {
|
for &position in &self.positions {
|
||||||
let pattern = &self.patterns[position as usize];
|
let pattern = &self.patterns[position as usize];
|
||||||
for line in 0..lines {
|
for line in 0..lines {
|
||||||
for (track, notes) in pattern.iter().enumerate() {
|
for (track, notes) in pattern.iter().enumerate() {
|
||||||
|
/*if track != 3 {
|
||||||
|
continue;
|
||||||
|
}*/
|
||||||
let note = notes[line].as_ref();
|
let note = notes[line].as_ref();
|
||||||
if note.is_some() {
|
if note.is_some() {
|
||||||
//println!("Playing note: {}", note.as_ref().unwrap());
|
//println!("Playing note: {}", note.as_ref().unwrap());
|
||||||
@@ -56,14 +64,14 @@ impl Tracker {
|
|||||||
self.samples[sample as usize].set_sample_rate(frequency);
|
self.samples[sample as usize].set_sample_rate(frequency);
|
||||||
self.sinks[track].append(
|
self.sinks[track].append(
|
||||||
self.samples[sample as usize].clone()
|
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)
|
.amplify(0.20)
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
//println!("Playing note: ---");
|
//println!("Playing note: ---");
|
||||||
self.sinks[track].append(
|
self.sinks[track].append(
|
||||||
SineWave::new(0.0)
|
SineWave::new(0.0)
|
||||||
.take_duration(Duration::from_secs_f64(60.0/375.0))
|
.take_duration(Duration::from_secs_f64(delay))
|
||||||
.amplify(0.20)
|
.amplify(0.20)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user