|
| 1 | +use caw::prelude::*; |
| 2 | + |
| 3 | +fn note_from_key( |
| 4 | + note_by_key: Vec<(KeyFrameSig, Note)>, |
| 5 | +) -> FrameSig<impl FrameSigT<Item = Option<Note>>> { |
| 6 | + FrameSig::option_first_some( |
| 7 | + note_by_key |
| 8 | + .into_iter() |
| 9 | + .map(|(key, note)| key.on(move || note)), |
| 10 | + ) |
| 11 | +} |
| 12 | + |
| 13 | +fn main() { |
| 14 | + let window = Window::builder().build(); |
| 15 | + let input = window.input(); |
| 16 | + let sig = { |
| 17 | + let keyboard = input.keyboard.clone(); |
| 18 | + let (gate, note) = note_from_key(vec![ |
| 19 | + (keyboard.q, Note::E2), |
| 20 | + (keyboard.w, Note::A2), |
| 21 | + (keyboard.e, Note::D3), |
| 22 | + (keyboard.r, Note::G3), |
| 23 | + (keyboard.t, Note::B3), |
| 24 | + (keyboard.y, Note::E4), |
| 25 | + ]) |
| 26 | + .map(|note_opt| (note_opt.is_some(), note_opt)) |
| 27 | + .unzip(); |
| 28 | + let note = note.option_or_last(note::C4); |
| 29 | + let env = adsr_linear_01(gate).release_s(1.0).build().exp_01(1.0); |
| 30 | + oscillator(Saw, note.freq_hz()) |
| 31 | + .build() |
| 32 | + .filter(low_pass::default(env * 10000.0)) |
| 33 | + .filter(reverb::default()) |
| 34 | + }; |
| 35 | + window.play_mono(sig, Default::default()).unwrap(); |
| 36 | +} |
0 commit comments