[SOLVED] Synchronizing VST with DAW MIDI Clock


#1

Hey there people !

I’m trying to create a 4x4 Cartesian Sequencer VST (feeling inspired by MakeNoise’s René module) and so far I haven’t met much difficulties with the GUI environment!
The problem is I can’t quite figure out how to get an input MIDI Clock (e.g from Ableton) and then use it in the Editor to at least have a visual feedback before I get into generating MIDI notes.
I started with the Handling MIDI Events & Slider Values examples but I don’t really know how to start.

So far my processBlock function (which I believe is the root of it all) looks like this (count variable is what I intend to use to determine my sequence):

void MatrixSequencerPluginAudioProcessor::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
{
    const int totalNumInputChannels  = getTotalNumInputChannels();
    const int totalNumOutputChannels = getTotalNumOutputChannels();
    for (int i = totalNumInputChannels; i < totalNumOutputChannels; ++i)
        buffer.clear (i, 0, buffer.getNumSamples());
    // Midi Processing
    MidiBuffer processMidi;
    int time;
    MidiMessage m;
    for(MidiBuffer::Iterator i (midiMessages); i.getNextEvent(m, time);)
    {
        if(m.isMidiClock())
        {
            count++;
            if(count%24==0) transmitFlagToEditor();
        }
    }
    //...Audio Processing part (not relevant here)
}

In short:

  • Is the isMidiClock() message the right one to get my External Clock? Or should I use the tempo-related Events such as getTempoMetaEventTickLength() ?
  • How can I set up a Listener on my Editor so that every time I get a MIDI tick I can visually move on to the next step ?

I believe this can solve a lot of my problems so thank you very much to whoever will find the time to help me!

Cheers


#2

Are you sure you need it to use MIDI clock? You can get the current playback position in your processBlock() callback by obtaining the AudioPlayHead object using getPlayHead(). Then you need to obtain the position information using AudioPlayHead::getCurrentPosition().

This gets you one of these: https://www.juce.com/doc/structAudioPlayHead_1_1CurrentPositionInfo


#3

Hi Martin, and many thanks for your reply, didn’t see those classes, seems exactly like what I need!

I found kind of a similar thread here: Getting host’s BPM from VST Plugin

Now that I can retrieve the infos in the processor, I’m still wondering how to get the ticks in my Editor though, do you have any idea on where to start ? I’m gonna check again on the forum at the same time!

Thanks again!


#4

I guess I just found what I was looking for with the Value Class !


#5

After a few problems with the Value Class (that’s a no-no for what I intended), I finally figured how to handle my events properly (thanks to you @martinrobinson & also the juce plugin demo)

The key is to start a Timer (30Hz seems reasonable for now) and use the timerCallback() function to update the GUI when a tick is generated by the DAW so only the updateCurrentInfoFromHost() function featured in the example is used in the Processor, which leads to not having any thread problems (the Value Class was actually messing up all my code because I didn’t put any mutex and frankly I’m relieved not to have to use some).

It’s actually quite simple once you get it but maybe this topic will help a rookie JUCE user one day!

Cheers!