3
TiMidity -- Experimental MIDI to WAVE converter
4
Copyright (C) 1995 Tuukka Toivonen <toivonen@clinet.fi>
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or
9
(at your option) any later version.
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26
#if defined(__linux__) || defined(__FreeBSD__) || defined(__bsdi__)
34
#define rindex strrchr
37
int getopt(int, char **, char *);
53
int free_instruments_afterwards=0;
54
static char def_instr_name[256]="";
57
extern void effect_activate( int iSwitch ) ;
58
extern int init_effect(void) ;
59
#endif /*CHANNEL_EFFECT*/
61
extern PlayMode arts_play_mode;
63
int have_commandline_midis = 0;
64
int output_device_open = 0;
68
CRITICAL_SECTION critSect;
71
static BOOL WINAPI handler (DWORD dw)
73
printf ("***BREAK\n");
75
play_mode->purge_output ();
80
static void help(void)
82
PlayMode **pmp=play_mode_list;
83
ControlMode **cmp=ctl_list;
86
* glibc headers break this code because printf is a macro there, and
87
* you cannot use a preprocessing instruction like #ifdef inside a macro.
88
* current workaround is not using printf ( Dirk )
90
fprintf(stdout, " TiMidity version " TIMID_VERSION " (C) 1995 Tuukka Toivonen "
91
"<toivonen@clinet.fi>\n"
92
" TiMidity is free software and comes with ABSOLUTELY NO WARRANTY.\n"
95
" Win32 version by Davide Moretti <dmoretti@iper.net>\n"
98
" KMidi version " KMIDIVERSION " MIDI to WAVE player/converter\n"
99
" Copyright (C) 1997 Bernd Johannes Wuebben <wuebben@math.cornell.edu>\n"
101
" KMidi is free software and comes with ABSOLUTELY NO WARRANTY.\n"
105
" %s [options] filename [...]\n"
108
/*does not work in Win32 */
109
" Use \"-\" as filename to read a MIDI file from stdin\n"
113
#if defined(AU_HPUX) || defined(hpux) || defined(__hpux)
114
" -o file Output to another file (or audio server) (Use \"-\" for stdout)\n"
115
#elif defined (AU_LINUX)
116
" -o file Output to another file (or device) (Use \"-\" for stdout)\n"
118
" -o file Output to another file (Use \"-\" for stdout)\n"
120
" -O mode Select output mode and format (see below for list)\n"
121
" -s f Set sampling frequency to f (Hz or kHz)\n"
122
" -a Enable the antialiasing filter\n"
131
" -p n Allow n-voice polyphony\n"
132
" -A n Amplify volume by n percent (may cause clipping)\n"
133
" -C n Set ratio of sampling and control frequencies\n"
135
" -# n Select patch set\n"
136
#ifdef CHANNEL_EFFECT
137
" -E Effects filter\n"
138
#endif /*CHANNEL_EFFECT*/
140
" -m Disable portamento\n"
142
" -L dir Append dir to search path\n"
143
" -c file Read extra configuration file\n"
144
" -I n Use program n as the default\n"
145
" -P file Use patch file for all programs\n"
146
" -D n Play drums on channel n\n"
147
" -Q n Ignore channel n\n"
148
" -R n Reverb options (1)(+2)(+4) [7]\n"
149
" -k n Resampling interpolation option (0-3) [1]\n"
150
" -r n Max ram to hold patches in megabytes [60]\n"
151
" -X n Midi expression is linear (0) or exponential (1-2) [1]\n"
152
" -V n Midi volume is linear (0) or exponential (1-2) [1]\n"
154
" -F Enable fast panning\n"
155
" -U Unload instruments from memory between MIDI files\n"
157
" -i mode Select user interface (see below for list)\n"
158
#if defined(AU_LINUX) || defined(AU_WIN32)
159
" -B n Set number of buffer fragments\n"
162
" -e Increase thread priority (evil) - be careful!\n"
164
" -h Display this help message\n"
168
printf("Available output modes (-O option):\n\n");
171
printf(" -O%c %s\n", (*pmp)->id_character, (*pmp)->id_name);
174
printf("\nOutput format options (append to -O? option):\n\n"
175
" `8' 8-bit sample width\n"
176
" `1' 16-bit sample width\n"
177
" `U' uLaw encoding\n"
178
" `l' linear encoding\n"
181
" `s' signed output\n"
182
" `u' unsigned output\n"
183
" `x' byte-swapped output\n");
185
printf("\nAvailable interfaces (-i option):\n\n");
188
printf(" -i%c %s\n", (*cmp)->id_character, (*cmp)->id_name);
191
printf("\nInterface options (append to -i? option):\n\n"
192
" `v' more verbose (cumulative)\n"
193
" `q' quieter (cumulative)\n"
194
" `t' trace playing\n\n");
198
static void interesting_message(void)
202
" TiMidity version " TIMID_VERSION " -- Experimental MIDI to WAVE converter\n"
203
" Copyright (C) 1995 Tuukka Toivonen <toivonen@clinet.fi>\n"
206
" Win32 version by Davide Moretti <dmoretti@iper.net>\n"
209
" This program is free software; you can redistribute it and/or modify\n"
210
" it under the terms of the GNU General Public License as published by\n"
211
" the Free Software Foundation; either version 2 of the License, or\n"
212
" (at your option) any later version.\n"
214
" This program is distributed in the hope that it will be useful,\n"
215
" but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
216
" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
217
" GNU General Public License for more details.\n"
219
" You should have received a copy of the GNU General Public License\n"
220
" along with this program; if not, write to the Free Software\n"
221
" Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n"
228
static int set_channel_flag(int32 *flags, int32 i, const char *name)
231
else if ((i<1 || i>16) && (i<-16 || i>-1))
234
"%s must be between 1 and 16, or between -1 and -16, or 0\n",
240
if (i>0) *flags |= (1<<(i-1));
241
else *flags &= ~ ((1<<(-1-i)));
246
static int set_value(int32 *param, int32 i, int32 low, int32 high, const char *name)
248
if (i<low || i > high)
250
fprintf(stderr, "%s must be between %ld and %ld\n", name, low, high);
257
int set_play_mode(char *cp)
259
PlayMode *pmp, **pmpp=play_mode_list;
261
while ((pmp=*pmpp++))
263
if (pmp->id_character == *cp)
269
case 'U': pmp->encoding |= PE_ULAW; break; /* uLaw */
270
case 'l': pmp->encoding &= ~PE_ULAW; break; /* linear */
272
case '1': pmp->encoding |= PE_16BIT; break; /* 1 for 16-bit */
273
case '8': pmp->encoding &= ~PE_16BIT; break;
275
case 'M': pmp->encoding |= PE_MONO; break;
276
case 'S': pmp->encoding &= ~PE_MONO; break; /* stereo */
278
case 's': pmp->encoding |= PE_SIGNED; break;
279
case 'u': pmp->encoding &= ~PE_SIGNED; break;
281
case 'x': pmp->encoding ^= PE_BYTESWAP; break; /* toggle */
284
fprintf(stderr, "Unknown format modifier `%c'\n", *cp);
291
fprintf(stderr, "Playmode `%c' is not compiled in.\n", *cp);
295
static int set_ctl(char *cp)
297
ControlMode *cmp, **cmpp=ctl_list;
299
while ((cmp=*cmpp++))
301
if (cmp->id_character == *cp)
307
case 'v': cmp->verbosity++; break;
308
case 'q': cmp->verbosity--; break;
309
case 't': /* toggle */
310
cmp->trace_playing= (cmp->trace_playing) ? 0 : 1;
314
fprintf(stderr, "Unknown interface option `%c'\n", *cp);
321
fprintf(stderr, "Interface `%c' is not compiled in.\n", *cp);
328
void clear_config(void)
333
for (i = 0; i < MAXBANK; i++)
338
if (bank->name) free((void *)bank->name);
340
for (j = 0; j < MAXPROG; j++)
341
if (bank->tone[j].name)
343
free((void *)bank->tone[j].name);
344
bank->tone[j].name = 0;
355
if (bank->name) free((void *)bank->name);
357
for (j = 0; j < MAXPROG; j++)
358
if (bank->tone[j].name)
360
free((void *)bank->tone[j].name);
361
bank->tone[j].name = 0;
371
memset(drumset[0], 0, sizeof(ToneBank));
372
memset(tonebank[0], 0, sizeof(ToneBank));
377
int reverb_options=7;
378
int global_reverb = 0;
379
int global_chorus = 0;
381
int global_detune = 0;
383
int got_a_configuration=0;
386
extern int createKApplication(int *argc, char ***argv);
390
int __cdecl main(int argc, char **argv)
392
int main(int argc, char **argv)
403
int32 tmpi32, output_rate=0;
407
#if defined(AU_LINUX) || defined(AU_WIN32)
408
int buffer_fragments=-1;
414
#ifdef DANGEROUS_RENICE
415
#include <sys/resource.h>
420
#define KMIDI_CONFIG_SUBDIR "/share/apps/kmidi/config"
425
for (i = 0; i < argc; i++) {
426
if (strlen(argv[i]) < 2) continue;
427
if (argv[i][0] != '-') continue;
428
if (argv[i][1] == 'h') break;
429
if (strlen(argv[i]) < 3) continue;
430
if (argv[i][1] != 'i') continue;
431
if (argv[i][2] == 'c') continue;
432
if (argv[i][2] != 'q') break;
436
if (!createKApplication(&argc, &argv)) return 0;
438
if ( ! (KDEdir = getenv("KDEDIR"))) {
439
kmidi_config = (char *)safe_malloc(strlen(DEFAULT_PATH)+1);
440
strcpy(kmidi_config, DEFAULT_PATH);
443
kmidi_config = (char *)safe_malloc(strlen(KDEdir)+strlen(KMIDI_CONFIG_SUBDIR)+1);
444
strcpy(kmidi_config, KDEdir);
445
strcat(kmidi_config, KMIDI_CONFIG_SUBDIR);
446
/* add_to_pathlist(kmidi_config, 0); */
448
add_to_pathlist(kmidi_config, 0);
451
add_to_pathlist(DEFAULT_PATH, 0);
456
#ifdef DANGEROUS_RENICE
457
if (setpriority(PRIO_PROCESS, 0, DANGEROUS_RENICE) < 0)
458
fprintf(stderr, "Couldn't set priority to %d.\n", DANGEROUS_RENICE);
459
setreuid(u_uid, u_uid);
463
if ((program_name=rindex(argv[0], '/'))) program_name++;
464
else program_name=argv[0];
468
interesting_message();
473
command_cutoff_allowed = 0;
474
#ifdef CHANNEL_EFFECT
476
#endif /*CHANNEL_EFFECT*/
479
if (argc >= 3 && !strcmp(argv[1],"-miniicon")) {
480
for (i=1; i<argc-2; i++) argv[i] = argv[i+2];
483
if (argc >= 3 && !strcmp(argv[1],"-icon")) {
484
for (i=1; i<argc-2; i++) argv[i] = argv[i+2];
489
while ((c=getopt(argc, argv, "UI:P:L:c:A:C:ap:fo:O:s:Q:R:FD:hi:#:qEmk:r:X:V:d-::"
490
#if defined(AU_LINUX) || defined(AU_WIN32)
491
"B:" /* buffer fragments */
494
"e" /* evil (be careful) */
499
case 'q': command_cutoff_allowed=1; break;
500
case 'U': free_instruments_afterwards=1; break;
501
case 'L': add_to_pathlist(optarg, 0); try_config_again=1; break;
503
if (read_config_file(optarg, 1)) cmderr++;
505
#ifdef CHANNEL_EFFECT
506
case 'E': effect_activate( 1 ); break ;
507
#endif /* CHANNEL_EFFECT */
510
if (set_channel_flag(&quietchannels, atoi(optarg), "Quiet channel"))
515
current_interpolation = atoi(optarg);
523
opt_expression_curve = atoi(optarg);
527
opt_volume_curve = atoi(optarg);
531
max_patch_memory = atoi(optarg) * 1000000;
534
case 'R': reverb_options = atoi(optarg); break;
537
if (set_channel_flag(&drumchannels, atoi(optarg), "Drum channel"))
541
case 'O': /* output mode */
542
if (set_play_mode(optarg))
546
case 'o': output_name=optarg; break;
548
case 'a': antialiasing_allowed=1; break;
550
case 'f': fast_decay=(fast_decay) ? 0 : 1; break;
552
case 'F': adjust_panning_immediately=1; break;
554
case 's': /* sampling rate */
556
if (i < 100) i *= 1000;
557
if (set_value(&output_rate, i, MIN_OUTPUT_RATE, MAX_OUTPUT_RATE,
558
"Resampling frequency")) cmderr++;
561
case 'P': /* set overriding instrument */
562
strncpy(def_instr_name, optarg, 255);
563
def_instr_name[255]='\0';
567
if (set_value(&tmpi32, atoi(optarg), 0, 127,
568
"Default program")) cmderr++;
569
else default_program=tmpi32;
572
if (set_value(&lification, atoi(optarg), 1, MAX_AMPLIFICATION,
573
"Amplification")) cmderr++;
576
if (set_value(&control_ratio, atoi(optarg), 1, MAX_CONTROL_RATIO,
577
"Control ratio")) cmderr++;
580
if (set_value(&tmpi32, atoi(optarg), 1, MAX_VOICES,
581
"Polyphony")) cmderr++;
588
#if defined(AU_LINUX) || defined(AU_WIN32)
589
else if (buffer_fragments==-1 && ctl->trace_playing)
590
/* user didn't specify anything, so use 2 for real-time response */
591
#if defined(AU_LINUX)
594
buffer_fragments=3; /* On Win32 2 is chunky */
599
#if defined(AU_LINUX) || defined(AU_WIN32)
602
if (set_value(&tmpi32, atoi(optarg), 0, 1000,
603
"Buffer fragments")) cmderr++;
604
else buffer_fragments=tmpi32;
614
cfg_select=atoi(optarg);
627
try_config_again = 1;
628
/* don't use unnecessary memory until we're a child process */
629
if (!got_a_configuration)
631
if (!try_config_again || read_config_file(CONFIG_FILE, 1)) cmderr++;
634
/* If there were problems, give up now */
637
fprintf(stderr, "Try %s -h for help\n", program_name);
638
return 1; /* problems with command line */
641
/* Set play mode parameters */
642
if (output_rate) play_mode->rate=output_rate;
645
play_mode->name=output_name;
646
if (!strcmp(output_name, "-"))
650
#if defined(AU_LINUX) || defined(AU_WIN32)
652
if (buffer_fragments != -1)
653
play_mode->extra_param[0]=buffer_fragments;
660
while (optind<argc) if (!strcmp(argv[optind++], "-")) need_stdin=1;
663
if(argc-optind > 0 ) have_commandline_midis = argc - optind;
664
else have_commandline_midis = 0;
666
if (play_mode->open_output()<0){
668
/* fprintf(stderr, "KMidi: Sorry, couldn't open %s.\n", play_mode->id_name); */
671
output_device_open = 0;
675
else output_device_open = 1;
677
if (!output_device_open && play_mode != &arts_play_mode) {
678
PlayMode *save_play_mode;
679
save_play_mode = play_mode;
680
play_mode = &arts_play_mode;
681
if (output_rate) play_mode->rate=output_rate;
682
if (output_name) play_mode->name=output_name;
683
if (play_mode->open_output()<0) play_mode = save_play_mode;
685
output_device_open = 1;
689
if (ctl->open(need_stdin, need_stdout)) {
691
fprintf(stderr, "Couldn't open %s\n", ctl->id_name);
692
play_mode->close_output();
697
if (!output_device_open) {
698
fprintf(stderr, "Couldn't open %s\n", play_mode->id_name);
702
#endif /* not KMIDI */
705
if (!control_ratio) {
707
control_ratio = play_mode->rate / CONTROLS_PER_SECOND;
710
else if (control_ratio > MAX_CONTROL_RATIO)
711
control_ratio=MAX_CONTROL_RATIO;
714
if (*def_instr_name) set_default_instrument(def_instr_name);
718
SetConsoleCtrlHandler (handler, TRUE);
719
InitializeCriticalSection (&critSect);
722
if (!SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL))
723
fprintf(stderr, "Error raising process priority.\n");
726
if (got_a_configuration < 2) read_config_file(current_config_file, 0);
728
ctl->pass_playing_list(argc-optind, (const char **)&argv[orig_optind]);
730
play_mode->close_output();
734
DeleteCriticalSection (&critSect);