mod aot;
mod jit;
mod midi;
use std::hash::Hash;
pub use aot::*;
pub use jit::*;
pub use midi::*;
use crate::note::Note;
use crate::note::NoteLetter;
use crate::pitch::Ratio;
pub trait TunableSynth {
type Result: IsErr;
type NoteAttr: Clone + Default;
type GlobalAttr;
fn num_channels(&self) -> usize;
fn group_by(&self) -> GroupBy;
fn notes_detune(&mut self, channel: usize, detuned_notes: &[(Note, Ratio)]) -> Self::Result;
fn note_on(&mut self, channel: usize, started_note: Note, attr: Self::NoteAttr)
-> Self::Result;
fn note_off(
&mut self,
channel: usize,
stopped_note: Note,
attr: Self::NoteAttr,
) -> Self::Result;
fn note_attr(
&mut self,
channel: usize,
affected_note: Note,
attr: Self::NoteAttr,
) -> Self::Result;
fn global_attr(&mut self, attr: Self::GlobalAttr) -> Self::Result;
}
pub trait IsErr {
fn is_err(&self) -> bool;
fn ok() -> Self;
}
impl<T: Default, E> IsErr for Result<T, E> {
fn is_err(&self) -> bool {
self.is_err()
}
fn ok() -> Self {
Ok(T::default())
}
}
impl IsErr for () {
fn is_err(&self) -> bool {
false
}
fn ok() -> Self {}
}
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum GroupBy {
Note,
NoteLetter,
Channel,
}
impl GroupBy {
pub fn group(self, note: Note) -> Group {
match self {
GroupBy::Note => Group::Note(note),
GroupBy::NoteLetter => Group::NoteLetter(note.letter_and_octave().0),
GroupBy::Channel => Group::Channel,
}
}
}
#[derive(Copy, Clone, Eq, Hash, PartialEq)]
pub enum Group {
Note(Note),
NoteLetter(NoteLetter),
Channel,
}
impl Group {
pub fn ungroup(self) -> Note {
match self {
Group::Note(note) => note,
Group::NoteLetter(note_letter) => note_letter.in_octave(0),
Group::Channel => Note::from_midi_number(0),
}
}
}