How to code a freeze track feature?

I’ve built a little sequencer and I’m trying to figure out how to get a freeze/render feature integrated. I have different objects holding audiosamplebuffers with different attributes like startsample, end sample, etc. and positions in the sequencing track, all of this works fine but I’m a bit stumped on how to render it…

I’m imagining I create a masteraudiosample buffer, somehow reuse the login from pluginproccer::processblock but with my own buffer, but if I iterate beyond the regular 256 samples per call and at a different time I’m not sure how to make sure everything stays sync’d properly on the track… maybe translate the position in the grid to the actual sample that it would be called on?

Just looking for some general advice if anyone’s done this before?

Is your sequencer a plugin or a host?

If it’s a host take a look at the tracktion engine: don’t know if it has a full freeze implementation but there’s a suspect track::isfrozen member laying around see here https://github.com/Tracktion/tracktion_engine/blob/6e39f07c040323b6b4e04300ddee49fd28c04016/modules/tracktion_engine/model/tracks/tracktion_AudioTrack.h

If it’s not a host i.e. you do not own the transport I really have no idea how to do this, unless you create a fake transport inside your plugin and ‘play’ it from bar/beat X to bar/beat Y
Again check the tracktion engine, or even the juce plugin host might have a transport you can start frome maybe.

Thanks for the link, I’ve figured it out, sometimes just typing the post is enough to give me the right direction haha! I’m making a plugin,

Basically my approach is:

  1. creating a master audiosamplebuffer which is the length of the song
  2. converting the different elements positions into samples (float adj = 60 / m_poTrack->m_fBPM; double samplesPerSecond = 44100 * adj; return p_iPosition * samplesPerSecon), and then
  3. basically looping over my data and using copyFrom and addFrom as necessary to recraft the track,
  4. finally writing as wav and done :slight_smile:
1 Like

For people wondering about Tracktion and freeze.

Renderer::renderToProjectItem ()

Actually im realizing that it’s annoying keeping track of when to copy and when to add… since using addFrom when there’s nothing in the buffer doesn’t seem to do anything :frowning:

EDIT: Ah just needed to call clear() on the buffer first and now we’re golden :slight_smile: Cheers

I’m a bit confused about what’s being asked here.
Are you trying to implement a freeze feature inside a plugin? If so, why?
What if the host changes the tempo as it plays back?

It’s almost always only the host’s responsibility to freeze tracks as the only real reason for doing this is CPU/memory consumption and only the host will have an idea about what parts of a session are causing problems…