mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
device: add DeviceAudio dispatcher
This commit is contained in:
parent
fb99128650
commit
c78b2dc9de
3 changed files with 62 additions and 34 deletions
|
|
@ -2,26 +2,20 @@ use crate::*;
|
||||||
impl HasJack for App { fn jack (&self) -> &Jack { &self.jack } }
|
impl HasJack for App { fn jack (&self) -> &Jack { &self.jack } }
|
||||||
audio!(
|
audio!(
|
||||||
|self: App, client, scope|{
|
|self: App, client, scope|{
|
||||||
|
|
||||||
// Start profiling cycle
|
// Start profiling cycle
|
||||||
let t0 = self.perf.get_t0();
|
let t0 = self.perf.get_t0();
|
||||||
|
|
||||||
// Update transport clock
|
// Update transport clock
|
||||||
self.clock().update_from_scope(scope).unwrap();
|
self.clock().update_from_scope(scope).unwrap();
|
||||||
// Collect MIDI input (TODO preallocate)
|
|
||||||
|
// Collect MIDI input (TODO preallocate large buffers)
|
||||||
let midi_in = self.midi_ins.iter()
|
let midi_in = self.midi_ins.iter()
|
||||||
.map(|port|port.port().iter(scope)
|
.map(|port|port.port().iter(scope)
|
||||||
.map(|RawMidi { time, bytes }|(time, LiveEvent::parse(bytes)))
|
.map(|RawMidi { time, bytes }|(time, LiveEvent::parse(bytes)))
|
||||||
.collect::<Vec<_>>())
|
.collect::<Vec<_>>())
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
// Update standalone MIDI sequencer
|
|
||||||
//if let Some(player) = self.player.as_mut() {
|
|
||||||
//if Control::Quit == PlayerAudio(
|
|
||||||
//player,
|
|
||||||
//&mut self.note_buf,
|
|
||||||
//&mut self.midi_buf,
|
|
||||||
//).process(client, scope) {
|
|
||||||
//return Control::Quit
|
|
||||||
//}
|
|
||||||
//}
|
|
||||||
// Update standalone sampler
|
// Update standalone sampler
|
||||||
//if let Some(sampler) = self.sampler.as_mut() {
|
//if let Some(sampler) = self.sampler.as_mut() {
|
||||||
//if Control::Quit == SamplerAudio(sampler).process(client, scope) {
|
//if Control::Quit == SamplerAudio(sampler).process(client, scope) {
|
||||||
|
|
@ -35,6 +29,7 @@ audio!(
|
||||||
//}
|
//}
|
||||||
//}
|
//}
|
||||||
//}
|
//}
|
||||||
|
|
||||||
// TODO move these to editor and sampler?:
|
// TODO move these to editor and sampler?:
|
||||||
//for port in midi_in.iter() {
|
//for port in midi_in.iter() {
|
||||||
//for event in port.iter() {
|
//for event in port.iter() {
|
||||||
|
|
@ -58,14 +53,21 @@ audio!(
|
||||||
//}
|
//}
|
||||||
//}
|
//}
|
||||||
//}
|
//}
|
||||||
// Update track sequencers
|
|
||||||
|
// Update track sequencers and devices
|
||||||
for track in self.tracks.iter_mut() {
|
for track in self.tracks.iter_mut() {
|
||||||
if PlayerAudio(
|
if Control::Quit == PlayerAudio(
|
||||||
track.player_mut(), &mut self.note_buf, &mut self.midi_buf
|
track.player_mut(), &mut self.note_buf, &mut self.midi_buf
|
||||||
).process(client, scope) == Control::Quit {
|
).process(client, scope) {
|
||||||
return Control::Quit
|
return Control::Quit
|
||||||
}
|
}
|
||||||
|
for device in track.devices.iter_mut() {
|
||||||
|
if Control::Quit == DeviceAudio(device).process(client, scope) {
|
||||||
|
return Control::Quit
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// End profiling cycle
|
// End profiling cycle
|
||||||
self.perf.update_from_jack_scope(t0, scope);
|
self.perf.update_from_jack_scope(t0, scope);
|
||||||
Control::Continue
|
Control::Continue
|
||||||
|
|
|
||||||
43
crates/device/src/device.rs
Normal file
43
crates/device/src/device.rs
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
use crate::*;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum Device {
|
||||||
|
#[cfg(feature = "sequencer")] Sequencer(MidiPlayer),
|
||||||
|
#[cfg(feature = "sampler")] Sampler(Sampler),
|
||||||
|
#[cfg(feature = "lv2")] Lv2(Lv2), // TODO
|
||||||
|
#[cfg(feature = "vst2")] Vst2, // TODO
|
||||||
|
#[cfg(feature = "vst3")] Vst3, // TODO
|
||||||
|
#[cfg(feature = "clap")] Clap, // TODO
|
||||||
|
#[cfg(feature = "sf2")] Sf2, // TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Device {
|
||||||
|
pub fn name (&self) -> &str {
|
||||||
|
match self {
|
||||||
|
Self::Sampler(sampler) => sampler.name.as_ref(),
|
||||||
|
_ => todo!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct DeviceAudio<'a>(pub &'a mut Device);
|
||||||
|
|
||||||
|
audio!(|self: DeviceAudio<'a>, client, scope|{
|
||||||
|
use Device::*;
|
||||||
|
match self.0 {
|
||||||
|
#[cfg(feature = "sequencer")] Sequencer(sequencer) =>
|
||||||
|
{ Control::Continue /* TODO */ },
|
||||||
|
#[cfg(feature = "sampler")] Sampler(sampler) =>
|
||||||
|
SamplerAudio(sampler).process(client, scope),
|
||||||
|
#[cfg(feature = "lv2")] Lv2(lv2) =>
|
||||||
|
{ todo!() }, // TODO
|
||||||
|
#[cfg(feature = "vst2")] Vst2 =>
|
||||||
|
{ todo!() }, // TODO
|
||||||
|
#[cfg(feature = "vst3")] Vst3 =>
|
||||||
|
{ todo!() }, // TODO
|
||||||
|
#[cfg(feature = "clap")] Clap =>
|
||||||
|
{ todo!() }, // TODO
|
||||||
|
#[cfg(feature = "sf2")] Sf2 =>
|
||||||
|
{ todo!() }, // TODO
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
@ -15,6 +15,9 @@ pub(crate) use ::tek_engine::midi::{u7, LiveEvent, MidiMessage};
|
||||||
pub(crate) use ::tek_engine::jack::{Control, ProcessScope, MidiWriter, RawMidi};
|
pub(crate) use ::tek_engine::jack::{Control, ProcessScope, MidiWriter, RawMidi};
|
||||||
pub(crate) use ratatui::{prelude::Rect, widgets::{Widget, canvas::{Canvas, Line}}};
|
pub(crate) use ratatui::{prelude::Rect, widgets::{Widget, canvas::{Canvas, Line}}};
|
||||||
|
|
||||||
|
mod device;
|
||||||
|
pub use self::device::*;
|
||||||
|
|
||||||
#[cfg(feature = "clock")] mod clock;
|
#[cfg(feature = "clock")] mod clock;
|
||||||
#[cfg(feature = "clock")] pub use self::clock::*;
|
#[cfg(feature = "clock")] pub use self::clock::*;
|
||||||
|
|
||||||
|
|
@ -38,23 +41,3 @@ pub(crate) use ratatui::{prelude::Rect, widgets::{Widget, canvas::{Canvas, Line}
|
||||||
|
|
||||||
#[cfg(feature = "clap")] mod clap;
|
#[cfg(feature = "clap")] mod clap;
|
||||||
#[cfg(feature = "clap")] pub use self::clap::*;
|
#[cfg(feature = "clap")] pub use self::clap::*;
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub enum Device {
|
|
||||||
#[cfg(feature = "sequencer")] Sequencer(MidiPlayer),
|
|
||||||
#[cfg(feature = "sampler")] Sampler(Sampler),
|
|
||||||
#[cfg(feature = "lv2")] Lv2(Lv2), // TODO
|
|
||||||
#[cfg(feature = "vst2")] Vst2, // TODO
|
|
||||||
#[cfg(feature = "vst3")] Vst3, // TODO
|
|
||||||
#[cfg(feature = "clap")] Clap, // TODO
|
|
||||||
#[cfg(feature = "sf2")] Sf2, // TODO
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Device {
|
|
||||||
pub fn name (&self) -> &str {
|
|
||||||
match self {
|
|
||||||
Self::Sampler(sampler) => sampler.name.as_ref(),
|
|
||||||
_ => todo!(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue