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
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);
+ }
}
}
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 *);
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;
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
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
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 */
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");
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