Getting PlayHead from AudioProcessorPlayer? (feature request)

i’ve been slowly grinding away at a small daw app that uses an AudioProcessorPlayer and a Custom AudioProcessor (just one for now) to playback audio, that is all set up and working fine so far but i’m having issues getting the PlayHead from the AudioProcessorPlayer.

whenever i call player.getCurrentProcessor()->getPlayHead() it returns null, maybe due to the fact that the AudioProcessorPlayer’s PlayHead class gets created and initialised in AudioProcessorPlayer::audioDeviceIOCallbackWithContext. is there any reason its not held as a private member and is done like this and if not would it be possible to change it to make it a private member with a more simple getPlayHead() directly from the player?

Quickly looking, what the AudioProcessorPlayer is doing is that it uses that very simple custom playhead object if the wrapped AudioProcessor doesn’t already have its own. So what I think you should do is to implement the playhead yourself for your custom AudioProcessor.

thanks for having a quick look, so if i’m trying to keep the PlayHead agnostic from the AudioProcessor’s process block (all that should need to worry about is using the getPlayHead method), what do you think is the best way to advance my derived PlayHead? (i’d like to be able to advance info.setHostTimeNs (hostTimeNs); info.setTimeInSamples ((int64_t) sampleCount); info.setTimeInSeconds (seconds); in the same way the AudioProcessorPlayer is doing it but have no way to access host time and sample count?

Hmm, as I understand things, the Playhead is used by the plugin to ask the daw, “Where are we?” in terms of seconds or samples from play start, current tempo, bpm etc.

As you are making the daw yourself, you are (that is the daw is) the one that should provide this info for anyone that needs it. There’s no one else there who knows.

If you’re not already collecting this information, it’s time to do it. A good place is to start counting samples is in the processBlock or any othe part of your daw that processes the samples being played. And from this you should be able to calculate other stuff like time in seconds etc.

yeah, i’m using a processor player to play my audio processor, i don’t really know how to get all that from there which is the issue!

As I said, start counting/accumulating the samples in the processBlock, sort of

void processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiBuffer) 
{
//... your other stuff

   timeLinePosInSamples += buffer.getNumSamples();
}

set timeLinePosInSamples = 0, at play start

ah yeah, its important if i keep my derived playhead agnostic from my AudioProcessor, so i can’t use it in my processBlock

To be honest I don’t understand what you need the Playhead for in the first place. It’s as I said used by plugins to ask the daw for it’s current play position in time. And since you’re making the actual daw, it’s only you who can provide this information, the playHead is not going to help you with that. It’s just (sometimes) convenient structure to use to put this information in.

A stand alone application like yours looks something like AudioDevice->input => your one or more processBlock functions => AudioDevice->output. It’s somewhere in this chain you’ll have to tap the information (number of played samples) you need. If you don’t want to collect this in the processBlock function, put a breakpoint there in the debugger and step through to the next function (and previous) to see i fyou find any better place to count the samples.

thanks! thats a good tip about the breakpoint and stepping through :slight_smile: