Working on integrating the EventWindowing into HexoDSP
This commit is contained in:
parent
fb3a7f9896
commit
22698c3a1a
1 changed files with 51 additions and 0 deletions
|
@ -4,6 +4,19 @@
|
|||
|
||||
use crate::dsp::MAX_BLOCK_SIZE;
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct TimedEvent {
|
||||
/// The frame number in the current block by the audio driver or plugin API/DAW
|
||||
timing: usize,
|
||||
kind: MidiEvent,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum MidiEvent {
|
||||
NoteOn { channel: u8, note: u8, vel: f32 },
|
||||
NoteOff { channel: u8, note: u8, vel: f32 },
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct NoteChannelState {
|
||||
pub vel: f32,
|
||||
|
@ -84,6 +97,44 @@ impl NoteBuffer {
|
|||
}
|
||||
}
|
||||
|
||||
struct EventWindowing {
|
||||
pub event: Option<TimedEvent>,
|
||||
}
|
||||
|
||||
impl EventWindowing {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
event: None,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn feed_me(&self) -> bool {
|
||||
self.event.is_none()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn feed(&mut self, event: TimedEvent) {
|
||||
self.event = Some(event);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn next_event_in_range(&mut self, to_time: usize) -> Option<NoteEvent> {
|
||||
let to_time = to_time as u32;
|
||||
|
||||
if let Some(event) = self.event.take() {
|
||||
if event.timing() < to_time {
|
||||
return Some(event);
|
||||
} else {
|
||||
self.event = Some(event);
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
Loading…
Reference in a new issue