use smallvec::SmallVec;
#[derive(Debug, Clone, Copy)]
pub struct Event {
pub sample_offset: u32,
pub body: EventBody,
}
#[derive(Debug, Clone, Copy)]
pub enum EventBody {
Midi(MidiData),
ParamValue {
param_id: u32,
value: f64,
},
ParamGesture {
param_id: u32,
active: bool,
},
TransportFlag(TransportFlag),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TransportFlag {
PlayStart,
PlayStop,
RecordStart,
RecordStop,
Looped,
}
#[derive(Debug, Clone, Copy)]
pub enum MidiData {
NoteOn {
channel: u8,
note: u8,
velocity: u8,
},
NoteOff {
channel: u8,
note: u8,
velocity: u8,
},
PolyAftertouch {
channel: u8,
note: u8,
pressure: u8,
},
ControlChange {
channel: u8,
controller: u8,
value: u8,
},
ProgramChange {
channel: u8,
program: u8,
},
ChannelAftertouch {
channel: u8,
pressure: u8,
},
PitchBend {
channel: u8,
value: u16,
},
Raw {
len: u8,
data: [u8; 8],
},
}
const EVENT_LIST_INLINE: usize = 32;
#[derive(Debug, Default, Clone)]
pub struct EventList {
events: SmallVec<[Event; EVENT_LIST_INLINE]>,
}
impl EventList {
#[must_use]
pub fn new() -> Self {
Self::default()
}
#[must_use]
pub fn from_slice(events: &[Event]) -> Self {
Self {
events: SmallVec::from_slice(events),
}
}
pub fn push(&mut self, event: Event) {
self.events.push(event);
}
pub fn clear(&mut self) {
self.events.clear();
}
#[must_use]
pub fn len(&self) -> usize {
self.events.len()
}
#[must_use]
pub fn is_empty(&self) -> bool {
self.events.is_empty()
}
#[must_use]
pub fn as_slice(&self) -> &[Event] {
&self.events
}
pub fn iter(&self) -> std::slice::Iter<'_, Event> {
self.events.iter()
}
}
impl<'a> IntoIterator for &'a EventList {
type Item = &'a Event;
type IntoIter = std::slice::Iter<'a, Event>;
fn into_iter(self) -> Self::IntoIter {
self.events.iter()
}
}