fluid-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[fluid-dev] Fluid Patch for Selecting Fonts


From: Yon P Mercury
Subject: [fluid-dev] Fluid Patch for Selecting Fonts
Date: Sat, 19 Apr 2003 10:34:55 -0700

Hi everyone--

While working on integrating Fluidsynth into looping software I am writing, I 
wanted a way to:

- find out all the patches that are loaded
- select arbitrary patches across arbitrary soundfonts, using MIDI

So I made the following modifications to fluidsynth-1.0.1 (see patch @ end).

I added a command "dumpinst" that dumps a list of all loaded patches along with 
their corresponding soundfont ID, bank # and program change # to the file 
'patches.dmp'. I initialize fluidsynth like so:

echo source startup.src | fluidsynth -a jack

startup.src contains names of banks to load, and the dumpinst command, which 
dumps the names out:

#fluidsynth banks to load for yon p mercury
#
#load ~/audio/fluidsynth-1.0.1/inst/RolandNicePiano.sf2
#
#pads n strings
load ~/audio/fluidsynth-1.0.1/inst/hs_pads_1.sf2
load ~/audio/fluidsynth-1.0.1/inst/hs_pads_2.sf2
load ~/audio/fluidsynth-1.0.1/inst/hs_string.sf2
load ~/audio/fluidsynth-1.0.1/inst/hs_synth_collection.sf2
#bloops
load ~/audio/fluidsynth-1.0.1/inst/hs_synthetic.sf2
load ~/audio/fluidsynth-1.0.1/inst/hs_tb303.sf2
load ~/audio/fluidsynth-1.0.1/inst/ClassicTechno.SF2
load ~/audio/fluidsynth-1.0.1/inst/cia.sf2
load ~/audio/fluidsynth-1.0.1/inst/Gort's-DoubleDecker.SF2   
load ~/audio/fluidsynth-1.0.1/inst/Gort's-Filters.SF2
load ~/audio/fluidsynth-1.0.1/inst/Gort's-Midget.SF2
load ~/audio/fluidsynth-1.0.1/inst/Gort's_Extras.sf2
load ~/audio/fluidsynth-1.0.1/inst/Gort's_Synth.SF2
#drums
load ~/audio/fluidsynth-1.0.1/inst/hs_magic_techno_drums.sf2
load ~/audio/fluidsynth-1.0.1/inst/hs_acoustic_perc.sf2
load ~/audio/fluidsynth-1.0.1/inst/hs_african_perc.sf2
load ~/audio/fluidsynth-1.0.1/inst/hs_linn_drums.sf2
load ~/audio/fluidsynth-1.0.1/inst/hs_m1_drums.sf2
load ~/audio/fluidsynth-1.0.1/inst/hs_r8_drums.sf2
#piano
load ~/audio/fluidsynth-1.0.1/inst/steinbow_mg.sf2
dumpinst
source /dev/tty

.. Then, I load my looper, which reads patches.dmp. The looper displays the 
current patch (fullname), and allows me to move by one patch, or jump by a 
whole soundfont. 

The actual patch change is done by sending first the soundfont id # via a new 
midi message SFONT_SELECT (0x09), then the bank # (MSB & LSB), then the program 
change #. Since the looper handles the #s, all I need to worry about is finding 
the right patch.

Note that I had to make a functional change to the way PROGRAM_CHANGE messages 
are handled in MIDI. Hopefully this doesn't break the original way of selecting 
programs.

I thought this patch might be of some use to y'all. Perhaps the Fluidsynth 
people would consider integrating something like it into Fluidsynth.

Thanks,
Yon P Mercury

patchfile:

diff -ur fluidsynth-1.0.1.old/src/fluid_chan.c fluidsynth-1.0.1/src/fluid_chan.c
--- fluidsynth-1.0.1.old/src/fluid_chan.c       2003-04-03 16:11:00.000000000 
-0500
+++ fluidsynth-1.0.1/src/fluid_chan.c   2003-04-06 23:54:04.000000000 -0400
@@ -189,7 +189,14 @@
       }
     }
     break;
-  
+    
+    // JMP
+  case SFONT_SELECT:
+    //printf("Sfont select: %d\n", value);
+    fluid_channel_set_sfontnum(chan,value);
+    break;
+    // JMP
+
   case BANK_SELECT_MSB:
     {
       chan->bank_msb = (unsigned char) (value & 0x7f);
diff -ur fluidsynth-1.0.1.old/src/fluid_cmd.c fluidsynth-1.0.1/src/fluid_cmd.c
--- fluidsynth-1.0.1.old/src/fluid_cmd.c        2003-03-11 11:57:14.000000000 
-0500
+++ fluidsynth-1.0.1/src/fluid_cmd.c    2003-04-08 17:58:06.000000000 -0400
@@ -48,6 +48,10 @@
 /** the table of all handled commands */
 
 fluid_cmd_t fluid_commands[] = {
+  // JMP
+  { "dumpinst", "general", (fluid_cmd_func_t) fluid_handle_dumpinst, NULL,
+    "dumpinst                       Dump loaded bank info to file." },
+  // JMP
   { "help", "general", (fluid_cmd_func_t) fluid_handle_help, NULL,
     "help                       Print command summary. 'help help': Show more 
help topics" },
   { "quit", "general", (fluid_cmd_func_t) fluid_handle_quit, NULL,
@@ -321,9 +325,9 @@
   fluid_shell_t shell;
 
 #ifdef WIN32 
-  file = _open(filename, _O_WRONLY);
+  file = _open(filename, _O_RDONLY);
 #else
-  file = open(filename, O_WRONLY);
+  file = open(filename, O_RDONLY);
 #endif
   if (file < 0) {
     return file;
@@ -839,6 +843,45 @@
   return 0;
 }
 
+// JMP
+int 
+fluid_handle_dumpinst(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t 
out)
+{
+  FILE *fout;
+  int i;
+  fluid_sfont_t* sfont;
+  fluid_preset_t preset;
+  int num;
+
+  fout = fopen("patches.dmp","wt");
+  num = fluid_synth_sfcount(synth);
+
+  if (num == 0) {
+    fluid_ostream_printf(out, "no SoundFont loaded (try load)\n");
+    return 0;
+  }
+
+  for (i = 0; i < num; i++) {
+    sfont = fluid_synth_get_sfont(synth, i);
+    //fprintf(fout, "%2d  %s\n", 
+    //     fluid_sfont_get_id(sfont), 
+    //    fluid_sfont_get_name(sfont));
+
+    fluid_sfont_iteration_start(sfont);
+    while (fluid_sfont_iteration_next(sfont, &preset)) {
+      fprintf(fout, "%02d %03d %03d %s\n", 
+             fluid_sfont_get_id(sfont),
+             fluid_preset_get_banknum(&preset), 
+             fluid_preset_get_num(&preset), 
+             fluid_preset_get_name(&preset));
+    }
+  }
+  
+  fclose(fout);
+  return 0;
+}
+// JMP
+
 /* Purpose:
  * Response to 'gain' command. */
 int
diff -ur fluidsynth-1.0.1.old/src/fluid_cmd.h fluidsynth-1.0.1/src/fluid_cmd.h
--- fluidsynth-1.0.1.old/src/fluid_cmd.h        2003-03-11 11:57:14.000000000 
-0500
+++ fluidsynth-1.0.1/src/fluid_cmd.h    2003-04-06 23:59:50.000000000 -0400
@@ -33,6 +33,9 @@
 char* fluid_expand_path(char* path, char* new_path, int len);
 
 /** the handlers for the command lines */
+// JMP
+int fluid_handle_dumpinst(fluid_synth_t* synth, int ac, char** av, 
fluid_ostream_t out);
+// JMP
 int fluid_handle_help(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t 
out);
 int fluid_handle_quit(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t 
out);
 int fluid_handle_noteon(fluid_synth_t* synth, int ac, char** av, 
fluid_ostream_t out);
diff -ur fluidsynth-1.0.1.old/src/fluid_midi.h fluidsynth-1.0.1/src/fluid_midi.h
--- fluidsynth-1.0.1.old/src/fluid_midi.h       2003-03-11 11:57:32.000000000 
-0500
+++ fluidsynth-1.0.1/src/fluid_midi.h   2003-04-06 23:53:40.000000000 -0400
@@ -80,6 +80,9 @@
   DATA_ENTRY_MSB = 0x06,
   VOLUME_MSB = 0x07,
   BALANCE_MSB = 0x08,
+  // JMP
+  SFONT_SELECT = 0x09,
+  // JMP
   PAN_MSB = 0x0A,
   EXPRESSION_MSB = 0x0B,
   EFFECTS1_MSB = 0x0C,
diff -ur fluidsynth-1.0.1.old/src/fluid_synth.c 
fluidsynth-1.0.1/src/fluid_synth.c
--- fluidsynth-1.0.1.old/src/fluid_synth.c      2003-04-03 16:09:19.000000000 
-0500
+++ fluidsynth-1.0.1/src/fluid_synth.c  2003-04-06 23:51:20.000000000 -0400
@@ -2620,6 +2620,12 @@
   int type = fluid_midi_event_get_type(event);
   int chan = fluid_midi_event_get_channel(event);
 
+  // JMP
+  unsigned int sfont_id,
+    bank_num,
+    preset_num;
+  // JMP
+
   switch(type) {
       case NOTE_ON:
        return fluid_synth_noteon(synth, chan, 
@@ -2635,7 +2641,16 @@
                             fluid_midi_event_get_value(event));
 
       case PROGRAM_CHANGE:
-       return fluid_synth_program_change(synth, chan, 
fluid_midi_event_get_program(event));
+       // JMP-
+       fluid_synth_get_program(synth, chan, &sfont_id, &bank_num, 
+                               &preset_num);
+       preset_num = fluid_midi_event_get_program(event);
+       
+       return fluid_synth_program_select(synth, chan, 
+                                         sfont_id, bank_num, preset_num);
+       // return fluid_synth_program_change(synth, chan, 
+       //  fluid_midi_event_get_program(event));
+       // JMP
 
       case PITCH_BEND:
        return fluid_synth_pitch_bend(synth, chan, 
fluid_midi_event_get_pitch(event));



____________________________________________________________
Get 25MB of email storage with Lycos Mail Plus!
Sign up today -- http://www.mail.lycos.com/brandPage.shtml?pageId=plus 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]