mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 04:06:45 +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
|
Control::Continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<E: Engine> PhrasePlayer<E> {
|
impl<E: Engine> Audio for PhrasePlayer<E> {
|
||||||
pub fn process (
|
fn process (&mut self, _: &Client, scope: &ProcessScope) -> Control {
|
||||||
&mut self,
|
let frame0 = scope.last_frame_time() as usize;
|
||||||
scope: &ProcessScope,
|
let frames = scope.n_frames() as usize;
|
||||||
(frame0, frames): (usize, usize),
|
|
||||||
(_usec0, _usecs): (usize, usize),
|
|
||||||
period: f64,
|
|
||||||
) {
|
|
||||||
let has_midi_outputs = self.has_midi_outputs();
|
let has_midi_outputs = self.has_midi_outputs();
|
||||||
if has_midi_outputs {
|
if has_midi_outputs {
|
||||||
self.clear_midi_out_buf(frames);
|
self.clear_midi_out_buf(frames);
|
||||||
|
|
@ -27,7 +23,7 @@ impl<E: Engine> PhrasePlayer<E> {
|
||||||
if has_midi_outputs {
|
if has_midi_outputs {
|
||||||
phrase.process_out(
|
phrase.process_out(
|
||||||
&mut self.midi_out_buf, &mut self.notes_out.write().unwrap(),
|
&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();
|
}).unwrap();
|
||||||
|
|
@ -41,9 +37,7 @@ impl<E: Engine> PhrasePlayer<E> {
|
||||||
for input in self.midi_inputs.iter() {
|
for input in self.midi_inputs.iter() {
|
||||||
for (frame, event, bytes) in parse_midi_input(input.iter(scope)) {
|
for (frame, event, bytes) in parse_midi_input(input.iter(scope)) {
|
||||||
if let LiveEvent::Midi { message, .. } = event {
|
if let LiveEvent::Midi { message, .. } = event {
|
||||||
if self.monitoring {
|
if self.monitoring { self.midi_out_buf[frame].push(bytes.to_vec()) }
|
||||||
self.midi_out_buf[frame].push(bytes.to_vec())
|
|
||||||
}
|
|
||||||
if self.recording {
|
if self.recording {
|
||||||
phrase.record_event({
|
phrase.record_event({
|
||||||
let pulse = self.clock.timebase.samples_to_pulse(
|
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() {
|
for port in self.midi_outputs.iter_mut() {
|
||||||
let writer = &mut port.writer(scope);
|
let writer = &mut port.writer(scope);
|
||||||
let output = &self.midi_out_buf;
|
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_inputs (&self) -> bool { self.midi_inputs.len() > 0 }
|
||||||
pub fn has_midi_outputs (&self) -> bool { self.midi_outputs.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
|
/// 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
|
/// Emit "all notes off" at start of buffer if requested
|
||||||
pub fn reset_midi_out_buf (&mut self, force_reset: bool) {
|
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);
|
all_notes_off(&mut self.midi_out_buf);
|
||||||
self.reset = false;
|
self.reset = false;
|
||||||
} else if force_reset {
|
|
||||||
all_notes_off(&mut self.midi_out_buf);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -108,7 +103,7 @@ impl Phrase {
|
||||||
output: &mut PhraseChunk,
|
output: &mut PhraseChunk,
|
||||||
notes_on: &mut [bool;128],
|
notes_on: &mut [bool;128],
|
||||||
timebase: &Timebase,
|
timebase: &Timebase,
|
||||||
(frame0, frames, _): (usize, usize, f64),
|
(frame0, frames): (usize, usize),
|
||||||
) {
|
) {
|
||||||
let mut buf = Vec::with_capacity(8);
|
let mut buf = Vec::with_capacity(8);
|
||||||
let ticks = Ticks(timebase.pulses_per_sample()).between_samples(frame0, frame0 + frames);
|
let ticks = Ticks(timebase.pulses_per_sample()).between_samples(frame0, frame0 + frames);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue