Gin
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
ModMatrix Class Reference

Modulation matrix system for routing multiple modulation sources to parameters. More...

#include <gin_modmatrix.h>

Classes

class  Listener
 

Public Types

enum  PolarityMode { unipolar , bipolar , sameAsSource }
 Modulation polarity modes for source-to-destination mapping. More...
 
enum  Function {
  linear , quadraticIn , quadraticInOut , quadraticOut ,
  sineIn , sineInOut , sineOut , exponentialIn ,
  exponentialInOut , exponentialOut , invLinear , invQuadraticIn ,
  invQuadraticInOut , invQuadraticOut , invSineIn , invSineInOut ,
  invSineOut , invExponentialIn , invExponentialInOut , invExponentialOut
}
 Modulation shaping functions for non-linear modulation curves. More...
 

Public Member Functions

 ModMatrix ()=default
 
void setDefaultPolarityMode (PolarityMode m)
 
void stateUpdated (const juce::ValueTree &vt)
 
void updateState (juce::ValueTree &vt)
 
float getValue (gin::Parameter *p, bool smoothed=true)
 
float getValue (ModVoice &voice, gin::Parameter *p, bool smoothed=true)
 
juce::Array< floatgetLiveValues (gin::Parameter *p)
 
void setMonoValue (ModSrcId id, float value)
 
void setPolyValue (ModVoice &voice, ModSrcId id, float value)
 
void finishBlock (int numSamples)
 
void addVoice (ModVoice *v)
 
ModSrcId addMonoModSource (const juce::String &id, const juce::String &name, bool bipolar)
 
ModSrcId addPolyModSource (const juce::String &id, const juce::String &name, bool bipolar)
 
void addParameter (gin::Parameter *p, bool poly, float smoothingTime=0.02f)
 
void setSampleRate (double sampleRate)
 
void build ()
 
void enableLearn (ModSrcId source)
 
void disableLearn ()
 
ModSrcId getLearn ()
 
int getNumModSources ()
 
juce::String getModSrcName (ModSrcId src)
 
bool getModSrcPoly (ModSrcId src)
 
bool getModSrcBipolar (ModSrcId src)
 
juce::String getModDstName (ModDstId dst)
 
juce::Array< ModSrcIdgetModSources (gin::Parameter *)
 
ParametergetParameter (ModDstId d)
 
bool isModulated (ModDstId param)
 
float getModDepth (ModSrcId src, ModDstId param)
 
std::vector< std::pair< ModDstId, float > > getModDepths (ModSrcId param)
 
std::vector< std::pair< ModSrcId, float > > getModDepths (ModDstId param)
 
void setModDepth (ModSrcId src, ModDstId param, float f)
 
void clearModDepth (ModSrcId src, ModDstId param)
 
Function getModFunction (ModSrcId src, ModDstId param)
 
void setModFunction (ModSrcId src, ModDstId param, Function f)
 
bool getModEnable (ModSrcId src, ModDstId param)
 
void setModEnable (ModSrcId src, ModDstId param, bool b)
 
bool getModBipolarMapping (ModSrcId src, ModDstId param)
 
void setModBipolarMapping (ModSrcId src, ModDstId param, bool b)
 
bool shouldShowLiveModValues ()
 
void setOnlyShowModWhenVoiceActive (bool b)
 
void addListener (Listener *l)
 
void removeListener (Listener *l)
 

Static Public Member Functions

static float shape (float v, Function f, bool biPolarSrc, bool biPolarDst)
 

Detailed Description

Modulation matrix system for routing multiple modulation sources to parameters.

The ModMatrix provides a flexible modulation routing system commonly used in synthesizers and audio effects. It allows multiple modulation sources (LFOs, envelopes, velocity, etc.) to control multiple destination parameters with configurable depth, enable/disable, and curve shaping.

Key Features:

Usage:

  1. Create a ModMatrix instance in your synthesizer
  2. Add all parameters using addParameter()
  3. Add modulation sources using addMonoModSource() or addPolyModSource()
  4. Update mod source values from your processing loop
  5. Always retrieve parameter values through the ModMatrix using getValue()

Example:

ModMatrix modMatrix;
// Setup
modMatrix.addParameter(filterCutoff, false);
auto lfo1 = modMatrix.addMonoModSource("lfo1", "LFO 1", true);
auto env1 = modMatrix.addPolyModSource("env1", "Envelope 1", false);
// In processing loop
modMatrix.setPolyValue(voice, env1, envelopeOutput);
float cutoff = modMatrix.getValue(filterCutoff);
Modulation matrix system for routing multiple modulation sources to parameters.
Definition gin_modmatrix.h:142
void setMonoValue(ModSrcId id, float value)
Definition gin_modmatrix.h:473
void setPolyValue(ModVoice &voice, ModSrcId id, float value)
Definition gin_modmatrix.h:481
ModSrcId addPolyModSource(const juce::String &id, const juce::String &name, bool bipolar)
float getValue(gin::Parameter *p, bool smoothed=true)
Definition gin_modmatrix.h:314
ModSrcId addMonoModSource(const juce::String &id, const juce::String &name, bool bipolar)
void addParameter(gin::Parameter *p, bool poly, float smoothingTime=0.02f)
A lightweight 2D point class for projects that don't use juce_graphics.
Definition gin_point.h:25
See also
ModVoice, ModSrcId, ModDstId

Member Enumeration Documentation

◆ PolarityMode

Modulation polarity modes for source-to-destination mapping.

PolarityMode determines how modulation values are interpreted when applied to parameters:

  • unipolar: Modulation ranges from 0 to 1 (always positive)
  • bipolar: Modulation ranges from -1 to 1 (positive and negative)
  • sameAsSource: Use the polarity of the modulation source

This affects how modulation depth is applied and visualized in the UI.

See also
ModMatrix, ModSrcId, ModDstId
Enumerator
unipolar 

0 to 1 (positive only)

bipolar 

-1 to 1 (positive and negative)

sameAsSource 

Match source polarity.

◆ Function

Modulation shaping functions for non-linear modulation curves.

Function provides various easing curves to shape modulation between source and destination. These allow creative control over how modulation values are mapped, enabling smooth fades, exponential responses, and inverted behaviors.

Curve Types:

  • linear: Direct 1:1 mapping (no curve)
  • quadratic: Smooth acceleration (parabolic)
  • sine: Smooth S-curve using sine function
  • exponential: Rapid acceleration (exponential)
  • inv*: Inverted versions (1 - f(x))

Curve Timing:

  • *In: Ease in (slow start, fast end)
  • *Out: Ease out (fast start, slow end)
  • *InOut: Ease in and out (smooth both ends)

These functions are applied after the modulation source value is retrieved and before it's scaled by depth and applied to the destination.

Usage Example:

// Create smooth fade-in modulation
// Create exponential response
// Inverted linear for reverse modulation
@ sineIn
Sine ease in.
Definition gin_modmatrix.h:218
@ exponentialOut
Exponential ease out.
Definition gin_modmatrix.h:224
@ invLinear
Inverted linear.
Definition gin_modmatrix.h:226
See also
ModMatrix, shape()
Enumerator
linear 

Linear (no shaping)

quadraticIn 

Quadratic ease in.

quadraticInOut 

Quadratic ease in and out.

quadraticOut 

Quadratic ease out.

sineIn 

Sine ease in.

sineInOut 

Sine ease in and out.

sineOut 

Sine ease out.

exponentialIn 

Exponential ease in.

exponentialInOut 

Exponential ease in and out.

exponentialOut 

Exponential ease out.

invLinear 

Inverted linear.

invQuadraticIn 

Inverted quadratic ease in.

invQuadraticInOut 

Inverted quadratic ease in and out.

invQuadraticOut 

Inverted quadratic ease out.

invSineIn 

Inverted sine ease in.

invSineInOut 

Inverted sine ease in and out.

invSineOut 

Inverted sine ease out.

invExponentialIn 

Inverted exponential ease in.

invExponentialInOut 

Inverted exponential ease in and out.

invExponentialOut 

Inverted exponential ease out.

Constructor & Destructor Documentation

◆ ModMatrix()

ModMatrix::ModMatrix ( )
default

Member Function Documentation

◆ setDefaultPolarityMode()

void ModMatrix::setDefaultPolarityMode ( PolarityMode  m)

◆ stateUpdated()

void ModMatrix::stateUpdated ( const juce::ValueTree &  vt)

◆ updateState()

void ModMatrix::updateState ( juce::ValueTree &  vt)

◆ shape()

static float ModMatrix::shape ( float  v,
Function  f,
bool  biPolarSrc,
bool  biPolarDst 
)
static

◆ getValue() [1/2]

float ModMatrix::getValue ( gin::Parameter *  p,
bool  smoothed = true 
)

◆ getValue() [2/2]

float ModMatrix::getValue ( ModVoice voice,
gin::Parameter *  p,
bool  smoothed = true 
)

References shape().

◆ getLiveValues()

juce::Array< float > ModMatrix::getLiveValues ( gin::Parameter *  p)

References shape().

◆ setMonoValue()

void ModMatrix::setMonoValue ( ModSrcId  id,
float  value 
)

◆ setPolyValue()

void ModMatrix::setPolyValue ( ModVoice voice,
ModSrcId  id,
float  value 
)

◆ finishBlock()

void ModMatrix::finishBlock ( int  numSamples)

◆ addVoice()

void ModMatrix::addVoice ( ModVoice v)

◆ addMonoModSource()

ModSrcId ModMatrix::addMonoModSource ( const juce::String &  id,
const juce::String &  name,
bool  bipolar 
)

◆ addPolyModSource()

ModSrcId ModMatrix::addPolyModSource ( const juce::String &  id,
const juce::String &  name,
bool  bipolar 
)

◆ addParameter()

void ModMatrix::addParameter ( gin::Parameter *  p,
bool  poly,
float  smoothingTime = 0.02f 
)

◆ setSampleRate()

void ModMatrix::setSampleRate ( double  sampleRate)

◆ build()

void ModMatrix::build ( )

◆ enableLearn()

void ModMatrix::enableLearn ( ModSrcId  source)

◆ disableLearn()

void ModMatrix::disableLearn ( )

◆ getLearn()

ModSrcId ModMatrix::getLearn ( )

◆ getNumModSources()

int ModMatrix::getNumModSources ( )

◆ getModSrcName()

juce::String ModMatrix::getModSrcName ( ModSrcId  src)

References ModSrcId::id.

◆ getModSrcPoly()

bool ModMatrix::getModSrcPoly ( ModSrcId  src)

References ModSrcId::id.

◆ getModSrcBipolar()

bool ModMatrix::getModSrcBipolar ( ModSrcId  src)

References ModSrcId::id.

◆ getModDstName()

juce::String ModMatrix::getModDstName ( ModDstId  dst)

◆ getModSources()

juce::Array< ModSrcId > ModMatrix::getModSources ( gin::Parameter *  )

◆ getParameter()

Parameter * ModMatrix::getParameter ( ModDstId  d)

◆ isModulated()

bool ModMatrix::isModulated ( ModDstId  param)

◆ getModDepth()

float ModMatrix::getModDepth ( ModSrcId  src,
ModDstId  param 
)

◆ getModDepths() [1/2]

std::vector< std::pair< ModDstId, float > > ModMatrix::getModDepths ( ModSrcId  param)

◆ getModDepths() [2/2]

std::vector< std::pair< ModSrcId, float > > ModMatrix::getModDepths ( ModDstId  param)

◆ setModDepth()

void ModMatrix::setModDepth ( ModSrcId  src,
ModDstId  param,
float  f 
)

◆ clearModDepth()

void ModMatrix::clearModDepth ( ModSrcId  src,
ModDstId  param 
)

◆ getModFunction()

Function ModMatrix::getModFunction ( ModSrcId  src,
ModDstId  param 
)

◆ setModFunction()

void ModMatrix::setModFunction ( ModSrcId  src,
ModDstId  param,
Function  f 
)

◆ getModEnable()

bool ModMatrix::getModEnable ( ModSrcId  src,
ModDstId  param 
)

◆ setModEnable()

void ModMatrix::setModEnable ( ModSrcId  src,
ModDstId  param,
bool  b 
)

◆ getModBipolarMapping()

bool ModMatrix::getModBipolarMapping ( ModSrcId  src,
ModDstId  param 
)

◆ setModBipolarMapping()

void ModMatrix::setModBipolarMapping ( ModSrcId  src,
ModDstId  param,
bool  b 
)

◆ shouldShowLiveModValues()

bool ModMatrix::shouldShowLiveModValues ( )

◆ setOnlyShowModWhenVoiceActive()

void ModMatrix::setOnlyShowModWhenVoiceActive ( bool  b)

◆ addListener()

void ModMatrix::addListener ( Listener l)

◆ removeListener()

void ModMatrix::removeListener ( Listener l)

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