The upgrade to my C++ MIDI player to utilise VST instruments on some channels is finally nearly complete, however there is a speed issue in loading. The BASS_VST_ChannelCreate call takes up to a second to run, so in songs when (eg) 6 channels are utilising VSTi, the song can take 5-6 seconds to load which is uncomfortably long. I thought to load them simultaneously in separate threads, using join() to wait for them all to complete. However there are tricky issues with some VSTi's (especially Addictive Keys), and I wonder if you have any advice on this multi-threading idea.
I expect the main issues relate to the three key lines:
m_hVST_stream = BASS_VST_ChannelCreate(44100, 2, getVSTiPlugin()->getPluginFilePath(), BASS_SAMPLE_FLOAT | BASS_STREAM_DECODE);
m_hGuitar_stream = BASS_MIDI_StreamGetChannel(m_hMIDI_chan, m_nChannel+16); // get a stream for the MIDI channel (0-15) to be handled by the VSTi
BASS_ChannelSetDSP(m_hGuitar_stream, Guitar_DSP_Callback, (VOID*)this, 0); // set a DSP function on the guitar channel to feed-in the VSTi output
Soon after the above lines, I set initial chunk data and parameters on the VSTi.
BASS_VST_SetChunk(m_hVST_stream, 1, lpszBuffer, nSize);
Sleep(100); // needed for execution of the VST_SetChunk()
BASS_VST_SetParam(m_hVST_stream, pProgram->getVSTiCommand(i)->getCommand(), pProgram->getVSTiCommand(i)->getValue());
BASS_VST_SetParam(m_hVST_stream, 0, 0.5);
These are all the BASS/BASSVST related calls that occur in the separate threads.
I learned through trial and error to mutex lock the top 3 lines per VSTi (eg Addictive Keys), because when I had 2 or more channels using Addictive Keys it was erroneously reporting wrong computer id. The mutex resolved that issue, but not other issues.
I'm wondering if you have any general advice/experience on multi-threading the creation of VSTi channels. Otherwise I seem to be stuck with the long song setup time. Thanks, as always.