Hi guys, I need to do some (I think) pretty simple VST work for a project and after a bit of messing around with JUCE, I thought it would be a good way to avoid having to deal with plugins directly.
I’m not aiming to write a full-fledged host or anything; all I need to do is put some midi events through a VST instrument and get the result for later use, but I am having a problem after getting quite close.
Some code thus far; this is the entirety of the test program I am writing:
juce::AudioPluginFormatManager::getInstance()->addDefaultFormats();
juce::OwnedArray <juce::PluginDescription> typesFound;
juce::KnownPluginList *list = new juce::KnownPluginList();
juce::File *file = new juce::File("{pathRemoved}4Front Piano Module.dll");
if(file->exists())
{
if(list->scanAndAddFile(*file, true, typesFound))
{
const juce::PluginDescription *des = list->getTypeForFile(*file);
juce::VSTPluginFormat *format = new juce::VSTPluginFormat();
juce::AudioPluginInstance *plugin = format->createInstanceFromDescription(*des);
if(plugin->acceptsMidi())
{
float midiDataGoesInHere[1];
midiDataGoesInHere[0] = 10;
float* start = midiDataGoesInHere;
juce::AudioSampleBuffer auBuff(&start, 1, 1);
juce::MidiBuffer midiBuff;
midiBuff.addEvent(juce::MidiMessage::noteOn(0, 50, (float)10), 0);
plugin->prepareToPlay(441000, 512);
plugin->processBlock(auBuff, midiBuff);
}
}
}
Stepping through, I get to the following lines in processBlock:
for (i = effect->numOutputs; --i >= 0;)
buffer.copyFrom (i, 0, outs[i], numSamples);
copyFrom then fails at
memcpy (channels [destChannel] + destStartSample,
source,
sizeof (float) * numSamples);
with the error:
An unhandled exception of type ‘System.AccessViolationException’ occurred in Audio2.exe
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Being a C# programmer in reality and this being my first foray into C++ in quite some time, I cannot figure out exactly what this memory error is. Perhaps the junk test data I am passing in is just inadequate? This particularly plugin (http://www.yohng.com/piano.html) has two outputs in case that is relevant.
Also, possibly not related, but I am not sure why VST instruments wants both MIDI input and float input?
Alsoooo, possibly bug in the JUCE code and possibly me not understanding something:
VSTPluginInstance::processBlock, the line ensureMidiEventSize (eventIndex), should it not be ensureMidiEventSize (eventIndex+1)?
Any help or suggestions greatly appreciated.