# Problems with the method addVoice\[SOLVED\]

**URL:** <https://forum.juce.com/t/problems-with-the-method-addvoice-solved/19418>\
**Category:** Audio Plugins\
**Created:** [October 10, 2016, 1:09pm UTC](https://forum.juce.com/t/problems-with-the-method-addvoice-solved/19418 "2016-10-10T13:09:50Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![noFanatic](https://avatars.discourse-cdn.com/v4/letter/n/a9a28c/32.png) [@noFanatic](https://forum.juce.com/u/noFanatic)\
**Post date:** [October 10, 2016, 1:09pm UTC](https://forum.juce.com/t/problems-with-the-method-addvoice-solved/19418/1 "2016-10-10T13:09:50Z")

</div>

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;  
synth.addVoice(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()?

Thanks.

---

<div class="post-metadata">

**Author:** ![ed95](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/ed95/32/7635_2.png) [@ed95](https://forum.juce.com/u/ed95)\
**Post date:** [October 10, 2016, 2:29pm UTC](https://forum.juce.com/t/problems-with-the-method-addvoice-solved/19418/2 "2016-10-10T14:29:08Z")

</div>

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.

Ed

---

<div class="post-metadata">

**Author:** ![noFanatic](https://avatars.discourse-cdn.com/v4/letter/n/a9a28c/32.png) [@noFanatic](https://forum.juce.com/u/noFanatic)\
**Post date:** [October 12, 2016, 7:21pm UTC](https://forum.juce.com/t/problems-with-the-method-addvoice-solved/19418/3 "2016-10-12T19:21:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![shossa3](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/shossa3/32/3860_2.png) [@shossa3](https://forum.juce.com/u/shossa3)\
**Post date:** [April 17, 2018, 4:54am UTC](https://forum.juce.com/t/problems-with-the-method-addvoice-solved/19418/4 "2018-04-17T04:54:07Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [April 17, 2018, 7:43am UTC](https://forum.juce.com/t/problems-with-the-method-addvoice-solved/19418/5 "2018-04-17T07:43:17Z")

</div>

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](https://docs.juce.com/develop/classSynthesiserSound.html#abc192aba46964c8539206db1e6f6f747) 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.

HTH

---

<div class="post-metadata">

**Author:** ![shossa3](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/shossa3/32/3860_2.png) [@shossa3](https://forum.juce.com/u/shossa3)\
**Post date:** [April 17, 2018, 4:32pm UTC](https://forum.juce.com/t/problems-with-the-method-addvoice-solved/19418/6 "2018-04-17T16:32:47Z")

</div>

> [@daniel](#):
>
> appliesToNote

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

mySynth.clearVoices();

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

mySynth.clearSounds();  
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.

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [April 17, 2018, 4:36pm UTC](https://forum.juce.com/t/problems-with-the-method-addvoice-solved/19418/7 "2018-04-17T16:36:55Z")

</div>

> [@shossa3](#):
>
> SynthSound

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…

HTH

---

<div class="post-metadata">

**Author:** ![shossa3](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/shossa3/32/3860_2.png) [@shossa3](https://forum.juce.com/u/shossa3)\
**Post date:** [April 17, 2018, 4:41pm UTC](https://forum.juce.com/t/problems-with-the-method-addvoice-solved/19418/8 "2018-04-17T16:41:42Z")

</div>

Yes, this is my SynthSound class:

class SynthSound : public SynthesiserSound  
{  
public:

```
bool appliestoNote(int midiNoteNumber)
{
    return true;
}

bool appliestoChannel(int midiChannel)
{
    return true;
}

```

};

---

<div class="post-metadata">

**Author:** ![shossa3](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/shossa3/32/3860_2.png) [@shossa3](https://forum.juce.com/u/shossa3)\
**Post date:** [April 17, 2018, 4:42pm UTC](https://forum.juce.com/t/problems-with-the-method-addvoice-solved/19418/9 "2018-04-17T16:42:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![xenakios](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/xenakios/32/4047_2.png) [@xenakios](https://forum.juce.com/u/xenakios)\
**Post date:** [April 17, 2018, 4:44pm UTC](https://forum.juce.com/t/problems-with-the-method-addvoice-solved/19418/10 "2018-04-17T16:44:41Z")

</div>

You have typos in the method names :

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

---

<div class="post-metadata">

**Author:** ![mcmartin](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/mcmartin/32/7432_2.png) [@mcmartin](https://forum.juce.com/u/mcmartin)\
**Post date:** [April 17, 2018, 8:41pm UTC](https://forum.juce.com/t/problems-with-the-method-addvoice-solved/19418/11 "2018-04-17T20:41:35Z")

</div>

You should ue the `override` keyword to get more useful error messages from the compiler. See [http://en.cppreference.com/w/cpp/language/override](http://en.cppreference.com/w/cpp/language/override) for the more details.
