I’m running into a strange issue with Logic Pro and AudioPlayHead’s position info.
When I put the play cursor at the start of the very first bar in the project, my plug-in gets the following positions for the playhead:
getTimeInSamples 540544
getTimeInSamples 540608
getTimeInSamples 540672
getTimeInSamples 540736
getTimeInSamples -383
getTimeInSamples -319
getTimeInSamples -255
getTimeInSamples -191
getTimeInSamples -127
getTimeInSamples -63
getTimeInSamples 0
getTimeInSamples 64
getTimeInSamples 128
getTimeInSamples 192
...
The buffer size is 64. The negative timestamps are not a problem, these are from Logic’s pre-roll feature. However the large numbers at the beginning (540544 etc) make no sense.
To reproduce this, make a new JUCE synth plug-in using Projucer and add the following code to processBlock:
if (auto* thePlayHead = getPlayHead()) {
if (auto position = thePlayHead->getPosition()) {
if (position.hasValue() && position->getIsPlaying()) {
juce::File file = juce::File::getSpecialLocation(juce::File::userDesktopDirectory).getChildFile("debug.txt");
char buf[100] = { 0 };
if (position->getTimeInSamples().hasValue()) {
snprintf(buf, 100, "getTimeInSamples %lld\n", *position->getTimeInSamples());
file.appendText(buf);
}
if (position->getTimeInSeconds().hasValue()) {
snprintf(buf, 100, "getTimeInSeconds %.10f\n", *position->getTimeInSeconds());
file.appendText(buf);
}
if (position->getPpqPosition().hasValue()) {
snprintf(buf, 100, "getPpqPosition %.10f\n", *position->getPpqPosition());
file.appendText(buf);
}
}
}
}
buffer.clear();
This logs the playhead position to a file debug.txt on the desktop.
I’m using JUCE 8.0.8, Logic Pro 11.2.2, Sequoia 15.6.1 on an ARM Mac.
Some notes:
- It does not go wrong when I use my USB audio interface (a Focusrite Scarlett). It does go wrong with my Mac’s built-in speakers. I tested with sample rate 48000.
- It seems to depend on the buffer size. With a synth plug-in, any buffer size of 256 and below gives this issue. (Update: actually managed to make it go wrong with 512 and 1024 as well, it just occurs less often.)
- With an effect plug-in, I need to enable record arming on the track to make it happen (since Logic otherwise uses a buffer size of 1024).
- You may need to enable looping to make it happen. Or repeat the test a few times (rewind to start of song, press play).
- It doesn’t just happen on my machine. It has been reproduced by other people too.
- These strange playhead positions are different every time, seemingly random. The PPQ position is also wrong.
Any thoughts? It seems like a bug in Logic to me. I couldn’t get this to happen with Logic 10.8 but that was also on a different machine, so who knows.
