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

A zone represents a collection of generator and modulator settings that apply to a range of MIDI key and velocity values. More...

#include <Zone.hpp>

Inherited by SF2::Render::InstrumentZone, and SF2::Render::PresetZone.

Public Types

using GeneratorCollection = IO::ChunkItems< Entity::Generator::Generator >::ItemRefCollection
 
using ModulatorCollection = IO::ChunkItems< Entity::Modulator::Modulator >::ItemRefCollection
 

Public Member Functions

const MIDIRangekeyRange () const
 
const MIDIRangevelocityRange () const
 
const GeneratorCollectiongenerators () const
 
const ModulatorCollectionmodulators () const
 
bool isGlobal () const
 
bool appliesTo (int key, int velocity) const
 Determines if this zone applies to a given MIDI key/velocity pair. More...
 

Static Public Attributes

static MIDIRange const all = MIDIRange(0, 255)
 A range that always returns true for any MIDI value. More...
 

Protected Member Functions

 Zone (GeneratorCollection &&gens, ModulatorCollection &&mods, Entity::Generator::Index terminal)
 Constructor. More...
 
uint16_t resourceLink () const
 Obtain the link to the resource used by this zone. More...
 
void apply (Voice::State &state) const
 Apply the instrument zone to the given voice state. More...
 
void refine (Voice::State &state) const
 Apply the zone to the given voice state by adjusting the value using the generator in the zone. More...
 

Detailed Description

A zone represents a collection of generator and modulator settings that apply to a range of MIDI key and velocity values.

There are two types: instrument zones and preset zones. Generator settings for the former specify actual values to use, while those in preset zones define adjustments to values set by the instrument.

Member Typedef Documentation

◆ GeneratorCollection

◆ ModulatorCollection

Constructor & Destructor Documentation

◆ Zone()

SF2::Render::Zone::Zone ( GeneratorCollection &&  gens,
ModulatorCollection &&  mods,
Entity::Generator::Index  terminal 
)
inlineprotected

Constructor.

Parameters
genscollection of generator for the zone
modscollection of modulators for the zone
terminalthe index type of a generator that signals the zone is NOT global

Member Function Documentation

◆ appliesTo()

bool SF2::Render::Zone::appliesTo ( int  key,
int  velocity 
) const
inline

Determines if this zone applies to a given MIDI key/velocity pair.

NOTE: this should not be called for a global zone, though technically doing so is OK since both key/velocity ranges will be set to all by default.

Parameters
keyMIDI key value
velocityMIDI velocity value
Returns
true if so

References SF2::Render::Range< T >::contains().

◆ apply()

void SF2::Render::Zone::apply ( Voice::State state) const
inlineprotected

Apply the instrument zone to the given voice state.

Parameters
statethe voice state to update

Referenced by SF2::Render::InstrumentZone::apply().

◆ generators()

const GeneratorCollection& SF2::Render::Zone::generators ( ) const
inline
Returns
collection of generators defined for this zone

◆ isGlobal()

bool SF2::Render::Zone::isGlobal ( ) const
inline
Returns
true if this is a global zone

◆ keyRange()

const MIDIRange& SF2::Render::Zone::keyRange ( ) const
inline
Returns
range of MID key values that this Zone handles

◆ modulators()

const ModulatorCollection& SF2::Render::Zone::modulators ( ) const
inline
Returns
collection of modulators defined for this zone

◆ refine()

void SF2::Render::Zone::refine ( Voice::State state) const
inlineprotected

Apply the zone to the given voice state by adjusting the value using the generator in the zone.

Note that here we blindly perform this operation to ALL generators regardless of type. The spec specifically says NOT to do this for some generator types, but in this implementation there are no issues with doing so:

  • State values start with a 0 value, so performing the += operation for an allowed index generator type is the same as setting it.
  • The range generators keyRange and velocityRange are only used during the filtering stage and so the update here is a waste of time but otherwise harmless.
Parameters
statethe voice state to update

Referenced by SF2::Render::PresetZone::refine().

◆ resourceLink()

uint16_t SF2::Render::Zone::resourceLink ( ) const
inlineprotected

Obtain the link to the resource used by this zone.

For an instrument zone, this points to the sample buffer to use to render sounds. For a preset zone, this points to an instrument.

Returns
index of the resource that this zone uses

References SF2::Entity::Generator::instrument, and SF2::Entity::Generator::sampleID.

◆ velocityRange()

const MIDIRange& SF2::Render::Zone::velocityRange ( ) const
inline
Returns
range of MIDI velocity values that this Zone handles

Member Data Documentation

◆ all

MIDIRange const Zone::all = MIDIRange(0, 255)
static

A range that always returns true for any MIDI value.


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