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.
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.
Then i tried to declare a pointer of the SynthVoice type:
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()?
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.
^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…
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.