1#[macro_use]
2extern crate log;
3extern crate derive_more;
4
5pub mod api;
6pub mod config;
7pub mod gui_channel;
8pub mod midi;
9pub mod music;
10
11pub fn clamp<T: PartialOrd + Copy>(v: T, min: T, max: T) -> T {
12 assert!(min <= max);
13 let mut x = v;
14 if x < min {
15 x = min;
16 }
17 if x > max {
18 x = max;
19 }
20 x
21}
22
23pub fn f32_to_i16(v: f32) -> i16 {
24 let v = clamp(v, -1.0, 1.0);
25 (v * 32768.0).floor() as i16
26}
27
28pub trait Host<'a> {
29 fn add_looper(&mut self, id: u32) -> Result<(), String>;
30 fn remove_looper(&mut self, id: u32) -> Result<(), String>;
31
32 fn output_for_looper<'b>(&'b mut self, id: u32) -> Option<[&'b mut [f32]; 2]>
33 where
34 'a: 'b;
35}