Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add setBank command to FluidSynth chugin
  • Loading branch information
forrcaho committed Jun 10, 2018
1 parent 25c5b1f commit 306541e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
42 changes: 38 additions & 4 deletions FluidSynth/FluidSynth.cpp
Expand Up @@ -23,6 +23,8 @@ CK_DLL_MFUN(fluidsynth_noteOnChan);
CK_DLL_MFUN(fluidsynth_noteOffChan);
CK_DLL_MFUN(fluidsynth_progChange);
CK_DLL_MFUN(fluidsynth_progChangeChan);
CK_DLL_MFUN(fluidsynth_setBank);
CK_DLL_MFUN(fluidsynth_setBankChan);

// this is a special offset reserved for Chugin internal data
t_CKINT fluidsynth_data_offset = 0;
Expand Down Expand Up @@ -81,6 +83,11 @@ class FluidSynth
fluid_synth_program_change(m_synth, chan, progNum);
}

void setBank(int chan, int bankNum)
{
fluid_synth_bank_select(m_synth, chan, bankNum);
}

private:
// instance data
float m_srate;
Expand Down Expand Up @@ -133,6 +140,13 @@ CK_DLL_QUERY( fluidsynth )
QUERY->add_arg(QUERY, "int", "progNum");
QUERY->add_arg(QUERY, "int", "chan");

QUERY->add_mfun(QUERY, fluidsynth_setBank, "void", "setBank");
QUERY->add_arg(QUERY, "int", "bankNum");

QUERY->add_mfun(QUERY, fluidsynth_setBankChan, "void", "setBank");
QUERY->add_arg(QUERY, "int", "bankNum");
QUERY->add_arg(QUERY, "int", "chan");

fluidsynth_data_offset = QUERY->add_mvar(QUERY, "int", "@f_data", false);

// IMPORTANT: this MUST be called!
Expand Down Expand Up @@ -245,17 +259,37 @@ CK_DLL_MFUN(fluidsynth_progChange)
{
FluidSynth * f_data = (FluidSynth *) OBJ_MEMBER_INT(SELF, fluidsynth_data_offset);

t_CKINT progChange = GET_NEXT_INT(ARGS);
t_CKINT progNum = GET_NEXT_INT(ARGS);

f_data->progChange(0, progChange);
f_data->progChange(0, progNum);
}

CK_DLL_MFUN(fluidsynth_progChangeChan)
{
FluidSynth * f_data = (FluidSynth *) OBJ_MEMBER_INT(SELF, fluidsynth_data_offset);

t_CKINT progChange = GET_NEXT_INT(ARGS);
t_CKINT progNum = GET_NEXT_INT(ARGS);
t_CKINT chan = GET_NEXT_INT(ARGS);

f_data->progChange(chan, progNum);
}

CK_DLL_MFUN(fluidsynth_setBank)
{
FluidSynth * f_data = (FluidSynth *) OBJ_MEMBER_INT(SELF, fluidsynth_data_offset);

t_CKINT bankNum = GET_NEXT_INT(ARGS);

f_data->setBank(0, bankNum);
}

CK_DLL_MFUN(fluidsynth_setBankChan)
{
FluidSynth * f_data = (FluidSynth *) OBJ_MEMBER_INT(SELF, fluidsynth_data_offset);

t_CKINT bankNum = GET_NEXT_INT(ARGS);
t_CKINT chan = GET_NEXT_INT(ARGS);

f_data->progChange(chan, progChange);
f_data->setBank(chan, bankNum);
}

8 changes: 5 additions & 3 deletions FluidSynth/fluidsynth-test.ck
Expand Up @@ -12,9 +12,11 @@ f.open("/usr/share/sounds/sf2/FluidR3_GM.sf2");
// scale (in semitones)
[ 0, 2, 4, 7, 9 ] @=> int scale[];

f.progChange(0); // piano on MIDI channel 1
f.progChange(6, 1); // harpsicord on MIDI channel 2
f.progChange(0); // piano on MIDI channel 1
f.progChange(6, 1); // harpsicord on MIDI channel 2
f.progChange(11, 2); // vibraphone on MIDI channel 3
f.setBank(128, 3);
f.progChange(0, 3); // standard drumkit on MIDI channel 4

// infinite time loop
while( true )
Expand All @@ -24,7 +26,7 @@ while( true )
45 + (Math.random2(0,3)*12 + freq) => int note;

// choose a channel we've set
Math.random2(0,2) => int chan;
Math.random2(0,3) => int chan;
f.noteOn(note, 100, chan);

// advance time
Expand Down

0 comments on commit 306541e

Please sign in to comment.