IpatchSF2Gen

IpatchSF2Gen — SoundFont generator routines

Synopsis




#define             IPATCH_SF2_GEN_COUNT
                    IpatchSF2GenArray;
                    IpatchSF2GenInfo;
#define             IPATCH_TYPE_SF2_GEN_ARRAY
union               IpatchSF2GenAmount;
struct              IpatchSF2Gen;
#define             IPATCH_SF2_GENID_SET                (genid)
#define             IPATCH_SF2_GEN_ARRAY_TEST_FLAG      (array, genid)
#define             IPATCH_SF2_GEN_ARRAY_SET_FLAG       (array, genid)
#define             IPATCH_SF2_GEN_ARRAY_CLEAR_FLAG     (array, genid)
enum                IpatchSF2GenType;
enum                IpatchSF2GenSampleModes;
extern              IpatchSF2GenArray *ipatch_sf2_gen_ofs_array;
extern              IpatchSF2GenArray *ipatch_sf2_gen_abs_array;
extern              guint64 ipatch_sf2_gen_ofs_valid_mask;
extern              guint64 ipatch_sf2_gen_abs_valid_mask;
GType               ipatch_sf2_gen_array_get_type       (void);
IpatchSF2GenArray*  ipatch_sf2_gen_array_new            (gboolean clear);
void                ipatch_sf2_gen_array_free           (IpatchSF2GenArray *genarray);
IpatchSF2GenArray*  ipatch_sf2_gen_array_duplicate      (const IpatchSF2GenArray *array);
void                ipatch_sf2_gen_array_init           (IpatchSF2GenArray *array,
                                                         gboolean offset,
                                                         gboolean set);
void                ipatch_sf2_gen_array_offset         (IpatchSF2GenArray *abs_array,
                                                         const IpatchSF2GenArray *ofs_array);
void                ipatch_sf2_gen_amount_to_value      (guint genid,
                                                         IpatchSF2GenAmount *amt,
                                                         GValue *value);
#define             ipatch_sf2_genid_is_valid           (genid, ispreset)
void                ipatch_sf2_genid_default_value      (guint16 genid,
                                                         gboolean ispreset,
                                                         IpatchSF2GenAmount *out_amt);
gboolean            ipatch_sf2_genid_offset             (int genid,
                                                         IpatchSF2GenAmount *dst,
                                                         const IpatchSF2GenAmount *ofs);
void                ipatch_sf2_units_sfont_to_user      (guint16 genid,
                                                         const IpatchSF2GenAmount *amt,
                                                         float *out_userval,
                                                         gboolean ispreset);
void                ipatch_sf2_units_sfont_to_user_str  (guint16 genid,
                                                         const IpatchSF2GenAmount *amt,
                                                         float *out_userval,
                                                         char **out_userstr,
                                                         gboolean ispreset);
int                 ipatch_sf2_units_user_to_sfont      (guint16 genid,
                                                         float userval,
                                                         gboolean ispreset,
                                                         gboolean clamp);
void                ipatch_sf2_units_clamp              (guint16 genid,
                                                         int *sfval,
                                                         gboolean ispreset);
gboolean            ipatch_sf2_units_range_intersect    (IpatchSF2GenAmount *dst,
                                                         const IpatchSF2GenAmount *src);
char*               ipatch_sf2_genid_unit_str           (guint16 genid,
                                                         gboolean ispreset);

Description

A SoundFont generator structure and related routines. Generators are effect parameters that reside in IpatchSF2Zone derived types.

Details

IPATCH_SF2_GEN_COUNT

#define IPATCH_SF2_GEN_COUNT 59


IpatchSF2GenArray

typedef struct {
  guint64 flags; /* 1 bit for each generator indicating if it is set */
  IpatchSF2GenAmount values[IPATCH_SF2_GEN_COUNT]; /* gen values */
} IpatchSF2GenArray;


IpatchSF2GenInfo

typedef struct {
  IpatchSF2GenAmount min;	/* minimum value allowed */
  IpatchSF2GenAmount max;	/* maximum value allowed */
  IpatchSF2GenAmount def;	/* default value */
  gint16 unit;			/* #IpatchUnitType type */
  char *label;			/* short descriptive label */
  char *descr;			/* more complete description */
} IpatchSF2GenInfo;

Per generator type information.

IpatchSF2GenAmount min; Minimum value of generator.
IpatchSF2GenAmount max; Maximum value of generator.
IpatchSF2GenAmount def; Default value of generator.
gint16 unit; IpatchUnitType enumeration for generator.
char *label; A short label for this generator.
char *descr; Description of generator.

IPATCH_TYPE_SF2_GEN_ARRAY

#define IPATCH_TYPE_SF2_GEN_ARRAY   (ipatch_sf2_gen_array_get_type ())


union IpatchSF2GenAmount

union IpatchSF2GenAmount
{
  /*< public >*/
  gint16 sword;			/* signed 16 bit value */
  guint16 uword;		/* unsigned 16 bit value */
  struct
  {
    guint8 low;			/* low value of range */
    guint8 high;		/* high value of range */
  } range;			/* range values, low - high */
};

A generator amount (signed/unsigned 16 bit or a range).


struct IpatchSF2Gen

struct IpatchSF2Gen {
  guint16 id;			/* generator #IPGenType ID */
  IpatchSF2GenAmount amount;	/* generator value */
};

SoundFont generator structure

guint16 id; IpatchSF2GenType enumeration.
IpatchSF2GenAmount amount; Generator amount.

IPATCH_SF2_GENID_SET()

#define IPATCH_SF2_GENID_SET(genid) ((guint64)0x1 << (genid))

genid :

IPATCH_SF2_GEN_ARRAY_TEST_FLAG()

#define             IPATCH_SF2_GEN_ARRAY_TEST_FLAG(array, genid)

array :
genid :

IPATCH_SF2_GEN_ARRAY_SET_FLAG()

#define             IPATCH_SF2_GEN_ARRAY_SET_FLAG(array, genid)

array :
genid :

IPATCH_SF2_GEN_ARRAY_CLEAR_FLAG()

#define             IPATCH_SF2_GEN_ARRAY_CLEAR_FLAG(array, genid)

array :
genid :

enum IpatchSF2GenType

typedef enum
{
  IPATCH_SF2_GEN_SAMPLE_START = 0, /* sample start offset */
  IPATCH_SF2_GEN_SAMPLE_END = 1,	/* sample end offset */
  IPATCH_SF2_GEN_SAMPLE_LOOP_START = 2,/* sample loop start offset */
  IPATCH_SF2_GEN_SAMPLE_LOOP_END = 3, /* sample loop end offset */
  IPATCH_SF2_GEN_SAMPLE_COARSE_START = 4, /* sample start coarse offset */
  IPATCH_SF2_GEN_MOD_LFO_TO_PITCH = 5, /* modulation LFO to pitch */
  IPATCH_SF2_GEN_VIB_LFO_TO_PITCH = 6, /* vibrato LFO to pitch */
  IPATCH_SF2_GEN_MOD_ENV_TO_PITCH = 7, /* modulation envelope to pitch */
  IPATCH_SF2_GEN_FILTER_FC = 8,	/* initial filter cutoff */
  IPATCH_SF2_GEN_FILTER_Q = 9,	/* filter Q */
  IPATCH_SF2_GEN_MOD_LFO_TO_FILTER_FC = 10, /* mod LFO to filter cutoff */
  IPATCH_SF2_GEN_MOD_ENV_TO_FILTER_FC = 11, /* mod envelope to filter cutoff */
  IPATCH_SF2_GEN_SAMPLE_COARSE_END = 12, /* sample end course offset */
  IPATCH_SF2_GEN_MOD_LFO_TO_VOL = 13, /* modulation LFO to volume */
  IPATCH_SF2_GEN_UNUSED1 = 14,
  IPATCH_SF2_GEN_CHORUS_SEND = 15, /* chorus */
  IPATCH_SF2_GEN_REVERB_SEND = 16, /* reverb */
  IPATCH_SF2_GEN_PAN = 17,	/* panning */
  IPATCH_SF2_GEN_UNUSED2 = 18,
  IPATCH_SF2_GEN_UNUSED3 = 19,
  IPATCH_SF2_GEN_UNUSED4 = 20,
  IPATCH_SF2_GEN_MOD_LFO_DELAY = 21, /* modulation LFO delay */
  IPATCH_SF2_GEN_MOD_LFO_FREQ = 22, /* modulation LFO frequency */
  IPATCH_SF2_GEN_VIB_LFO_DELAY = 23, /* vibrato LFO delay */
  IPATCH_SF2_GEN_VIB_LFO_FREQ = 24, /* vibrato LFO frequency */
  IPATCH_SF2_GEN_MOD_ENV_DELAY = 25, /* modulation envelope delay */
  IPATCH_SF2_GEN_MOD_ENV_ATTACK = 26, /* modulation envelope attack */
  IPATCH_SF2_GEN_MOD_ENV_HOLD = 27, /* modulation envelope hold */
  IPATCH_SF2_GEN_MOD_ENV_DECAY = 28, /* modulation envelope decay */
  IPATCH_SF2_GEN_MOD_ENV_SUSTAIN = 29, /* modulation envelope sustain */
  IPATCH_SF2_GEN_MOD_ENV_RELEASE = 30, /* modulation envelope release */
  IPATCH_SF2_GEN_KEY_TO_MOD_ENV_HOLD = 31, /* MIDI key to mod envelope hold */
  IPATCH_SF2_GEN_KEY_TO_MOD_ENV_DECAY = 32, /* MIDI key to mod env decay */
  IPATCH_SF2_GEN_VOL_ENV_DELAY = 33, /* volume envelope delay */
  IPATCH_SF2_GEN_VOL_ENV_ATTACK = 34, /* volume envelope attack */
  IPATCH_SF2_GEN_VOL_ENV_HOLD = 35, /* volume envelope hold */
  IPATCH_SF2_GEN_VOL_ENV_DECAY = 36, /* volume envelope decay */
  IPATCH_SF2_GEN_VOL_ENV_SUSTAIN = 37, /* volume envelope sustain */
  IPATCH_SF2_GEN_VOL_ENV_RELEASE = 38, /* volume envelope release */
  IPATCH_SF2_GEN_KEY_TO_VOL_ENV_HOLD = 39, /* MIDI key to vol envelope hold */
  IPATCH_SF2_GEN_KEY_TO_VOL_ENV_DECAY = 40, /* MIDI key to volume env decay */
  IPATCH_SF2_GEN_INSTRUMENT_ID = 41, /* instrument ID */
  IPATCH_SF2_GEN_RESERVED1 = 42,
  IPATCH_SF2_GEN_KEY_RANGE = 43,	/* note on key range */
  IPATCH_SF2_GEN_VELOCITY_RANGE = 44, /* note on velocity range */
  IPATCH_SF2_GEN_SAMPLE_COARSE_LOOP_START = 45, /* sample coarse loop start */
  IPATCH_SF2_GEN_FIXED_NOTE = 46, /* MIDI fixed note */
  IPATCH_SF2_GEN_FIXED_VELOCITY = 47, /* MIDI fixed velocity */
  IPATCH_SF2_GEN_ATTENUATION = 48, /* initial volume attenuation */
  IPATCH_SF2_GEN_RESERVED2 = 49,
  IPATCH_SF2_GEN_SAMPLE_COARSE_LOOP_END = 50, /* sample end loop course ofs */
  IPATCH_SF2_GEN_COARSE_TUNE = 51, /* course tuning */
  IPATCH_SF2_GEN_FINE_TUNE_OVERRIDE = 52, /* fine tune override */
  IPATCH_SF2_GEN_SAMPLE_ID = 53,	/* sample ID */
  IPATCH_SF2_GEN_SAMPLE_MODES = 54, /* sample flags (IpatchSF2GenSampleModes)*/
  IPATCH_SF2_GEN_RESERVED3 = 55,
  IPATCH_SF2_GEN_SCALE_TUNE = 56, /* scale tuning (tuning per MIDI key) */
  IPATCH_SF2_GEN_EXCLUSIVE_CLASS = 57, /* exclusive class (only 1 at a time) */
  IPATCH_SF2_GEN_ROOT_NOTE_OVERRIDE = 58 /* root note override */
} IpatchSF2GenType;

Generator ID.

IPATCH_SF2_GEN_SAMPLE_START Sample start offset (< 32k)
IPATCH_SF2_GEN_SAMPLE_END Sample end offset (< 32k)
IPATCH_SF2_GEN_SAMPLE_LOOP_START Sample loop start offset (< 32k)
IPATCH_SF2_GEN_SAMPLE_LOOP_END Sample loop end offset (< 32k)
IPATCH_SF2_GEN_SAMPLE_COARSE_START Sample start coarse offset (* 32k)
IPATCH_SF2_GEN_MOD_LFO_TO_PITCH Modulation LFO to pitch
IPATCH_SF2_GEN_VIB_LFO_TO_PITCH Vibrato LFO to pitch
IPATCH_SF2_GEN_MOD_ENV_TO_PITCH Modulation envelope to pitch
IPATCH_SF2_GEN_FILTER_FC Filter cutoff
IPATCH_SF2_GEN_FILTER_Q Filter Q
IPATCH_SF2_GEN_MOD_LFO_TO_FILTER_FC Modulation LFO to filter cutoff
IPATCH_SF2_GEN_MOD_ENV_TO_FILTER_FC Modulation envelope to filter cutoff
IPATCH_SF2_GEN_SAMPLE_COARSE_END Sample end coarse offset (* 32k)
IPATCH_SF2_GEN_MOD_LFO_TO_VOL Modulation LFO to volume
IPATCH_SF2_GEN_UNUSED1 Unused
IPATCH_SF2_GEN_CHORUS_SEND Chorus effect amount
IPATCH_SF2_GEN_REVERB_SEND Reverb effect amount
IPATCH_SF2_GEN_PAN Panning amount
IPATCH_SF2_GEN_UNUSED2 Unused
IPATCH_SF2_GEN_UNUSED3 Unused
IPATCH_SF2_GEN_UNUSED4 Unused
IPATCH_SF2_GEN_MOD_LFO_DELAY Modulation LFO delay
IPATCH_SF2_GEN_MOD_LFO_FREQ Modulation LFO frequency
IPATCH_SF2_GEN_VIB_LFO_DELAY Vibrato LFO delay
IPATCH_SF2_GEN_VIB_LFO_FREQ Vbirato LFO frequency
IPATCH_SF2_GEN_MOD_ENV_DELAY Modulation envelope delay
IPATCH_SF2_GEN_MOD_ENV_ATTACK Modulation envelope attack
IPATCH_SF2_GEN_MOD_ENV_HOLD Modulation envelope hold
IPATCH_SF2_GEN_MOD_ENV_DECAY Modulation envelope decay
IPATCH_SF2_GEN_MOD_ENV_SUSTAIN Modulation envelope sustain
IPATCH_SF2_GEN_MOD_ENV_RELEASE Modulation envelope release
IPATCH_SF2_GEN_KEY_TO_MOD_ENV_HOLD MIDI note # to modulation envelope hold
IPATCH_SF2_GEN_KEY_TO_MOD_ENV_DECAY MIDI note # to modulation envelope decay
IPATCH_SF2_GEN_VOL_ENV_DELAY Volume envelope decay
IPATCH_SF2_GEN_VOL_ENV_ATTACK Volume envelope attack
IPATCH_SF2_GEN_VOL_ENV_HOLD Volume envelope hold
IPATCH_SF2_GEN_VOL_ENV_DECAY Volume envelope decay
IPATCH_SF2_GEN_VOL_ENV_SUSTAIN Volume envelope sustain
IPATCH_SF2_GEN_VOL_ENV_RELEASE Volume envelope release
IPATCH_SF2_GEN_KEY_TO_VOL_ENV_HOLD MIDI note # to volume envelope hold
IPATCH_SF2_GEN_KEY_TO_VOL_ENV_DECAY MIDI note # to volume envelope decay
IPATCH_SF2_GEN_INSTRUMENT_ID Instrument index
IPATCH_SF2_GEN_RESERVED1 Reserved
IPATCH_SF2_GEN_KEY_RANGE MIDI note range
IPATCH_SF2_GEN_VELOCITY_RANGE MIDI velocity range
IPATCH_SF2_GEN_SAMPLE_COARSE_LOOP_START Sample loop start coarse offset (* 32k)
IPATCH_SF2_GEN_FIXED_NOTE
IPATCH_SF2_GEN_FIXED_VELOCITY
IPATCH_SF2_GEN_ATTENUATION Initial volume attenuation
IPATCH_SF2_GEN_RESERVED2 Reserved
IPATCH_SF2_GEN_SAMPLE_COARSE_LOOP_END Sample loop end coarse offset (* 32k)
IPATCH_SF2_GEN_COARSE_TUNE Coarse tuning
IPATCH_SF2_GEN_FINE_TUNE_OVERRIDE
IPATCH_SF2_GEN_SAMPLE_ID Sample index
IPATCH_SF2_GEN_SAMPLE_MODES Sample mode flags (IpatchSF2GenSampleModes)
IPATCH_SF2_GEN_RESERVED3 Reserved
IPATCH_SF2_GEN_SCALE_TUNE Scale tuning
IPATCH_SF2_GEN_EXCLUSIVE_CLASS Exclusive class
IPATCH_SF2_GEN_ROOT_NOTE_OVERRIDE

enum IpatchSF2GenSampleModes

typedef enum
{
  IPATCH_SF2_GEN_SAMPLE_MODE_NOLOOP = 0,
  IPATCH_SF2_GEN_SAMPLE_MODE_LOOP   = 1 << 0,
  IPATCH_SF2_GEN_SAMPLE_MODE_LOOP_RELEASE = 1 << 1
} IpatchSF2GenSampleModes;

Values for IPATCH_SF_GEN_SAMPLE_MODES generator.

IPATCH_SF2_GEN_SAMPLE_MODE_NOLOOP No sample looping (single shot)
IPATCH_SF2_GEN_SAMPLE_MODE_LOOP Sample looping
IPATCH_SF2_GEN_SAMPLE_MODE_LOOP_RELEASE

ipatch_sf2_gen_ofs_array

extern IpatchSF2GenArray *ipatch_sf2_gen_ofs_array;


ipatch_sf2_gen_abs_array

extern IpatchSF2GenArray *ipatch_sf2_gen_abs_array;


ipatch_sf2_gen_ofs_valid_mask

extern guint64 ipatch_sf2_gen_ofs_valid_mask;


ipatch_sf2_gen_abs_valid_mask

extern guint64 ipatch_sf2_gen_abs_valid_mask;


ipatch_sf2_gen_array_get_type ()

GType               ipatch_sf2_gen_array_get_type       (void);

Returns :

ipatch_sf2_gen_array_new ()

IpatchSF2GenArray*  ipatch_sf2_gen_array_new            (gboolean clear);

Create a new generator array object. A convenience function really, because one could just allocate an IpatchSF2GenArray structure instead.

clear : If TRUE then array will be cleared, FALSE will not initalize it and it is up to the caller to do so.
Returns : New generator

ipatch_sf2_gen_array_free ()

void                ipatch_sf2_gen_array_free           (IpatchSF2GenArray *genarray);

genarray :

ipatch_sf2_gen_array_duplicate ()

IpatchSF2GenArray*  ipatch_sf2_gen_array_duplicate      (const IpatchSF2GenArray *array);

Duplicates a generator array structure.

array : Generator array to duplicate
Returns : A newly allocated generator array structure which is a duplicate of array.

ipatch_sf2_gen_array_init ()

void                ipatch_sf2_gen_array_init           (IpatchSF2GenArray *array,
                                                         gboolean offset,
                                                         gboolean set);

Initialize a generator array to default values.

array : Generator array
offset : TRUE = initialize to Preset offset (zero) values, FALSE = initialize to instrument default values
set : TRUE to set flags indicating generator values are set, FALSE to clear all flag "set" bits

ipatch_sf2_gen_array_offset ()

void                ipatch_sf2_gen_array_offset         (IpatchSF2GenArray *abs_array,
                                                         const IpatchSF2GenArray *ofs_array);

Offsets the generators amount array in abs_array by adding the values in ofs_array to it. Values are clamped to their valid ranges.

abs_array : Destination generator amount array that contains absolute (Instrument) generator values
ofs_array : Source generator amount array that contains offset (Preset) generator values

ipatch_sf2_gen_amount_to_value ()

void                ipatch_sf2_gen_amount_to_value      (guint genid,
                                                         IpatchSF2GenAmount *amt,
                                                         GValue *value);

Converts a generator amount to a GValue. Value will be initialized to one of two types: G_TYPE_INT for signed/unsigned integers or IPATCH_TYPE_RANGE for velocity or key split ranges.

genid : Generator ID
amt : Generator amount for given genid
value : Uninitialized GValue to set to amt

ipatch_sf2_genid_is_valid()

#define             ipatch_sf2_genid_is_valid(genid, ispreset)

genid :
ispreset :
Returns :

ipatch_sf2_genid_default_value ()

void                ipatch_sf2_genid_default_value      (guint16 genid,
                                                         gboolean ispreset,
                                                         IpatchSF2GenAmount *out_amt);

Get default value for a generator ID for the specified (ispreset) zone type.

genid : Generator ID
ispreset : TRUE for preset generators, FALSE for instrument
out_amt : A pointer to store the default amount into

ipatch_sf2_genid_offset ()

gboolean            ipatch_sf2_genid_offset             (int genid,
                                                         IpatchSF2GenAmount *dst,
                                                         const IpatchSF2GenAmount *ofs);

Offsets a generator amount. Result of offset is clamped to maximum and minimum values for the given generator ID.

genid : ID of Generator to offset. Must be a valid preset generator.
dst : Pointer to the initial amount to offset, result is stored back into this parameter.
ofs : Pointer to offset amount.
Returns : TRUE if value was clamped, FALSE otherwise.

ipatch_sf2_units_sfont_to_user ()

void                ipatch_sf2_units_sfont_to_user      (guint16 genid,
                                                         const IpatchSF2GenAmount *amt,
                                                         float *out_userval,
                                                         gboolean ispreset);

Convert a SoundFont generator amount to user units

genid : Generator ID
amt : Pointer to generator amount to convert
out_userval : Output: Pointer to return user units value in
ispreset : TRUE if its a Preset generator, FALSE if Instrument

ipatch_sf2_units_sfont_to_user_str ()

void                ipatch_sf2_units_sfont_to_user_str  (guint16 genid,
                                                         const IpatchSF2GenAmount *amt,
                                                         float *out_userval,
                                                         char **out_userstr,
                                                         gboolean ispreset);

Convert a SoundFont generator amount to user units and formatted string.

genid : Generator ID
amt : Pointer to generator amount to convert
out_userval : Output: Pointer to return user units value in (or NULL to ignore)
out_userstr : Output: Pointer to return user units formatted string in (or NULL to ignore). Free userstr when finished with it. Could be NULL if error occurs (invalid genid).
ispreset : TRUE if its a Preset generator, FALSE if Instrument

ipatch_sf2_units_user_to_sfont ()

int                 ipatch_sf2_units_user_to_sfont      (guint16 genid,
                                                         float userval,
                                                         gboolean ispreset,
                                                         gboolean clamp);

Convert user units to SoundFont generator units

genid : Generator ID (IpatchSF2GenType)
userval : User units value to convert
ispreset : TRUE if its a Preset generator, FALSE if Instrument
clamp : TRUE to clamp SoundFont units result to generators valid range
Returns : Value converted to SoundFont units

ipatch_sf2_units_clamp ()

void                ipatch_sf2_units_clamp              (guint16 genid,
                                                         int *sfval,
                                                         gboolean ispreset);

Clamp a generators value to its valid range.

genid : Generator ID (IpatchSF2GenType)
sfval : Generator value to clamp (changed in place)
ispreset : TRUE if its a Preset generator, FALSE if Instrument

ipatch_sf2_units_range_intersect ()

gboolean            ipatch_sf2_units_range_intersect    (IpatchSF2GenAmount *dst,
                                                         const IpatchSF2GenAmount *src);

Find intersection of two generator ranges (common shared range). If ranges don't share anything in common a 0-0 range is stored (note that this is technically a valid 1 note range).

dst : First generator amount range, result is also stored here
src : Second generator amount range
Returns : FALSE if ranges don't share any range in common which can be used to check de-generate 0-0 range mentioned above.

ipatch_sf2_genid_unit_str ()

char*               ipatch_sf2_genid_unit_str           (guint16 genid,
                                                         gboolean ispreset);

Get a short unit label for the given generator id for offset generators (if ispreset is TRUE) or absolute generators (if ispreset is FALSE).

genid : Generator ID to get unit label string for
ispreset : Set to TRUE to get offset generator label, FALSE for absolute generator label.
Returns : The label string or NULL if the generator ID is invalid. The returned string is internal and should not be modified or freed.

See Also

IpatchSF2Zone, IpatchSF2PZone, IpatchSF2IZone