Hey all, JUCE noob here - and C++ noob in general (Although I’m quite experienced in Java)
Basically, I’m trying to make a plugin for personal use which can be configured so on bar X, it will output a program change message to the DAW it’s running in.
I’ve got the actual timing part* done so I know which bar I’m on - what I’m struggling with is the outputting of the MIDI message. After a couple of hours of googling everything seems quite over complicated for what I’m doing, things like arpeggiators which need specific timing or stuff for writing fully-blown DAWs. My PC messages don’t need any specific timing and in fact should send as quickly as possible once the bar is reached.
So, my question is what’s the most simple way to output a MIDI message - and (I think this is where I’m having issues) how do I specify which device it should be sent to? I know on Mac you have various different devices and from my understanding I need to send it to an IAC driver in order to pass it on to the host. (What about in Windows though - I’m writing for OSX primarily but it’d be nice if I can support windows for anyone else who may want it)
I’ve tried various things but it doesn’t seem to be working. To test I’m loading it into a clean MainStage (which is what I’ll be using the final plugin in), with three patches. Sending a PC with values 1-3 into Mainstage will select those patches, but running my little AU doesn’t do anything. Also MidiMonitor shows no MIDI being passed on any device/channel, so I’m relatively confident the issue lies somewhere in my MIDI output. processBlock Code is below, and is a sort of amalgamation of stuff I’ve found from google and the tutorial code from the MIDI volume slider. (Sorry if it’s super messy/any bad practices - like I said I’m new to C++ in general but trying to learn!)
void BeatNotesAudioProcessor::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
{
playHead = this->getPlayHead();
playHead->getCurrentPosition(currentPositionInfo);
bpm = currentPositionInfo.bpm;
ppq = currentPositionInfo.ppqPosition;
midiMessages.clear();
int pcId = -1;
if (ppq >= 4.0 && ppq <= 5.0) {
//send PC 002
pcId = 2;
}
if (ppq >= 8 && ppq <= 9.0) {
//send PC 003
pcId = 3;
}
buffer.clear();
MidiBuffer processedMidi;
int time;
MidiMessage m;
for(MidiBuffer::Iterator i (midiMessages); i.getNextEvent(m, time);)
{
if (pcId >= 0) {
m = MidiMessage::programChange(1, pcId);
pcId = -1;
}
processedMidi.addEvent(m, time);
}
midiMessages.swapWith(processedMidi);
}
Any help would be great
*I’m currently getting timing info in the form of PPQ, which from what I can see is a double and every full integer = 1 beat, so the math should be pretty easy to actually figure out the bars. However, currently I’ve got my plugin GUI trying to display the current PPQ value, but it’s only updating when I click on or click off the window instead of updating in real time. For bonus points how would I get my GUI to update roughly in real time?