IT IS MUSIC

This commit is contained in:
2026-03-11 12:58:02 -06:00
parent c0930d1ccc
commit b2095c4229
3 changed files with 25 additions and 6 deletions

View File

@@ -28,6 +28,8 @@ fn play(mut s: seq::SynSeq, sample_rate: usize, bpm: usize) {
sample_rate: sample_rate,
channel_sample_count: samples_per_beat,
};
let beats = s.beats();
let duration = 1 + 60 * beats / bpm;
let sample_count = (params.channel_sample_count) as usize;
let mut left: Vec<f32> = vec![0_f32; sample_count];
@@ -44,5 +46,5 @@ fn play(mut s: seq::SynSeq, sample_rate: usize, bpm: usize) {
.unwrap();
// Wait it out
std::thread::sleep(std::time::Duration::from_secs(2));
std::thread::sleep(std::time::Duration::from_secs(duration as u64));
}

View File

@@ -20,10 +20,14 @@ impl SynSeq {
pub fn render(&mut self, left: &mut [f32], right: &mut [f32]) {
if let Some(tone) = self.seq.pop() {
self.syn.tone_on(tone);
self.syn.set(tone);
}
self.syn.render(left, right);
}
pub fn beats(&self) -> usize {
self.seq.beats.len()
}
}
#[derive(PartialEq)]

View File

@@ -31,14 +31,28 @@ impl Syn {
Syn::Real(synthesizer)
}
pub fn tone_on(&mut self, b: tone::Tone) {
pub fn set(&mut self, b: tone::Tone) {
let a = 0 as i32;
match self {
// channel=[0..16)
// velocity=[0..128)
Syn::Real(syn) => {
syn.note_off_all_channel(a, false);
},
Syn::Text{m, ..} => {
m.clear();
},
};
self.tone_on(b);
}
fn tone_on(&mut self, b: tone::Tone) {
let a = 0 as i32;
match self {
// channel=[0..16)
// velocity=[0..128)
Syn::Real(syn) => syn.note_on(a, b.i32(), 127),
Syn::Text{m, ..} => {
eprintln!("tone_on({:?}, {:?}, {:?})", a, b.i32(), 127);
match m.get_mut(&a) {
Some(m2) => { m2.insert(b.i32(), 127); },
None => {
@@ -51,12 +65,11 @@ impl Syn {
};
}
pub fn tone_off(&mut self, b: tone::Tone) {
fn tone_off(&mut self, b: tone::Tone) {
let a = 0 as i32;
match self {
Syn::Real(syn) => syn.note_off(a, b.i32()),
Syn::Text{m, ..} => {
eprintln!("tone_off({:?}, {:?})", a, b.i32());
match m.get_mut(&a) {
Some(m) => { m.remove(&b.i32()); },
None => {},