OpenShot Library | libopenshot-audio  0.1.9
juce::SynthesiserVoice Class Referenceabstract

Represents a voice that a Synthesiser can use to play a SynthesiserSound. More...

#include <juce_Synthesiser.h>

+ Inheritance diagram for juce::SynthesiserVoice:

Public Member Functions

 SynthesiserVoice ()
 Creates a voice. More...
 
virtual ~SynthesiserVoice ()
 Destructor. More...
 
int getCurrentlyPlayingNote () const noexcept
 Returns the midi note that this voice is currently playing. More...
 
SynthesiserSound::Ptr getCurrentlyPlayingSound () const noexcept
 Returns the sound that this voice is currently playing. More...
 
virtual bool canPlaySound (SynthesiserSound *)=0
 Must return true if this voice object is capable of playing the given sound. More...
 
virtual void startNote (int midiNoteNumber, float velocity, SynthesiserSound *sound, int currentPitchWheelPosition)=0
 Called to start a new note. More...
 
virtual void stopNote (float velocity, bool allowTailOff)=0
 Called to stop a note. More...
 
virtual bool isVoiceActive () const
 Returns true if this voice is currently busy playing a sound. More...
 
virtual void pitchWheelMoved (int newPitchWheelValue)=0
 Called to let the voice know that the pitch wheel has been moved. More...
 
virtual void controllerMoved (int controllerNumber, int newControllerValue)=0
 Called to let the voice know that a midi controller has been moved. More...
 
virtual void aftertouchChanged (int newAftertouchValue)
 Called to let the voice know that the aftertouch has changed. More...
 
virtual void channelPressureChanged (int newChannelPressureValue)
 Called to let the voice know that the channel pressure has changed. More...
 
virtual void renderNextBlock (AudioBuffer< float > &outputBuffer, int startSample, int numSamples)=0
 Renders the next block of data for this voice. More...
 
virtual void renderNextBlock (AudioBuffer< double > &outputBuffer, int startSample, int numSamples)
 A double-precision version of renderNextBlock()
 
virtual void setCurrentPlaybackSampleRate (double newRate)
 Changes the voice's reference sample rate. More...
 
virtual bool isPlayingChannel (int midiChannel) const
 Returns true if the voice is currently playing a sound which is mapped to the given midi channel. More...
 
double getSampleRate () const noexcept
 Returns the current target sample rate at which rendering is being done. More...
 
bool isKeyDown () const noexcept
 Returns true if the key that triggered this voice is still held down. More...
 
void setKeyDown (bool isNowDown) noexcept
 Allows you to modify the flag indicating that the key that triggered this voice is still held down. More...
 
bool isSustainPedalDown () const noexcept
 Returns true if the sustain pedal is currently active for this voice. More...
 
void setSustainPedalDown (bool isNowDown) noexcept
 Modifies the sustain pedal flag. More...
 
bool isSostenutoPedalDown () const noexcept
 Returns true if the sostenuto pedal is currently active for this voice. More...
 
void setSostenutoPedalDown (bool isNowDown) noexcept
 Modifies the sostenuto pedal flag. More...
 
bool isPlayingButReleased () const noexcept
 Returns true if a voice is sounding in its release phase.
 
bool wasStartedBefore (const SynthesiserVoice &other) const noexcept
 Returns true if this voice started playing its current note before the other voice did. More...
 

Protected Member Functions

void clearCurrentNote ()
 Resets the state of this voice after a sound has finished playing. More...
 

Friends

class Synthesiser
 

Detailed Description

Represents a voice that a Synthesiser can use to play a SynthesiserSound.

A voice plays a single sound at a time, and a synthesiser holds an array of voices so that it can play polyphonically.

See also
Synthesiser, SynthesiserSound

Definition at line 91 of file juce_Synthesiser.h.

Constructor & Destructor Documentation

◆ SynthesiserVoice()

juce::SynthesiserVoice::SynthesiserVoice ( )

Creates a voice.

Definition at line 30 of file juce_Synthesiser.cpp.

◆ ~SynthesiserVoice()

juce::SynthesiserVoice::~SynthesiserVoice ( )
virtual

Destructor.

Definition at line 31 of file juce_Synthesiser.cpp.

Member Function Documentation

◆ getCurrentlyPlayingNote()

int juce::SynthesiserVoice::getCurrentlyPlayingNote ( ) const
inlinenoexcept

Returns the midi note that this voice is currently playing.

Returns a value less than 0 if no note is playing.

Definition at line 105 of file juce_Synthesiser.h.

Referenced by juce::Synthesiser::findVoiceToSteal(), and juce::Synthesiser::stopVoice().

◆ getCurrentlyPlayingSound()

SynthesiserSound::Ptr juce::SynthesiserVoice::getCurrentlyPlayingSound ( ) const
inlinenoexcept

Returns the sound that this voice is currently playing.

Returns nullptr if it's not playing.

Definition at line 110 of file juce_Synthesiser.h.

Referenced by juce::Synthesiser::stopVoice().

◆ canPlaySound()

virtual bool juce::SynthesiserVoice::canPlaySound ( SynthesiserSound )
pure virtual

Must return true if this voice object is capable of playing the given sound.

If there are different classes of sound, and different classes of voice, a voice can choose which ones it wants to take on.

A typical implementation of this method may just return true if there's only one type of voice and sound, or it might check the type of the sound object passed-in and see if it's one that it understands.

Implemented in juce::SamplerVoice.

◆ startNote()

virtual void juce::SynthesiserVoice::startNote ( int  midiNoteNumber,
float  velocity,
SynthesiserSound sound,
int  currentPitchWheelPosition 
)
pure virtual

Called to start a new note.

This will be called during the rendering callback, so must be fast and thread-safe.

Implemented in juce::SamplerVoice.

Referenced by juce::Synthesiser::startVoice().

◆ stopNote()

virtual void juce::SynthesiserVoice::stopNote ( float  velocity,
bool  allowTailOff 
)
pure virtual

Called to stop a note.

This will be called during the rendering callback, so must be fast and thread-safe.

The velocity indicates how quickly the note was released - 0 is slowly, 1 is quickly.

If allowTailOff is false or the voice doesn't want to tail-off, then it must stop all sound immediately, and must call clearCurrentNote() to reset the state of this voice and allow the synth to reassign it another sound.

If allowTailOff is true and the voice decides to do a tail-off, then it's allowed to begin fading out its sound, and it can stop playing until it's finished. As soon as it finishes playing (during the rendering callback), it must make sure that it calls clearCurrentNote().

Implemented in juce::SamplerVoice.

Referenced by juce::Synthesiser::startVoice(), and juce::Synthesiser::stopVoice().

◆ isVoiceActive()

bool juce::SynthesiserVoice::isVoiceActive ( ) const
virtual

Returns true if this voice is currently busy playing a sound.

By default this just checks the getCurrentlyPlayingNote() value, but can be overridden for more advanced checking.

Definition at line 43 of file juce_Synthesiser.cpp.

◆ pitchWheelMoved()

virtual void juce::SynthesiserVoice::pitchWheelMoved ( int  newPitchWheelValue)
pure virtual

Called to let the voice know that the pitch wheel has been moved.

This will be called during the rendering callback, so must be fast and thread-safe.

Implemented in juce::SamplerVoice.

◆ controllerMoved()

virtual void juce::SynthesiserVoice::controllerMoved ( int  controllerNumber,
int  newControllerValue 
)
pure virtual

Called to let the voice know that a midi controller has been moved.

This will be called during the rendering callback, so must be fast and thread-safe.

Implemented in juce::SamplerVoice.

◆ aftertouchChanged()

void juce::SynthesiserVoice::aftertouchChanged ( int  newAftertouchValue)
virtual

Called to let the voice know that the aftertouch has changed.

This will be called during the rendering callback, so must be fast and thread-safe.

Definition at line 55 of file juce_Synthesiser.cpp.

◆ channelPressureChanged()

void juce::SynthesiserVoice::channelPressureChanged ( int  newChannelPressureValue)
virtual

Called to let the voice know that the channel pressure has changed.

This will be called during the rendering callback, so must be fast and thread-safe.

Definition at line 56 of file juce_Synthesiser.cpp.

◆ renderNextBlock()

virtual void juce::SynthesiserVoice::renderNextBlock ( AudioBuffer< float > &  outputBuffer,
int  startSample,
int  numSamples 
)
pure virtual

Renders the next block of data for this voice.

The output audio data must be added to the current contents of the buffer provided. Only the region of the buffer between startSample and (startSample + numSamples) should be altered by this method.

If the voice is currently silent, it should just return without doing anything.

If the sound that the voice is playing finishes during the course of this rendered block, it must call clearCurrentNote(), to tell the synthesiser that it has finished.

The size of the blocks that are rendered can change each time it is called, and may involve rendering as little as 1 sample at a time. In between rendering callbacks, the voice's methods will be called to tell it about note and controller events.

Implemented in juce::SamplerVoice.

◆ setCurrentPlaybackSampleRate()

void juce::SynthesiserVoice::setCurrentPlaybackSampleRate ( double  newRate)
virtual

Changes the voice's reference sample rate.

The rate is set so that subclasses know the output rate and can set their pitch accordingly.

This method is called by the synth, and subclasses can access the current rate with the currentSampleRate member.

Definition at line 38 of file juce_Synthesiser.cpp.

Referenced by juce::Synthesiser::addVoice().

◆ isPlayingChannel()

bool juce::SynthesiserVoice::isPlayingChannel ( int  midiChannel) const
virtual

Returns true if the voice is currently playing a sound which is mapped to the given midi channel.

If it's not currently playing, this will return false.

Definition at line 33 of file juce_Synthesiser.cpp.

◆ getSampleRate()

double juce::SynthesiserVoice::getSampleRate ( ) const
inlinenoexcept

Returns the current target sample rate at which rendering is being done.

Subclasses may need to know this so that they can pitch things correctly.

Definition at line 219 of file juce_Synthesiser.h.

◆ isKeyDown()

bool juce::SynthesiserVoice::isKeyDown ( ) const
inlinenoexcept

Returns true if the key that triggered this voice is still held down.

Note that the voice may still be playing after the key was released (e.g because the sostenuto pedal is down).

Definition at line 225 of file juce_Synthesiser.h.

Referenced by juce::Synthesiser::findVoiceToSteal().

◆ setKeyDown()

void juce::SynthesiserVoice::setKeyDown ( bool  isNowDown)
inlinenoexcept

Allows you to modify the flag indicating that the key that triggered this voice is still held down.

See also
isKeyDown

Definition at line 230 of file juce_Synthesiser.h.

Referenced by juce::Synthesiser::startVoice().

◆ isSustainPedalDown()

bool juce::SynthesiserVoice::isSustainPedalDown ( ) const
inlinenoexcept

Returns true if the sustain pedal is currently active for this voice.

Definition at line 233 of file juce_Synthesiser.h.

◆ setSustainPedalDown()

void juce::SynthesiserVoice::setSustainPedalDown ( bool  isNowDown)
inlinenoexcept

Modifies the sustain pedal flag.

Definition at line 236 of file juce_Synthesiser.h.

Referenced by juce::Synthesiser::startVoice().

◆ isSostenutoPedalDown()

bool juce::SynthesiserVoice::isSostenutoPedalDown ( ) const
inlinenoexcept

Returns true if the sostenuto pedal is currently active for this voice.

Definition at line 239 of file juce_Synthesiser.h.

◆ setSostenutoPedalDown()

void juce::SynthesiserVoice::setSostenutoPedalDown ( bool  isNowDown)
inlinenoexcept

Modifies the sostenuto pedal flag.

Definition at line 242 of file juce_Synthesiser.h.

Referenced by juce::Synthesiser::startVoice().

◆ wasStartedBefore()

bool juce::SynthesiserVoice::wasStartedBefore ( const SynthesiserVoice other) const
noexcept

Returns true if this voice started playing its current note before the other voice did.

Definition at line 58 of file juce_Synthesiser.cpp.

Referenced by juce::Synthesiser::findVoiceToSteal().

◆ clearCurrentNote()

void juce::SynthesiserVoice::clearCurrentNote ( )
protected

Resets the state of this voice after a sound has finished playing.

The subclass must call this when it finishes playing a note and becomes available to play new ones.

It must either call it in the stopNote() method, or if the voice is tailing off, then it should call it later during the renderNextBlock method, as soon as it finishes its tail-off.

It can also be called at any time during the render callback if the sound happens to have finished, e.g. if it's playing a sample and the sample finishes.

Definition at line 48 of file juce_Synthesiser.cpp.


The documentation for this class was generated from the following files: