SoundFontInfoLib  2.21.6
Library for parsing and rendering SF2 files
SF2::Render::Voice::State Class Reference

Generator state values for a rendering voice. More...

#include <State.hpp>

Public Types

enum  LoopingMode { none = 0 , continuously = 1 , duringKeyPress = 3 }
 These are values for the sampleModes (#54) generator. More...
 
using Amount = Entity::Generator::Amount
 
using Index = Entity::Generator::Index
 
using Definition = Entity::Generator::Definition
 

Public Member Functions

 State (double sampleRate, const MIDI::Channel &channel, int key, int velocity)
 Mock constructor – only used in unit tests. More...
 
 State (double sampleRate, const MIDI::Channel &channel, const Setup &setup)
 Create new state vector with a given sample rate. More...
 
void setValue (Index index, int value)
 Set a generator value. More...
 
void adjustValue (Index index, int value)
 Set a generator's adjustment value. More...
 
void addModulator (const Entity::Modulator::Modulator &modulator)
 Install a modulator. More...
 
double modulated (Index index) const
 Obtain a generator value after applying any registered modulators to it. More...
 
int unmodulated (Index index) const
 Obtain a generator value without any modulation applied to it. More...
 
double pitch () const
 
int key () const
 
int velocity () const
 
int eventKey () const
 
int eventVelocity () const
 
double keyedVolumeEnvelopeHold () const
 
double keyedVolumeEnvelopeDecay () const
 
double keyedModulatorEnvelopeHold () const
 
double keyedModulatorEnvelopeDecay () const
 
double sustainLevelVolumeEnvelope () const
 
double sustainLevelModulatorEnvelope () const
 
LoopingMode loopingMode () const
 
const MIDI::Channelchannel () const
 
double sampleRate () const
 

Detailed Description

Generator state values for a rendering voice.

These are the values from generators. There is the initial state which is the default values. Next, there are instrument generators from the zones that match the MIDI key/velocity values of a MIDI event. These can override any default values. Finally, there are the preset generators which refine any values by adding to them. Note that not all generators are available for refining. Those that are return true from Generator::Definition::isAvailableInPreset.

Member Typedef Documentation

◆ Amount

◆ Definition

◆ Index

Member Enumeration Documentation

◆ LoopingMode

These are values for the sampleModes (#54) generator.

  • none – rendering does not loop
  • continuously – loop as long as the envelope allows
  • duringKeyPress – loop only while they key is down
Enumerator
none 
continuously 
duringKeyPress 

Constructor & Destructor Documentation

◆ State() [1/2]

SF2::Render::Voice::State::State ( double  sampleRate,
const MIDI::Channel channel,
int  key,
int  velocity 
)
inline

Mock constructor – only used in unit tests.

◆ State() [2/2]

State::State ( double  sampleRate,
const MIDI::Channel channel,
const Setup setup 
)

Create new state vector with a given sample rate.

Parameters
sampleRatethe sample rate of audio being rendered
channelthe MIDI channel that is in control
setupthe voice configuration to use

References SF2::Render::Voice::Setup::apply().

Member Function Documentation

◆ addModulator()

void State::addModulator ( const Entity::Modulator::Modulator modulator)

◆ adjustValue()

void SF2::Render::Voice::State::adjustValue ( Index  index,
int  value 
)
inline

Set a generator's adjustment value.

Instrument zones set generator values; preset zones set their adjustments. It can be set twice, once by a global preset generator setting, and again by a non-global preset generator setting.

Parameters
indexthe generator to set
valuethe value to use

References SF2::Logger::debug(), SF2::Entity::Generator::Definition::definition(), and SF2::Entity::Generator::Definition::name().

◆ channel()

const MIDI::Channel& SF2::Render::Voice::State::channel ( ) const
inline
Returns
the MIDI channel state associated with the rendering

◆ eventKey()

int SF2::Render::Voice::State::eventKey ( ) const
inline
Returns
key from MIDI event that triggered the voice rendering

Referenced by key().

◆ eventVelocity()

int SF2::Render::Voice::State::eventVelocity ( ) const
inline
Returns
velocity from MIDI event that triggered the voice rendering

Referenced by velocity().

◆ key()

int SF2::Render::Voice::State::key ( ) const
inline
Returns
key value to use

References eventKey(), and unmodulated().

Referenced by pitch().

◆ keyedModulatorEnvelopeDecay()

double SF2::Render::Voice::State::keyedModulatorEnvelopeDecay ( ) const
inline
Returns
the adjustment to the modulator envelope's decay stage timing based on the MIDI key event

Referenced by SF2::Render::Envelope::Generator::Modulator().

◆ keyedModulatorEnvelopeHold()

double SF2::Render::Voice::State::keyedModulatorEnvelopeHold ( ) const
inline
Returns
the adjustment to the modulator envelope's hold stage timing based on the MIDI key event

Referenced by SF2::Render::Envelope::Generator::Modulator().

◆ keyedVolumeEnvelopeDecay()

double SF2::Render::Voice::State::keyedVolumeEnvelopeDecay ( ) const
inline
Returns
the adjustment to the volume envelope's decay stage timing based on the MIDI key event

Referenced by SF2::Render::Envelope::Generator::Volume().

◆ keyedVolumeEnvelopeHold()

double SF2::Render::Voice::State::keyedVolumeEnvelopeHold ( ) const
inline
Returns
the adjustment to the volume envelope's hold stage timing based on the MIDI key event

Referenced by SF2::Render::Envelope::Generator::Volume().

◆ loopingMode()

LoopingMode SF2::Render::Voice::State::loopingMode ( ) const
inline
Returns
looping mode of the sample being rendered

References unmodulated().

◆ modulated()

double SF2::Render::Voice::State::modulated ( Index  index) const
inline

Obtain a generator value after applying any registered modulators to it.

Due to the modulation calculations this returns a floating-point value, but the value has not been converted from/into any particular units and should still reflect the definitions found in the spec.

Parameters
indexthe index of the generator
Returns
current value of the generator

Referenced by SF2::Render::Envelope::Generator::Modulator(), pitch(), SF2::Render::Sample::PitchControl::PitchControl(), SF2::Render::Voice::Voice::render(), and SF2::Render::Envelope::Generator::Volume().

◆ pitch()

double SF2::Render::Voice::State::pitch ( ) const
inline
Returns
fundamental pitch to generate when rendering (semitones)

References key(), and modulated().

◆ sampleRate()

double SF2::Render::Voice::State::sampleRate ( ) const
inline
Returns
sample rate defined at construction

Referenced by SF2::Render::Envelope::Generator::Modulator(), and SF2::Render::Envelope::Generator::Volume().

◆ setValue()

void SF2::Render::Voice::State::setValue ( Index  index,
int  value 
)
inline

Set a generator value.

Instrument zones set generator values; preset zones set their adjustments. It can be set twice, once by a global instrument generator setting, and again by a non-global instrument generator setting.

Parameters
indexthe generator to set
valuethe value to use

References SF2::Logger::debug(), SF2::Entity::Generator::Definition::definition(), and SF2::Entity::Generator::Definition::name().

◆ sustainLevelModulatorEnvelope()

double SF2::Render::Voice::State::sustainLevelModulatorEnvelope ( ) const
inline
Returns
the sustain level for the modulator envelope

Referenced by SF2::Render::Envelope::Generator::Modulator().

◆ sustainLevelVolumeEnvelope()

double SF2::Render::Voice::State::sustainLevelVolumeEnvelope ( ) const
inline
Returns
the sustain level for the volume envelope (gain)

Referenced by SF2::Render::Envelope::Generator::Volume().

◆ unmodulated()

int SF2::Render::Voice::State::unmodulated ( Index  index) const
inline

Obtain a generator value without any modulation applied to it.

This is the original result from the zone generator definitions and so it is expressed as an integer. Most of the time, the modulated method is what is desired in order to account for any MIDI controller values.

Parameters
indexthe index of the generator
Returns
configured value of the generator

Referenced by SF2::Render::Sample::Bounds::Bounds(), key(), loopingMode(), and velocity().

◆ velocity()

int SF2::Render::Voice::State::velocity ( ) const
inline
Returns
key velocity to use when calculating attenuation

References eventVelocity(), and unmodulated().


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