Time Based Gate Using Pulses Per Quarter Note?


#1

Hi,

I am building a plugin that is basically a gate that cuts according to time. So if you set the speed to 2 for example, the audio will cut from max volume to min volume twice a bar. I have already coded a bug free GUI that works fine.

What is the best way to work out what position in the bar you are in and hence when to close the gate and when to open the gate.

My idea was to use the ppqPosition function within the processBlock method , but will ppq reset to 0 every time the host is paused and the played? If so how do I get round this? Also any other ideas?

Thanks for any help!

Matt


#2

You need a few values from the CurrentPositionInfo Struct.

Here’s some code from my arp:

 CurrentPositionInfo pos;
     if (getCurrentPositionInfo (pos))
     {
      arp->processMidi(midiMessages, (int)getSampleRate(), pos.isPlaying, pos.ppqPosition, pos.ppqPositionOfLastBarStart, pos.bpm, output.getNumSamples());

     }

Then you need to calculate the samples per step which will probably look something like:

SamplesPerStep = (int(60 / bpm) * SampleRate * 4);

Now you know the distance between the on and off in samples, so all you need to do is figure out how far along in the count you are for a given start position:

SampleCount = int((ppqPosition - ppqPositionOfLastBarStart) * ((60 / bpm) * SampleRate));

Here, sampleCount is an accumulator, an when it exceeds SamplesPerStep you know it’s time to fire off what ever even it is you want to trigger.