defPresetSoundfont

maelzel.core.presetmanager.defPresetSoundfont(name='', sf2path='', preset=(0, 0), init='', postproc='', reverb=False, includes=(), args=None, interpolation='', mono=False, ampDivisor=0, turnoffWhenSilent=True, description='', normalize=False, velocityCurve=(), reverbChanPrefix='', _builtin=False)

Define a new instrument preset based on a soundfont

Once the instr preset is defined the soundfont preset is fixed. To use multiple soundfont presets, define one instr preset for each.

Use ‘?’ as the preset to select a preset from a dialog.

To list all presets in a soundfont, see csoundengine.csoundlib.soundfontGetPresets

>>> import csoundengine
>>> csoundengine.csoundlib.soundfontGetPresets("~/sf2/Yamaha-C5-Salamander.sf2")
[(0, 0, 'Yamaha C5 Grand'),
 (0, 1, 'Dynamic Yamaha C5'),
 (0, 2, 'Dark Grand'),
 (0, 3, 'Mellow Grand'),
 (0, 4, 'Bright Grand'),
 (0, 5, 'Very Bright Grand')]
Parameters:
  • name – the name of the preset. If not given, the name of the preset is used.

  • sf2path – the path to the soundfont. Use “?” open a dialog to select a .sf2 file or None to use the default soundfont

  • preset (tuple[int, int] | str) – the preset to use. Either a tuple (bank: int, presetnum: int) or the name of the preset as string. Use “?” to select from all available presets in the soundfont.

  • init – global code needed by postproc.

  • postproc – code to modify the generated audio before it is sent to the outputs. NB: the audio is placed in aout1, aout2, etc. depending on the number of channels (normally 2)

  • includes (Sequence[str]) – files to include (if needed by init or postproc)

  • args (Optional[dict[str, float]]) – mutable values needed by postproc (if any). See defPreset()

  • mono – if True, only the left channel of the soundfont is read

  • velocityCurve (Union[Sequence[float], GainToVelocityCurve]) – either a flat list of pairs of the form [db0, vel0, db1, vel1, …], mapping dB values to velocities, or an instance of GainToVelocityCurve

  • ampDivisor (int | float) – most soundfonts are PCM 16bit files and need to be scaled down to use them in the range of -1:1. This value is used to scale amp down. The default is 16384 (it can be changed in the config (key ‘play.soundfontAmpDiv’), but different soundfonts might need different scaling factors.

  • interpolation – one of ‘linear’, ‘cubic’. Refers to the interpolation used when reading the sample waveform. If None, use the default defined in the config (key ‘play.soundfontInterpol’)

  • turnoffWhenSilent – if True, turn a note off when the sample stops (by detecting silence for a given amount of time)

  • description – a short string describing this preset

  • normalize – if True, queries the amplitude divisor of the soundfont at runtime and uses that to scale amplitudes to 0dbfs

  • reverbChanPrefix

    ???

  • _builtin – if True, marks this preset as built-in

Return type:

PresetDef

Example

>>> from maelzel.core import *
>>> defPresetSoundfont('yamahagrand', '/path/to/yamahapiano.sf2',
...                    preset='Yamaha C5 Grand')
>>> Note("C4", dur=5).play(instr='yamahagrand')

See also

defPreset()