fluidControl
Prev | Orchestra Opcodes and Operators | Next

## fluidControl

fluidControl — Sends MIDI note on, note off, and other messages to a SoundFont preset.

## Syntax

    fluidControl ienginenum, kstatus, kchannel, \
        kdata1, kdata2 [,imsgs]

## Description

Plugin opcode in fluidOpcodes.

The fluid opcodes provide a simple Csound opcode wrapper around Peter Hanappe's Fluidsynth SoundFont2 synthesizer. This implementation accepts any MIDI note on, note off, controller, pitch bend, or program change message at k-rate. Maximum polyphony is 4096 simultaneously sounding voices. Any number of SoundFonts may be loaded and played simultaneously.

## Initialization

ienginenum -- engine number assigned from fluidEngine

imsgs -- if zero suppresses printing of messages when commands arrive. Default value is 1.

## Performance

kstatus -- MIDI channel message status byte: 128 for note off, 144 for note on, 176 for control change, 192 for program change, or 224 for pitch bend.

kchannel -- MIDI channel number to which the Fluidsynth program is assigned: from 0 to 255. MIDI channels numbered 16 or higher are virtual channels.

kdata1 -- For note on, MIDI key number: from 0 (lowest) to 127 (highest), where 60 is middle C. For continuous controller messages, controller number.

kdata2 -- For note on, MIDI key velocity: from 0 (no sound) to 127 (loudest). For continous controller messages, controller value.

Invoke fluidControl in instrument definitions that actually play notes and send control messages. Each instrument definition must consistently use one MIDI channel that was assigned to a Fluidsynth program using fluidLoad.

In this implementation, SoundFont effects such as chorus or reverb are used if and only if they are defaults for the preset. There are some ways of turning effects chorus and reverb on or off using fluidEngine, and of changing some of their parameters with fluidCCi and fluidCCk.

## Examples

Here is a 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
    ;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

Opcodes by Michael Gogins (gogins at pipeline dot com). Thanks to Peter Hanappe for Fluidsynth, and to Steven Yi for seeing that it is necessary to break up the Fluidsynth into several different Csound opcodes.

New in Csound5.00

Optional imsgs parameter introduced in version 6.14.

Prev | Up | Next
fluidCCk | Home | fluidEngine