mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +01:00
fold Phrase::process_out into PhrasePlayer::process
This commit is contained in:
parent
a1453908d3
commit
d64f4b8af7
1 changed files with 18 additions and 29 deletions
|
|
@ -19,12 +19,25 @@ impl<E: Engine> Audio for PhrasePlayer<E> {
|
|||
let has_midi_inputs = self.has_midi_inputs();
|
||||
let quant = self.clock.quant();
|
||||
if let Some((start_frame, phrase)) = self.playing_phrase() {
|
||||
// Write chunk of phrase to output
|
||||
phrase.read().map(|phrase|{
|
||||
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)
|
||||
);
|
||||
let output = &mut self.midi_out_buf;
|
||||
let notes_on = &mut self.notes_out.write().unwrap();
|
||||
let frame0 = frame0.saturating_sub(start_frame);
|
||||
let mut buf = Vec::with_capacity(8);
|
||||
let ticks = Ticks(self.clock.timebase.pulses_per_sample());
|
||||
for (time, tick) in ticks.between_samples(frame0, frame0 + frames) {
|
||||
let tick = tick % phrase.length;
|
||||
for message in phrase.notes[tick].iter() {
|
||||
buf.clear();
|
||||
let channel = 0.into();
|
||||
let message = *message;
|
||||
LiveEvent::Midi { channel, message }.write(&mut buf).unwrap();
|
||||
output[time as usize].push(buf.clone());
|
||||
update_keys(notes_on, &message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}).unwrap();
|
||||
let mut phrase = phrase.write().unwrap();
|
||||
|
|
@ -57,8 +70,8 @@ impl<E: Engine> Audio for PhrasePlayer<E> {
|
|||
}
|
||||
} else if has_midi_inputs && has_midi_outputs && self.monitoring {
|
||||
let mut notes_in = self.notes_in.write().unwrap();
|
||||
// Monitor each input
|
||||
for input in self.midi_inputs.iter() {
|
||||
// Monitor each input
|
||||
for (frame, event, bytes) in parse_midi_input(input.iter(scope)) {
|
||||
if let LiveEvent::Midi { message, .. } = event {
|
||||
self.midi_out_buf[frame].push(bytes.to_vec());
|
||||
|
|
@ -96,30 +109,6 @@ impl<E: Engine> PhrasePlayer<E> {
|
|||
}
|
||||
}
|
||||
}
|
||||
impl Phrase {
|
||||
/// Write a chunk of MIDI events to an output port.
|
||||
pub fn process_out (
|
||||
&self,
|
||||
output: &mut PhraseChunk,
|
||||
notes_on: &mut [bool;128],
|
||||
timebase: &Timebase,
|
||||
(frame0, frames): (usize, usize),
|
||||
) {
|
||||
let mut buf = Vec::with_capacity(8);
|
||||
let ticks = Ticks(timebase.pulses_per_sample()).between_samples(frame0, frame0 + frames);
|
||||
for (time, tick) in ticks {
|
||||
let tick = tick % self.length;
|
||||
for message in self.notes[tick].iter() {
|
||||
buf.clear();
|
||||
let channel = 0.into();
|
||||
let message = *message;
|
||||
LiveEvent::Midi { channel, message }.write(&mut buf).unwrap();
|
||||
output[time as usize].push(buf.clone());
|
||||
update_keys(notes_on, &message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/// Add "all notes off" to the start of a buffer.
|
||||
pub fn all_notes_off (output: &mut PhraseChunk) {
|
||||
let mut buf = vec![];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue