Hi. I work with my vst and have already implemented some cases.
But not sure if it’s good enough. Just want to ask your advice what I can improve.
The first moment.
On a screen I have different icons. Each icon has its own midi not. And each midi note has its own .wav sample. So, onclick I want to hear this sample.
I do it like this:
void Project1AudioProcessor::createMidiMessage(int noteNumber, float velocity)
{
auto midiChannel = 1;
auto message = MidiMessage::noteOn(midiChannel, noteNumber, static_cast<float>(velocity));
auto timestamp = message.getTimeStamp();
auto sampleNumber = static_cast<int>(timestamp * lastSampleRate);
midiBuffer.addEvent(message, sampleNumber);
}
and then I have method
void Project1AudioProcessor::processBlock(AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
{
buffer.clear();
synth.renderNextBlock(buffer, midiMessages, 0, buffer.getNumSamples());
if (!midiBuffer.isEmpty()) {
synth.renderNextBlock(buffer, midiBuffer, 0, buffer.getNumSamples());
midiBuffer.clear();
}
}
Is it good? Or maybe something wrong?
The second moment
I want to ignore the length of midi notes and always play the whole sample.
Now I have override method
void stopNote(float velocity, bool allowTailOff) override
{
if (allowTailOff)
{
adsr.noteOff();
}
else
{
clearCurrentNote();
adsr.reset();
}
}
if allowTailOff = false. It plays the sample only with the midi note length. So it’s not my option.
if allawTailOff = true. It ignores midi length, but I can hear the additional artificial noises.
So, any ideas how can I improve my code in these two cases?
Thank you