use super::SimpleMidiSong;
use midix::prelude::*;
pub struct Beat<'a> {
pub(crate) song: &'a mut SimpleMidiSong,
pub(crate) beat_no: u64,
}
impl<'s> Beat<'s> {
pub fn channel<'b>(&'b mut self, channel: Channel) -> ChannelBeat<'b, 's> {
ChannelBeat {
beat: self,
channel,
}
}
}
pub struct ChannelBeat<'b, 's> {
beat: &'b mut Beat<'s>,
channel: Channel,
}
impl<'b, 's> ChannelBeat<'b, 's> {
pub fn play(self, note: Note) -> &'b mut Beat<'s> {
let event =
ChannelVoiceMessage::new(self.channel, VoiceEvent::note_on(note, Velocity::MAX));
self.beat.song.add_event(self.beat.beat_no, event);
self.beat
}
pub fn play_notes<Notes>(self, notes: Notes) -> &'b mut Beat<'s>
where
Notes: IntoIterator<Item = Note>,
{
let events = notes.into_iter().map(|key| {
ChannelVoiceMessage::new(self.channel, VoiceEvent::note_on(key, Velocity::MAX))
});
self.beat.song.add_events(self.beat.beat_no, events);
self.beat
}
}