use bevy::platform::collections::HashMap;
use midix::prelude::*;
#[derive(Default)]
pub struct SimpleSection {
beat: HashMap<u64, Vec<VoiceEvent>>,
}
impl SimpleSection {
pub fn beat(&mut self, beat_no: u64) -> SectionBeat<'_> {
SectionBeat {
section: self,
beat_no,
}
}
pub fn events(&self) -> &HashMap<u64, Vec<VoiceEvent>> {
&self.beat
}
}
pub struct SectionBeat<'a> {
section: &'a mut SimpleSection,
beat_no: u64,
}
impl<'a> SectionBeat<'a> {
pub fn play(self, note: Note) -> &'a mut SimpleSection {
let events = self.section.beat.entry(self.beat_no).or_default();
events.push(VoiceEvent::note_on(note, Velocity::MAX));
self.section
}
}