Sample pos 0 inside of block (Cubase), how to identify when sample 0 is reached?

I have Cubase LE AI Elements 10.5 (fresh install without custom configuration) on Windows 10.
In my JUCE VST3 plugin I take a look at the host provided transport information.
This was a bit problematic first, because the juce_VST3_Wrapper.cpp uses max() to eliminate negative values, which Cubase provides:

info.setTimeInSamples (jmax ((juce::int64) 0, processContext.projectTimeSamples));
info.setTimeInSeconds (static_cast (*info.getTimeInSamples()) / processContext.sampleRate);

To be able to further examine things, I have temporary removed the max() to see negative values.
Without any additional configuration change to Cubase, Cubase will start at timeInSamples = -8160.
The worse thing is, sample no. 0 is somewhere inside of a block, not at the start of a block.
This means, when a song in Cubase is started, we cannot tell when sample position 0 is reached. Am I wrong?
So the start of a “synchronized” LFO in e.g. an effect plugin or the start in a drum sequencer plugin will be wrong. Especially for the latter case this should be quite noticable.
Is there some kind of solution to this problem? How would it be possible to detect or calculate sample position 0 safely? Please note that I would like to revert juce_VST3_Wrapper.cpp to its original state.

timeInSamples is some sort of integer, so it can’t be -0.185034. you were probably refering to ppq, which can surely be below 0 if you start playback at 0, because of the little pre-roll it performs. this preroll can be pretty long if there are even more plugins with latency on the fx chain but it’s short typically. your dsp has to be able to deal with negative ppq. however so far i didn’t run into issues where this required extra edge case handling. you can calculate where the actual 0’s ppq is by also taking the bpm into account. when working with project positions you’ll have to do that sooner or later anyway to get precise musical values in general

Sorry about the wrong number, that was a copy/paste error. The sample pos is of course an integer. I have corrected it in my post now, it’s -8160.
So you mean, PPQ is the only way to syncronize e.g. a drum sequencer and sample number accurate starting when a song really begins playing is not possible?

1 Like