sfpreset
Prev | Orchestra Opcodes and Operators | Next

## sfpreset

sfpreset — Assigns an existing preset of a SoundFont2 (SF2) sample file to an index number.

## Description

Assigns an existing preset of a previously loaded SoundFont2 (SF2) sample file to an index number. These opcodes allow management the sample-structure of SF2 files. In order to understand the usage of these opcodes, the user must have some knowledge of the SF2 format, so a brief description of this format can be found in the SoundFont2 File Format Appendix.

sfpreset should be placed in the header section of a Csound orchestra.

## Syntax

    ir sfpreset iprog, ibank, ifilhandle, ipreindex

## Initialization

ir -- output to be used by other SF2 opcodes. For sfpreset, ir is ipreindex.

iprog -- program number of a bank of presets in a SF2 file

ibank -- number of a specific bank of a SF2 file

ifilhandle -- unique number generated by sfload opcode to be used as an identifier for a SF2 file. Several SF2 files can be loaded and activated at the same time.

ipreindex -- preset index

## Performance

sfpreset assigns an existing preset of a previously loaded SF2 file to an index number, to be used later with the opcodes sfplay and sfplaym. The user must previously know the program and the bank numbers of the preset in order to fill the corresponding arguments. Any number of sfpreset instances can be placed in the header section of an orchestra, each one assigning a different preset belonging to the same (or different) SF2 file to different index numbers.

These opcodes only support the sample structure of SF2 files. The modulator structure of the SoundFont2 format is not supported in Csound. Any modulation or processing to the sample data is left to the Csound user, bypassing all restrictions forced by the SF2 standard.

## Examples

Here is an example of the sfpreset opcode. It uses the file sfpreset.csd.

Example 761. Example of the sfpreset opcode.

See the sections Real-time Audio and Command Line Flags for more information on using command line flags.

    <CsoundSynthesizer>
    <CsOptions>
    ; Select audio/midi flags here according to platform
    -odac -+rtmidi=virtual -M0  ;;;realtime audio out, virtual midi in
    ;-iadc    ;;;uncomment -iadc if RT audio input is needed too
    ; For Non-realtime ouput leave only the line below:
    ; -o sfpreset.wav -W ;;; for file output any platform
    </CsOptions>
    <CsInstruments>

    sr = 44100
    ksmps = 32
    nchnls = 2
    0dbfs  = 1

    gisf1	sfload	 "sf_GMbank.sf2"
    	sfplist	 gisf1						;list presets of first soundfont
    gisf2	sfload	 "07AcousticGuitar.sf2"
    	sfplist	 gisf2						;list presets of second soundfont
    gir	sfpreset 50, 0, gisf1, 0 				;assign Synth Strings to index 0
    giv	sfpreset 0, 0, gisf2, 1					;assign AcousticGuitar to index 1
    print gir
    print giv

    instr 1	; play from score and midi keyboard

    	mididefault	60, p3
    	midinoteonkey	p4, p5
    inum	init	p4
    ivel	init	p5
    ivel	init	ivel/127					;make velocity dependent
    kamp	linsegr	1, 1, 1, .1, 0
    kamp	= kamp/5000						;scale amplitude
    kfreq	init	1						;do not change freq from sf
    a1,a2	sfplay3	ivel, inum, kamp*ivel, kfreq, p6
    	outs	a1, a2

    endin

    </CsInstruments>
    <CsScore>
    f0  60		; stay active for 1 minute

    i1 0 1 60 127 0	;= Synth Strings I from first soundfont
    i1 + 1 62 <   .
    i1 + 1 65 <   .
    i1 + 1 69 10  .

    i1 5 1 60 127 1	;= AcousticGuitar from second soundfont
    i1 + 1 62 <   .
    i1 + 1 65 <   .
    i1 + 1 69 10  .
    e
    </CsScore>
    </CsoundSynthesizer>

## See Also

sfilist, sfinstr, sfinstrm, sfload, sfpassign, sfplay, sfplaym, sfplist

## Credits

Author: Gabriel Maldonado
Italy
May 2000

New in Csound Version 4.07

Prev | Up | Next
sfplist | Home | shaker