From 52d7b47a24bbf4a4bccc016f9936b9ff2bc542f0 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Fri, 8 Apr 2022 23:10:38 +0200 Subject: [PATCH] Improve block splitting transport information Don't do any recomputations at the start of the buffer, and also recompute the bar positions and numbers. --- src/wrapper/clap/wrapper.rs | 23 +++++++++++++++++++---- src/wrapper/vst3/wrapper.rs | 16 ++++++++++++++-- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/wrapper/clap/wrapper.rs b/src/wrapper/clap/wrapper.rs index 2e10abf9..91742b35 100644 --- a/src/wrapper/clap/wrapper.rs +++ b/src/wrapper/clap/wrapper.rs @@ -1349,8 +1349,11 @@ impl Wrapper

{ if context.flags & CLAP_TRANSPORT_HAS_BEATS_TIMELINE != 0 { let beats = context.song_pos_beats as f64 / CLAP_BEATTIME_FACTOR as f64; - // This is a bit messy, but we'll try to compensate for the block splitting + // This is a bit messy, but we'll try to compensate for the block splitting. + // We can't use the functions on the transport information object for this + // because we don't have any sample information. if P::SAMPLE_ACCURATE_AUTOMATION + && block_start > 0 && (context.flags & CLAP_TRANSPORT_HAS_TEMPO != 0) { transport.pos_beats = Some( @@ -1367,6 +1370,7 @@ impl Wrapper

{ // Same here if P::SAMPLE_ACCURATE_AUTOMATION + && block_start > 0 && (context.flags & CLAP_TRANSPORT_HAS_TEMPO != 0) { transport.pos_seconds = @@ -1376,9 +1380,20 @@ impl Wrapper

{ } } // TODO: CLAP does not mention whether this is behind a flag or not - transport.bar_start_pos_beats = - Some(context.bar_start as f64 / CLAP_BEATTIME_FACTOR as f64); - transport.bar_number = Some(context.bar_number); + if P::SAMPLE_ACCURATE_AUTOMATION && block_start > 0 { + transport.bar_start_pos_beats = match transport.bar_start_pos_beats() { + Some(updated) => Some(updated), + None => Some(context.bar_start as f64 / CLAP_BEATTIME_FACTOR as f64), + }; + transport.bar_number = match transport.bar_number() { + Some(updated) => Some(updated), + None => Some(context.bar_number), + }; + } else { + transport.bar_start_pos_beats = + Some(context.bar_start as f64 / CLAP_BEATTIME_FACTOR as f64); + transport.bar_number = Some(context.bar_number); + } // TODO: They also aren't very clear about this, but presumably if the loop is // active and the corresponding song transport information is available then // this is also available diff --git a/src/wrapper/vst3/wrapper.rs b/src/wrapper/vst3/wrapper.rs index 04cab378..d44dedd5 100644 --- a/src/wrapper/vst3/wrapper.rs +++ b/src/wrapper/vst3/wrapper.rs @@ -994,7 +994,10 @@ impl IAudioProcessor for Wrapper

{ Some(context.project_time_samples + block_start as i64); if context.state & (1 << 9) != 0 { // kProjectTimeMusicValid - if P::SAMPLE_ACCURATE_AUTOMATION && (context.state & (1 << 10) != 0) { + if P::SAMPLE_ACCURATE_AUTOMATION + && block_start > 0 + && (context.state & (1 << 10) != 0) + { // kTempoValid transport.pos_beats = Some( context.project_time_music @@ -1008,7 +1011,16 @@ impl IAudioProcessor for Wrapper

{ if context.state & (1 << 11) != 0 { // kBarPositionValid - transport.bar_start_pos_beats = Some(context.bar_position_music); + if P::SAMPLE_ACCURATE_AUTOMATION && block_start > 0 { + // The transport object knows how to recompute this from the other information + transport.bar_start_pos_beats = + match transport.bar_start_pos_beats() { + Some(updated) => Some(updated), + None => Some(context.bar_position_music), + }; + } else { + transport.bar_start_pos_beats = Some(context.bar_position_music); + } } if context.state & (1 << 2) != 0 && context.state & (1 << 12) != 0 { // kCycleActive && kCycleValid