mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 04:06:45 +01:00
wip: refactor pt.19: 22 errors
This commit is contained in:
parent
2be2c8aca2
commit
914c2d6c09
12 changed files with 78 additions and 61 deletions
|
|
@ -6,3 +6,4 @@ version = "0.1.0"
|
|||
[dependencies]
|
||||
tek_core = { path = "../tek_core" }
|
||||
tek_api = { path = "../tek_api" }
|
||||
livi = "0.7.4"
|
||||
|
|
|
|||
|
|
@ -5,5 +5,8 @@ pub(crate) use tek_core::midly::{*, live::LiveEvent, num::u7};
|
|||
submod! {
|
||||
snd_arrange
|
||||
snd_mixer
|
||||
snd_plugin
|
||||
snd_sampler
|
||||
snd_sequencer
|
||||
snd_transport
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ impl From<&Arc<RwLock<Arrangement>>> for ArrangementAudio {
|
|||
impl Audio for ArrangementAudio {
|
||||
#[inline] fn process (&mut self, client: &Client, scope: &ProcessScope) -> Control {
|
||||
for track in self.model.write().unwrap().tracks.iter_mut() {
|
||||
if track.player.process(client, scope) == Control::Quit {
|
||||
if MIDIPlayerAudio::from(&mut track.player).process(client, scope) == Control::Quit {
|
||||
return Control::Quit
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,18 +1,17 @@
|
|||
use crate::*;
|
||||
|
||||
pub struct PluginAudio {
|
||||
model: Arc<RwLock<Plugin>>
|
||||
}
|
||||
pub struct PluginAudio(Arc<RwLock<Plugin>>);
|
||||
|
||||
impl From<&Arc<RwLock<Plugin>>> for PluginAudio {
|
||||
fn from (model: &Arc<RwLock<Plugin>>) -> Self {
|
||||
Self { model: model.clone() }
|
||||
Self(model.clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl Audio for PluginAudio {
|
||||
fn process (&mut self, _: &Client, scope: &ProcessScope) -> Control {
|
||||
match self.plugin.as_mut() {
|
||||
let state = &mut*self.0.write().unwrap();
|
||||
match state.plugin.as_mut() {
|
||||
Some(PluginKind::LV2(LV2Plugin {
|
||||
features,
|
||||
ref mut instance,
|
||||
|
|
@ -21,7 +20,7 @@ impl Audio for PluginAudio {
|
|||
})) => {
|
||||
let urid = features.midi_urid();
|
||||
input_buffer.clear();
|
||||
for port in self.midi_ins.iter() {
|
||||
for port in state.midi_ins.iter() {
|
||||
let mut atom = ::livi::event::LV2AtomSequence::new(
|
||||
&features,
|
||||
scope.n_frames() as usize
|
||||
|
|
@ -39,7 +38,7 @@ impl Audio for PluginAudio {
|
|||
input_buffer.push(atom);
|
||||
}
|
||||
let mut outputs = vec![];
|
||||
for _ in self.midi_outs.iter() {
|
||||
for _ in state.midi_outs.iter() {
|
||||
outputs.push(::livi::event::LV2AtomSequence::new(
|
||||
&features,
|
||||
scope.n_frames() as usize
|
||||
|
|
@ -48,8 +47,8 @@ impl Audio for PluginAudio {
|
|||
let ports = ::livi::EmptyPortConnections::new()
|
||||
.with_atom_sequence_inputs(input_buffer.iter())
|
||||
.with_atom_sequence_outputs(outputs.iter_mut())
|
||||
.with_audio_inputs(self.audio_ins.iter().map(|o|o.as_slice(scope)))
|
||||
.with_audio_outputs(self.audio_outs.iter_mut().map(|o|o.as_mut_slice(scope)));
|
||||
.with_audio_inputs(state.audio_ins.iter().map(|o|o.as_slice(scope)))
|
||||
.with_audio_outputs(state.audio_outs.iter_mut().map(|o|o.as_mut_slice(scope)));
|
||||
unsafe {
|
||||
instance.run(scope.n_frames() as usize, ports).unwrap()
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,51 +1,50 @@
|
|||
use crate::*;
|
||||
|
||||
pub struct SequencerAudio {
|
||||
transport: Arc<RwLock<Transport>>,
|
||||
player: Arc<RwLock<MIDIPlayer>>,
|
||||
}
|
||||
pub struct SequencerAppAudio<'a>(&'a mut Transport, &'a mut MIDIPlayer);
|
||||
|
||||
/// JACK process callback for sequencer app
|
||||
impl Audio for SequencerAudio {
|
||||
impl<'a> Audio for SequencerAppAudio<'a> {
|
||||
fn process (&mut self, client: &Client, scope: &ProcessScope) -> Control {
|
||||
self.transport.write().unwrap().process(client, scope);
|
||||
self.player.write().unwrap().process(client, scope);
|
||||
if TransportAudio::from(&mut*self.0).process(client, scope) == Control::Quit {
|
||||
return Control::Quit
|
||||
}
|
||||
if MIDIPlayerAudio::from(&mut*self.1).process(client, scope) == Control::Quit {
|
||||
return Control::Quit
|
||||
}
|
||||
Control::Continue
|
||||
}
|
||||
}
|
||||
|
||||
pub struct MIDIPlayerAudio {
|
||||
model: Arc<RwLock<MIDIPlayer>>
|
||||
}
|
||||
pub struct MIDIPlayerAudio<'a>(&'a mut MIDIPlayer);
|
||||
|
||||
impl From<&Arc<RwLock<MIDIPlayer>>> for MIDIPlayerAudio {
|
||||
fn from (model: &Arc<RwLock<MIDIPlayer>>) -> Self {
|
||||
Self { model: model.clone() }
|
||||
impl<'a> From<&'a mut MIDIPlayer> for MIDIPlayerAudio<'a> {
|
||||
fn from (model: &'a mut MIDIPlayer) -> Self {
|
||||
Self(model)
|
||||
}
|
||||
}
|
||||
|
||||
/// JACK process callback for a sequencer's phrase player/recorder.
|
||||
impl Audio for MIDIPlayer {
|
||||
impl<'a> Audio for MIDIPlayerAudio<'a> {
|
||||
fn process (&mut self, _: &Client, scope: &ProcessScope) -> Control {
|
||||
let has_midi_outputs = self.has_midi_outputs();
|
||||
let has_midi_inputs = self.has_midi_inputs();
|
||||
let has_midi_outputs = self.0.has_midi_outputs();
|
||||
let has_midi_inputs = self.0.has_midi_inputs();
|
||||
// Clear output buffer(s)
|
||||
self.clear(scope, false);
|
||||
self.0.clear(scope, false);
|
||||
// Write chunk of phrase to output, handle switchover
|
||||
if self.play(scope) {
|
||||
self.switchover(scope);
|
||||
if self.0.play(scope) {
|
||||
self.0.switchover(scope);
|
||||
}
|
||||
if has_midi_inputs {
|
||||
if self.recording || self.monitoring {
|
||||
if self.0.recording || self.0.monitoring {
|
||||
// Record and/or monitor input
|
||||
self.record(scope)
|
||||
} else if has_midi_outputs && self.monitoring {
|
||||
self.0.record(scope)
|
||||
} else if has_midi_outputs && self.0.monitoring {
|
||||
// Monitor input to output
|
||||
self.monitor(scope)
|
||||
self.0.monitor(scope)
|
||||
}
|
||||
}
|
||||
// Write to output port(s)
|
||||
self.write(scope);
|
||||
self.0.write(scope);
|
||||
Control::Continue
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,24 +1,23 @@
|
|||
use crate::*;
|
||||
|
||||
pub struct TransportAudio {
|
||||
model: Transport
|
||||
}
|
||||
pub struct TransportAudio<'a>(&'a mut Transport);
|
||||
|
||||
impl From<&Arc<RwLock<Transport>>> for TransportAudio {
|
||||
fn from (model: &Arc<RwLock<Transport>>) -> Self {
|
||||
Self { model: model.clone() }
|
||||
impl<'a> From<&'a mut Transport> for TransportAudio<'a> {
|
||||
fn from (model: &'a mut Transport) -> Self {
|
||||
Self(model)
|
||||
}
|
||||
}
|
||||
|
||||
impl Audio for Transport {
|
||||
impl<'a> Audio for TransportAudio<'a> {
|
||||
fn process (&mut self, _: &Client, scope: &ProcessScope) -> Control {
|
||||
let times = scope.cycle_times().unwrap();
|
||||
let state = &mut self.0;
|
||||
let times = scope.cycle_times().unwrap();
|
||||
let CycleTimes { current_frames, current_usecs, next_usecs: _, period_usecs: _ } = times;
|
||||
let _chunk_size = scope.n_frames() as usize;
|
||||
let transport = self.transport.query().unwrap();
|
||||
self.clock.current.sample.set(transport.pos.frame() as f64);
|
||||
let mut playing = self.clock.playing.write().unwrap();
|
||||
let mut started = self.clock.started.write().unwrap();
|
||||
let transport = state.transport.query().unwrap();
|
||||
state.clock.current.sample.set(transport.pos.frame() as f64);
|
||||
let mut playing = state.clock.playing.write().unwrap();
|
||||
let mut started = state.clock.started.write().unwrap();
|
||||
if *playing != Some(transport.state) {
|
||||
match transport.state {
|
||||
TransportState::Rolling => {
|
||||
|
|
@ -34,7 +33,7 @@ impl Audio for Transport {
|
|||
if *playing == Some(TransportState::Stopped) {
|
||||
*started = None;
|
||||
}
|
||||
self.clock.current.update_from_usec(match *started {
|
||||
state.clock.current.update_from_usec(match *started {
|
||||
Some((_, usecs)) => current_usecs as f64 - usecs as f64,
|
||||
None => 0.
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue