debugger shows bpm beats k
This commit is contained in:
@@ -5,9 +5,12 @@ pub struct Flags {
|
||||
#[arg(short, long, default_value_t = false)]
|
||||
pub debug: bool,
|
||||
|
||||
#[arg(long, default_value_t = 4)]
|
||||
#[arg(long, default_value_t = 16)]
|
||||
pub smallest_note: usize,
|
||||
|
||||
#[arg(long, default_value_t = 60)]
|
||||
pub bpm: usize,
|
||||
|
||||
#[arg(long, default_value_t = 44100)]
|
||||
pub sample_rate: usize,
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ fn main() {
|
||||
let params = OutputDeviceParameters {
|
||||
channels_count: 2,
|
||||
sample_rate: flags.sample_rate,
|
||||
channel_sample_count: flags.sample_rate / flags.smallest_note,
|
||||
channel_sample_count: flags.sample_rate / flags.bpm * 60 / flags.smallest_note,
|
||||
};
|
||||
|
||||
// Play some notes (middle C, E, G). // 16 channels actually // 60=c 64=e 67=g //up to 128velocity though dont go below 50 tbh // 12 notes per octave
|
||||
|
||||
16
src/syn.rs
16
src/syn.rs
@@ -5,14 +5,17 @@ use std::sync::Arc;
|
||||
|
||||
pub enum Syn {
|
||||
Real(Synthesizer),
|
||||
Text(std::collections::HashMap<i32, std::collections::HashMap<i32, i32>>),
|
||||
Text{
|
||||
m: std::collections::HashMap<i32, std::collections::HashMap<i32, i32>>,
|
||||
i: u32,
|
||||
},
|
||||
}
|
||||
|
||||
impl Syn {
|
||||
pub fn new(debug: bool, sound_font: String, sample_rate: usize) -> Syn {
|
||||
match debug {
|
||||
false => Syn::new_real(sound_font, sample_rate),
|
||||
true => Syn::Text(std::collections::HashMap::new()),
|
||||
true => Syn::Text{m: std::collections::HashMap::new(), i: 0},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +32,7 @@ impl Syn {
|
||||
pub fn note_on(&mut self, a: i32, b: i32, c: i32) {
|
||||
match self {
|
||||
Syn::Real(syn) => syn.note_on(a, b, c),
|
||||
Syn::Text(m) => {
|
||||
Syn::Text{m, ..} => {
|
||||
eprintln!("note_on({:?}, {:?}, {:?})", a, b, c);
|
||||
match m.get_mut(&a) {
|
||||
Some(m2) => { m2.insert(b, c); },
|
||||
@@ -46,7 +49,7 @@ impl Syn {
|
||||
pub fn note_off(&mut self, a: i32, b: i32) {
|
||||
match self {
|
||||
Syn::Real(syn) => syn.note_off(a, b),
|
||||
Syn::Text(m) => {
|
||||
Syn::Text{m, ..} => {
|
||||
eprintln!("note_off({:?}, {:?})", a, b);
|
||||
match m.get_mut(&a) {
|
||||
Some(m) => { m.remove(&b); },
|
||||
@@ -60,8 +63,9 @@ impl Syn {
|
||||
pub fn render(&mut self, a: &mut [f32], b: &mut [f32]) {
|
||||
match self {
|
||||
Syn::Real(syn) => syn.render(a, b),
|
||||
Syn::Text(m) => {
|
||||
eprintln!("render({:?})", m)
|
||||
Syn::Text{m, i} => {
|
||||
eprintln!("render[{}]({:?})", i, m);
|
||||
*i += 1;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user