Best way to delay an "event" like a frequency change for an oscillator by a certain amount of time with startNote and stopNote?

I have a basic synthesiser working. For my more complex designs, I need to be able to delay certain “events” like, for example, when a sine wave should change frequency on a ‘startNote’ trigger, by a certain amount of time.

ie. Here is a basic synth voice I am playing with:

Here is the basic code for the oscillator from Maximilian library:

What would be the most useful or practical way to write something that will delay the frequency change of the oscillator by an arbitrary amount, such as 10 ms?

Should I write a for loop sort of like in an envelope code like this, triggered by noteOn that just counts up by sample until a certain number of samples are reached? Then once that condition is met, frequencyDelayed = frequency, and feed frequencyDelayed into the oscillator?

^ That is using a switch with cases for each envelope stage. I presume I might need the same technique for this as well so the thing knows when to start looping or not. Ie. On startNote, enter the switch case that triggers beginning the counting loop. Once the number of samples are met, switch to the case that triggers ‘frequencyDelayed = frequency’, and it can just idle there or go to another separate idle case until the next startNote.

Does this make sense? Or is there a more sensible way of doing this?

I have access to an audio delay I’ve implemented from Maximilian, but I’m not sure if that is any use in this utility. In Reaktor this was done just by feeding the GateOn or Pitch data into a delay unit by a certain number of ms.

Thinking about it more, if I were to use the approach I mentioned, it would likely work “okay” but it’s not ideal, because if multiple events were to happen during the “delay” phase, they would be lost, rather than passed along in a delayed sequence. So there probably needs to be some “buffer” function to hold the values and pass them along in order when they are due.

I imagine this is more of a general C++ problem than a JUCE specific one. If anyone can at least outline the general or types of C++ techniques I’d need to solve this, that might at least get the ball rolling for me.


not an answer, but you can paste code directly, instead of screenshots like you’re currently doing, if you put three backticks on the lines before and after your code.

this symbol: ```