note struct
This commit is contained in:
@@ -2,6 +2,7 @@ use itertools::Itertools;
|
|||||||
|
|
||||||
mod flags;
|
mod flags;
|
||||||
mod syn;
|
mod syn;
|
||||||
|
mod note;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let flags = flags::Flags::new();
|
let flags = flags::Flags::new();
|
||||||
@@ -12,7 +13,7 @@ fn main() {
|
|||||||
flags.sample_rate,
|
flags.sample_rate,
|
||||||
);
|
);
|
||||||
// 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
|
// 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.note_on(0, note::new("any").i32(), 127);
|
||||||
|
|
||||||
play(syn, flags.sample_rate, flags.bpm, flags.smallest_note);
|
play(syn, flags.sample_rate, flags.bpm, flags.smallest_note);
|
||||||
}
|
}
|
||||||
@@ -21,7 +22,7 @@ fn play(mut s: syn::Syn, sample_rate: usize, bpm: usize, smallest_note: usize) {
|
|||||||
let params = tinyaudio::prelude::OutputDeviceParameters {
|
let params = tinyaudio::prelude::OutputDeviceParameters {
|
||||||
channels_count: 2,
|
channels_count: 2,
|
||||||
sample_rate: sample_rate,
|
sample_rate: sample_rate,
|
||||||
channel_sample_count: sample_rate / bpm * 60 / smallest_note,
|
channel_sample_count: sample_rate / bpm * 60 / smallest_note,
|
||||||
};
|
};
|
||||||
|
|
||||||
let sample_count = (params.channel_sample_count) as usize;
|
let sample_count = (params.channel_sample_count) as usize;
|
||||||
|
|||||||
14
src/note.rs
Normal file
14
src/note.rs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
pub struct Note(String);
|
||||||
|
|
||||||
|
pub fn new<S: ToString>(s: S) -> Note {
|
||||||
|
Note(s.to_string())
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Note {
|
||||||
|
pub fn i32(&self) -> i32 {
|
||||||
|
// 60 = middle c
|
||||||
|
// 64 = middle e
|
||||||
|
// 67 = middle g
|
||||||
|
64 + 12
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user