mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +01:00
extract fn switchover
This commit is contained in:
parent
b2680914d7
commit
0c850913f9
1 changed files with 37 additions and 26 deletions
|
|
@ -17,7 +17,9 @@ impl Audio for PhrasePlayer {
|
|||
// Clear output buffer(s)
|
||||
self.clear(scope, false);
|
||||
// Write chunk of phrase to output, handle switchover
|
||||
self.play(scope);
|
||||
if self.play(scope) {
|
||||
self.switchover(scope);
|
||||
}
|
||||
if has_midi_inputs {
|
||||
if self.recording || self.monitoring {
|
||||
// Record and/or monitor input
|
||||
|
|
@ -34,8 +36,15 @@ impl Audio for PhrasePlayer {
|
|||
}
|
||||
/// Methods used primarily by the process callback
|
||||
impl PhrasePlayer {
|
||||
fn has_midi_inputs (&self) -> bool { self.midi_inputs.len() > 0 }
|
||||
fn has_midi_outputs (&self) -> bool { self.midi_outputs.len() > 0 }
|
||||
fn is_rolling (&self) -> bool {
|
||||
*self.clock.playing.read().unwrap() == Some(TransportState::Rolling)
|
||||
}
|
||||
fn has_midi_inputs (&self) -> bool {
|
||||
self.midi_inputs.len() > 0
|
||||
}
|
||||
fn has_midi_outputs (&self) -> bool {
|
||||
self.midi_outputs.len() > 0
|
||||
}
|
||||
/// Clear the section of the output buffer that we will be using,
|
||||
/// emitting "all notes off" at start of buffer if requested.
|
||||
fn clear (&mut self, scope: &ProcessScope, force_reset: bool) {
|
||||
|
|
@ -46,16 +55,14 @@ impl PhrasePlayer {
|
|||
all_notes_off(&mut self.midi_out_buf); self.reset = false;
|
||||
}
|
||||
}
|
||||
fn is_rolling (&self) -> bool {
|
||||
*self.clock.playing.read().unwrap() == Some(TransportState::Rolling)
|
||||
}
|
||||
fn play (&mut self, scope: &ProcessScope) {
|
||||
fn play (&mut self, scope: &ProcessScope) -> bool {
|
||||
let sample0 = scope.last_frame_time() as usize;
|
||||
let samples = scope.n_frames() as usize;
|
||||
let mut next = false;
|
||||
// Write MIDI events from currently playing phrase (if any) to MIDI output buffer
|
||||
if self.is_rolling() {
|
||||
// If no phrase is playing, prepare for switchover immediately
|
||||
let mut next = self.phrase.is_none();
|
||||
next = self.phrase.is_none();
|
||||
if let Some((started, phrase)) = &self.phrase {
|
||||
// First sample to populate. Greater than 0 means that the first
|
||||
// pulse of the phrase falls somewhere in the middle of the chunk.
|
||||
|
|
@ -105,8 +112,13 @@ impl PhrasePlayer {
|
|||
}
|
||||
}
|
||||
}
|
||||
// If it's time for the next enqueued phrase, handle it here:
|
||||
if next {
|
||||
}
|
||||
next
|
||||
}
|
||||
fn switchover (&mut self, scope: &ProcessScope) {
|
||||
let sample0 = scope.last_frame_time() as usize;
|
||||
let samples = scope.n_frames() as usize;
|
||||
if self.is_rolling() {
|
||||
if let Some((start_at, phrase)) = &self.next_phrase {
|
||||
let start = start_at.sample.get() as usize;
|
||||
// If it's time to switch to the next phrase:
|
||||
|
|
@ -126,7 +138,6 @@ impl PhrasePlayer {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fn record (&mut self, scope: &ProcessScope) {
|
||||
let sample0 = scope.last_frame_time() as usize;
|
||||
if let (true, Some((started, phrase))) = (self.is_rolling(), &self.phrase) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue