need tone unset and rests

This commit is contained in:
2026-03-11 12:51:26 -06:00
parent fc91b666ce
commit c0930d1ccc
3 changed files with 44 additions and 14 deletions

View File

@@ -8,17 +8,20 @@ mod seq;
fn main() { fn main() {
let flags = flags::Flags::new(); let flags = flags::Flags::new();
let mut syn = syn::Syn::new( let mut syn_seq = seq::new_syn(syn::Syn::new(
flags.debug, flags.debug,
flags.sound_font, flags.sound_font,
flags.sample_rate, flags.sample_rate,
); ));
syn.tone_on(0, tone::new("c+5")); syn_seq.append("c");
syn_seq.append("2e");
syn_seq.append("g");
//syn.tone_on(0, tone::new("c+5"));
play(syn, flags.sample_rate, flags.bpm); play(syn_seq, flags.sample_rate, flags.bpm);
} }
fn play(mut s: syn::Syn, sample_rate: usize, bpm: usize) { fn play(mut s: seq::SynSeq, sample_rate: usize, bpm: usize) {
let samples_per_beat = sample_rate / bpm * 60; let samples_per_beat = sample_rate / bpm * 60;
let params = tinyaudio::prelude::OutputDeviceParameters { let params = tinyaudio::prelude::OutputDeviceParameters {
channels_count: 2, channels_count: 2,

View File

@@ -1,8 +1,33 @@
use crate::tone; use crate::tone;
use crate::syn; use crate::syn;
pub struct SynSeq {
seq: Seq,
syn: syn::Syn,
}
pub fn new_syn(syn: syn::Syn) -> SynSeq {
SynSeq{
seq: new(),
syn: syn,
}
}
impl SynSeq {
pub fn append<S: ToString>(&mut self, s: S) {
self.seq.append(s);
}
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.render(left, right);
}
}
#[derive(PartialEq)] #[derive(PartialEq)]
struct Seq { pub struct Seq {
beats: Vec<(i32, tone::Tone)>, beats: Vec<(i32, tone::Tone)>,
} }

View File

@@ -31,7 +31,8 @@ impl Syn {
Syn::Real(synthesizer) Syn::Real(synthesizer)
} }
pub fn tone_on(&mut self, a: i32, b: tone::Tone) { pub fn tone_on(&mut self, b: tone::Tone) {
let a = 0 as i32;
match self { match self {
// channel=[0..16) // channel=[0..16)
// velocity=[0..128) // velocity=[0..128)
@@ -50,7 +51,8 @@ impl Syn {
}; };
} }
pub fn tone_off(&mut self, a: i32, b: tone::Tone) { pub fn tone_off(&mut self, b: tone::Tone) {
let a = 0 as i32;
match self { match self {
Syn::Real(syn) => syn.note_off(a, b.i32()), Syn::Real(syn) => syn.note_off(a, b.i32()),
Syn::Text{m, ..} => { Syn::Text{m, ..} => {
@@ -83,10 +85,10 @@ mod test {
fn test_new_real() { fn test_new_real() {
let mut syn = Syn::new(false, "super_small_font.sf2".to_string(), 44100); let mut syn = Syn::new(false, "super_small_font.sf2".to_string(), 44100);
syn.tone_on(1, tone::new("c")); syn.tone_on(tone::new("c"));
syn.tone_on(2, tone::new("d")); syn.tone_on(tone::new("d"));
syn.tone_off(2, tone::new("d")); syn.tone_off(tone::new("d"));
let mut buffer1 = Vec::<f32>::new(); let mut buffer1 = Vec::<f32>::new();
let mut buffer2 = Vec::<f32>::new(); let mut buffer2 = Vec::<f32>::new();
@@ -97,10 +99,10 @@ mod test {
fn test_text() { fn test_text() {
let mut syn = Syn::new(true, ".sf2".to_string(), 1); let mut syn = Syn::new(true, ".sf2".to_string(), 1);
syn.tone_on(1, tone::new("c")); syn.tone_on(tone::new("c"));
syn.tone_on(2, tone::new("d")); syn.tone_on(tone::new("d"));
syn.tone_off(2, tone::new("d")); syn.tone_off(tone::new("d"));
let mut buffer1 = Vec::<f32>::new(); let mut buffer1 = Vec::<f32>::new();
let mut buffer2 = Vec::<f32>::new(); let mut buffer2 = Vec::<f32>::new();