Represents a voice that a Synthesiser can use to play a SynthesiserSound. More...
Inherited by SamplerVoice.
Public Member Functions | |
| SynthesiserVoice () | |
| Creates a voice. | |
| virtual | ~SynthesiserVoice () |
| Destructor. | |
| int | getCurrentlyPlayingNote () const |
| Returns the midi note that this voice is currently playing. | |
| SynthesiserSound::Ptr | getCurrentlyPlayingSound () const |
| Returns the sound that this voice is currently playing. | |
| virtual bool | canPlaySound (SynthesiserSound *sound)=0 |
| Must return true if this voice object is capable of playing the given sound. | |
| virtual void | startNote (const int midiNoteNumber, const float velocity, SynthesiserSound *sound, const int currentPitchWheelPosition)=0 |
| Called to start a new note. | |
| virtual void | stopNote (const bool allowTailOff)=0 |
| Called to stop a note. | |
| virtual void | pitchWheelMoved (const int newValue)=0 |
| Called to let the voice know that the pitch wheel has been moved. | |
| virtual void | controllerMoved (const int controllerNumber, const int newValue)=0 |
| Called to let the voice know that a midi controller has been moved. | |
| virtual void | renderNextBlock (AudioSampleBuffer &outputBuffer, int startSample, int numSamples)=0 |
| Renders the next block of data for this voice. | |
| bool | isPlayingChannel (int midiChannel) const |
| Returns true if the voice is currently playing a sound which is mapped to the given midi channel. | |
| void | setCurrentPlaybackSampleRate (double newRate) |
| Changes the voice's reference sample rate. | |
Protected Member Functions | |
| double | getSampleRate () const |
| Returns the current target sample rate at which rendering is being done. | |
| void | clearCurrentNote () |
| Resets the state of this voice after a sound has finished playing. | |
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.
Creates a voice.
| virtual SynthesiserVoice::~SynthesiserVoice | ( | ) | [virtual] |
Destructor.
| int SynthesiserVoice::getCurrentlyPlayingNote | ( | ) | const |
Returns the midi note that this voice is currently playing.
Returns a value less than 0 if no note is playing.
Returns the sound that this voice is currently playing.
Returns 0 if it's not playing.
| virtual bool SynthesiserVoice::canPlaySound | ( | SynthesiserSound * | sound | ) | [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 SamplerVoice.
| virtual void SynthesiserVoice::startNote | ( | const int | midiNoteNumber, |
| const float | velocity, | ||
| SynthesiserSound * | sound, | ||
| const 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 SamplerVoice.
| virtual void SynthesiserVoice::stopNote | ( | const bool | allowTailOff | ) | [pure virtual] |
Called to stop a note.
This will be called during the rendering callback, so must be fast and thread-safe.
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 SamplerVoice.
| virtual void SynthesiserVoice::pitchWheelMoved | ( | const int | newValue | ) | [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 SamplerVoice.
| virtual void SynthesiserVoice::controllerMoved | ( | const int | controllerNumber, |
| const int | newValue | ||
| ) | [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 SamplerVoice.
| virtual void SynthesiserVoice::renderNextBlock | ( | AudioSampleBuffer & | 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 SamplerVoice.
| bool SynthesiserVoice::isPlayingChannel | ( | int | midiChannel | ) | const |
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.
| void SynthesiserVoice::setCurrentPlaybackSampleRate | ( | double | newRate | ) |
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.
| double SynthesiserVoice::getSampleRate | ( | ) | const [protected] |
Returns the current target sample rate at which rendering is being done.
This is available for subclasses so they can pitch things correctly.
| void 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.