LMMS
Loading...
Searching...
No Matches
water::SynthesiserVoice Class Referenceabstract

#include <Synthesiser.h>

Inheritance diagram for water::SynthesiserVoice:
sfzero::Voice

Public Member Functions

 SynthesiserVoice ()
virtual ~SynthesiserVoice ()
int getCurrentlyPlayingNote () const noexcept
SynthesiserSound::Ptr getCurrentlyPlayingSound () const noexcept
virtual bool canPlaySound (SynthesiserSound *)=0
virtual void startNote (int midiNoteNumber, float velocity, SynthesiserSound *sound, int currentPitchWheelPosition)=0
virtual void stopNote (float velocity, bool allowTailOff)=0
virtual bool isVoiceActive () const
virtual void pitchWheelMoved (int newPitchWheelValue)=0
virtual void controllerMoved (int controllerNumber, int newControllerValue)=0
virtual void aftertouchChanged (int newAftertouchValue)
virtual void channelPressureChanged (int newChannelPressureValue)
virtual void renderNextBlock (AudioSampleBuffer &outputBuffer, int startSample, int numSamples)=0
virtual void setCurrentPlaybackSampleRate (double newRate)
virtual bool isPlayingChannel (int midiChannel) const
double getSampleRate () const noexcept
bool isKeyDown () const noexcept
bool isSustainPedalDown () const noexcept
bool isSostenutoPedalDown () const noexcept
bool isPlayingButReleased () const noexcept
bool wasStartedBefore (const SynthesiserVoice &other) const noexcept

Protected Member Functions

void clearCurrentNote ()

Private Attributes

double currentSampleRate
int currentlyPlayingNote
int currentPlayingMidiChannel
uint32 noteOnTime
SynthesiserSound::Ptr currentlyPlayingSound
bool keyIsDown
bool sustainPedalDown
bool sostenutoPedalDown
AudioSampleBuffer tempBuffer

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

Constructor & Destructor Documentation

◆ SynthesiserVoice()

water::SynthesiserVoice::SynthesiserVoice ( )

Creates a voice.

◆ ~SynthesiserVoice()

water::SynthesiserVoice::~SynthesiserVoice ( )
virtual

Destructor.

Member Function Documentation

◆ aftertouchChanged()

void water::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.

◆ canPlaySound()

virtual bool water::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 sfzero::Voice.

◆ channelPressureChanged()

void water::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.

◆ clearCurrentNote()

void water::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.

◆ controllerMoved()

virtual void water::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 sfzero::Voice.

◆ getCurrentlyPlayingNote()

int water::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.

◆ getCurrentlyPlayingSound()

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

Returns the sound that this voice is currently playing. Returns nullptr if it's not playing.

◆ getSampleRate()

double water::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.

◆ isKeyDown()

bool water::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).

◆ isPlayingButReleased()

bool water::SynthesiserVoice::isPlayingButReleased ( ) const
inlinenoexcept

Returns true if a voice is sounding in its release phase

◆ isPlayingChannel()

bool water::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.

◆ isSostenutoPedalDown()

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

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

◆ isSustainPedalDown()

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

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

◆ isVoiceActive()

bool water::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.

◆ pitchWheelMoved()

virtual void water::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 sfzero::Voice.

◆ renderNextBlock()

virtual void water::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 sfzero::Voice.

◆ setCurrentPlaybackSampleRate()

void water::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.

◆ startNote()

virtual void water::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 sfzero::Voice.

◆ stopNote()

virtual void water::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 sfzero::Voice.

◆ wasStartedBefore()

bool water::SynthesiserVoice::wasStartedBefore ( const SynthesiserVoice & other) const
noexcept

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

◆ Synthesiser

friend class Synthesiser
friend

Member Data Documentation

◆ currentlyPlayingNote

int water::SynthesiserVoice::currentlyPlayingNote
private

◆ currentlyPlayingSound

SynthesiserSound::Ptr water::SynthesiserVoice::currentlyPlayingSound
private

◆ currentPlayingMidiChannel

int water::SynthesiserVoice::currentPlayingMidiChannel
private

◆ currentSampleRate

double water::SynthesiserVoice::currentSampleRate
private

◆ keyIsDown

bool water::SynthesiserVoice::keyIsDown
private

◆ noteOnTime

uint32 water::SynthesiserVoice::noteOnTime
private

◆ sostenutoPedalDown

bool water::SynthesiserVoice::sostenutoPedalDown
private

◆ sustainPedalDown

bool water::SynthesiserVoice::sustainPedalDown
private

◆ tempBuffer

AudioSampleBuffer water::SynthesiserVoice::tempBuffer
private

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