wip: correct cycle timings (jitter eats notes)

This commit is contained in:
🪞👃🪞 2024-07-05 14:36:09 +03:00
parent e83802e1fd
commit 665885f6ff
5 changed files with 90 additions and 76 deletions

View file

@ -115,10 +115,11 @@ impl Track {
input: MidiIter,
timebase: &Arc<Timebase>,
playing: Option<TransportState>,
scope: &ProcessScope,
frame0: usize,
frames: usize,
panic: bool,
scope: &ProcessScope,
(frame0, frames): (usize, usize),
(usec0, usecs): (usize, usize),
period: f64,
) {
// Need to be borrowed outside the conditionals?
let recording = self.recording;
@ -132,14 +133,14 @@ impl Track {
all_notes_off(&mut self.midi_out_buf);
}
// Play from phrase into output buffer
if let Some(Some(phrase)) = self.sequence.map(|id|self.phrases.get(id)) {
if playing == Some(TransportState::Rolling) {
let phrase = &mut self.sequence.map(|id|self.phrases.get_mut(id)).flatten();
if playing == Some(TransportState::Rolling) {
if let Some(phrase) = phrase {
phrase.process_out(
&mut self.midi_out_buf,
&mut self.notes_on,
timebase,
frame0,
frames
(usec0, usecs, period)
);
}
}
@ -147,7 +148,6 @@ impl Track {
if self.recording || self.monitoring {
// For highlighting keys
let notes_on = &mut self.notes_on;
let phrase = &mut self.sequence.map(|id|self.phrases.get_mut(id));
for (time, event, bytes) in parse_midi_input(input) {
match event {
LiveEvent::Midi { message, .. } => {
@ -155,7 +155,7 @@ impl Track {
self.midi_out_buf[time].push(bytes.to_vec())
}
if recording {
if let Some(Some(phrase)) = phrase {
if let Some(phrase) = phrase {
let pulse = timebase.frames_pulses((frame0 + time) as f64) as usize;
let pulse = pulse % phrase.length;
let contains = phrase.notes.contains_key(&pulse);