use bevy::prelude::*;
use midix::prelude::*;
use crate::assets::SoundFontAsset;
#[derive(Component)]
pub struct SynthPlayer {
pub(crate) handle: Handle<SoundFontAsset>,
pub(crate) midi_input_enabled: bool,
}
impl SynthPlayer {
pub fn new(handle: Handle<SoundFontAsset>, midi_input_enabled: bool) -> Self {
Self {
handle,
midi_input_enabled,
}
}
pub fn handle(&self) -> &Handle<SoundFontAsset> {
&self.handle
}
}
#[derive(Component, Default)]
pub struct SynthCommands {
pub queue: Vec<ChannelVoiceMessage>,
}
impl SynthCommands {
pub fn send(&mut self, command: ChannelVoiceMessage) {
self.queue.push(command);
}
pub fn send_batch(&mut self, commands: impl IntoIterator<Item = ChannelVoiceMessage>) {
self.queue.extend(commands);
}
pub fn take(&mut self) -> Vec<ChannelVoiceMessage> {
std::mem::take(&mut self.queue)
}
}