JUCE  v5.4.1-191-g0ab5e696f
JUCE API
Looking for a senior C++ dev?
I'm looking for work. Hire me!
juce::SamplerVoice Class Reference

A subclass of SynthesiserVoice that can play a SamplerSound. More...

#include <juce_Sampler.h>

Inheritance diagram for juce::SamplerVoice:
Collaboration diagram for juce::SamplerVoice:

Public Member Functions

 SamplerVoice ()
 Creates a SamplerVoice. More...
 
 ~SamplerVoice () override
 Destructor. More...
 
virtual void aftertouchChanged (int newAftertouchValue)
 Called to let the voice know that the aftertouch has changed. More...
 
bool canPlaySound (SynthesiserSound *) override
 Must return true if this voice object is capable of playing the given sound. More...
 
virtual void channelPressureChanged (int newChannelPressureValue)
 Called to let the voice know that the channel pressure has changed. More...
 
void controllerMoved (int controllerNumber, int newValue) override
 Called to let the voice know that a midi controller has been moved. 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...
 
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...
 
bool isPlayingButReleased () const noexcept
 Returns true if a voice is sounding in its release phase. 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...
 
bool isSostenutoPedalDown () const noexcept
 Returns true if the sostenuto pedal is currently active for this voice. More...
 
bool isSustainPedalDown () const noexcept
 Returns true if the sustain pedal is currently active for this voice. More...
 
virtual bool isVoiceActive () const
 Returns true if this voice is currently busy playing a sound. More...
 
void pitchWheelMoved (int newValue) override
 Called to let the voice know that the pitch wheel has been moved. More...
 
void renderNextBlock (AudioBuffer< float > &, int startSample, int numSamples) override
 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() More...
 
virtual void setCurrentPlaybackSampleRate (double newRate)
 Changes the voice's reference sample rate. 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...
 
void setSostenutoPedalDown (bool isNowDown) noexcept
 Modifies the sostenuto pedal flag. More...
 
void setSustainPedalDown (bool isNowDown) noexcept
 Modifies the sustain pedal flag. More...
 
void startNote (int midiNoteNumber, float velocity, SynthesiserSound *, int pitchWheel) override
 Called to start a new note. More...
 
void stopNote (float velocity, bool allowTailOff) override
 Called to stop a note. More...
 
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...
 

Private Attributes

ADSR adsr
 
float lgain = 0
 
double pitchRatio = 0
 
float rgain = 0
 
double sourceSamplePosition = 0
 

Detailed Description

A subclass of SynthesiserVoice that can play a SamplerSound.

To use it, create a Synthesiser, add some SamplerVoice objects to it, then give it some SampledSound objects to play.

See also
SamplerSound, Synthesiser, SynthesiserVoice

{Audio}

Constructor & Destructor Documentation

◆ SamplerVoice()

juce::SamplerVoice::SamplerVoice ( )

Creates a SamplerVoice.

◆ ~SamplerVoice()

juce::SamplerVoice::~SamplerVoice ( )
override

Destructor.

Member Function Documentation

◆ aftertouchChanged()

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

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.

◆ canPlaySound()

bool juce::SamplerVoice::canPlaySound ( SynthesiserSound )
overridevirtual

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.

Implements juce::SynthesiserVoice.

◆ channelPressureChanged()

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

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.

◆ clearCurrentNote()

void juce::SynthesiserVoice::clearCurrentNote ( )
protectedinherited

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.

◆ controllerMoved()

void juce::SamplerVoice::controllerMoved ( int  controllerNumber,
int  newControllerValue 
)
overridevirtual

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.

Implements juce::SynthesiserVoice.

◆ getCurrentlyPlayingNote()

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

Returns the midi note that this voice is currently playing.

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

◆ getCurrentlyPlayingSound()

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

Returns the sound that this voice is currently playing.

Returns nullptr if it's not playing.

◆ getSampleRate()

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

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.

◆ isKeyDown()

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

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).

◆ isPlayingButReleased()

bool juce::SynthesiserVoice::isPlayingButReleased ( ) const
inlinenoexceptinherited

Returns true if a voice is sounding in its release phase.

◆ isPlayingChannel()

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

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.

◆ isSostenutoPedalDown()

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

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

◆ isSustainPedalDown()

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

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

◆ isVoiceActive()

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

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.

◆ pitchWheelMoved()

void juce::SamplerVoice::pitchWheelMoved ( int  newPitchWheelValue)
overridevirtual

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.

Implements juce::SynthesiserVoice.

◆ renderNextBlock() [1/2]

void juce::SamplerVoice::renderNextBlock ( AudioBuffer< float > &  outputBuffer,
int  startSample,
int  numSamples 
)
overridevirtual

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.

Implements juce::SynthesiserVoice.

◆ renderNextBlock() [2/2]

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

A double-precision version of renderNextBlock()

◆ setCurrentPlaybackSampleRate()

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

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.

◆ setKeyDown()

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

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

See also
isKeyDown

◆ setSostenutoPedalDown()

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

Modifies the sostenuto pedal flag.

◆ setSustainPedalDown()

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

Modifies the sustain pedal flag.

◆ startNote()

void juce::SamplerVoice::startNote ( int  midiNoteNumber,
float  velocity,
SynthesiserSound sound,
int  currentPitchWheelPosition 
)
overridevirtual

Called to start a new note.

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

Implements juce::SynthesiserVoice.

◆ stopNote()

void juce::SamplerVoice::stopNote ( float  velocity,
bool  allowTailOff 
)
overridevirtual

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().

Implements juce::SynthesiserVoice.

◆ wasStartedBefore()

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

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

Member Data Documentation

◆ adsr

ADSR juce::SamplerVoice::adsr
private

◆ lgain

float juce::SamplerVoice::lgain = 0
private

◆ pitchRatio

double juce::SamplerVoice::pitchRatio = 0
private

◆ rgain

float juce::SamplerVoice::rgain = 0
private

◆ sourceSamplePosition

double juce::SamplerVoice::sourceSamplePosition = 0
private

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