Deriving SamplerVoice Class


#1

Continuing the discussion from Help for a SamplerVoice based sample reader VST plugin:

Hello, I am trying to derive a SamplerVoice Class so it can have different pan parameters for different notes being played. I figured out how to pan audio, and to override renderNextBlock method but I would like to get my pan parameters from my audio processor object.
I have done the same thing as in linked forum post, and here it is:

class CustomVoice :public SamplerVoice
{
public:
CustomVoice(DrPadAudioProcessor& myPluginProcessor);
virtual ~CustomVoice() {}
void renderNextBlock(AudioBuffer< float > &outputBuffer, int startSample, int numSamples) override;
private:
DrPadAudioProcessor& parent;
float panning;
};

And in my .cpp file:

#include “CustomVoice.h”
CustomVoice::CustomVoice(DrPadAudioProcessor& myPluginProcessor):panning(0),parent(myPluginProcessor){}
void CustomVoice::renderNextBlock(AudioBuffer< float > &outputBuffer, int startSample, int numSamples){
/*
int noteWhichIsBeingPlayed = getCurrentlyPlayingNote();
int panId;
for (int i = 0; i < 16; i++) {
if (noteWhichIsBeingPlayed == parent.notes[i])
panId = i;
}
*/
//panning = parent.panPad[panId];
double pan = panning + 50;
pan = (pan * 127) / 100;
pan /= 127.0;
SamplerVoice::renderNextBlock(outputBuffer, startSample, numSamples);
outputBuffer.applyGain(0, 0, outputBuffer.getNumSamples(), jmin(1.0, (1.0 - pan) * 2.0));
outputBuffer.applyGain(1, 0, outputBuffer.getNumSamples(), jmin(1.0, pan * 2.0));
}

Now in my processor .cpp file, I have synth initialisation function where I add voices to my synth.

synth.addVoice(new CustomVoice(*this));

The thing is that I get bunch of errors as:

Severity Code Description Project File Line
Error C2664 ‘CustomVoice::CustomVoice(const CustomVoice &)’: cannot convert argument 1 from ‘DrPadAudioProcessor’ to ‘const CustomVoice &’ DrPad_SharedCode E:\AudioPlug-ins\DrPad\Source\PluginProcessor.cpp 63
Error C2061 syntax error: identifier ‘DrPadAudioProcessor’ (compiling source file …\Source\PluginProcessor.cpp) DrPad_SharedCode e:\audioplug-ins\drpad\source\CustomVoice.h 19
Error C2061 syntax error: identifier ‘DrPadAudioProcessor’ (compiling source file …\Source\PluginEditor.cpp) DrPad_SharedCode e:\audioplug-ins\drpad\source\CustomVoice.h 19
Error C2143 syntax error: missing ‘;’ before ‘&’ (compiling source file …\Source\PluginProcessor.cpp) DrPad_SharedCode e:\audioplug-ins\drpad\source\CustomVoice.h 23
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int (compiling source file …\Source\PluginProcessor.cpp) DrPad_SharedCode e:\audioplug-ins\drpad\source\CustomVoice.h 23
Error C2238 unexpected token(s) preceding ‘;’ (compiling source file …\Source\PluginProcessor.cpp) DrPad_SharedCode e:\audioplug-ins\drpad\source\CustomVoice.h 23
Error C2143 syntax error: missing ‘;’ before ‘&’ (compiling source file …\Source\PluginEditor.cpp) DrPad_SharedCode e:\audioplug-ins\drpad\source\CustomVoice.h 23
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int (compiling source file …\Source\PluginEditor.cpp) DrPad_SharedCode e:\audioplug-ins\drpad\source\CustomVoice.h 23
Error C2238 unexpected token(s) preceding ‘;’ (compiling source file …\Source\PluginEditor.cpp) DrPad_SharedCode e:\audioplug-ins\drpad\source\CustomVoice.h 23

Is this the correct way to parse data from processor to Voice and I am missing something, or I am completely heading the wrong way and should look for a way around?

Thanks in advance,
Cila


#2

I believe that the SamplerVoice class has a default constructor with no parameters. If your CustomVoice class has one parameter it’s fine, but I don’t think you actually need that parent(myPluginProcessor) in the CustomVoice constructor.
Also, it should be a better design not to let the child class to know anything about its parent, better to send it some additional parameters from the processor.


#3

Thank you for your reply! I have managed to fix my problems with more complex derivation of necessary classes. Everything works fine for now.
Cila