sym to own file

This commit is contained in:
breel
2026-03-10 22:21:15 -06:00
parent 04645c0d17
commit e9cbb86735
3 changed files with 77 additions and 64 deletions

View File

@@ -1,36 +1,24 @@
use itertools::Itertools;
use rustysynth::SoundFont;
use rustysynth::Synthesizer;
use rustysynth::SynthesizerSettings;
use std::fs::File;
use std::sync::Arc;
use tinyaudio::prelude::*;
mod flags;
mod syn;
fn main() {
let flags = flags::Flags::new();
// Load the SoundFont.
let mut sf2 = File::open("super_small_font.sf2").unwrap();
let sound_font = Arc::new(SoundFont::new(&mut sf2).unwrap());
let mut syn = syn::Syn::new(
flags.debug,
flags.sound_font,
flags.sample_rate,
);
// Setup the audio output.
let params = OutputDeviceParameters {
channels_count: 2,
sample_rate: flags.sample_rate,
channel_sample_count: flags.sample_rate / flags.smallest_note,
};
// Create the synthesizer.
let settings = SynthesizerSettings::new(params.sample_rate as i32);
let synthesizer = Synthesizer::new(&sound_font, &settings).unwrap();
let mut syn = match &flags.debug{
false => Syn::Real(synthesizer),
true => Syn::Text(std::collections::HashMap::new()),
};
// 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
syn.note_on(0, 64 + 12, 127);
//syn.render(&mut left[..], &mut right[..]); // puts in a state of rendering the first loop of these notes
@@ -54,49 +42,3 @@ fn main() {
std::thread::sleep(std::time::Duration::from_secs(2));
}
enum Syn {
Real(Synthesizer),
Text(std::collections::HashMap<i32, std::collections::HashMap<i32, i32>>),
}
impl Syn {
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) => {
eprintln!("note_on({:?}, {:?}, {:?})", a, b, c);
match m.get_mut(&a) {
Some(m2) => { m2.insert(b, c); },
None => {
let mut m2 = std::collections::HashMap::new();
m2.insert(b, c);
m.insert(a, m2);
},
};
},
};
}
fn note_off(&mut self, a: i32, b: i32) {
match self {
Syn::Real(syn) => syn.note_off(a, b),
Syn::Text(m) => {
eprintln!("note_off({:?}, {:?})", a, b);
match m.get_mut(&a) {
Some(m) => { m.remove(&b); },
None => {},
};
},
};
}
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)
},
};
}
}