fluidProgramSelect

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

Syntax

fluidProgramSelect ienginenum, ichannelnum, isfnum, ibanknum, ipresetnum

Description

Plugin opcode in fluidOpcodes. This opcode is part of the plugin repository and has to be installed separately. The plugin repository can be found here: https://github.com/csound/plugins

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. Play 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. Play fluidcomplex.csd

<CsoundSynthesizer>
<CsOptions>
; Select audio/midi flags here according to platform
;Anna.mid is a midi file, a song by The Beatles and can be found on the internet
-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 is in the Floss Manuals: https://flossmanual.csound.com/midi/reading-midi-files

For other information on soundfonts look in the Wikipedia: http://en.wikipedia.org/wiki/Soundfont

Credits

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