mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
convert PhrasePlayer::process to Audio trait
This commit is contained in:
parent
02f691c494
commit
a1453908d3
1 changed files with 12 additions and 17 deletions
|
|
@ -7,14 +7,10 @@ impl<E: Engine> Audio for Sequencer<E> {
|
|||
Control::Continue
|
||||
}
|
||||
}
|
||||
impl<E: Engine> PhrasePlayer<E> {
|
||||
pub fn process (
|
||||
&mut self,
|
||||
scope: &ProcessScope,
|
||||
(frame0, frames): (usize, usize),
|
||||
(_usec0, _usecs): (usize, usize),
|
||||
period: f64,
|
||||
) {
|
||||
impl<E: Engine> Audio for PhrasePlayer<E> {
|
||||
fn process (&mut self, _: &Client, scope: &ProcessScope) -> Control {
|
||||
let frame0 = scope.last_frame_time() as usize;
|
||||
let frames = scope.n_frames() as usize;
|
||||
let has_midi_outputs = self.has_midi_outputs();
|
||||
if has_midi_outputs {
|
||||
self.clear_midi_out_buf(frames);
|
||||
|
|
@ -27,7 +23,7 @@ impl<E: Engine> PhrasePlayer<E> {
|
|||
if has_midi_outputs {
|
||||
phrase.process_out(
|
||||
&mut self.midi_out_buf, &mut self.notes_out.write().unwrap(),
|
||||
&self.clock.timebase, (frame0.saturating_sub(start_frame), frames, period)
|
||||
&self.clock.timebase, (frame0.saturating_sub(start_frame), frames)
|
||||
);
|
||||
}
|
||||
}).unwrap();
|
||||
|
|
@ -41,9 +37,7 @@ impl<E: Engine> PhrasePlayer<E> {
|
|||
for input in self.midi_inputs.iter() {
|
||||
for (frame, event, bytes) in parse_midi_input(input.iter(scope)) {
|
||||
if let LiveEvent::Midi { message, .. } = event {
|
||||
if self.monitoring {
|
||||
self.midi_out_buf[frame].push(bytes.to_vec())
|
||||
}
|
||||
if self.monitoring { self.midi_out_buf[frame].push(bytes.to_vec()) }
|
||||
if self.recording {
|
||||
phrase.record_event({
|
||||
let pulse = self.clock.timebase.samples_to_pulse(
|
||||
|
|
@ -73,7 +67,7 @@ impl<E: Engine> PhrasePlayer<E> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Write to midi output
|
||||
for port in self.midi_outputs.iter_mut() {
|
||||
let writer = &mut port.writer(scope);
|
||||
let output = &self.midi_out_buf;
|
||||
|
|
@ -84,7 +78,10 @@ impl<E: Engine> PhrasePlayer<E> {
|
|||
}
|
||||
}
|
||||
}
|
||||
Control::Continue
|
||||
}
|
||||
}
|
||||
impl<E: Engine> PhrasePlayer<E> {
|
||||
pub fn has_midi_inputs (&self) -> bool { self.midi_inputs.len() > 0 }
|
||||
pub fn has_midi_outputs (&self) -> bool { self.midi_outputs.len() > 0 }
|
||||
/// Clear the section of the output buffer that we will be using
|
||||
|
|
@ -93,11 +90,9 @@ impl<E: Engine> PhrasePlayer<E> {
|
|||
}
|
||||
/// Emit "all notes off" at start of buffer if requested
|
||||
pub fn reset_midi_out_buf (&mut self, force_reset: bool) {
|
||||
if self.reset {
|
||||
if self.reset || force_reset {
|
||||
all_notes_off(&mut self.midi_out_buf);
|
||||
self.reset = false;
|
||||
} else if force_reset {
|
||||
all_notes_off(&mut self.midi_out_buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -108,7 +103,7 @@ impl Phrase {
|
|||
output: &mut PhraseChunk,
|
||||
notes_on: &mut [bool;128],
|
||||
timebase: &Timebase,
|
||||
(frame0, frames, _): (usize, usize, f64),
|
||||
(frame0, frames): (usize, usize),
|
||||
) {
|
||||
let mut buf = Vec::with_capacity(8);
|
||||
let ticks = Ticks(timebase.pulses_per_sample()).between_samples(frame0, frame0 + frames);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue