defPresetSoundfont

maelzel.core.presetmanager.defPresetSoundfont(name='', sf2path='', preset=(0, 0), init='', postproc='', includes=None, args=None, interpolation='', mono=False, ampDivisor=None, turnoffWhenSilent=True, description='', _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 (Optional[list[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

  • ampDivisor (Optional[int]) – 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, but it can be changed in the config (key ‘play.soundfontAmpDiv’)

  • 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.soundfontInterpolation’)

  • 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

  • _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()