--- On Fri, 1/28/11, David Henningsson <di...@ubuntu.com> wrote:
>
> On 2011-01-28 23:07, jimmy wrote:
> >
> > Here's the revised patch file for the new channel
> field "is_drum_channel".
> 
> Thanks, but you're missing the patch :-)
> 
> // David
> 

Oops, here it is.

Jimmy



      
diff -pur fluidsynth.svn399.20101221/src/synth/fluid_chan.c fluidsynth.svn399.20101221.jnDrumChannel//src/synth/fluid_chan.c
--- fluidsynth.svn399.20101221/src/synth/fluid_chan.c	2010-12-21 19:02:53.000000000 -0500
+++ fluidsynth.svn399.20101221.jnDrumChannel//src/synth/fluid_chan.c	2011-01-28 13:30:52.000000000 -0500
@@ -52,6 +52,7 @@ new_fluid_channel(fluid_synth_t* synth,
 
   chan->synth = synth;
   chan->channum = num;
+  chan->is_drum_channel = (9 == num) ? CHANNEL_TYPE_DRUM : CHANNEL_TYPE_MELODIC;
   chan->preset = NULL;
   chan->tuning = NULL;
 
@@ -68,7 +69,7 @@ fluid_channel_init(fluid_channel_t* chan
   int prognum, banknum;
 
   prognum = 0;
-  banknum = (chan->channum == 9)? 128 : 0; /* ?? */
+  banknum = (chan->is_drum_channel) ? DRUM_INST_BANK : 0;
 
   chan->sfont_bank_prog = 0 << SFONT_SHIFTVAL | banknum << BANK_SHIFTVAL
     | prognum << PROG_SHIFTVAL;
@@ -231,9 +232,9 @@ fluid_channel_set_bank_lsb(fluid_channel
   int oldval, newval, style;
 
   style = chan->synth->bank_select;
-  if (style == FLUID_BANK_STYLE_GM ||
-      style == FLUID_BANK_STYLE_GS ||
-      chan->channum == 9) //TODO: ask for channel drum mode, instead of number
+  if (FLUID_BANK_STYLE_GM == style ||
+      FLUID_BANK_STYLE_GS == style ||
+      chan->is_drum_channel)
       return; /* ignored */
 
   oldval = chan->sfont_bank_prog;
@@ -251,11 +252,9 @@ fluid_channel_set_bank_msb(fluid_channel
   int oldval, newval, style;
 
   style = chan->synth->bank_select;
-  if (style == FLUID_BANK_STYLE_GM ||
-      style == FLUID_BANK_STYLE_XG ||
-      chan->channum == 9) //TODO: ask for channel drum mode, instead of number
+  if (FLUID_BANK_STYLE_GM == style ||
+      chan->is_drum_channel)
       return; /* ignored */
-  //TODO: if style == XG and bankmsb == 127, convert the channel to drum mode
 
   oldval = chan->sfont_bank_prog;
   if (style == FLUID_BANK_STYLE_GS)
@@ -263,6 +262,14 @@ fluid_channel_set_bank_msb(fluid_channel
   else /* style == FLUID_BANK_STYLE_MMA */
       newval = (oldval & ~BANKMSB_MASKVAL) | (bankmsb << (BANK_SHIFTVAL + 7));
   chan->sfont_bank_prog = newval;
+
+  /* if style == XG and bankmsb == 127, convert the channel to drum mode.
+   * How should "newval" above be calculated (same as MMA style) ??? */
+  if (style == FLUID_BANK_STYLE_XG && (127 == bankmsb))
+  {
+      chan->is_drum_channel = CHANNEL_TYPE_DRUM;
+  }
+
 }
 
 /* Get SoundFont ID, MIDI bank and/or program.  Use NULL to ignore a value. */
diff -pur fluidsynth.svn399.20101221/src/synth/fluid_chan.h fluidsynth.svn399.20101221.jnDrumChannel//src/synth/fluid_chan.h
--- fluidsynth.svn399.20101221/src/synth/fluid_chan.h	2010-12-21 19:02:53.000000000 -0500
+++ fluidsynth.svn399.20101221.jnDrumChannel//src/synth/fluid_chan.h	2011-01-28 13:08:42.000000000 -0500
@@ -74,6 +74,10 @@ struct _fluid_channel_t
    * flag indicating whether the NRPN value is absolute or not.
    */
   char gen_abs[GEN_LAST];
+
+  /* Drum channel flag, CHANNEL_TYPE_MELODIC, or CHANNEL_TYPE_DRUM. */
+   int is_drum_channel;
+
 };
 
 fluid_channel_t* new_fluid_channel(fluid_synth_t* synth, int num);
diff -pur fluidsynth.svn399.20101221/src/synth/fluid_synth.c fluidsynth.svn399.20101221.jnDrumChannel//src/synth/fluid_synth.c
--- fluidsynth.svn399.20101221/src/synth/fluid_synth.c	2010-12-21 19:02:53.000000000 -0500
+++ fluidsynth.svn399.20101221.jnDrumChannel//src/synth/fluid_synth.c	2011-01-28 13:48:14.000000000 -0500
@@ -1876,13 +1876,13 @@ fluid_synth_program_change(fluid_synth_t
   /* Special handling of channel 10 (or 9 counting from 0). channel
    * 10 is the percussion channel.
    *
-   * FIXME - Shouldn't hard code bank selection for channel 10.  I think this
+   * FIXME - I think this
    * is a hack for MIDI files that do bank changes in GM mode.  Proper way to
    * handle this would probably be to ignore bank changes when in GM mode. - JG
    */
   if (prognum != FLUID_UNSET_PROGRAM)
   {
-    if (channel->channum == 9)
+    if (channel->is_drum_channel)
       preset = fluid_synth_find_preset(synth, DRUM_INST_BANK, prognum);
     else preset = fluid_synth_find_preset(synth, banknum, prognum);
 
@@ -1893,7 +1893,7 @@ fluid_synth_program_change(fluid_synth_t
       subst_prog = prognum;
 
       /* Melodic instrument? */
-      if (channel->channum != 9 && banknum != DRUM_INST_BANK)
+      if ((! channel->is_drum_channel) && (DRUM_INST_BANK != banknum))
       {
         subst_bank = 0;
 
@@ -4990,3 +4990,22 @@ void fluid_synth_api_exit(fluid_synth_t*
   }
   
 }
+
+
+/**
+ * Set midi channel type 
+ * @param synth FluidSynth instance
+ * @param chan MIDI channel number (0 to MIDI channel count - 1)
+ * @param type CHANNEL_TYPE_MELODIC, or CHANNEL_TYPE_DRUM
+ * @return FLUID_OK on success, FLUID_FAILED otherwise
+ */
+int fluid_synth_set_channel_type(fluid_synth_t* synth, int chan, int type)
+{
+  fluid_return_val_if_fail (synth != NULL, FLUID_FAILED);
+  fluid_return_val_if_fail (chan >= 0 && chan < synth->midi_channels, FLUID_FAILED);
+  fluid_return_val_if_fail ((type >= CHANNEL_TYPE_MELODIC) && (type <= CHANNEL_TYPE_DRUM), FLUID_FAILED);
+  
+  synth->channel[chan]->is_drum_channel = type;
+
+  FLUID_API_RETURN(FLUID_OK);
+}
diff -pur fluidsynth.svn399.20101221/src/synth/fluid_synth.h fluidsynth.svn399.20101221.jnDrumChannel//src/synth/fluid_synth.h
--- fluidsynth.svn399.20101221/src/synth/fluid_synth.h	2010-12-21 19:02:53.000000000 -0500
+++ fluidsynth.svn399.20101221.jnDrumChannel//src/synth/fluid_synth.h	2011-01-28 13:34:18.000000000 -0500
@@ -88,6 +88,12 @@ enum fluid_synth_status
   FLUID_SYNTH_STOPPED
 };
 
+enum fluid_midi_channel_type
+{
+  CHANNEL_TYPE_MELODIC,
+  CHANNEL_TYPE_DRUM
+};
+
 #define SYNTH_REVERB_CHANNEL 0
 #define SYNTH_CHORUS_CHANNEL 1
 
@@ -221,6 +227,8 @@ int fluid_synth_set_chorus_full(fluid_sy
 fluid_sample_timer_t* new_fluid_sample_timer(fluid_synth_t* synth, fluid_timer_callback_t callback, void* data);
 int delete_fluid_sample_timer(fluid_synth_t* synth, fluid_sample_timer_t* timer);
 
+int fluid_synth_set_channel_type(fluid_synth_t* synth, int chan, int type);
+
 void fluid_synth_api_enter(fluid_synth_t* synth);
 void fluid_synth_api_exit(fluid_synth_t* synth);
 
diff -pur fluidsynth.svn399.20101221/src/synth/fluid_voice.c fluidsynth.svn399.20101221.jnDrumChannel//src/synth/fluid_voice.c
--- fluidsynth.svn399.20101221/src/synth/fluid_voice.c	2010-12-21 19:02:53.000000000 -0500
+++ fluidsynth.svn399.20101221.jnDrumChannel//src/synth/fluid_voice.c	2011-01-23 12:19:21.000000000 -0500
@@ -1493,7 +1493,7 @@ fluid_voice_get_overflow_prio(fluid_voic
    * Then it is very important.
    * Also skip the released and sustained scores.
    */
-  if (voice->chan == 9){
+  if (voice->channel->is_drum_channel){
     this_voice_prio += score->percussion;
   } 
   else if (voice->has_noteoff) {
_______________________________________________
fluid-dev mailing list
fluid-dev@nongnu.org
http://lists.nongnu.org/mailman/listinfo/fluid-dev

Reply via email to