use crate::math::Rational;
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct NoteEvent {
pub degree: i32,
pub octave: i32,
pub velocity: Rational,
pub gate: Rational,
pub params: Vec<(u32, f64)>,
}
impl NoteEvent {
pub fn new(degree: i32, octave: i32, velocity: Rational) -> Self {
Self {
degree,
octave,
velocity,
gate: Rational::new(7, 8),
params: Vec::new(),
}
}
pub fn simple(degree: i32) -> Self {
Self::new(degree, 0, Rational::new(3, 4))
}
pub fn with_gate(mut self, gate: Rational) -> Self {
self.gate = gate;
self
}
pub fn with_param(mut self, id: u32, value: f64) -> Self {
self.params.push((id, value));
self
}
}
#[derive(Clone, Debug)]
pub enum GraphEvent {
NoteOn {
frequency: f64,
velocity: f64,
voice: u32,
},
NoteOff { voice: u32 },
Param { node: u32, param: u32, value: f64 },
}
#[derive(Clone, Debug)]
pub struct TimedEvent {
pub sample_offset: usize,
pub event: GraphEvent,
}