Hi,
I make vst plugin. I use Juce Synthesiser class to play different samples on different notes. Everything is good with that.
But now I want to add functionality to play sounds on button click (sounds which were not loaded to my synth).
I tried an example from Juce tutorial. But have no sound.
What could be wrong?
My code
void MySynthAudioProcessor::playSound(File file){
auto* reader = formatManager.createReaderFor(file);
if (reader != nullptr)
{
AudioFormatReaderSource* newSource = new AudioFormatReaderSource(reader, true);
transportSource.setSource(newSource, 32768, &readAheadThread, reader->sampleRate);
transportSource.setGain(1);
}
}
void MySynthAudioProcessor::processBlock(AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
{
synth.renderNextBlock(buffer, midiMessages, 0, buffer.getNumSamples());
transportSource.getNextAudioBlock(AudioSourceChannelInfo(buffer));
}
void MySynthAudioProcessor::prepareToPlay(double sampleRate, int samplesPerBlock)
{
ignoreUnused(samplesPerBlock);
synth.setCurrentPlaybackSampleRate(lastSampleRate);
transportSource.prepareToPlay(samplesPerBlock, sampleRate);
}
Thank you