Problems with the method addVoice[SOLVED]


Hi, i’m trying to make a Plug-In synthesiser using the classes Synthesiser, SynthesiserVoice and SynthesiserSound.
I read the Documentation and it says that i need to create a SynthesiserVoice, a SynthesiserSound and then pass them respectively in the method of the class Synthesiser addVoice and addSound. I have a problem when i call addVoice method. I tried to use two ways to add a SynthesiserVoice that i created.

  1. In the first one i followed the example found in the Juce library.

synth.addVoice(new SynthVoice()); // SynthVoice is the class that inherits SynthesiserVoice
In this case the console report an error: Allocating an object of abstract class type SynthesiserVoice.

  1. Then i tried to declare a pointer of the SynthVoice type:

SynthVoice *newVoice;
In this case i don’t have syntax errors but when i open the plug-in with the plugin Host it crashes.

Where is the problem? Why can it allocate the object of class derived from the SynthesiserVoice class in the Juce example using the constructor new SynthVoice()?



The first method should work. What does your SynthVoice class look like? It needs to implement all the pure virtual functions from the SynthesiserVoice base class.



I just discovered that i forgot to implement one of the methods.
Thanks for your helping.


I’m having a similar problem with addSound. The two methods are appliestoNote and appliestoChannel. However, I’m not sure if I should simply add those function to my PluginProcessor or if I have to define them for every single sound I add. Any advice?


The methods are members of the sound, so you need to implement them there (it is part of the interface the sound has to satisfy).
The docs say:

virtual bool SynthesiserSound::appliesToNote (int midiNoteNumber) - pure virtual
Returns true if this sound should be played when a given midi note is pressed.

The Synthesiser will use this information when deciding which sounds to trigger for a given note.

Which means, if your sound can play all notes, you can simply return true in every case, if your sound is e.g. a drum kit, that reacts only to a certain key, or key range, you can check here and return true or false.


RackAFX single sample to JUCE audio buffer example?

Where do you mean by “there”? In the PluginProcessor itself? Below is my code:


for (int i =0; i < 16; i++)
mySynth.addVoice(new SynthVoice());

mySynth.addSound(new SynthSound());

^With the last line generating the error related to abstract class type. Do I specify the funcitons within the “new SynthSound()” or do I simply add those functions in PluginProcessor? Example code would be useful. Thanks for your help.


SynthSound is inheriting the juce class SynthesizerSound, am I correct?

That means, it will understand all methods, that SynthesizerSound declared. However, because there is no generic solution to some methods, they left it out, that’s called “pure virtual”. So any class inheriting from SynthesizerSound need to implement all pure virtual functions, otherwise tha class itself becomes “pure virtual”, which results in an error, if you try to instanciate the class (which you do, when you call “new SynthSound()”.

So add the two methods to your SynthSound() class, and the error will go away. To get started, simply return true, so your sound will react to all notes on all channels…



Yes, this is my SynthSound class:

class SynthSound : public SynthesiserSound

bool appliestoNote(int midiNoteNumber)
    return true;

bool appliestoChannel(int midiChannel)
    return true;



So I have defined those functions in the class itself but the error persists. Therefore, I wasn’t sure if I had to somehow specify inputs to these functions when I call new SynthSound or somewhere in the PluginProcessor.h file.


You have typos in the method names :

appliestoNote should be appliesToNote and appliestoChannel should be appliesToChannel. C++ is very specific about things like this.


You should ue the override keyword to get more useful error messages from the compiler. See for the more details.