@@ -99,7 +99,7 @@ class YUP_API SynthesiserSound : public ReferenceCountedObject
9999
100100 @tags{Audio}
101101*/
102- class YUP_API SynthesiserVoice
102+ class YUP_API SynthesiserVoice : public ReferenceCountedObject
103103{
104104public:
105105 // ==============================================================================
@@ -261,6 +261,9 @@ class YUP_API SynthesiserVoice
261261 /* * Returns true if this voice started playing its current note before the other voice did. */
262262 bool wasStartedBefore (const SynthesiserVoice& other) const noexcept ;
263263
264+ /* * The class is reference-counted, so this is a handy pointer class for it. */
265+ using Ptr = ReferenceCountedObjectPtr<SynthesiserVoice>;
266+
264267protected:
265268 /* * Resets the state of this voice after a sound has finished playing.
266269
@@ -337,17 +340,16 @@ class YUP_API Synthesiser
337340 int getNumVoices () const noexcept { return voices.size (); }
338341
339342 /* * Returns one of the voices that have been added. */
340- SynthesiserVoice* getVoice (int index) const ;
343+ SynthesiserVoice::Ptr getVoice (int index) const ;
341344
342345 /* * Adds a new voice to the synth.
343346
344347 All the voices should be the same class of object and are treated equally.
345348
346- The object passed in will be managed by the synthesiser, which will delete
347- it later on when no longer needed. The caller should not retain a pointer to the
348- voice.
349+ The object passed in is reference counted, so will be deleted when the
350+ synthesiser and all voices are no longer using it.
349351 */
350- SynthesiserVoice* addVoice (SynthesiserVoice* newVoice);
352+ SynthesiserVoice* addVoice (SynthesiserVoice::Ptr newVoice);
351353
352354 /* * Deletes one of the voices. */
353355 void removeVoice (int index);
@@ -400,9 +402,7 @@ class YUP_API Synthesiser
400402
401403 The midiChannel parameter is the channel, between 1 and 16 inclusive.
402404 */
403- virtual void noteOn (int midiChannel,
404- int midiNoteNumber,
405- float velocity);
405+ virtual void noteOn (int midiChannel, int midiNoteNumber, float velocity);
406406
407407 /* * Triggers a note-off event.
408408
@@ -416,10 +416,7 @@ class YUP_API Synthesiser
416416
417417 The midiChannel parameter is the channel, between 1 and 16 inclusive.
418418 */
419- virtual void noteOff (int midiChannel,
420- int midiNoteNumber,
421- float velocity,
422- bool allowTailOff);
419+ virtual void noteOff (int midiChannel, int midiNoteNumber, float velocity, bool allowTailOff);
423420
424421 /* * Turns off all notes.
425422
@@ -435,8 +432,7 @@ class YUP_API Synthesiser
435432 This method will be called automatically according to the midi data passed into
436433 renderNextBlock(), but may be called explicitly too.
437434 */
438- virtual void allNotesOff (int midiChannel,
439- bool allowTailOff);
435+ virtual void allNotesOff (int midiChannel, bool allowTailOff);
440436
441437 /* * Sends a pitch-wheel message to any active voices.
442438
@@ -449,8 +445,7 @@ class YUP_API Synthesiser
449445 @param midiChannel the midi channel, from 1 to 16 inclusive
450446 @param wheelValue the wheel position, from 0 to 0x3fff, as returned by MidiMessage::getPitchWheelValue()
451447 */
452- virtual void handlePitchWheel (int midiChannel,
453- int wheelValue);
448+ virtual void handlePitchWheel (int midiChannel, int wheelValue);
454449
455450 /* * Sends a midi controller message to any active voices.
456451
@@ -464,9 +459,7 @@ class YUP_API Synthesiser
464459 @param controllerNumber the midi controller type, as returned by MidiMessage::getControllerNumber()
465460 @param controllerValue the midi controller value, between 0 and 127, as returned by MidiMessage::getControllerValue()
466461 */
467- virtual void handleController (int midiChannel,
468- int controllerNumber,
469- int controllerValue);
462+ virtual void handleController (int midiChannel, int controllerNumber, int controllerValue);
470463
471464 /* * Sends an aftertouch message.
472465
@@ -510,8 +503,7 @@ class YUP_API Synthesiser
510503 The base class implementation of this has no effect, but you may want to make your
511504 own synth react to program changes.
512505 */
513- virtual void handleProgramChange (int midiChannel,
514- int programNumber);
506+ virtual void handleProgramChange (int midiChannel, int programNumber);
515507
516508 // ==============================================================================
517509 /* * Tells the synthesiser what the sample rate is for the audio it's being used to render.
@@ -575,7 +567,7 @@ class YUP_API Synthesiser
575567 /* * This is used to control access to the rendering callback and the note trigger methods. */
576568 CriticalSection lock;
577569
578- OwnedArray <SynthesiserVoice> voices;
570+ ReferenceCountedArray <SynthesiserVoice> voices;
579571 ReferenceCountedArray<SynthesiserSound> sounds;
580572
581573 /* * The last pitch-wheel values for each midi channel. */
0 commit comments