fluidProgramSelect

fluidProgramSelect — Assigns a preset from a SoundFont to a channel on a fluidEngine.

Syntax

fluidProgramSelect ienginenum, ichannelnum, isfnum, ibanknum, ipresetnum

Description

Assigns a preset from a SoundFont to a channel on a fluidEngine.

Initialization

ienginenum -- engine number assigned from fluidEngine

ichannelnum -- which channel number to use for the preset in the given fluidEngine

isfnum -- number of the SoundFont from which the preset is assigned

ibanknum -- number of the bank in the SoundFont from which the preset is assigned

ipresetnum -- number of the preset to assign

Examples

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

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

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

giengine fluidEngine
; soundfont path to manual/examples
isfnum	 fluidLoad "19Trumpet.sf2", giengine, 1
	 fluidProgramSelect giengine, 1, isfnum, 0, 56

instr 1

	mididefault   60, p3
	midinoteonkey p4, p5
ikey	init p4
ivel	init p5
	fluidNote giengine, 1, ikey, ivel

endin

instr 99

imvol  init 7
asigl, asigr fluidOut giengine
       outs asigl*imvol, asigr*imvol

endin
</CsInstruments>
<CsScore>

i 1 0 2 60 100 ;play one note from score and...
i 99 0 60      ;play virtual keyboard for 60 sec.
e

</CsScore>
</CsoundSynthesizer>

Here is another more complex example of the fluidsynth opcodes written by Istvan Varga. It uses the file fluidcomplex.csd.

<CsoundSynthesizer>
<CsOptions>
; Select audio/midi flags here according to platform
;Load external midi file from manual/examples
-odac -T -F  Anna.mid;;;realtime audio I/O and midifile in
;-iadc    ;;;uncomment -iadc if realtime audio input is needed too
; For Non-realtime ouput leave only the line below:
; -o fluidcomplex.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>

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

; Example by Istvan Varga

; disable triggering of instruments by MIDI events

ichn = 1
lp1:
        massign   ichn, 0
        loop_le   ichn, 1, 16, lp1
        pgmassign 0, 0

; initialize FluidSynth

gifld   fluidEngine
gisf2   fluidLoad "sf_GMbank.sf2", gifld, 1

; k-rate version of fluidProgramSelect

opcode fluidProgramSelect_k, 0, kkkkk
  keng, kchn, ksf2, kbnk, kpre xin
        igoto     skipInit
  doInit:
        fluidProgramSelect i(keng), i(kchn), i(ksf2), i(kbnk), i(kpre)
        reinit    doInit
        rireturn
  skipInit:
endop

instr 1
  ; initialize channels
  kchn  init 1
  if (kchn == 1) then
lp2:
        fluidControl gifld, 192, kchn - 1, 0, 0
        fluidControl gifld, 176, kchn - 1, 7, 100
        fluidControl gifld, 176, kchn - 1, 10, 64
        loop_le   kchn, 1, 16, lp2
  endif

  ; send any MIDI events received to FluidSynth
nxt:
  kst, kch, kd1, kd2 midiin
  if (kst != 0) then
    if (kst != 192) then
        fluidControl gifld, kst, kch - 1, kd1, kd2
    else
        fluidProgramSelect_k gifld, kch - 1, gisf2, 0, kd1
    endif
      kgoto nxt
  endif

; get audio output from FluidSynth
  ivol   init 3 ;a bit louder
  aL, aR fluidOut gifld
         outs     aL*ivol, aR*ivol
endin

</CsInstruments>
<CsScore>

i 1 0 3600
e

</CsScore>
</CsoundSynthesizer>

See Also

fluidEngine, fluidNote, fluidLoad

More information on soundfonts in the Floss Manuals: http://en.flossmanuals.net/csound/ch048_d-reading-midi-files

Other information on soundfonts on Wikipedia: http://en.wikipedia.org/wiki/Soundfont

Credits

Michael Gogins (gogins at pipeline dot com), Steven Yi. Thanks to Peter Hanappe for Fluidsynth.