Compare commits
2 Commits
12c6f6b1ae
...
ff3911fee9
| Author | SHA1 | Date | |
|---|---|---|---|
| ff3911fee9 | |||
| 37fb8940ec |
@@ -13,7 +13,7 @@ fn main() {
|
|||||||
flags.sample_rate,
|
flags.sample_rate,
|
||||||
);
|
);
|
||||||
// Play some tones (middle C, E, G). // 16 channels actually // 60=c 64=e 67=g //up to 128velocity though dont go below 50 tbh // 12 tones per octave
|
// Play some tones (middle C, E, G). // 16 channels actually // 60=c 64=e 67=g //up to 128velocity though dont go below 50 tbh // 12 tones per octave
|
||||||
syn.note_on(0, tone::new("c").i32(), 127);
|
syn.tone_on(0, tone::new("c+5"), 127);
|
||||||
|
|
||||||
play(syn, flags.sample_rate, flags.bpm, flags.smallest_note);
|
play(syn, flags.sample_rate, flags.bpm, flags.smallest_note);
|
||||||
}
|
}
|
||||||
|
|||||||
32
src/syn.rs
32
src/syn.rs
@@ -3,6 +3,8 @@ use rustysynth::SoundFont;
|
|||||||
use rustysynth::SynthesizerSettings;
|
use rustysynth::SynthesizerSettings;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use crate::tone;
|
||||||
|
|
||||||
pub enum Syn {
|
pub enum Syn {
|
||||||
Real(Synthesizer),
|
Real(Synthesizer),
|
||||||
Text{
|
Text{
|
||||||
@@ -29,16 +31,16 @@ impl Syn {
|
|||||||
Syn::Real(synthesizer)
|
Syn::Real(synthesizer)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn note_on(&mut self, a: i32, b: i32, c: i32) {
|
pub fn tone_on(&mut self, a: i32, b: tone::Tone, c: i32) {
|
||||||
match self {
|
match self {
|
||||||
Syn::Real(syn) => syn.note_on(a, b, c),
|
Syn::Real(syn) => syn.note_on(a, b.i32(), c),
|
||||||
Syn::Text{m, ..} => {
|
Syn::Text{m, ..} => {
|
||||||
eprintln!("note_on({:?}, {:?}, {:?})", a, b, c);
|
eprintln!("tone_on({:?}, {:?}, {:?})", a, b.i32(), c);
|
||||||
match m.get_mut(&a) {
|
match m.get_mut(&a) {
|
||||||
Some(m2) => { m2.insert(b, c); },
|
Some(m2) => { m2.insert(b.i32(), c); },
|
||||||
None => {
|
None => {
|
||||||
let mut m2 = std::collections::HashMap::new();
|
let mut m2 = std::collections::HashMap::new();
|
||||||
m2.insert(b, c);
|
m2.insert(b.i32(), c);
|
||||||
m.insert(a, m2);
|
m.insert(a, m2);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -46,13 +48,13 @@ impl Syn {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn note_off(&mut self, a: i32, b: i32) {
|
pub fn tone_off(&mut self, a: i32, b: tone::Tone) {
|
||||||
match self {
|
match self {
|
||||||
Syn::Real(syn) => syn.note_off(a, b),
|
Syn::Real(syn) => syn.note_off(a, b.i32()),
|
||||||
Syn::Text{m, ..} => {
|
Syn::Text{m, ..} => {
|
||||||
eprintln!("note_off({:?}, {:?})", a, b);
|
eprintln!("tone_off({:?}, {:?})", a, b.i32());
|
||||||
match m.get_mut(&a) {
|
match m.get_mut(&a) {
|
||||||
Some(m) => { m.remove(&b); },
|
Some(m) => { m.remove(&b.i32()); },
|
||||||
None => {},
|
None => {},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -79,10 +81,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.note_on(1, 2, 3);
|
syn.tone_on(1, tone::new("c"), 3);
|
||||||
syn.note_on(2, 3, 4);
|
syn.tone_on(2, tone::new("d"), 4);
|
||||||
|
|
||||||
syn.note_off(2, 3);
|
syn.tone_off(2, 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();
|
||||||
@@ -93,10 +95,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.note_on(1, 2, 3);
|
syn.tone_on(1, tone::new("c"), 3);
|
||||||
syn.note_on(2, 3, 4);
|
syn.tone_on(2, tone::new("d"), 4);
|
||||||
|
|
||||||
syn.note_off(2, 3);
|
syn.tone_off(2, 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();
|
||||||
|
|||||||
Reference in New Issue
Block a user