OSDN Git Service

Bug fix --force-program
authorShoichi Tamuki <tamuki@linet.gr.jp>
Sun, 17 Aug 2003 07:03:26 +0000 (07:03 +0000)
committerShoichi Tamuki <tamuki@linet.gr.jp>
Sun, 17 Aug 2003 07:03:26 +0000 (07:03 +0000)
ChangeLog
timidity/playmidi.c
timidity/timidity.c

index 1c51b8a..e4c18ce 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,12 +1,17 @@
+2003-08-17  TAMUKI Shoichi <tamuki@linet.gr.jp>
+
+       * timidity/playmidi.c, timidity/timidity.c:
+         Bug fix --force-program
+
 2003-08-17  mput <root@mput.dip.jp>
 
        * timidity/timidity.c (parse_opt_h): Bug Fix
 
 2003-08-17 Eric A. Welsh <ewelsh@ccb.wustl.edu>
 
-       * timidity/timidity.c (parse_opt_s): -s option works correctly aain
-       * timidity/reverb.c (init_reverb): -EFchorus=3 was cousing mono
-         output to crash.
+       * timidity/timidity.c (parse_opt_s): -s option works correctly again
+       * timidity/reverb.c (init_reverb):
+         -EFchorus=3 was cousing mono output to crash.
 
 2003-08-15  TAMUKI Shoichi <tamuki@linet.gr.jp>
 
index b5536da..55b4f4c 100644 (file)
@@ -1112,84 +1112,48 @@ void free_tone_bank_element(int dr, int bk, int prog)
 
 Instrument *play_midi_load_instrument(int dr, int bk, int prog)
 {
-    ToneBank **bank = ((dr) ? drumset : tonebank);
+       ToneBank **bank = (dr) ? drumset : tonebank;
+       Instrument *ip;
        ToneBankElement *elm;
-    Instrument *ip;
-    int load_success;
-
-    if(bank[bk] == NULL)
-       bk = 0;
-
-    load_success = 0;
-    if(! opt_realtime_playing)
-    {
-       ip = bank[bk]->tone[prog].instrument;
+       int load_success = 0;
+       
+       if (bank[bk] == NULL)
+               bk = 0;
+       if ((ip = bank[bk]->tone[prog].instrument) ==
+                       ((opt_realtime_playing) ? NULL : MAGIC_LOAD_INSTRUMENT)) {
+               if (ip = bank[bk]->tone[prog].instrument =
+                               load_instrument(dr, bk, prog))
+                       load_success = 1;
 #ifndef SUPPRESS_CHANNEL_LAYER
-       if(ip == MAGIC_LOAD_INSTRUMENT || ip == NULL)
-#else
-       if(ip == MAGIC_LOAD_INSTRUMENT)
-#endif
-       {
-           ip = bank[bk]->tone[prog].instrument =
-               load_instrument(dr, bk, prog);
-           if(ip != NULL)
-               load_success = 1;
-       }
-       if(ip == NULL && bk != 0)
-       {
-           /* Instrument is not found.
-              Retry to load the instrument from bank 0 */
-           if((ip = bank[0]->tone[prog].instrument) == NULL)
-               ip = bank[0]->tone[prog].instrument =
-                   load_instrument(dr, 0, prog);
-           if(ip != NULL)
-           {
-                       /* duplicate tone bank parameter */
-                       elm = &bank[bk]->tone[prog];
-                       memcpy(elm, &bank[0]->tone[prog], sizeof(ToneBankElement));
-                       elm->instrument = ip;
-                       dup_tone_bank_element(dr, bk, prog);
+       } else if (ip == NULL) {
+               if (ip = bank[bk]->tone[prog].instrument =
+                               load_instrument(dr, bk, prog))
                        load_success = 1;
-           }
-       }
-    }
-    else
-    {
-       if((ip = bank[bk]->tone[prog].instrument) == NULL)
-       {
-           ip = bank[bk]->tone[prog].instrument =
-               load_instrument(dr, bk, prog);
-           if(ip != NULL)
-               load_success = 1;
+#endif
        }
-       if(ip == NULL && bk != 0)
-       {
-           /* Instrument is not found.
-              Retry to load the instrument from bank 0 */
-           if((ip = bank[0]->tone[prog].instrument) == NULL)
-               ip = bank[0]->tone[prog].instrument =
-                   load_instrument(dr, 0, prog);
-           if(ip != NULL)
-           {
+       if (ip == NULL && bk) {
+               /* Instrument is not found.
+                * Retry to load the instrument from bank 0
+                */
+               if ((ip = bank[0]->tone[prog].instrument) == NULL)
+                       ip = bank[0]->tone[prog].instrument =
+                                       load_instrument(dr, 0, prog);
+               if (ip) {
                        /* duplicate tone bank parameter */
                        elm = &bank[bk]->tone[prog];
                        memcpy(elm, &bank[0]->tone[prog], sizeof(ToneBankElement));
                        elm->instrument = ip;
                        dup_tone_bank_element(dr, bk, prog);
                        load_success = 1;
-           }
+               }
        }
-    }
-
-    if(load_success)
-       aq_add(NULL, 0); /* Update software buffer */
-
-    if(ip == MAGIC_ERROR_INSTRUMENT)
-       return NULL;
-    if(ip == NULL)
-       bank[bk]->tone[prog].instrument = MAGIC_ERROR_INSTRUMENT;
-
-    return ip;
+       if (load_success)
+               aq_add(NULL, 0);        /* Update software buffer */
+       if (ip == MAGIC_ERROR_INSTRUMENT)
+               return NULL;
+       if (ip == NULL)
+               bank[bk]->tone[prog].instrument = MAGIC_ERROR_INSTRUMENT;
+       return ip;
 }
 
 #if 0
@@ -2893,106 +2857,79 @@ int midi_drumpart_change(int ch, int isdrum)
 
 void midi_program_change(int ch, int prog)
 {
-    int newbank, dr;
-
-    dr = (int)ISDRUMCHANNEL(ch);
-    if(dr)
-       newbank = channel[ch].program;
-    else
-       newbank = channel[ch].bank;
-
-    switch(play_system_mode)
-    {
-      case GS_SYSTEM_MODE: /* GS */
-       switch(channel[ch].bank_lsb)
-       {
-         case 0:       /* No change */
-           break;
-         case 1:
-           channel[ch].mapID = (!ISDRUMCHANNEL(ch) ? SC_55_TONE_MAP
-                                : SC_55_DRUM_MAP);
-           break;
-         case 2:
-           channel[ch].mapID = (!ISDRUMCHANNEL(ch) ? SC_88_TONE_MAP
-                                : SC_88_DRUM_MAP);
-           break;
-         case 3:
-           channel[ch].mapID = (!ISDRUMCHANNEL(ch) ? SC_88PRO_TONE_MAP
-                                : SC_88PRO_DRUM_MAP);
-           break;
-         default:
-           break;
-       }
-       newbank = channel[ch].bank_msb;
-       break;
-
-      case XG_SYSTEM_MODE: /* XG */
-       switch(channel[ch].bank_msb)
-       {
-         case 0: /* Normal */
-           if(ch == 9  && channel[ch].bank_lsb == 127 && channel[ch].mapID == XG_DRUM_MAP) {
-             /* FIXME: Why this part is drum?  Is this correct? */
-             ;
-           } else {
-             midi_drumpart_change(ch, 0);
-             channel[ch].mapID = XG_NORMAL_MAP;
-           }
-           break;
-         case 64: /* SFX voice */
-           midi_drumpart_change(ch, 0);
-           channel[ch].mapID = XG_SFX64_MAP;
-           break;
-         case 126: /* SFX kit */
-           midi_drumpart_change(ch, 1);
-           channel[ch].mapID = XG_SFX126_MAP;
-           break;
-         case 127: /* Drumset */
-           midi_drumpart_change(ch, 1);
-           channel[ch].mapID = XG_DRUM_MAP;
-           break;
-         default:
-           break;
+       int dr = ISDRUMCHANNEL(ch);
+       int newbank, b, p;
+       
+       switch (play_system_mode) {
+       case GS_SYSTEM_MODE:    /* GS */
+               switch (channel[ch].bank_lsb) {
+               case 0:         /* No change */
+                       break;
+               case 1:
+                       channel[ch].mapID = (dr) ? SC_55_DRUM_MAP : SC_55_TONE_MAP;
+                       break;
+               case 2:
+                       channel[ch].mapID = (dr) ? SC_88_DRUM_MAP : SC_88_TONE_MAP;
+                       break;
+               case 3:
+                       channel[ch].mapID = (dr) ? SC_88PRO_DRUM_MAP : SC_88PRO_TONE_MAP;
+                       break;
+               default:
+                       break;
+               }
+               newbank = channel[ch].bank_msb;
+               break;
+       case XG_SYSTEM_MODE:    /* XG */
+               switch (channel[ch].bank_msb) {
+               case 0:         /* Normal */
+                       if (ch == 9 && channel[ch].bank_lsb == 127
+                                       && channel[ch].mapID == XG_DRUM_MAP)
+                               /* FIXME: Why this part is drum?  Is this correct? */
+                               break;
+                       midi_drumpart_change(ch, 0);
+                       channel[ch].mapID = XG_NORMAL_MAP;
+                       break;
+               case 64:        /* SFX voice */
+                       midi_drumpart_change(ch, 0);
+                       channel[ch].mapID = XG_SFX64_MAP;
+                       break;
+               case 126:       /* SFX kit */
+                       midi_drumpart_change(ch, 1);
+                       channel[ch].mapID = XG_SFX126_MAP;
+                       break;
+               case 127:       /* Drumset */
+                       midi_drumpart_change(ch, 1);
+                       channel[ch].mapID = XG_DRUM_MAP;
+                       break;
+               default:
+                       break;
+               }
+               newbank = channel[ch].bank_lsb;
+               break;
+       default:
+               newbank = channel[ch].bank_msb;
+               break;
        }
-       dr = ISDRUMCHANNEL(ch);
-       newbank = channel[ch].bank_lsb;
-       break;
-
-      default:
-       newbank = channel[ch].bank_msb;
-       break;
-    }
-
-    if(dr)
-    {
-       channel[ch].bank = prog; /* newbank is ignored */
-       if(drumset[prog] == NULL || drumset[prog]->alt == NULL)
-           channel[ch].altassign = drumset[0]->alt;
-       else
-           channel[ch].altassign = drumset[prog]->alt;
-       ctl_mode_event(CTLE_DRUMPART, 1, ch, 1);
-    }
-    else
-    {
-       if(special_tonebank >= 0)
-           newbank = special_tonebank;
-       channel[ch].bank = newbank;
-       channel[ch].altassign = NULL;
-       ctl_mode_event(CTLE_DRUMPART, 1, ch, 0);
-    }
-
-    if(!dr && default_program[ch] == SPECIAL_PROGRAM)
-      channel[ch].program = SPECIAL_PROGRAM;
-    else
-      channel[ch].program = prog;
-
-    if(opt_realtime_playing && !dr && (play_mode->flag & PF_PCM_STREAM))
-    {
-       int b, p;
-
-       p = prog;
-       b = channel[ch].bank;
-       instrument_map(channel[ch].mapID, &b, &p);
-       play_midi_load_instrument(0, b, p);
+       if (dr) {
+               channel[ch].bank = prog;        /* newbank is ignored */
+               channel[ch].program = prog;
+               if (drumset[prog] == NULL || drumset[prog]->alt == NULL)
+                       channel[ch].altassign = drumset[0]->alt;
+               else
+                       channel[ch].altassign = drumset[prog]->alt;
+               ctl_mode_event(CTLE_DRUMPART, 1, ch, 1);
+       } else {
+               channel[ch].bank = (special_tonebank >= 0)
+                               ? special_tonebank : newbank;
+               channel[ch].program = (default_program[ch] == SPECIAL_PROGRAM)
+                               ? SPECIAL_PROGRAM : prog;
+               channel[ch].altassign = NULL;
+               ctl_mode_event(CTLE_DRUMPART, 1, ch, 0);
+               if (opt_realtime_playing && play_mode->flag & PF_PCM_STREAM) {
+                       b = channel[ch].bank, p = prog;
+                       instrument_map(channel[ch].mapID, &b, &p);
+                       play_midi_load_instrument(0, b, p);
+               }
        }
 }
 
index 94b7762..2a78d8e 100644 (file)
@@ -283,6 +283,7 @@ static inline int parse_opt_EC(const char *);
 static inline int parse_opt_ED(const char *);
 static inline int parse_opt_EE(const char *);
 static inline int parse_opt_EF(const char *);
+static inline int set_default_program(int);
 static inline int parse_opt_EG(const char *);
 static inline int parse_opt_EH(const char *);
 static inline int parse_opt_EI(const char *);
@@ -355,7 +356,6 @@ static inline int set_flag(int32 *, int32, const char *);
 static inline FILE *open_pager(void);
 static inline void close_pager(FILE *);
 static void interesting_message(void);
-static int set_default_program(int);
 
 #ifdef IA_DYNAMIC
 MAIN_INTERFACE char dynamic_interface_id;
@@ -2756,7 +2756,7 @@ static inline int parse_opt_EE(const char *arg)
        prog = tmpi32;
        if (p = strchr(arg, '/')) {
                if (set_value(&tmpi32, atoi(++p), 1, MAX_CHANNELS,
-                               "Default program channel"))
+                               "Program channel"))
                        return 1;
                default_program[tmpi32 - 1] = prog;
        } else
@@ -2775,9 +2775,11 @@ static inline int parse_opt_EF(const char *arg)
        if (set_value(&tmpi32, atoi(arg), -1, 0x7f, "Program number"))
                return 1;
        def_prog = tmpi32;
+       if (ctl->trace_playing)
+               set_default_program(def_prog);
        if (p = strchr(arg, '/')) {
                if (set_value(&tmpi32, atoi(++p), 1, MAX_CHANNELS,
-                               "Special program channel"))
+                               "Program channel"))
                        return 1;
                default_program[tmpi32 - 1] = SPECIAL_PROGRAM;
        } else
@@ -2786,6 +2788,18 @@ static inline int parse_opt_EF(const char *arg)
        return 0;
 }
 
+static inline int set_default_program(int prog)
+{
+       int bank;
+       Instrument *ip;
+       
+       bank = (special_tonebank >= 0) ? special_tonebank : default_tonebank;
+       if ((ip = play_midi_load_instrument(0, bank, prog)) == NULL)
+               return 1;
+       default_instrument = ip;
+       return 0;
+}
+
 static inline int parse_opt_EG(const char *arg)
 {
        /* --delay */
@@ -3858,9 +3872,9 @@ static inline int parse_opt_S(const char *arg)
 static inline int parse_opt_s(const char *arg)
 {
        /* sampling rate */
-       int32 tmpi32 = atoi(arg);
+       int32 tmpi32;
 
-       if (tmpi32 < 100)
+       if (atoi(arg) < 100)
                tmpi32 = atof(arg) * 1000 + 0.5;
        return set_value(&opt_output_rate, tmpi32,
                        MIN_OUTPUT_RATE, MAX_OUTPUT_RATE, "Resampling frequency");
@@ -4158,20 +4172,6 @@ static void interesting_message(void)
                        NLS, timidity_version);
 }
 
-static int set_default_program(int prog)
-{
-       int bank;
-       Instrument *ip;
-       
-       bank = (special_tonebank >= 0) ? special_tonebank : default_tonebank;
-       if ((ip = load_instrument(0, bank, prog)) == NULL)
-               return 1;
-       if (default_instrument)
-               free_instrument(default_instrument);
-       default_instrument = ip;
-       return 0;
-}
-
 /* -------- functions for getopt_long ends here --------- */
 
 #ifdef HAVE_SIGNAL