2 TiMidity++ -- MIDI to WAVE converter and player
3 Copyright (C) 1999-2018 Masanao Izumo <iz@onicos.co.jp>
4 Copyright (C) 1995 Tuukka Toivonen <tt@cgs.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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #endif /* HAVE_CONFIG_H */
25 #include <sys/types.h>
32 #endif /* STDC_HEADERS */
37 #endif /* !NO_STRING_H */
46 #include "tmdy_getopt.h"
49 #endif /* HAVE_UNISTD_H */
50 #ifdef TIME_WITH_SYS_TIME
54 #ifdef HAVE_SYS_TIME_H
58 #endif /* HAVE_SYS_TIME_H */
59 #endif /* TIME_WITH_SYS_TIME */
61 #include <fcntl.h> /* for open */
62 #endif /* HAVE_FCNTL_H */
64 #ifdef BORLANDC_EXCEPTION
66 #endif /* BORLANDC_EXCEPTION */
69 #if defined(__FreeBSD__) && !defined(__alpha__)
70 #include <floatingpoint.h> /* For FP exceptions */
72 #if defined(__NetBSD__) || defined(__OpenBSD__)
73 #include <ieeefp.h> /* For FP exceptions */
84 #include "miditrace.h"
87 #ifdef SUPPORT_SOUNDSPEC
88 #include "soundspec.h"
89 #endif /* SUPPORT_SOUNDSPEC */
95 #define DEFINE_GLOBALS
100 #include "quantity.h"
102 #include "sndfontini.h"
104 #include "miditrace.h"
115 #include "w32g_subwin.h"
116 #include "w32g_utl.h"
120 /* supress std outputs */
125 #define __attribute__(x) /* ignore */
136 #include "wasapi_a.h"
140 #include "portaudio_a.h"
144 #include "w32g_utl.h"
148 uint8 opt_normal_chorus_plus = 5; // chorusEX
150 extern DWORD processPriority;
151 DWORD processPriority = NORMAL_PRIORITY_CLASS; //
\83v
\83\8d\83Z
\83X
\82Ì
\83v
\83\89\83C
\83I
\83\8a\83e
\83B
152 #if defined(IA_W32G_SYN) || defined(WINDRV)
153 DWORD syn_ThreadPriority = THREAD_PRIORITY_NORMAL;
155 int GUIThreadPriority = THREAD_PRIORITY_NORMAL;
157 int PlayerThreadPriority = THREAD_PRIORITY_NORMAL;
163 TIM_OPT_VOLUME = TIM_OPT_FIRST,
164 TIM_OPT_MASTER_VOLUME,
168 TIM_OPT_BUFFER_FRAGS,
169 TIM_OPT_CONTROL_RATIO,
171 TIM_OPT_DRUM_CHANNEL,
182 TIM_OPT_OVERLAP_COUNT,
183 TIM_OPT_MAX_CHANNEL_VOICES,
188 TIM_OPT_DEFAULT_BANK,
200 TIM_OPT_RESAMPLE_FILTER,
201 TIM_OPT_RESAMPLE_OVER_SAMPLING,
202 TIM_OPT_PRE_RESAMPLE,
220 TIM_OPT_RTSYN_LATENCY,
221 TIM_OPT_RTSYN_SKIP_AQ,
222 TIM_OPT_RTSYN_PRINT_PORTS,
223 TIM_OPT_REALTIME_LOAD,
227 TIM_OPT_RESAMPLE_QUEUE,
228 TIM_OPT_POLYPHONY_QUEUE,
229 TIM_OPT_ADD_PLAY_TIME,
230 TIM_OPT_ADD_SILENT_TIME,
231 TIM_OPT_EMU_DELAY_TIME,
232 TIM_OPT_PROCESS_PRIORITY,
233 TIM_OPT_PLAYER_THREAD_PRIORITY,
245 TIM_OPT_INTERPOLATION,
247 TIM_OPT_OUTPUT_STEREO,
248 TIM_OPT_OUTPUT_SIGNED,
249 TIM_OPT_OUTPUT_BITWIDTH,
250 TIM_OPT_OUTPUT_FORMAT,
253 TIM_OPT_OUTPUT_DEVICE_ID,
254 TIM_OPT_WMME_DEVICE_ID,
255 TIM_OPT_WAVE_FORMAT_EXT,
256 TIM_OPT_WDMKS_DEVICE_ID,
257 TIM_OPT_WDMKS_LATENCY,
258 TIM_OPT_WDMKS_FORMAT_EXT,
259 TIM_OPT_WDMKS_POLLING,
260 TIM_OPT_WDMKS_THREAD_PRIORITY,
261 TIM_OPT_WDMKS_RT_PRIORITY,
262 TIM_OPT_WDMKS_PIN_PRIORITY,
263 TIM_OPT_WASAPI_DEVICE_ID,
264 TIM_OPT_WASAPI_LATENCY,
265 TIM_OPT_WASAPI_FORMAT_EXT,
266 TIM_OPT_WASAPI_EXCLUSIVE,
267 TIM_OPT_WASAPI_POLLING,
268 TIM_OPT_WASAPI_PRIORITY,
269 TIM_OPT_WASAPI_STREAM_CATEGORY,
270 TIM_OPT_WASAPI_STREAM_OPTION,
271 TIM_OPT_PA_WMME_DEVICE_ID,
272 TIM_OPT_PA_DS_DEVICE_ID,
273 TIM_OPT_PA_ASIO_DEVICE_ID,
274 TIM_OPT_PA_WDMKS_DEVICE_ID,
275 TIM_OPT_PA_WASAPI_DEVICE_ID,
276 TIM_OPT_PA_WASAPI_FLAG,
277 TIM_OPT_PA_WASAPI_STREAM_CATEGORY,
278 TIM_OPT_PA_WASAPI_STREAM_OPTION,
280 TIM_OPT_WAVE_EXTENSIBLE,
281 TIM_OPT_WAVE_UPDATE_STEP,
283 TIM_OPT_FLAC_PADDING,
284 TIM_OPT_FLAC_COMPLEVEL,
285 TIM_OPT_FLAC_OGGFLAC,
286 TIM_OPT_OPUS_NFRAMES,
287 TIM_OPT_OPUS_BITRATE,
288 TIM_OPT_OPUS_COMPLEXITY,
291 TIM_OPT_SPEEX_QUALITY,
296 TIM_OPT_SPEEX_COMPLEXITY,
297 TIM_OPT_SPEEX_NFRAMES,
304 TIM_OPT_PRESERVE_SILENCE,
305 TIM_OPT_AUDIO_BUFFER,
307 TIM_OPT_COMPUTE_BUFFER,
312 TIM_OPT_COMPUTE_THREAD_NUM,
313 TIM_OPT_TRACE_MODE_UPDATE,
314 TIM_OPT_LOAD_ALL_INSTRUMENT,
320 TIM_OPT_ADJUST_TEMPO,
323 TIM_OPT_VOLUME_CALC_RMS,
324 TIM_OPT_VOLUME_CALC_TRIM,
325 TIM_OPT_VOLUME_CURVE,
333 TIM_OPT_DUMMY_SETTING,
334 TIM_OPT_INT_SYNTH_RATE,
335 TIM_OPT_INT_SYNTH_SINE,
336 TIM_OPT_INT_SYNTH_UPDATE,
338 TIM_OPT_LAST = TIM_OPT_MODULE,
342 const char *optcommands =
344 static const char *optcommands =
347 // "4A:aB:b:C:c:D:d:E:eFfg:H:hI:i:jK:k:L:M:m:N:"
348 // "O:o:P:p:Q:q:R:S:s:T:t:UV:vW:"
349 "4A:aB:b:C:c:D:d:E:eF:fg:H:hI:i:jK:k:L:lM:m:N:n"
350 "O:o:P:p:Q:q:R:rS:s:T:t:UV:vW:"
354 "xY:Z:"; /* Only GJluXyz are remain... */
356 const struct option longopts[] = {
358 static const struct option longopts[] = {
360 { "volume", required_argument, NULL, TIM_OPT_VOLUME },
361 { "master-volume", required_argument, NULL, TIM_OPT_MASTER_VOLUME },
362 { "drum-power", required_argument, NULL, TIM_OPT_DRUM_POWER },
363 { "no-volume-compensation", optional_argument, NULL, TIM_OPT_VOLUME_COMP },
364 { "volume-compensation", optional_argument, NULL, TIM_OPT_VOLUME_COMP },
365 { "no-anti-alias", no_argument, NULL, TIM_OPT_ANTI_ALIAS },
366 { "anti-alias", optional_argument, NULL, TIM_OPT_ANTI_ALIAS },
367 { "buffer-fragments", required_argument, NULL, TIM_OPT_BUFFER_FRAGS },
368 { "control-ratio", required_argument, NULL, TIM_OPT_CONTROL_RATIO },
369 { "config-file", required_argument, NULL, TIM_OPT_CONFIG_FILE },
370 { "drum-channel", required_argument, NULL, TIM_OPT_DRUM_CHANNEL },
371 { "interface-path", required_argument, NULL, TIM_OPT_IFACE_PATH },
372 { "ext", required_argument, NULL, TIM_OPT_EXT },
373 { "no-mod-wheel", no_argument, NULL, TIM_OPT_MOD_WHEEL },
374 { "mod-wheel", optional_argument, NULL, TIM_OPT_MOD_WHEEL },
375 { "no-portamento", no_argument, NULL, TIM_OPT_PORTAMENTO },
376 { "portamento", optional_argument, NULL, TIM_OPT_PORTAMENTO },
377 { "no-vibrato", no_argument, NULL, TIM_OPT_VIBRATO },
378 { "vibrato", optional_argument, NULL, TIM_OPT_VIBRATO },
379 { "no-ch-pressure", no_argument, NULL, TIM_OPT_CH_PRESS },
380 { "ch-pressure", optional_argument, NULL, TIM_OPT_CH_PRESS },
381 { "no-mod-envelope", no_argument, NULL, TIM_OPT_MOD_ENV },
382 { "mod-envelope", optional_argument, NULL, TIM_OPT_MOD_ENV },
383 { "no-trace-text-meta", no_argument, NULL, TIM_OPT_TRACE_TEXT },
384 { "trace-text-meta", optional_argument, NULL, TIM_OPT_TRACE_TEXT },
385 { "no-overlap-voice", no_argument, NULL, TIM_OPT_OVERLAP },
386 { "overlap-voice", optional_argument, NULL, TIM_OPT_OVERLAP },
388 { "overlap-voice-count", required_argument, NULL, TIM_OPT_OVERLAP_COUNT },
389 { "max-channel-voices", required_argument, NULL, TIM_OPT_MAX_CHANNEL_VOICES },
391 { "no-temper-control", no_argument, NULL, TIM_OPT_TEMPER_CTRL },
392 { "temper-control", optional_argument, NULL, TIM_OPT_TEMPER_CTRL },
393 { "default-mid", required_argument, NULL, TIM_OPT_DEFAULT_MID },
394 { "system-mid", required_argument, NULL, TIM_OPT_SYSTEM_MID },
395 { "default-bank", required_argument, NULL, TIM_OPT_DEFAULT_BANK },
396 { "force-bank", required_argument, NULL, TIM_OPT_FORCE_BANK },
397 { "default-program", required_argument, NULL, TIM_OPT_DEFAULT_PGM },
398 { "force-program", required_argument, NULL, TIM_OPT_FORCE_PGM },
399 { "delay", required_argument, NULL, TIM_OPT_DELAY },
400 { "chorus", required_argument, NULL, TIM_OPT_CHORUS },
401 { "reverb", required_argument, NULL, TIM_OPT_REVERB },
402 { "voice-lpf", required_argument, NULL, TIM_OPT_VOICE_LPF },
403 { "voice-hpf", required_argument, NULL, TIM_OPT_VOICE_HPF },
404 { "noise-shaping", required_argument, NULL, TIM_OPT_NS },
405 #ifndef FIXED_RESAMPLATION
406 { "resample", required_argument, NULL, TIM_OPT_RESAMPLE },
408 { "resample-filter", required_argument, NULL, TIM_OPT_RESAMPLE_FILTER },
409 { "resample-over-sampling", required_argument, NULL, TIM_OPT_RESAMPLE_OVER_SAMPLING },
410 { "pre-resample", required_argument, NULL, TIM_OPT_PRE_RESAMPLE },
411 { "evil", no_argument, NULL, TIM_OPT_EVIL },
412 { "no-fast-panning", no_argument, NULL, TIM_OPT_FAST_PAN },
413 { "fast-panning", optional_argument, NULL, TIM_OPT_FAST_PAN },
414 { "no-fast-decay", no_argument, NULL, TIM_OPT_FAST_DECAY },
415 { "fast-decay", optional_argument, NULL, TIM_OPT_FAST_DECAY },
416 { "segment", required_argument, NULL, TIM_OPT_SEGMENT },
417 { "spectrogram", required_argument, NULL, TIM_OPT_SPECTROGRAM },
418 { "force-keysig", required_argument, NULL, TIM_OPT_KEYSIG },
419 { "help", optional_argument, NULL, TIM_OPT_HELP },
420 { "interface", required_argument, NULL, TIM_OPT_INTERFACE },
421 { "verbose", optional_argument, NULL, TIM_OPT_VERBOSE },
422 { "quiet", optional_argument, NULL, TIM_OPT_QUIET },
423 { "no-trace", no_argument, NULL, TIM_OPT_TRACE },
424 { "trace", optional_argument, NULL, TIM_OPT_TRACE },
425 { "no-loop", no_argument, NULL, TIM_OPT_LOOP },
426 { "loop", optional_argument, NULL, TIM_OPT_LOOP },
427 { "no-random", no_argument, NULL, TIM_OPT_RANDOM },
428 { "random", optional_argument, NULL, TIM_OPT_RANDOM },
429 { "no-sort", no_argument, NULL, TIM_OPT_SORT },
430 { "sort", optional_argument, NULL, TIM_OPT_SORT },
432 { "no-background", no_argument, NULL, TIM_OPT_BACKGROUND },
433 { "background", optional_argument, NULL, TIM_OPT_BACKGROUND },
434 { "realtime-priority", required_argument, NULL, TIM_OPT_RT_PRIO },
435 { "sequencer-ports", required_argument, NULL, TIM_OPT_SEQ_PORTS },
437 { "no-realtime-load", no_argument, NULL, TIM_OPT_REALTIME_LOAD },
438 { "realtime-load", optional_argument, NULL, TIM_OPT_REALTIME_LOAD },
439 { "adjust-key", required_argument, NULL, TIM_OPT_ADJUST_KEY },
440 { "voice-queue", required_argument, NULL, TIM_OPT_VOICE_QUEUE },
442 { "resample-queue", required_argument, NULL, TIM_OPT_RESAMPLE_QUEUE },
443 { "polyphony-queue", required_argument, NULL, TIM_OPT_POLYPHONY_QUEUE },
444 { "add-play-time", required_argument, NULL, TIM_OPT_ADD_PLAY_TIME },
445 { "add-silent-time", required_argument, NULL, TIM_OPT_ADD_SILENT_TIME },
446 { "emu-delay-time", required_argument, NULL, TIM_OPT_EMU_DELAY_TIME },
448 { "process-priority", required_argument, NULL, TIM_OPT_PROCESS_PRIORITY },
449 #if !(defined(IA_W32G_SYN) || defined(WINDRV))
450 { "player-thread-priority", required_argument, NULL, TIM_OPT_PLAYER_THREAD_PRIORITY },
453 { "od-level-gs", required_argument, NULL, TIM_OPT_OD_LEVEL_GS },
454 { "od-drive-gs", required_argument, NULL, TIM_OPT_OD_DRIVE_GS },
455 { "od-level-xg", required_argument, NULL, TIM_OPT_OD_LEVEL_XG },
456 { "od-drive-xg", required_argument, NULL, TIM_OPT_OD_DRIVE_XG },
457 { "patch-path", required_argument, NULL, TIM_OPT_PATCH_PATH },
458 { "pcm-file", required_argument, NULL, TIM_OPT_PCM_FILE },
459 { "decay-time", required_argument, NULL, TIM_OPT_DECAY_TIME },
460 { "interpolation", required_argument, NULL, TIM_OPT_INTERPOLATION },
461 { "output-mode", required_argument, NULL, TIM_OPT_OUTPUT_MODE },
462 { "output-stereo", no_argument, NULL, TIM_OPT_OUTPUT_STEREO },
463 { "output-mono", no_argument, NULL, TIM_OPT_OUTPUT_STEREO },
464 { "output-signed", no_argument, NULL, TIM_OPT_OUTPUT_SIGNED },
465 { "output-unsigned", no_argument, NULL, TIM_OPT_OUTPUT_SIGNED },
466 { "output-16bit", no_argument, NULL, TIM_OPT_OUTPUT_BITWIDTH },
467 { "output-24bit", no_argument, NULL, TIM_OPT_OUTPUT_BITWIDTH },
469 { "output-32bit", no_argument, NULL, TIM_OPT_OUTPUT_BITWIDTH },
470 { "output-f32bit", no_argument, NULL, TIM_OPT_OUTPUT_BITWIDTH },
471 { "output-float32bit", no_argument, NULL, TIM_OPT_OUTPUT_BITWIDTH },
472 { "output-64bit", no_argument, NULL, TIM_OPT_OUTPUT_BITWIDTH },
473 { "output-f64bit", no_argument, NULL, TIM_OPT_OUTPUT_BITWIDTH },
474 { "output-float64bit", no_argument, NULL, TIM_OPT_OUTPUT_BITWIDTH },
476 { "output-8bit", no_argument, NULL, TIM_OPT_OUTPUT_BITWIDTH },
477 { "output-linear", no_argument, NULL, TIM_OPT_OUTPUT_FORMAT },
478 { "output-ulaw", no_argument, NULL, TIM_OPT_OUTPUT_FORMAT },
479 { "output-alaw", no_argument, NULL, TIM_OPT_OUTPUT_FORMAT },
480 { "no-output-swab", no_argument, NULL, TIM_OPT_OUTPUT_SWAB },
481 { "output-swab", optional_argument, NULL, TIM_OPT_OUTPUT_SWAB },
482 #if defined(IA_WINSYN) || defined(IA_NPSYN) || defined(IA_PORTMIDI) || \
483 defined(IA_W32G_SYN) || defined(IA_W32GUI)
484 { "rtsyn-latency", required_argument, NULL, TIM_OPT_RTSYN_LATENCY },
485 { "rtsyn-skip-aq", required_argument, NULL, TIM_OPT_RTSYN_SKIP_AQ },
486 { "rtsyn-print-ports", no_argument, NULL, TIM_OPT_RTSYN_PRINT_PORTS },
487 { "rtsyn-list", no_argument, NULL, TIM_OPT_RTSYN_PRINT_PORTS },
488 #endif /* RTSYN || IA_W32GUI */
490 { "output-device-id", required_argument, NULL, TIM_OPT_OUTPUT_DEVICE_ID },
492 { "wmme-device-id", required_argument, NULL, TIM_OPT_WMME_DEVICE_ID },
493 { "wave-format-ext", required_argument, NULL, TIM_OPT_WAVE_FORMAT_EXT },
494 { "wmme-format-ext", required_argument, NULL, TIM_OPT_WAVE_FORMAT_EXT },
497 { "wdmks-device-id", required_argument, NULL, TIM_OPT_WDMKS_DEVICE_ID },
498 { "wdmks-latency", required_argument, NULL, TIM_OPT_WDMKS_LATENCY },
499 { "wdmks-format-ext", required_argument, NULL, TIM_OPT_WDMKS_FORMAT_EXT },
500 { "wdmks-polling", required_argument, NULL, TIM_OPT_WDMKS_POLLING },
501 { "wdmks-thread-priority", required_argument, NULL, TIM_OPT_WDMKS_THREAD_PRIORITY },
502 { "wdmks-rt-priority", required_argument, NULL, TIM_OPT_WDMKS_RT_PRIORITY },
503 { "wdmks-pin-priority", required_argument, NULL, TIM_OPT_WDMKS_PIN_PRIORITY },
506 { "wasapi-device-id", required_argument, NULL, TIM_OPT_WASAPI_DEVICE_ID },
507 { "wasapi-latency", required_argument, NULL, TIM_OPT_WASAPI_LATENCY },
508 { "wasapi-format-ext", required_argument, NULL, TIM_OPT_WASAPI_FORMAT_EXT },
509 { "wasapi-exclusive", required_argument, NULL, TIM_OPT_WASAPI_EXCLUSIVE },
510 { "wasapi-polling", required_argument, NULL, TIM_OPT_WASAPI_POLLING },
511 { "wasapi-priority", required_argument, NULL, TIM_OPT_WASAPI_PRIORITY },
512 { "wasapi-stream-category", required_argument, NULL, TIM_OPT_WASAPI_STREAM_CATEGORY },
513 { "wasapi-stream-option", required_argument, NULL, TIM_OPT_WASAPI_STREAM_OPTION },
516 { "pa-wmme-device-id", required_argument, NULL, TIM_OPT_PA_WMME_DEVICE_ID },
517 { "pa-ds-device-id", required_argument, NULL, TIM_OPT_PA_DS_DEVICE_ID },
518 { "pa-asio-device-id", required_argument, NULL, TIM_OPT_PA_ASIO_DEVICE_ID },
520 { "pa-wdmks-device-id", required_argument, NULL, TIM_OPT_PA_WDMKS_DEVICE_ID },
521 { "pa-wasapi-device-id", required_argument, NULL, TIM_OPT_PA_WASAPI_DEVICE_ID },
522 { "pa-wasapi-flag", required_argument, NULL, TIM_OPT_PA_WASAPI_FLAG },
523 { "pa-wasapi-stream-category",required_argument, NULL, TIM_OPT_PA_WASAPI_STREAM_CATEGORY },
524 { "pa-wasapi-stream-option",required_argument, NULL, TIM_OPT_PA_WASAPI_STREAM_OPTION },
527 { "wave-extensible", no_argument, NULL, TIM_OPT_WAVE_EXTENSIBLE },
528 { "wave-update-step", optional_argument, NULL, TIM_OPT_WAVE_UPDATE_STEP },
530 { "flac-verify", no_argument, NULL, TIM_OPT_FLAC_VERIFY },
531 { "flac-padding", required_argument, NULL, TIM_OPT_FLAC_PADDING },
532 { "flac-complevel", required_argument, NULL, TIM_OPT_FLAC_COMPLEVEL },
534 { "oggflac", no_argument, NULL, TIM_OPT_FLAC_OGGFLAC },
535 #endif /* AU_OGGFLAC */
538 { "opus-nframes", required_argument, NULL, TIM_OPT_OPUS_NFRAMES },
539 { "opus-bitrate", required_argument, NULL, TIM_OPT_OPUS_BITRATE },
540 { "opus-complexity", required_argument, NULL, TIM_OPT_OPUS_COMPLEXITY },
541 { "opus-vbr", no_argument, NULL, TIM_OPT_OPUS_VBR },
542 { "opus-cvbr", no_argument, NULL, TIM_OPT_OPUS_CVBR },
545 { "speex-quality", required_argument, NULL, TIM_OPT_SPEEX_QUALITY },
546 { "speex-vbr", no_argument, NULL, TIM_OPT_SPEEX_VBR },
547 { "speex-abr", required_argument, NULL, TIM_OPT_SPEEX_ABR },
548 { "speex-vad", no_argument, NULL, TIM_OPT_SPEEX_VAD },
549 { "speex-dtx", no_argument, NULL, TIM_OPT_SPEEX_DTX },
550 { "speex-complexity", required_argument, NULL, TIM_OPT_SPEEX_COMPLEXITY },
551 { "speex-nframes", required_argument, NULL, TIM_OPT_SPEEX_NFRAMES },
552 #endif /* AU_SPEEX */
553 { "output-file", required_argument, NULL, TIM_OPT_OUTPUT_FILE },
554 { "patch-file", required_argument, NULL, TIM_OPT_PATCH_FILE },
555 { "polyphony", required_argument, NULL, TIM_OPT_POLYPHONY },
556 { "no-polyphony-reduction", no_argument, NULL, TIM_OPT_POLY_REDUCE },
557 { "polyphony-reduction", optional_argument, NULL, TIM_OPT_POLY_REDUCE },
558 { "mute", required_argument, NULL, TIM_OPT_MUTE },
559 { "temper-mute", required_argument, NULL, TIM_OPT_TEMPER_MUTE },
560 { "preserve-silence", no_argument, NULL, TIM_OPT_PRESERVE_SILENCE },
561 { "audio-buffer", required_argument, NULL, TIM_OPT_AUDIO_BUFFER },
563 { "compute-buffer", required_argument, NULL, TIM_OPT_COMPUTE_BUFFER },
564 { "mix-envelope", required_argument, NULL, TIM_OPT_MIX_ENV },
565 { "modulation-update", required_argument, NULL, TIM_OPT_MOD_UPDATE },
566 { "cut-short-time", required_argument, NULL, TIM_OPT_CUT_SHORT },
567 { "limiter", required_argument, NULL, TIM_OPT_LIMITER },
568 { "compute-thread-num", required_argument, NULL, TIM_OPT_COMPUTE_THREAD_NUM },
569 { "trace-mode-update-time", required_argument, NULL, TIM_OPT_TRACE_MODE_UPDATE },
570 { "load-all-instrument", required_argument, NULL, TIM_OPT_LOAD_ALL_INSTRUMENT },
571 { "loop-repeat", required_argument, NULL, TIM_OPT_LOOP_REPEAT },
572 { "loop-filter", required_argument, NULL, TIM_OPT_LOOP_FILTER },
574 { "cache-size", required_argument, NULL, TIM_OPT_CACHE_SIZE },
575 { "sampling-freq", required_argument, NULL, TIM_OPT_SAMPLE_FREQ },
576 { "adjust-tempo", required_argument, NULL, TIM_OPT_ADJUST_TEMPO },
577 { "output-charset", required_argument, NULL, TIM_OPT_CHARSET },
578 { "no-unload-instruments", no_argument, NULL, TIM_OPT_UNLOAD_INST },
579 { "unload-instruments", optional_argument, NULL, TIM_OPT_UNLOAD_INST },
580 #if defined(AU_VOLUME_CALC)
581 { "volume-calc-rms", no_argument, NULL, TIM_OPT_VOLUME_CALC_RMS },
582 { "volume-calc-trim", no_argument, NULL, TIM_OPT_VOLUME_CALC_TRIM },
583 #endif /* AU_VOLUME_CALC */
584 { "volume-curve", required_argument, NULL, TIM_OPT_VOLUME_CURVE },
585 { "version", no_argument, NULL, TIM_OPT_VERSION },
586 { "wrd", required_argument, NULL, TIM_OPT_WRD },
588 { "rcpcv-dll", required_argument, NULL, TIM_OPT_RCPCV_DLL },
590 { "config-string", required_argument, NULL, TIM_OPT_CONFIG_STR },
591 { "freq-table", required_argument, NULL, TIM_OPT_FREQ_TABLE },
592 { "pure-intonation", optional_argument, NULL, TIM_OPT_PURE_INT },
593 { "module", required_argument, NULL, TIM_OPT_MODULE },
594 { "disable-chorus-plus", no_argument, NULL, TIM_OPT_DUMMY_SETTING},
596 { "int-synth-rate", required_argument, NULL, TIM_OPT_INT_SYNTH_RATE },
597 { "int-synth-sine", required_argument, NULL, TIM_OPT_INT_SYNTH_SINE },
598 { "int-synth-update", required_argument, NULL, TIM_OPT_INT_SYNTH_UPDATE },
600 { NULL, no_argument, NULL, '\0' }
602 #define INTERACTIVE_INTERFACE_IDS "kmqagrwAWNP"
606 /* main interfaces (To be used another main) */
607 #if defined(main) || defined(ANOTHER_MAIN) || defined ( IA_W32GUI ) || defined ( IA_W32G_SYN )
608 #define MAIN_INTERFACE
610 #define MAIN_INTERFACE static
613 MAIN_INTERFACE void timidity_start_initialize(void);
614 MAIN_INTERFACE int timidity_pre_load_configuration(void);
615 MAIN_INTERFACE int timidity_post_load_configuration(void);
616 MAIN_INTERFACE void timidity_init_player(void);
617 MAIN_INTERFACE int timidity_play_main(int nfiles, char **files);
618 MAIN_INTERFACE int got_a_configuration;
619 char *wrdt_open_opts = NULL;
620 char *opt_aq_max_buff = NULL,
621 *opt_aq_fill_buff = NULL;
622 void timidity_init_aq_buff(void);
623 int opt_control_ratio = 0; /* Save -C option */
625 char *opt_reduce_voice_threshold = NULL;
626 char *opt_reduce_quality_threshold = NULL;
627 char *opt_reduce_polyphony_threshold = NULL;
629 #if (defined(IA_W32GUI) || defined(IA_W32G_SYN)) && \
630 defined(__GNUC__) && !defined(SUPPORT_WINMAIN)
631 extern int RestartTimidity;
632 #endif /* (IA_W32GUI || IA_W32G_SYN) && __GNUC__ && !SUPPORT_WINMAIN */
634 int set_extension_modes(char *);
636 int set_play_mode(char *);
638 MAIN_INTERFACE int set_tim_opt_short(int c, const char *);
639 MAIN_INTERFACE int set_tim_opt_long(int, const char *, int);
640 static inline int parse_opt_A(const char *);
641 static inline int parse_opt_master_volume(const char *arg);
642 static inline int parse_opt_drum_power(const char *);
643 static inline int parse_opt_volume_comp(const char *);
644 static inline int parse_opt_a(const char *);
645 static inline int parse_opt_B(const char *);
646 static inline int parse_opt_C(const char *);
647 static inline int parse_opt_c(const char *);
648 static inline int parse_opt_D(const char *);
649 static inline int parse_opt_d(const char *);
650 static inline int parse_opt_E(const char *);
651 static inline int parse_opt_mod_wheel(const char *);
652 static inline int parse_opt_portamento(const char *);
653 static inline int parse_opt_vibrato(const char *);
654 static inline int parse_opt_ch_pressure(const char *);
655 static inline int parse_opt_mod_env(const char *);
656 static inline int parse_opt_trace_text(const char *);
657 static inline int parse_opt_overlap_voice(const char *);
659 static inline int parse_opt_overlap_voice_count(const char *);
660 static inline int parse_opt_max_channel_voices(const char *);
662 static inline int parse_opt_temper_control(const char *);
663 static inline int parse_opt_default_mid(const char *);
664 static inline int parse_opt_system_mid(const char *);
665 static inline int parse_opt_default_bank(const char *);
666 static inline int parse_opt_force_bank(const char *);
667 static inline int parse_opt_default_program(const char *);
668 static inline int parse_opt_force_program(const char *);
669 static inline int set_default_program(int);
670 static inline int parse_opt_delay(const char *arg);
671 static inline int parse_opt_chorus(const char *);
672 static inline int parse_opt_reverb(const char *);
673 static int parse_opt_reverb_freeverb(const char *arg, char type);
674 static inline int parse_opt_voice_lpf(const char *);
675 static inline int parse_opt_voice_hpf(const char *);
676 static inline int parse_opt_noise_shaping(const char *);
677 static inline int parse_opt_resample(const char *);
678 static inline int parse_opt_e(const char *);
679 static inline int parse_opt_F(const char *);
680 static inline int parse_opt_f(const char *);
681 static inline int parse_opt_G(const char*);
682 static inline int parse_opt_G1(const char*);
683 static int parse_segment(TimeSegment*, const char*);
684 static int parse_segment2(TimeSegment*, const char*);
685 static int parse_time(FLOAT_T*, const char*);
686 static int parse_time2(Measure*, const char*);
687 static inline int parse_opt_g(const char *);
688 static inline int parse_opt_H(const char *);
689 __attribute__((noreturn))
690 static inline int parse_opt_h(const char *);
692 static inline void list_dyna_interface(FILE *, char *, char *);
693 ControlMode *dynamic_interface_module(int);
695 static inline int parse_opt_i(const char *);
696 static inline int parse_opt_verbose(const char *);
697 static inline int parse_opt_quiet(const char *);
698 static inline int parse_opt_trace(const char *);
699 static inline int parse_opt_loop(const char *);
700 static inline int parse_opt_random(const char *);
701 static inline int parse_opt_sort(const char *);
703 static inline int parse_opt_background(const char *);
704 static inline int parse_opt_rt_prio(const char *);
705 static inline int parse_opt_seq_ports(const char *);
707 #if defined(IA_WINSYN) || defined(IA_NPSYN) || defined(IA_PORTMIDI) || \
708 defined(IA_W32G_SYN) || defined(IA_W32GUI)
709 static inline int parse_opt_rtsyn_latency(const char*);
710 static inline int parse_opt_rtsyn_skip_aq(const char*);
711 static inline int parse_opt_rtsyn_print_ports(const char*);
712 #endif /* RTSYN || IA_W32GUI */
713 static inline int parse_opt_j(const char *);
714 static inline int parse_opt_K(const char *);
715 static inline int parse_opt_k(const char *);
716 static inline int parse_opt_L(const char *);
717 static inline int parse_opt_l(const char *);
718 static inline int parse_opt_resample_over_sampling(const char *);
719 static inline int parse_opt_pre_resample(const char *);
720 static inline int parse_opt_M(const char *);
721 static inline int parse_opt_m(const char *);
722 static inline int parse_opt_N(const char *);
723 static inline int parse_opt_n(const char *);
724 static inline int parse_opt_O(const char *);
725 static inline int parse_opt_output_stereo(const char *);
726 static inline int parse_opt_output_signed(const char *);
727 static inline int parse_opt_output_bitwidth(const char *);
728 static inline int parse_opt_output_format(const char *);
729 static inline int parse_opt_output_swab(const char *);
731 static inline int parse_opt_output_device_id(const char *);
733 static inline int parse_opt_wmme_device_id(const char *);
734 static inline int parse_opt_wave_format_ext(const char *arg);
737 static inline int parse_opt_wdmks_device_id(const char *arg);
738 static inline int parse_opt_wdmks_latency(const char *arg);
739 static inline int parse_opt_wdmks_format_ext(const char *arg);
740 static inline int parse_opt_wdmks_polling(const char *arg);
741 static inline int parse_opt_wdmks_thread_priority(const char *arg);
742 static inline int parse_opt_wdmks_rt_priority(const char *arg);
743 static inline int parse_opt_wdmks_pin_priority(const char *arg);
746 static inline int parse_opt_wasapi_device_id(const char *arg);
747 static inline int parse_opt_wasapi_latency(const char *arg);
748 static inline int parse_opt_wasapi_format_ext(const char *arg);
749 static inline int parse_opt_wasapi_exclusive(const char *arg);
750 static inline int parse_opt_wasapi_polling(const char *arg);
751 static inline int parse_opt_wasapi_priority(const char *arg);
752 static inline int parse_opt_wasapi_stream_category(const char *arg);
753 static inline int parse_opt_wasapi_stream_option(const char *arg);
756 static inline int parse_opt_pa_wmme_device_id(const char *);
757 static inline int parse_opt_pa_ds_device_id(const char *);
758 static inline int parse_opt_pa_asio_device_id(const char *);
760 static inline int parse_opt_pa_wdmks_device_id(const char *);
761 static inline int parse_opt_pa_wasapi_device_id(const char *);
762 static inline int parse_opt_pa_wasapi_flag(const char *);
763 static inline int parse_opt_pa_wasapi_stream_category(const char *arg);
764 static inline int parse_opt_pa_wasapi_stream_option(const char *arg);
768 #if defined(AU_PORTAUDIO) || defined(AU_W32)
769 static inline int parse_opt_output_device(const char*);
771 static inline int parse_opt_wave_extensible(const char*);
772 static inline int parse_opt_wave_update_step(const char*);
774 static inline int parse_opt_flac_verify(const char *);
775 static inline int parse_opt_flac_padding(const char *);
776 static inline int parse_opt_flac_complevel(const char *);
778 static inline int parse_opt_flac_oggflac(const char *);
779 #endif /* AU_OGGFLAC */
782 static inline int parse_opt_opus_nframes(const char *);
783 static inline int parse_opt_opus_bitrate(const char *);
784 static inline int parse_opt_opus_complexity(const char *);
785 static inline int parse_opt_opus_vbr(const char *);
786 static inline int parse_opt_opus_cvbr(const char *);
789 static inline int parse_opt_speex_quality(const char *);
790 static inline int parse_opt_speex_vbr(const char *);
791 static inline int parse_opt_speex_abr(const char *);
792 static inline int parse_opt_speex_vad(const char *);
793 static inline int parse_opt_speex_dtx(const char *);
794 static inline int parse_opt_speex_complexity(const char *);
795 static inline int parse_opt_speex_nframes(const char *);
796 #endif /* AU_SPEEX */
797 static inline int parse_opt_o(const char *);
798 static inline int parse_opt_P(const char *);
799 static inline int parse_opt_p(const char *);
800 static inline int parse_opt_p1(const char *);
801 static inline int parse_opt_Q(const char *);
802 static inline int parse_opt_Q1(const char *);
803 static inline int parse_opt_preserve_silence(const char *);
804 static inline int parse_opt_q(const char *);
805 static inline int parse_opt_R(const char *);
807 static inline int parse_opt_r(const char *);
809 static inline int parse_opt_S(const char *);
810 static inline int parse_opt_s(const char *);
811 static inline int parse_opt_T(const char *);
812 static inline int parse_opt_t(const char *);
813 static inline int parse_opt_U(const char *);
814 #if defined(AU_VOLUME_CALC)
815 static inline int parse_opt_volume_calc_rms(const char *);
816 static inline int parse_opt_volume_calc_trim(const char *);
817 #endif /* AU_VOLUME_CALC */
818 static inline int parse_opt_volume_curve(const char *);
819 __attribute__((noreturn))
820 static inline int parse_opt_v(const char *);
821 static inline int parse_opt_W(const char *);
823 static inline int parse_opt_w(const char *);
825 static inline int parse_opt_x(const char *);
827 static inline int parse_opt_Y(const char *);
828 static inline void expand_escape_string(char *);
829 static inline int parse_opt_Z(const char *);
830 static inline int parse_opt_Z1(const char *);
831 static inline int parse_opt_default_module(const char *);
832 __attribute__((noreturn))
833 static inline int parse_opt_fail(const char *);
834 static inline int set_value(int *, int, int, int, const char *);
835 static inline int set_val_i32(int32 *, int32, int32, int32, const char *);
836 static int parse_val_float_t(FLOAT_T *param, const char *arg, FLOAT_T low, FLOAT_T high, const char *name);
837 static inline int set_val_float_t(FLOAT_T *param, FLOAT_T i, FLOAT_T low, FLOAT_T high, const char *name);
838 static inline int set_channel_flag(ChannelBitMask *, int32, const char *);
839 static inline int y_or_n_p(const char *);
840 static inline int set_flag(int32 *, int32, const char *);
841 static inline FILE *open_pager(void);
842 static inline void close_pager(FILE *);
843 static void interesting_message(void);
845 static inline int parse_opt_add_play_time(const char *arg);
846 static inline int parse_opt_add_silent_time(const char *arg);
847 static inline int parse_opt_emu_delay_time(const char *arg);
848 static inline int parse_opt_mix_envelope(const char *arg);
849 static inline int parse_opt_modulation_update(const char *arg);
851 static inline int parse_opt_cut_short_time(const char *arg);
852 static inline int parse_opt_limiter(const char *arg);
853 static inline int parse_opt_compute_thread_num(const char *arg);
854 static inline int parse_opt_trace_mode_update(const char *arg);
855 static inline int parse_opt_load_all_instrument(const char *arg);
856 static inline int parse_opt_int_synth_rate(const char *arg);
857 static inline int parse_opt_int_synth_sine(const char *arg);
858 static inline int parse_opt_int_synth_update(const char *arg);
859 #ifdef SUPPORT_LOOPEVENT
860 static inline int parse_opt_midi_loop_repeat(const char*);
861 static inline int parse_opt_midi_loop_filter(const char *arg);
862 #endif /* SUPPORT_LOOPEVENT */
863 static inline int parse_opt_od_level_gs(const char *arg);
864 static inline int parse_opt_od_drive_gs(const char *arg);
865 static inline int parse_opt_od_level_xg(const char *arg);
866 static inline int parse_opt_od_drive_xg(const char *arg);
867 static inline int parse_opt_od_level_sd(const char *arg);
868 static inline int parse_opt_od_drive_sd(const char *arg);
871 static inline int parse_opt_process_priority(const char *arg);
872 #if !(defined(IA_W32G_SYN) || defined(WINDRV))
873 static inline int parse_opt_player_thread_priority(const char *arg);
875 static void w32_exit(void);
876 static int w32_atexit = 1;
879 extern StringTable wrd_read_opts;
881 extern int SecondMode;
883 extern struct URL_module URL_module_file;
885 extern struct URL_module URL_module_dir;
886 #endif /* __MACOS__ */
887 #ifdef SUPPORT_SOCKET
888 extern struct URL_module URL_module_http;
889 extern struct URL_module URL_module_ftp;
890 extern struct URL_module URL_module_news;
891 extern struct URL_module URL_module_newsgroup;
892 #endif /* SUPPORT_SOCKET */
894 extern struct URL_module URL_module_pipe;
895 #endif /* HAVE_POPEN */
897 MAIN_INTERFACE struct URL_module *url_module_list[] =
902 #endif /* __MACOS__ */
903 #ifdef SUPPORT_SOCKET
907 &URL_module_newsgroup,
908 #endif /* SUPPORT_SOCKET */
909 #if !defined(__MACOS__) && defined(HAVE_POPEN)
912 #if defined(main) || defined(ANOTHER_MAIN)
913 /* You can put some other modules */
928 #ifndef SHARED_LIB_PATH
929 #define SHARED_LIB_PATH PKGLIBDIR
930 #endif /* SHARED_LIB_PATH */
931 static char *dynamic_lib_root = NULL;
932 #endif /* IA_DYNAMIC */
935 #define MAXPATHLEN 1024
936 #endif /* MAXPATHLEN */
938 int free_instruments_afterwards = 1;
940 char def_instr_name[FILEPATH_MAX] = "";
941 VOLATILE int intr = 0;
944 CRITICAL_SECTION critSect;
947 static BOOL WINAPI handler(DWORD dw)
949 #if defined(IA_WINSYN) || defined(IA_PORTMIDISYN)
950 if (ctl->id_character == 'W' || ctl->id_character == 'P')
951 rtsyn_midiports_close();
952 #endif /* IA_WINSYN || IA_PORTMIDISYN */
955 if (ctl->id_character == 'N')
956 return FALSE; /* why FALSE need? It must close by intr++; */
957 #endif /* IA_NPSYN */
959 printf ("***BREAK" NLS);
966 int effect_lr_mode = -1;
972 int effect_lr_delay_msec = 25;
974 extern char* pcm_alternate_file;
975 /* NULL, "none": disabled (default)
976 * "auto": automatically selected
977 * filename: use the one.
981 extern double atof(const char *);
985 /*! copy bank and, if necessary, map appropriately */
986 static void copybank(ToneBank *to, ToneBank *from, int mapid, int bankmapfrom, int bankno)
988 ToneBankElement *toelm, *fromelm;
994 for(i = 0; i < 128; i++){
995 if(from->tone[i][0] == NULL)
997 for(elm = 0; elm <= from->tone[i][0]->element_num; elm++) {
998 toelm = to->tone[i][elm];
999 fromelm = from->tone[i][elm];
1000 if (fromelm->name == NULL)
1003 if(alloc_tone_bank_element(&to->tone[i][elm])){
1004 ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "copybank ToneBankElement malloc error ",mapid, bankmapfrom, bankno, elm);
1007 toelm = to->tone[i][elm];
1009 copy_tone_bank_element(toelm, fromelm);
1010 toelm->instrument = NULL;
1011 if (mapid != INST_NO_MAP)
1012 set_instrument_map(mapid, bankmapfrom, i, bankno, i);
1017 /*! copy the whole mapped bank. returns 0 if no error. */
1018 static int copymap(int mapto, int mapfrom, int isdrum)
1020 ToneBank **tb = isdrum ? drumset : tonebank;
1021 int i, bankfrom, bankto;
1023 for(i = 0; i < 128; i++)
1025 bankfrom = find_instrument_map_bank(isdrum, mapfrom, i);
1026 if (bankfrom <= 0) /* not mapped */
1028 bankto = alloc_instrument_map_bank(isdrum, mapto, i);
1029 if (bankto == -1) /* failed */
1031 copybank(tb[bankto], tb[bankfrom], mapto, i, bankto);
1036 static float *config_parse_tune(const char *cp, int *num)
1044 while ((p = strchr(p, ',')) != NULL)
1047 tune_list = (float *) safe_malloc((*num) * sizeof(float));
1049 for (i = 0, p = cp; i < *num; i++, p++) {
1050 tune_list[i] = atof(p);
1051 if (! (p = strchr(p, ',')))
1057 static int16 *config_parse_int16(const char *cp, int *num)
1065 while ((p = strchr(p, ',')) != NULL)
1068 list = (int16 *) safe_malloc((*num) * sizeof(int16));
1070 for (i = 0, p = cp; i < *num; i++, p++) {
1072 if (! (p = strchr(p, ',')))
1078 static int16 *config_parse_lfo_rate(const char *cp, int *num)
1086 while ((p = strchr(p, ',')) != NULL)
1089 list = (int16 *) safe_malloc((*num) * sizeof(int16));
1091 for (i = 0, p = cp; i < *num; i++, p++) {
1092 if ((! strcmp(p, "off")) || (! strcmp(p, "-0")))
1096 if (! (p = strchr(p, ',')))
1102 static int **config_parse_envelope(const char *cp, int *num)
1110 while ((p = strchr(p, ',')) != NULL)
1113 env_list = (int **) safe_malloc((*num) * sizeof(int *));
1114 for (i = 0; i < *num; i++)
1115 env_list[i] = (int *) safe_malloc(6 * sizeof(int));
1117 for (i = 0; i < *num; i++)
1118 for (j = 0; j < 6; j++)
1119 env_list[i][j] = -1;
1121 for (i = 0, p = cp; i < *num; i++, p++) {
1122 px = strchr(p, ',');
1123 for (j = 0; j < 6; j++, p++) {
1126 env_list[i][j] = atoi(p);
1127 if (! (p = strchr(p, ':')))
1139 static int **config_parse_pitch_envelope(const char *cp, int *num)
1147 while ((p = strchr(p, ',')) != NULL)
1150 env_list = (int **) safe_malloc((*num) * sizeof(int *));
1151 for (i = 0; i < *num; i++)
1152 env_list[i] = (int *) safe_malloc(9 * sizeof(int));
1154 for (i = 0; i < *num; i++)
1155 for (j = 0; j < 9; j++)
1158 for (i = 0, p = cp; i < *num; i++, p++) {
1159 px = strchr(p, ',');
1160 for (j = 0; j < 9; j++, p++) {
1163 env_list[i][j] = atoi(p);
1164 if (! (p = strchr(p, ':')))
1176 static int **config_parse_hpfparam(const char *cp, int *num)
1184 while ((p = strchr(p, ',')) != NULL)
1187 hpf_param = (int **) safe_malloc((*num) * sizeof(int *));
1188 for (i = 0; i < *num; i++)
1189 hpf_param[i] = (int *) safe_malloc(HPF_PARAM_NUM * sizeof(int));
1191 for (i = 0; i < *num; i++)
1192 for (j = 0; j < HPF_PARAM_NUM; j++)
1193 hpf_param[i][j] = 0;
1195 for (i = 0, p = cp; i < *num; i++, p++) {
1196 px = strchr(p, ',');
1197 for (j = 0; j < HPF_PARAM_NUM; j++, p++) {
1200 hpf_param[i][j] = atoi(p);
1201 if (! (p = strchr(p, ':')))
1212 static int **config_parse_vfxparam(const char *cp, int *num)
1220 while ((p = strchr(p, ',')) != NULL)
1223 vfx_param = (int **) safe_malloc((*num) * sizeof(int *));
1224 for (i = 0; i < *num; i++)
1225 vfx_param[i] = (int *) safe_malloc(VOICE_EFFECT_PARAM_NUM * sizeof(int));
1227 for (i = 0; i < *num; i++)
1228 for (j = 0; j < VOICE_EFFECT_PARAM_NUM; j++)
1229 vfx_param[i][j] = 0; // init param
1231 for (i = 0, p = cp; i < *num; i++, p++) {
1232 px = strchr(p, ',');
1233 for (j = 0; j < VOICE_EFFECT_PARAM_NUM; j++, p++) {
1236 vfx_param[i][j] = atoi(p);
1237 if (! (p = strchr(p, ':')))
1248 static Quantity **config_parse_modulation(const char *name, int line, const char *cp, int *num, int mod_type)
1250 const char *p, *px, *err;
1251 char buf[128], *delim;
1252 Quantity **mod_list;
1254 static const char * qtypestr[] = {"tremolo", "vibrato"};
1255 static const uint16 qtypes[] = {
1256 QUANTITY_UNIT_TYPE(LFO_SWEEP), QUANTITY_UNIT_TYPE(LFO_RATE), QUANTITY_UNIT_TYPE(TREMOLO_DEPTH),
1257 QUANTITY_UNIT_TYPE(LFO_SWEEP), QUANTITY_UNIT_TYPE(LFO_RATE), QUANTITY_UNIT_TYPE(DIRECT_INT)
1262 while ((p = strchr(p, ',')) != NULL)
1265 mod_list = (Quantity **) safe_malloc((*num) * sizeof(Quantity *));
1266 for (i = 0; i < *num; i++)
1267 mod_list[i] = (Quantity *) safe_malloc(3 * sizeof(Quantity));
1269 for (i = 0; i < *num; i++)
1270 for (j = 0; j < 3; j++)
1271 INIT_QUANTITY(mod_list[i][j]);
1272 buf[sizeof buf - 1] = '\0';
1274 for (i = 0, p = cp; i < *num; i++, p++) {
1275 px = strchr(p, ',');
1276 for (j = 0; j < 3; j++, p++) {
1279 if ((delim = strpbrk(strncpy(buf, p, sizeof buf - 1), ":,")) != NULL)
1281 if (*buf != '\0' && (err = string_to_quantity(buf, &mod_list[i][j], qtypes[mod_type * 3 + j])) != NULL) {
1282 ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "%s: line %d: %s: parameter %d of item %d: %s (%s)",
1283 name, line, qtypestr[mod_type], j+1, i+1, err, buf);
1284 free_ptr_list(mod_list, *num);
1289 if (! (p = strchr(p, ':')))
1301 extern int16 sd_mfx_patch_param[13][9][128][33];
1302 static int config_parse_mfx_patch(char *w[], int words, int mapid, int bank, int prog)
1307 case SDXX_TONE80_MAP: num = 0; break; /* Special 1 */
1308 case SDXX_TONE81_MAP: num = 1; break; /* Special 2 */
1309 case SDXX_TONE87_MAP: num = 2; break; /* Usr Inst*/ /* SD-50 Preset Inst */
1310 case SDXX_TONE89_MAP: num = -1; break; /* SD-50 Solo */
1311 case SDXX_TONE96_MAP: num = 3; break; /* Clsc Inst */
1312 case SDXX_TONE97_MAP: num = 4; break; /* Cntn Inst */
1313 case SDXX_TONE98_MAP: num = 5; break; /* Solo Inst */
1314 case SDXX_TONE99_MAP: num = 6; break; /* Ehnc Inst */
1315 case SDXX_DRUM86_MAP: num = 7; break; /* Usr Drum */ /* SD-50 Preset Rhythm */
1316 case SDXX_DRUM104_MAP: num = 8; break; /* Clsc Drum */
1317 case SDXX_DRUM105_MAP: num = 9; break; /* Cntn Drum */
1318 case SDXX_DRUM106_MAP: num = 10; break; /* Solo Drum */
1319 case SDXX_DRUM107_MAP: num = 11; break; /* Ehnc Drum */
1320 //case GM2_TONE_MAP: num = 12; break; /* GM2 tone */ // test
1321 default: num = -1; break;
1327 memset(sd_mfx_patch_param[num][bank][prog], 0, sizeof(int16) * 33);
1328 for(i = 0; i < words && i <= 33; i++){
1329 int32 tmp = atoi(w[i]);
1330 if(tmp < INT16_MIN || tmp > INT16_MAX)
1332 sd_mfx_patch_param[num][bank][prog][i] = tmp;
1338 static int set_gus_patchconf_opts(const char *name,
1339 int line, char *opts, ToneBankElement *tone)
1345 if (! (cp = strchr(opts, '='))) {
1346 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
1347 "%s: line %d: bad patch option %s", name, line, opts);
1351 if (! strcmp(opts, "amp")) {
1352 #if 1 // float (instrum.c apply_bank_parameter()
1353 double fk = atof(cp);
1354 if ((fk < 0 || fk > MAX_AMPLIFICATION) || (*cp < '0' || *cp > '9') && (*cp != '.')) {
1355 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
1356 "%s: line %d: amplification must be between 0 and %d",
1357 name, line, MAX_AMPLIFICATION);
1360 k = fk * DIV_100 * M_12BIT; // max 32768 = 8 * 4096
1362 k = INT16_MAX; // 32767
1365 if ((k < 0 || k > MAX_AMPLIFICATION) || (*cp < '0' || *cp > '9')) {
1366 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
1367 "%s: line %d: amplification must be between 0 and %d",
1368 name, line, MAX_AMPLIFICATION);
1373 } else if (! strcmp(opts, "amp_normalize")) {
1374 if (! strcmp(cp, "on"))
1376 else if (! strcmp(cp, "off"))
1380 if ((k < 0 || k > 1)
1381 || (k == 0 && *cp != '-' && (*cp < '0' || *cp > '1'))) {
1382 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
1383 "%s: line %d: amp_normalize must be off, on, 0, 1",
1388 tone->amp_normalize = k;
1389 } else if (! strcmp(opts, "lokey")) {
1391 if ((k < 0 || k > 127) || (*cp < '0' || *cp > '9')) {
1392 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
1393 "%s: line %d: lokey must be between 0 and 127",
1398 } else if (! strcmp(opts, "hikey")) {
1400 if ((k < 0 || k > 127) || (*cp < '0' || *cp > '9')) {
1401 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
1402 "%s: line %d: hikey must be between 0 and 127",
1407 } else if (! strcmp(opts, "lovel")) {
1409 if ((k < 0 || k > 127) || (*cp < '0' || *cp > '9')) {
1410 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
1411 "%s: line %d: lovel must be between 0 and 127",
1416 } else if (! strcmp(opts, "hivel")) {
1418 if ((k < 0 || k > 127) || (*cp < '0' || *cp > '9')) {
1419 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
1420 "%s: line %d: hivel must be between 0 and 127",
1425 }else if (! strcmp(opts, "sample_lokey")){
1426 if(tone->sample_lokeynum)
1427 safe_free(tone->sample_lokey);
1428 tone->sample_lokey = config_parse_int16(cp, &tone->sample_lokeynum);
1429 }else if (! strcmp(opts, "sample_hikey")){
1430 if(tone->sample_hikeynum)
1431 safe_free(tone->sample_hikey);
1432 tone->sample_hikey = config_parse_int16(cp, &tone->sample_hikeynum);
1433 }else if (! strcmp(opts, "sample_lovel")){
1434 if(tone->sample_lovelnum)
1435 safe_free(tone->sample_lovel);
1436 tone->sample_lovel = config_parse_int16(cp, &tone->sample_lovelnum);
1437 }else if (! strcmp(opts, "sample_hivel")){
1438 if(tone->sample_hivelnum)
1439 safe_free(tone->sample_hivel);
1440 tone->sample_hivel = config_parse_int16(cp, &tone->sample_hivelnum);
1441 } else if (! strcmp(opts, "note")) {
1443 if ((k < 0 || k > 127) || (*cp < '0' || *cp > '9')) {
1444 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
1445 "%s: line %d: note must be between 0 and 127",
1450 if(tone->scltunenum)
1451 safe_free(tone->scltune);
1452 tone->scltune = config_parse_int16("100", &tone->scltunenum);
1454 } else if (! strcmp(opts, "pan")) {
1455 if (! strcmp(cp, "center"))
1457 else if (! strcmp(cp, "left"))
1459 else if (! strcmp(cp, "right"))
1467 else if(tmp == -100)
1470 k = 0x40 + (tmp * 63) / 100;
1472 k = 0x40 + (tmp * 64) / 100;
1473 if ((k < 0 || k > 127)
1474 || (k == 0 && *cp != '-' && (*cp < '0' || *cp > '9'))) {
1475 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
1476 "%s: line %d: panning must be left, right, "
1477 "center, or between -100 and 100",
1484 } else if (! strcmp(opts, "sample_pan")) {
1485 if (! strcmp(cp, "left"))
1487 else if (! strcmp(cp, "right"))
1491 if ((k < -200 || k > 200)
1492 || (k == 0 && *cp != '-' && (*cp < '0' || *cp > '9'))) {
1493 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
1494 "%s: line %d: sample_pan must be left, right, "
1495 "or between -200 and 200",
1500 tone->sample_pan = k + 200; // offset +200
1501 } else if (! strcmp(opts, "sample_width")) {
1502 if (! strcmp(cp, "center"))
1504 else if (! strcmp(cp, "reverse"))
1508 if ((k < -800 || k > 800)
1509 || (k == 0 && *cp != '-' && (*cp < '0' || *cp > '9'))) {
1510 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
1511 "%s: line %d: sample_width must be center, reverse, "
1512 "or between -800 and 800",
1517 tone->sample_width = k + 800; // offset +800
1518 } else if (! strcmp(opts, "tune")){
1520 safe_free(tone->tune);
1521 tone->tune = config_parse_tune(cp, &tone->tunenum);
1522 }else if (! strcmp(opts, "rate")){
1523 if(tone->envratenum)
1524 free_ptr_list(tone->envrate, tone->envratenum);
1525 tone->envrate = config_parse_envelope(cp, &tone->envratenum);
1526 }else if (! strcmp(opts, "offset")){
1528 free_ptr_list(tone->envofs, tone->envofsnum);
1529 tone->envofs = config_parse_envelope(cp, &tone->envofsnum);
1530 }else if (! strcmp(opts, "keep")) {
1531 if (! strcmp(cp, "env"))
1532 tone->strip_envelope = 0;
1533 else if (! strcmp(cp, "loop"))
1534 tone->strip_loop = 0;
1535 else if (! strcmp(cp, "voice"))
1536 tone->keep_voice = 1;
1538 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
1539 "%s: line %d: keep must be env or loop or voice", name, line);
1542 } else if (! strcmp(opts, "strip")) {
1543 if (! strcmp(cp, "env"))
1544 tone->strip_envelope = 1;
1545 else if (! strcmp(cp, "loop"))
1546 tone->strip_loop = 1;
1547 else if (! strcmp(cp, "tail"))
1548 tone->strip_tail = 1;
1550 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
1551 "%s: line %d: strip must be env, loop, or tail",
1555 } else if (! strcmp(opts, "tremolo")){
1557 free_ptr_list(tone->trem, tone->tremnum);
1558 if ((tone->trem = config_parse_modulation(name,
1559 line, cp, &tone->tremnum, 0)) == NULL)
1562 }else if (! strcmp(opts, "tremdelay")){
1563 if(tone->tremdelaynum)
1564 safe_free(tone->tremdelay);
1565 tone->tremdelay = config_parse_int16(cp, &tone->tremdelaynum);
1566 }else if (! strcmp(opts, "tremsweep")){
1567 if(tone->tremsweepnum)
1568 safe_free(tone->tremsweep);
1569 tone->tremsweep = config_parse_lfo_rate(cp, &tone->tremsweepnum);
1570 }else if (! strcmp(opts, "tremfreq")){
1571 if(tone->tremfreqnum)
1572 safe_free(tone->tremfreq);
1573 tone->tremfreq = config_parse_lfo_rate(cp, &tone->tremfreqnum);
1574 }else if (! strcmp(opts, "tremamp")){
1575 if(tone->tremampnum)
1576 safe_free(tone->tremamp);
1577 tone->tremamp = config_parse_int16(cp, &tone->tremampnum);
1578 }else if (! strcmp(opts, "trempitch")){
1579 if(tone->trempitchnum)
1580 safe_free(tone->trempitch);
1581 tone->trempitch = config_parse_int16(cp, &tone->trempitchnum);
1582 }else if (! strcmp(opts, "tremfc")){
1584 safe_free(tone->tremfc);
1585 tone->tremfc = config_parse_int16(cp, &tone->tremfcnum);
1586 } else if (! strcmp(opts, "vibrato")){
1588 free_ptr_list(tone->vib, tone->vibnum);
1589 if ((tone->vib = config_parse_modulation(name,
1590 line, cp, &tone->vibnum, 1)) == NULL)
1593 }else if (! strcmp(opts, "vibdelay")){
1594 if(tone->vibdelaynum)
1595 safe_free(tone->vibdelay);
1596 tone->vibdelay = config_parse_int16(cp, &tone->vibdelaynum);
1597 }else if (! strcmp(opts, "vibsweep")){
1598 if(tone->vibsweepnum)
1599 safe_free(tone->vibsweep);
1600 tone->vibsweep = config_parse_lfo_rate(cp, &tone->vibsweepnum);
1601 }else if (! strcmp(opts, "vibfreq")){
1602 if(tone->vibfreqnum)
1603 safe_free(tone->vibfreq);
1604 tone->vibfreq = config_parse_lfo_rate(cp, &tone->vibfreqnum);
1605 }else if (! strcmp(opts, "vibamp")){
1607 safe_free(tone->vibamp);
1608 tone->vibamp = config_parse_int16(cp, &tone->vibampnum);
1609 }else if (! strcmp(opts, "vibpitch")){
1610 if(tone->vibpitchnum)
1611 safe_free(tone->vibpitch);
1612 tone->vibpitch = config_parse_int16(cp, &tone->vibpitchnum);
1613 }else if (! strcmp(opts, "vibfc")){
1615 safe_free(tone->vibfc);
1616 tone->vibfc = config_parse_int16(cp, &tone->vibfcnum);
1617 } else if (! strcmp(opts, "sclnote")){
1618 if(tone->sclnotenum)
1619 safe_free(tone->sclnote);
1620 tone->sclnote = config_parse_int16(cp, &tone->sclnotenum);
1621 }else if (! strcmp(opts, "scltune")){
1622 if(tone->scltunenum)
1623 safe_free(tone->scltune);
1624 tone->scltune = config_parse_int16(cp, &tone->scltunenum);
1625 }else if (! strcmp(opts, "comm")) {
1629 tone->comment = (char *)safe_malloc(sizeof(char) * MAX_TONEBANK_COMM_LEN);
1630 strncpy(tone->comment, cp, MAX_TONEBANK_COMM_LEN - 1);
1631 tone->comment[MAX_TONEBANK_COMM_LEN - 1] = '\0';
1638 } else if (! strcmp(opts, "modrate")){
1639 if(tone->modenvratenum)
1640 free_ptr_list(tone->modenvrate, tone->modenvratenum);
1641 tone->modenvrate = config_parse_envelope(cp, &tone->modenvratenum);
1642 }else if (! strcmp(opts, "modoffset")){
1643 if(tone->modenvofsnum)
1644 free_ptr_list(tone->modenvofs, tone->modenvofsnum);
1645 tone->modenvofs = config_parse_envelope(cp, &tone->modenvofsnum);
1646 }else if (! strcmp(opts, "envkeyf")){
1647 if(tone->envkeyfnum)
1648 free_ptr_list(tone->envkeyf, tone->envkeyfnum);
1649 tone->envkeyf = config_parse_envelope(cp, &tone->envkeyfnum);
1650 }else if (! strcmp(opts, "envvelf")){
1651 if(tone->envvelfnum)
1652 free_ptr_list(tone->envvelf, tone->envvelfnum);
1653 tone->envvelf = config_parse_envelope(cp, &tone->envvelfnum);
1654 }else if (! strcmp(opts, "modkeyf")){
1655 if(tone->modenvkeyfnum)
1656 free_ptr_list(tone->modenvkeyf, tone->modenvkeyfnum);
1657 tone->modenvkeyf = config_parse_envelope(cp, &tone->modenvkeyfnum);
1658 }else if (! strcmp(opts, "modvelf")){
1659 if(tone->modenvvelfnum)
1660 free_ptr_list(tone->modenvvelf, tone->modenvvelfnum);
1661 tone->modenvvelf = config_parse_envelope(cp, &tone->modenvvelfnum);
1662 }else if (! strcmp(opts, "modpitch")){
1663 if(tone->modpitchnum)
1664 safe_free(tone->modpitch);
1665 tone->modpitch = config_parse_int16(cp, &tone->modpitchnum);
1666 }else if (! strcmp(opts, "modfc")){
1668 safe_free(tone->modfc);
1669 tone->modfc = config_parse_int16(cp, &tone->modfcnum);
1670 }else if (! strcmp(opts, "fc")){
1672 safe_free(tone->fc);
1673 tone->fc = config_parse_int16(cp, &tone->fcnum);
1674 }else if (! strcmp(opts, "q")){
1676 safe_free(tone->reso);
1677 tone->reso = config_parse_int16(cp, &tone->resonum);
1679 }else if (! strcmp(opts, "fclow")){
1681 safe_free(tone->fclow);
1682 tone->fclow = config_parse_int16(cp, &tone->fclownum);
1683 }else if (! strcmp(opts, "fcmul")){
1685 safe_free(tone->fcmul);
1686 tone->fcmul = config_parse_int16(cp, &tone->fcmulnum);
1687 }else if (! strcmp(opts, "fcadd")){
1689 safe_free(tone->fcadd);
1690 tone->fcadd = config_parse_int16(cp, &tone->fcaddnum);
1691 } else if (! strcmp(opts, "pitenv")){
1693 free_ptr_list(tone->pitenv, tone->pitenvnum);
1694 tone->pitenv = config_parse_pitch_envelope(cp, &tone->pitenvnum);
1695 }else if (! strcmp(opts, "fckeyf")) /* filter key-follow */
1696 tone->key_to_fc = atoi(cp);
1697 else if (! strcmp(opts, "fcvelf")) /* filter velocity-follow */
1698 tone->vel_to_fc = atoi(cp);
1699 else if (! strcmp(opts, "qvelf")) /* resonance velocity-follow */
1700 tone->vel_to_resonance = atoi(cp);
1702 else if (! strcmp(opts, "perc"))
1703 tone->rx_note_off = atoi(cp) ? 0 : 1;
1704 else if (! strcmp(opts, "rxnoteoff"))
1705 tone->rx_note_off = atoi(cp);
1706 else if (! strcmp(opts, "lpf")) /* lpf type */
1707 tone->lpf_type = atoi(cp);
1708 else if (! strcmp(opts, "hpf")){ /* hpf */
1710 free_ptr_list(tone->hpf, tone->hpfnum);
1711 tone->hpf = config_parse_hpfparam(cp, &tone->hpfnum);
1713 }else if (! strcmp(opts, "vfx")){ /* voice effect*/
1715 for (i = 0; i < VOICE_EFFECT_NUM; i++){
1716 if(tone->vfxnum[i]) // already use
1719 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,"VFX ERROR: read cfg. vfx pointer already exist.");
1720 continue; // error check
1722 tone->vfx[i] = config_parse_vfxparam(cp, &tone->vfxnum[i]);
1723 tone->vfxe_num = i + 1;
1729 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
1730 "%s: line %d: bad patch option %s",
1738 #define SET_GUS_PATCHCONF_COMMENT
1739 static int set_gus_patchconf(const char *name, int line,
1740 ToneBankElement *tone, char *pat, char **opts)
1743 #ifdef SET_GUS_PATCHCONF_COMMENT
1744 char *old_name = NULL;
1746 if(tone != NULL && tone->name != NULL)
1747 old_name = safe_strdup(tone->name);
1749 // reinit_tone_bank_element(tone);
1751 if(strcmp(pat, "%font") == 0 || strcmp(pat, "%sf2") == 0 || strcmp(pat, "%sbk") == 0) /* Font extention */
1753 /* %font filename bank prog [note-to-use]
1754 * %font filename 128 bank key
1757 if(opts[0] == NULL || opts[1] == NULL || opts[2] == NULL ||
1758 (atoi(opts[1]) == 128 && opts[3] == NULL))
1760 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
1761 "%s: line %d: Syntax error", name, line);
1764 tone->name = safe_strdup(opts[0]);
1765 tone->instype = 1; // sf2
1766 if(atoi(opts[1]) == 128) /* drum */
1768 tone->font_bank = 128;
1769 tone->font_preset = atoi(opts[2]);
1770 tone->font_keynote = atoi(opts[3]);
1775 tone->font_bank = atoi(opts[1]);
1776 tone->font_preset = atoi(opts[2]);
1778 if(opts[3] && isdigit(opts[3][0]))
1780 tone->font_keynote = atoi(opts[3]);
1785 tone->font_keynote = -1;
1790 else if(strcmp(pat, "%sample") == 0) /* Sample extention */
1792 /* %sample filename */
1795 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
1796 "%s: line %d: Syntax error", name, line);
1799 tone->name = safe_strdup(opts[0]);
1800 tone->instype = 2; // wav
1805 else if(strcmp(pat, "%mms") == 0) /* mms extention */
1807 /* %mms filename num */
1808 if(opts[0] == NULL || opts[1] == NULL)
1810 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
1811 "%s: line %d: Syntax error", name, line);
1814 tone->name = safe_strdup(opts[0]);
1815 tone->instype = 3; // mms
1816 tone->is_preset = atoi(opts[1]);
1817 cfg_flg_int_synth_mms = 1;
1820 else if(strcmp(pat, "%scc") == 0) /* scc extention */
1822 /* %scc filename num */
1823 if(opts[0] == NULL || opts[1] == NULL)
1825 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
1826 "%s: line %d: Syntax error", name, line);
1829 tone->name = safe_strdup(opts[0]);
1830 tone->instype = 4; // scc
1831 tone->is_preset = atoi(opts[1]);
1832 cfg_flg_int_synth_scc = 1;
1837 else if(strcmp(pat, "%sfz") == 0) /* sfz extension */
1840 if (opts[0] == NULL)
1842 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
1843 "%s: line %d: Syntax error", name, line);
1846 tone->name = safe_strdup(opts[0]);
1847 tone->instype = 5; // sfz
1852 else if (strcmp(pat, "%dls") == 0) /* dls extension */
1854 /* %dls filename bank prog [note-to-use]
1855 * %dls filename 128 bank key
1858 if (opts[0] == NULL || opts[1] == NULL || opts[2] == NULL ||
1859 (atoi(opts[1]) == 128 && opts[3] == NULL))
1861 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
1862 "%s: line %d: Syntax error", name, line);
1865 tone->name = safe_strdup(opts[0]);
1866 tone->instype = 6; // dls
1867 if (atoi(opts[1]) == 128) /* drum */
1869 tone->font_bank = 128;
1870 tone->font_preset = atoi(opts[2]);
1871 tone->font_keynote = atoi(opts[3]);
1876 tone->font_bank = atoi(opts[1]);
1877 tone->font_preset = atoi(opts[2]);
1879 if (opts[3] && isdigit(opts[3][0]))
1881 tone->font_keynote = atoi(opts[3]);
1886 tone->font_keynote = -1;
1892 else if(strcmp(pat, "%pat") == 0) /* pat extention */
1894 tone->instype = 0; // pat
1895 tone->name = safe_strdup(pat);
1899 tone->instype = 0; // pat
1900 tone->name = safe_strdup(pat);
1903 for(j = 0; opts[j] != NULL; j++)
1906 if((err = set_gus_patchconf_opts(name, line, opts[j], tone)) != 0)
1909 #if 0 // c210 CFG comm
1911 \82±
\82±
\82Åtone->comment
\82ð
\83Z
\83b
\83g
\82·
\82é
\97\9d\97R
\82ª
\95s
\96¾
1912 CFG
\82Ìcomm
\82Å
\83Z
\83b
\83g
\82µ
\82½
\82©
\82Ç
\82¤
\82©
\82ª
\8cã
\82Å
\82í
\82©
\82ç
\82È
\82
\82È
\82é
1913 CFG
\82Ìcomm
\82ð
\97D
\90æ
\82·
\82é
\82×
\82«
1914 \83T
\83\93\83v
\83\8b\83\8d\81[
\83h
\82Ì
\8e\9e\82É instrum.c *load_instrument()
\82Å
\83Z
\83b
\83g
\82·
\82é
1916 #ifdef SET_GUS_PATCHCONF_COMMENT
1917 if(tone->comment == NULL ||
1918 (old_name != NULL && strcmp(old_name,tone->comment) == 0))
1920 tone->comment = (char *)safe_malloc(sizeof(char) * MAX_TONEBANK_COMM_LEN);
1921 strncpy(tone->comment, tone->name, MAX_TONEBANK_COMM_LEN - 1);
1922 tone->comment[MAX_TONEBANK_COMM_LEN - 1] = '\0';
1924 safe_free(old_name);
1927 if(tone->comment == NULL)
1929 //tone->comment = safe_strdup(tone->name);
1930 tone->comment = (char *)safe_malloc(sizeof(char) * MAX_TONEBANK_COMM_LEN);
1931 strncpy(tone->comment, tone->name, MAX_TONEBANK_COMM_LEN - 1);
1932 tone->comment[MAX_TONEBANK_COMM_LEN - 1] = '\0';
1939 static int set_patchconf(const char *name, int line, ToneBank *bank, char *w[], int dr, int mapid, int bankmapfrom, int bankno, int add)
1947 if(i < 0 || i > 127)
1950 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
1951 "%s: line %d: Drum number must be between "
1955 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
1956 "%s: line %d: Program must be between "
1958 name, line, progbase, 127 + progbase);
1963 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
1964 "%s: line %d: Must specify tone bank or drum set "
1965 "before assignment", name, line);
1969 if(bank->tone[i][0] == NULL){
1970 ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "%s: line %d: undeine normal program" "xx: add ", name, line);
1973 elm = bank->tone[i][0]->element_num + 1; // next add_elm
1974 if(elm >= MAX_ELEMENT){
1975 ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "%s: line %d: Too much program" "%d: add ", name, line, elm);
1978 if(bank->tone[i][elm] == NULL){
1979 if(alloc_tone_bank_element(&bank->tone[i][elm])){
1980 ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "%s: line %d: ToneBankElement malloc error" "%d: add ", name, line, elm);
1984 reinit_tone_bank_element(bank->tone[i][elm]);
1985 bank->tone[i][0]->element_num = elm;
1986 if(set_gus_patchconf(name, line, bank->tone[i][elm], w[1], w + 2))
1989 if(bank->tone[i][0] == NULL){
1990 if(alloc_tone_bank_element(&bank->tone[i][0])){
1991 ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "%s: line %d: ToneBankElement malloc error.", name, line);
1995 reinit_tone_bank_element(bank->tone[i][0]);
1996 for(elm = 1; elm < MAX_ELEMENT; elm++){ // delete add_elm
1997 if(bank->tone[i][elm]){
1998 free_tone_bank_element(bank->tone[i][elm]);
1999 safe_free(bank->tone[i][elm]);
2000 bank->tone[i][elm] = NULL;
2003 if(set_gus_patchconf(name, line, bank->tone[i][0], w[1], w + 2)){
2006 if (mapid != INST_NO_MAP)
2007 set_instrument_map(mapid, bankmapfrom, i, bankno, i);
2017 static int mapnamecompare(const void *name, const void *entry)
2019 return strcmp((const char *)name, ((const MapNameEntry *)entry)->name);
2022 static int mapname2id(char *name, int *isdrum)
2024 static const MapNameEntry data[] = {
2025 /* sorted in alphabetical order */
2026 {"cm32drum", CM32_DRUM_MAP, 1},
2027 {"cm32l", CM32L_TONE_MAP, 0},
2028 {"cm32p", CM32P_TONE_MAP, 0},
2029 {"gm2", GM2_TONE_MAP, 0},
2030 {"gm2drum", GM2_DRUM_MAP, 1},
2031 {"gm2drum", GM2_DRUM_MAP, 1},
2032 {"k05rw000", K05RW_TONE0_MAP, 0},
2033 {"k05rw056", K05RW_TONE56_MAP, 0},
2034 {"k05rw057", K05RW_TONE57_MAP, 0},
2035 {"k05rwdrum062",K05RW_DRUM62_MAP, 1},
2036 {"mt32", MT32_TONE_MAP, 0},
2037 {"mt32drum", MT32_DRUM_MAP, 1},
2038 {"nx5r000", NX5R_TONE0_MAP, 0},
2039 {"nx5r001", NX5R_TONE1_MAP, 0},
2040 {"nx5r002", NX5R_TONE2_MAP, 0},
2041 {"nx5r003", NX5R_TONE3_MAP, 0},
2042 {"nx5r004", NX5R_TONE4_MAP, 0},
2043 {"nx5r005", NX5R_TONE5_MAP, 0},
2044 {"nx5r006", NX5R_TONE6_MAP, 0},
2045 {"nx5r007", NX5R_TONE7_MAP, 0},
2046 {"nx5r008", NX5R_TONE8_MAP, 0},
2047 {"nx5r009", NX5R_TONE9_MAP, 0},
2048 {"nx5r010", NX5R_TONE10_MAP, 0},
2049 {"nx5r011", NX5R_TONE11_MAP, 0},
2050 {"nx5r016", NX5R_TONE16_MAP, 0},
2051 {"nx5r017", NX5R_TONE17_MAP, 0},
2052 {"nx5r018", NX5R_TONE18_MAP, 0},
2053 {"nx5r019", NX5R_TONE19_MAP, 0},
2054 {"nx5r024", NX5R_TONE24_MAP, 0},
2055 {"nx5r025", NX5R_TONE25_MAP, 0},
2056 {"nx5r026", NX5R_TONE26_MAP, 0},
2057 {"nx5r032", NX5R_TONE32_MAP, 0},
2058 {"nx5r033", NX5R_TONE33_MAP, 0},
2059 {"nx5r040", NX5R_TONE40_MAP, 0},
2060 {"nx5r056", NX5R_TONE56_MAP, 0},
2061 {"nx5r057", NX5R_TONE57_MAP, 0},
2062 {"nx5r064", NX5R_TONE64_MAP, 0},
2063 {"nx5r080", NX5R_TONE80_MAP, 0},
2064 {"nx5r081", NX5R_TONE81_MAP, 0},
2065 {"nx5r082", NX5R_TONE82_MAP, 0},
2066 {"nx5r083", NX5R_TONE83_MAP, 0},
2067 {"nx5r088", NX5R_TONE88_MAP, 0},
2068 {"nx5r089", NX5R_TONE89_MAP, 0},
2069 {"nx5r090", NX5R_TONE90_MAP, 0},
2070 {"nx5r091", NX5R_TONE91_MAP, 0},
2071 {"nx5r125", NX5R_TONE125_MAP, 0},
2072 {"nx5rdrum061", NX5R_DRUM61_MAP, 1},
2073 {"nx5rdrum062", NX5R_DRUM61_MAP, 1},
2074 {"nx5rdrum126", NX5R_DRUM126_MAP, 1},
2075 {"nx5rdrum127", NX5R_DRUM127_MAP, 1},
2076 {"sc55", SC_55_TONE_MAP, 0},
2077 {"sc55drum", SC_55_DRUM_MAP, 1},
2078 {"sc88", SC_88_TONE_MAP, 0},
2079 {"sc8850", SC_8850_TONE_MAP, 0},
2080 {"sc8850drum", SC_8850_DRUM_MAP, 1},
2081 {"sc88drum", SC_88_DRUM_MAP, 1},
2082 {"sc88pro", SC_88PRO_TONE_MAP, 0},
2083 {"sc88prodrum", SC_88PRO_DRUM_MAP, 1},
2084 {"sd080", SDXX_TONE80_MAP, 0},
2085 {"sd081", SDXX_TONE81_MAP, 0},
2086 {"sd087", SDXX_TONE87_MAP, 0},
2087 {"sd089", SDXX_TONE89_MAP, 0},
2088 {"sd096", SDXX_TONE96_MAP, 0},
2089 {"sd097", SDXX_TONE97_MAP, 0},
2090 {"sd098", SDXX_TONE98_MAP, 0},
2091 {"sd099", SDXX_TONE99_MAP, 0},
2092 {"sddrum104", SDXX_DRUM104_MAP, 1},
2093 {"sddrum105", SDXX_DRUM105_MAP, 1},
2094 {"sddrum106", SDXX_DRUM106_MAP, 1},
2095 {"sddrum107", SDXX_DRUM107_MAP, 1},
2096 {"sddrum86", SDXX_DRUM86_MAP, 1},
2097 {"sn01", SN01_TONE_MAP, 0},
2098 {"sn02", SN02_TONE_MAP, 0},
2099 {"sn02drum", SN02_DRUM_MAP, 1},
2100 {"sn03", SN03_TONE_MAP, 0},
2101 {"sn04", SN04_TONE_MAP, 0},
2102 {"sn05", SN05_TONE_MAP, 0},
2103 {"sn06", SN06_TONE_MAP, 0},
2104 {"sn07", SN07_TONE_MAP, 0},
2105 {"sn08", SN08_TONE_MAP, 0},
2106 {"sn09", SN09_TONE_MAP, 0},
2107 {"sn10drum", SN10_DRUM_MAP, 1},
2108 {"sn11", SN11_TONE_MAP, 0},
2109 {"sn12", SN12_TONE_MAP, 0},
2110 {"sn13", SN13_TONE_MAP, 0},
2111 {"sn14", SN14_TONE_MAP, 0},
2112 {"sn15", SN15_TONE_MAP, 0},
2113 {"xg", XG_NORMAL_MAP, 0},
2114 {"xg000", XG_NORMAL_MAP, 0},
2115 {"xg016", XG_SAMPLING16_MAP, 0},
2116 {"xg032", XG_PCM_USER_MAP, 0},
2117 {"xg033", XG_VA_USER_MAP, 0},
2118 {"xg034", XG_SG_USER_MAP, 0},
2119 {"xg035", XG_FM_USER_MAP, 0},
2120 {"xg048", XG_MU100EXC_MAP, 0},
2121 {"xg063", XG_FREE_MAP, 0},
2122 {"xg064", XG_PCM_SFX_MAP, 0},
2123 {"xg065", XG_VA_SFX_MAP, 0},
2124 {"xg066", XG_SG_SFX_MAP, 0},
2125 {"xg067", XG_FM_SFX_MAP, 0},
2126 {"xg080", XG_PCM_A_MAP, 0},
2127 {"xg081", XG_VA_A_MAP, 0},
2128 {"xg082", XG_SG_A_MAP, 0},
2129 {"xg083", XG_FM_A_MAP, 0},
2130 {"xg096", XG_PCM_B_MAP, 0},
2131 {"xg097", XG_VA_B_MAP, 0},
2132 {"xg098", XG_SG_B_MAP, 0},
2133 {"xg099", XG_FM_B_MAP, 0},
2134 {"xg126", XG_SFX_KIT_MAP, 1},
2135 {"xg127", XG_DRUM_KIT_MAP, 1},
2136 {"xgdrum", XG_DRUM_KIT_MAP, 1},
2137 {"xgexclusive48", XG_MU100EXC_MAP, 0},
2138 {"xgfma", XG_FM_A_MAP, 0},
2139 {"xgfmb", XG_FM_B_MAP, 0},
2140 {"xgfmsfx", XG_FM_SFX_MAP, 0},
2141 {"xgfmuser", XG_FM_USER_MAP, 0},
2142 {"xgfree", XG_FREE_MAP, 0},
2143 {"xgpcma", XG_PCM_A_MAP, 0},
2144 {"xgpcmb", XG_PCM_B_MAP, 0},
2145 {"xgpcmsfx", XG_PCM_SFX_MAP, 0},
2146 {"xgpcmuser", XG_PCM_USER_MAP, 0},
2147 {"xgsampling126",XG_SAMPLING126_MAP, 1},
2148 {"xgsampling16",XG_SAMPLING16_MAP, 0},
2149 {"xgsfx126", XG_SFX_KIT_MAP, 1},
2150 {"xgsfx64", XG_PCM_SFX_MAP, 0}, // = xgpcmsfx
2151 {"xgsga", XG_SG_A_MAP, 0},
2152 {"xgsgb", XG_SG_B_MAP, 0},
2153 {"xgsgsfx", XG_SG_SFX_MAP, 0},
2154 {"xgsguser", XG_SG_USER_MAP, 0},
2155 {"xgvaa", XG_VA_A_MAP, 0},
2156 {"xgvab", XG_VA_B_MAP, 0},
2157 {"xgvasfx", XG_VA_SFX_MAP, 0},
2158 {"xgvauser", XG_VA_USER_MAP, 0},
2160 const MapNameEntry *found;
2162 found = (MapNameEntry *)bsearch(name, data, sizeof data / sizeof data[0], sizeof data[0], mapnamecompare);
2165 *isdrum = found->isdrum;
2166 return found->mapid;
2171 /* string[0] should not be '#' */
2172 static int strip_trailing_comment(char *string, int next_token_index)
2174 if (string[next_token_index - 1] == '#' /* strip \1 in /^\S+(#*[ \t].*)/ */
2175 && (string[next_token_index] == ' ' || string[next_token_index] == '\t'))
2177 string[next_token_index] = '\0'; /* new c-string terminator */
2178 while(string[--next_token_index - 1] == '#')
2181 return next_token_index;
2184 static char *expand_variables(char *string, MBlockList *varbuf, const char *basedir)
2187 const char *copystr;
2188 int limlen, copylen, explen, varlen, braced;
2190 if ((p = strchr(string, '$')) == NULL)
2192 varlen = strlen(basedir);
2193 explen = limlen = 0;
2196 copylen = p - string;
2200 if (explen + copylen + 1 > limlen)
2202 limlen += copylen + 128;
2203 expstr = memcpy(new_segment(varbuf, limlen), expstr, explen);
2205 memcpy(&expstr[explen], copystr, copylen);
2207 if (*string == '\0')
2209 else if (*string == '$')
2211 braced = *++string == '{';
2214 if ((p = strchr(string + 1, '}')) == NULL)
2215 p = string; /* no closing brace */
2220 for(p = string; isalnum(*p) || *p == '_'; p++) ;
2221 if (p == string) /* empty */
2224 copylen = 1 + braced;
2228 if (p - string == 7 && memcmp(string, "basedir", 7) == 0)
2233 else /* undefined variable */
2235 string = p + braced;
2238 else /* search next */
2240 p = strchr(string, '$');
2242 copylen = strlen(string);
2244 copylen = p - string;
2249 expstr[explen] = '\0';
2253 #define MAXWORDS 130
2254 #define CHECKERRLIMIT \
2255 if(++errcnt >= 10) { \
2256 ctl->cmsg(CMSG_ERROR, VERB_NORMAL, \
2257 "Too many errors... Give up read %s", name); \
2258 reuse_mblock(&varbuf); \
2259 close_file(tf); return 1; }
2261 #define READ_CONFIG_SUCCESS 0
2262 #define READ_CONFIG_ERROR 1
2263 #define READ_CONFIG_RECURSION 2 /* Too much recursion */
2264 #define READ_CONFIG_FILE_NOT_FOUND 3 /* Returned only w. allow_missing_file */
2267 MAIN_INTERFACE int read_config_file(const char *name, int self, int allow_missing_file) // changed elion static int -> int
2269 struct timidity_file *tf = NULL;
2270 char buf[2048] = "", *tmp = NULL, *w[MAXWORDS + 1] = { NULL }, *cp = NULL;
2271 ToneBank *bank = NULL;
2272 int i, j, k, line = 0, words, errcnt = 0, elm;
2273 static int rcf_count = 0;
2274 int dr = 0, bankno = 0, mapid = INST_NO_MAP, origbankno = 0x7FFFFFFF;
2275 int extension_flag, param_parse_err;
2277 char *basedir = NULL, *sep = NULL;
2278 char *onmemory = NULL;
2285 cfg_flg_int_synth_mms = 0;
2286 cfg_flg_int_synth_scc = 0;
2292 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
2293 "Probable source loop in configuration files");
2294 return READ_CONFIG_RECURSION;
2299 tf = open_with_constmem(name, strlen(name), OF_VERBOSE);
2300 name = "(configuration)";
2302 else if (check_file_extension(name, ".sf2", 0) == 1 || check_file_extension(name, ".sf3", 0) == 1)
2304 const char fmt[] = "soundfont \"%s\"\n";
2305 onmemory = (char*) safe_malloc(strlen(fmt) + strlen(name) + 1);
2306 snprintf(onmemory, strlen(fmt) + strlen(name), fmt, name);
2307 tf = open_with_mem(onmemory, strlen(onmemory), OF_VERBOSE);
2308 name = "(configuration)";
2311 tf = open_file(name, 1, allow_missing_file ? OF_NORMAL : OF_VERBOSE);
2313 return allow_missing_file ? READ_CONFIG_FILE_NOT_FOUND :
2316 init_mblock(&varbuf);
2319 basedir = strdup_mblock(&varbuf, current_filename);
2320 if (is_url_prefix(basedir))
2321 sep = strrchr(basedir, '/');
2323 sep = pathsep_strrchr(basedir);
2337 if ((cp = strchr(sep, '#')) != NULL)
2338 sep = cp + 1; /* inclusive of '#' */
2343 while (tf_gets(buf, sizeof(buf), tf))
2347 if (!strncmp(buf, "#@extension", 11)) {
2350 }else if (!strncmp(buf, "#extension", 10)) {
2360 while (isspace(buf[i])) /* skip /^\s*(?#)/ */
2362 if (buf[i] == '#' || buf[i] == '\0') /* /^#|^$/ */
2364 tmp = expand_variables(buf, &varbuf, basedir);
2365 j = strcspn(tmp + i, " \t\r\n\240");
2367 j = strlen(tmp + i);
2368 j = strip_trailing_comment(tmp + i, j);
2369 tmp[i + j] = '\0'; /* terminate the first token */
2372 words = param_parse_err = 0;
2373 while (words < MAXWORDS - 1) /* -1 : next arg */
2377 while (isspace(tmp[i])) /* skip /^\s*(?#)/ */
2380 || tmp[i] == '#') /* /\s#/ */
2382 if ((tmp[i] == '"' || tmp[i] == '\'')
2383 && (terminator = strchr(tmp + i + 1, tmp[i])) != NULL)
2385 if (!isspace(terminator[1]) && terminator[1] != '\0')
2387 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
2388 "%s: line %d: there must be at least one whitespace between "
2389 "string terminator (%c) and the next parameter", name, line, tmp[i]);
2391 param_parse_err = 1;
2394 w[++words] = tmp + i + 1;
2395 i = terminator - tmp + 1;
2398 else /* not terminated */
2400 j = strcspn(tmp + i, " \t\r\n\240");
2402 j = strip_trailing_comment(tmp + i, j);
2403 w[++words] = tmp + i;
2405 if (tmp[i] != '\0') /* unless at the end-of-string (i.e. EOF) */
2406 tmp[i++] = '\0'; /* terminate the token */
2409 if (param_parse_err)
2414 * #extension [something...]
2417 /* #extension comm program comment */
2418 if (!strcmp(w[0], "comm"))
2424 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
2425 "%s: line %d: syntax error", name, line);
2431 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
2432 "%s: line %d: Must specify tone bank or drum "
2433 "set before assignment", name, line);
2438 if (i < 0 || i > 127)
2440 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
2441 "%s: line %d: extension comm must be "
2442 "between 0 and 127", name, line);
2446 if(bank->tone[i][0] == NULL){
2447 if(alloc_tone_bank_element(&bank->tone[i][0])){
2448 ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "%s: line %d: ToneBankElement malloc error.", name, line);
2452 if (!bank->tone[i][0]->comment)
2453 bank->tone[i][0]->comment = (char*) safe_malloc(sizeof(char) * MAX_TONEBANK_COMM_LEN);
2454 strncpy(bank->tone[i][0]->comment, w[2], MAX_TONEBANK_COMM_LEN - 1);
2455 bank->tone[i][0]->comment[MAX_TONEBANK_COMM_LEN - 1] = '\0';
2456 p = bank->tone[i][0]->comment;
2459 if (*p == ',') *p = ' ';
2463 /* #extension timeout program sec */
2464 else if (!strcmp(w[0], "timeout"))
2468 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
2469 "%s: line %d: syntax error", name, line);
2475 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
2476 "%s: line %d: Must specify tone bank or drum set "
2477 "before assignment", name, line);
2482 if (i < 0 || i > 127)
2484 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
2485 "%s: line %d: extension timeout "
2486 "must be between 0 and 127", name, line);
2490 if(bank->tone[i][0])
2491 bank->tone[i][0]->loop_timeout = atoi(w[2]) & 0xFF;
2493 /* #extension copydrumset drumset */
2494 else if (!strcmp(w[0], "copydrumset"))
2498 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
2499 "%s: line %d: No copydrumset number given",
2505 if (i < 0 || i > 127)
2507 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
2508 "%s: line %d: extension copydrumset "
2509 "must be between 0 and 127", name, line);
2515 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
2516 "%s: line %d: Must specify tone bank or "
2517 "drum set before assignment", name, line);
2521 copybank(bank, drumset[i], mapid, origbankno, bankno);
2523 /* #extension copybank bank */
2524 else if (!strcmp(w[0], "copybank"))
2528 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
2529 "%s: line %d: No copybank number given",
2535 if (i < 0 || i > 127)
2537 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
2538 "%s: line %d: extension copybank "
2539 "must be between 0 and 127", name, line);
2545 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
2546 "%s: line %d: Must specify tone bank or "
2547 "drum set before assignment", name, line);
2551 copybank(bank, tonebank[i], mapid, origbankno, bankno);
2553 /* #extension copymap tomapid frommapid */
2554 else if (!strcmp(w[0], "copymap"))
2557 int toisdrum, fromisdrum;
2561 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
2562 "%s: line %d: syntax error", name, line);
2566 if ((mapto = mapname2id(w[1], &toisdrum)) == -1)
2568 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
2569 "%s: line %d: Invalid map name: %s", name, line, w[1]);
2573 if ((mapfrom = mapname2id(w[2], &fromisdrum)) == -1)
2575 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
2576 "%s: line %d: Invalid map name: %s", name, line, w[2]);
2580 if (toisdrum != fromisdrum)
2582 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
2583 "%s: line %d: Map type should be matched", name, line);
2587 if (copymap(mapto, mapfrom, toisdrum))
2589 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
2590 "%s: line %d: No free %s available to map",
2591 name, line, toisdrum ? "drum set" : "tone bank");
2596 /* #extension HTTPproxy hostname:port */
2597 else if (!strcmp(w[0], "HTTPproxy"))
2599 char r_bracket, l_bracket;
2603 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
2604 "%s: line %d: No proxy name given",
2609 /* If network is not supported, this extension is ignored. */
2610 #ifdef SUPPORT_SOCKET
2611 url_http_proxy_host = safe_strdup(w[1]);
2612 if ((cp = strrchr(url_http_proxy_host, ':')) == NULL)
2614 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
2615 "%s: line %d: Syntax error", name, line);
2620 if ((url_http_proxy_port = atoi(cp)) <= 0)
2622 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
2623 "%s: line %d: Port number must be "
2624 "positive number", name, line);
2629 l_bracket = url_http_proxy_host[0];
2630 r_bracket = url_http_proxy_host[strlen(url_http_proxy_host) - 1];
2632 if (l_bracket == '[' || r_bracket == ']')
2634 if (l_bracket != '[' || r_bracket != ']')
2636 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
2637 "%s: line %d: Malformed IPv6 address",
2642 url_http_proxy_host++;
2643 url_http_proxy_host[strlen(url_http_proxy_host) - 1] = '\0';
2645 #endif /* SUPPORT_SOCKET */
2647 /* #extension FTPproxy hostname:port */
2648 else if (!strcmp(w[0], "FTPproxy"))
2650 char l_bracket, r_bracket;
2654 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
2655 "%s: line %d: No proxy name given",
2660 /* If network is not supported, this extension is ignored. */
2661 #ifdef SUPPORT_SOCKET
2662 url_ftp_proxy_host = safe_strdup(w[1]);
2663 if ((cp = strrchr(url_ftp_proxy_host, ':')) == NULL)
2665 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
2666 "%s: line %d: Syntax error", name, line);
2671 if ((url_ftp_proxy_port = atoi(cp)) <= 0)
2673 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
2674 "%s: line %d: Port number "
2675 "must be positive number", name, line);
2680 l_bracket = url_ftp_proxy_host[0];
2681 r_bracket = url_ftp_proxy_host[strlen(url_ftp_proxy_host) - 1];
2683 if (l_bracket == '[' || r_bracket == ']')
2685 if (l_bracket != '[' || r_bracket != ']')
2687 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
2688 "%s: line %d: Malformed IPv6 address",
2693 url_ftp_proxy_host++;
2694 url_ftp_proxy_host[strlen(url_ftp_proxy_host) - 1] = '\0';
2696 #endif /* SUPPORT_SOCKET */
2698 /* #extension mailaddr somebody@someware.domain.com */
2699 else if (!strcmp(w[0], "mailaddr"))
2703 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
2704 "%s: line %d: No mail address given",
2709 if (strchr(w[1], '@') == NULL) {
2710 ctl->cmsg(CMSG_WARNING, VERB_NOISY,
2711 "%s: line %d: Warning: Mail address %s is not valid",
2715 /* If network is not supported, this extension is ignored. */
2716 #ifdef SUPPORT_SOCKET
2717 user_mailaddr = safe_strdup(w[1]);
2718 #endif /* SUPPORT_SOCKET */
2720 /* #extension opt [-]{option}[optarg] */
2721 else if (!strcmp(w[0], "opt")) {
2722 int c, longind, err;
2723 char *p, *cmd, *arg;
2725 if (words != 2 && words != 3) {
2726 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
2727 "%s: line %d: Syntax error", name, line);
2732 int optind_save = optind;
2734 c = getopt_long(words, w, optcommands, longopts, &longind);
2735 err = set_tim_opt_long(c, optarg, longind);
2736 optind = optind_save;
2738 /* backward compatibility */
2739 if ((p = strchr(optcommands, c = *(cmd = w[1]))) == NULL)
2742 if (*(p + 1) == ':')
2743 arg = (words == 2) ? cmd + 1 : w[2];
2746 err = set_tim_opt_short(c, arg);
2751 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
2752 "%s: line %d: Invalid command line option",
2759 /* #extension undef program */
2760 else if (!strcmp(w[0], "undef"))
2764 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
2765 "%s: line %d: No undef number given",
2771 if (i < 0 || i > 127)
2773 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
2774 "%s: line %d: extension undef "
2775 "must be between 0 and 127", name, line);
2781 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
2782 "%s: line %d: Must specify tone bank or "
2783 "drum set before assignment", name, line);
2788 for (elm = 0; elm < MAX_ELEMENT; elm++)
2789 if(bank->tone[i][elm])
2790 free_tone_bank_element(bank->tone[i][elm]);
2792 /* #extension altassign numbers... */
2793 else if (!strcmp(w[0], "altassign"))
2799 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
2800 "%s: line %d: Must specify tone bank or drum set "
2801 "before altassign", name, line);
2807 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
2808 "%s: line %d: No alternate assignment", name, line);
2814 ctl->cmsg(CMSG_WARNING, VERB_NORMAL,
2815 "%s: line %d: Warning: Not a drumset altassign"
2821 bk = drumset[bankno];
2822 bk->alt = add_altassign_string(bk->alt, w + 1, words - 1);
2824 /* #extension legato [program] [0 or 1] */
2825 else if (!strcmp(w[0], "legato"))
2829 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
2830 "%s: line %d: syntax error", name, line);
2836 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
2837 "%s: line %d: Must specify tone bank or drum set "
2838 "before assignment", name, line);
2843 if (i < 0 || i > 127)
2845 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
2846 "%s: line %d: extension legato "
2847 "must be between 0 and 127", name, line);
2852 if(bank->tone[i][0] == NULL){
2853 if(alloc_tone_bank_element(&bank->tone[i][0])){
2854 ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "%s: line %d: ToneBankElement malloc error.", name, line);
2855 return READ_CONFIG_ERROR;
2858 bank->tone[i][0]->legato = atoi(w[2]);
2860 } /* #extension damper [program] [0 or 1] */
2861 else if (!strcmp(w[0], "damper"))
2865 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
2866 "%s: line %d: syntax error", name, line);
2872 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
2873 "%s: line %d: Must specify tone bank or drum set "
2874 "before assignment", name, line);
2879 if (i < 0 || i > 127)
2881 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
2882 "%s: line %d: extension damper "
2883 "must be between 0 and 127", name, line);
2888 if(bank->tone[i][0] == NULL){
2889 if(alloc_tone_bank_element(&bank->tone[i][0])){
2890 ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "%s: line %d: ToneBankElement malloc error.", name, line);
2891 return READ_CONFIG_ERROR;
2894 bank->tone[i][0]->damper_mode = atoi(w[2]);
2895 } /* #extension rnddelay [program] [0 or 1] */
2896 else if (!strcmp(w[0], "rnddelay"))
2900 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
2901 "%s: line %d: syntax error", name, line);
2907 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
2908 "%s: line %d: Must specify tone bank or drum set "
2909 "before assignment", name, line);
2914 if (i < 0 || i > 127)
2916 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
2917 "%s: line %d: extension rnddelay "
2918 "must be between 0 and 127", name, line);
2923 if(bank->tone[i][0] == NULL){
2924 if(alloc_tone_bank_element(&bank->tone[i][0])){
2925 ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "%s: line %d: ToneBankElement malloc error.", name, line);
2926 return READ_CONFIG_ERROR;
2929 bank->tone[i][0]->rnddelay = atoi(w[2]);
2930 } /* #extension level program tva_level */
2931 else if (!strcmp(w[0], "level"))
2935 ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "%s: line %d: syntax error", name, line);
2941 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
2942 "%s: line %d: Must specify tone bank or drum set "
2943 "before assignment", name, line);
2948 if (i < 0 || i > 127)
2950 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
2951 "%s: line %d: extension level "
2952 "must be between 0 and 127", name, line);
2958 if (string_to_7bit_range(cp, &j, &k))
2961 if(bank->tone[j][0] == NULL){
2962 if(alloc_tone_bank_element(&bank->tone[j][0])){
2963 ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "%s: line %d: ToneBankElement malloc error.", name, line);
2964 return READ_CONFIG_ERROR;
2967 bank->tone[j][0]->tva_level = i;
2971 cp = strchr(cp, ',');
2973 } /* #extension reverbsend */
2974 else if (!strcmp(w[0], "reverbsend"))
2978 ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "%s: line %d: syntax error", name, line);
2984 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
2985 "%s: line %d: Must specify tone bank or drum set "
2986 "before assignment", name, line);
2991 if (i < 0 || i > 127)
2993 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
2994 "%s: line %d: extension reverbsend "
2995 "must be between 0 and 127", name, line);
3001 if (string_to_7bit_range(cp, &j, &k))
3004 if(bank->tone[j][0] == NULL){
3005 if(alloc_tone_bank_element(&bank->tone[j][0])){
3006 ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "%s: line %d: ToneBankElement malloc error.", name, line);
3007 return READ_CONFIG_ERROR;
3010 bank->tone[j][0]->reverb_send = i;
3014 cp = strchr(cp, ',');
3016 } /* #extension chorussend */
3017 else if (!strcmp(w[0], "chorussend"))
3021 ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "%s: line %d: syntax error", name, line);
3027 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
3028 "%s: line %d: Must specify tone bank or drum set "
3029 "before assignment", name, line);
3034 if (i < 0 || i > 127)
3036 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
3037 "%s: line %d: extension chorussend "
3038 "must be between 0 and 127", name, line);
3044 if (string_to_7bit_range(cp, &j, &k))
3047 if(bank->tone[j][0] == NULL){
3048 if(alloc_tone_bank_element(&bank->tone[j][0])){
3049 ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "%s: line %d: ToneBankElement malloc error.", name, line);
3050 return READ_CONFIG_ERROR;
3053 bank->tone[j][0]->chorus_send = i;
3057 cp = strchr(cp, ',');
3059 } /* #extension delaysend */
3060 else if (!strcmp(w[0], "delaysend"))
3064 ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "%s: line %d: syntax error", name, line);
3070 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
3071 "%s: line %d: Must specify tone bank or drum set "
3072 "before assignment", name, line);
3078 if (i < 0 || i > 127)
3080 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
3081 "%s: line %d: extension delaysend "
3082 "must be between 0 and 127", name, line);
3088 if (string_to_7bit_range(cp, &j, &k))
3091 if(bank->tone[j][0] == NULL){
3092 if(alloc_tone_bank_element(&bank->tone[j][0])){
3093 ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "%s: line %d: ToneBankElement malloc error.", name, line);
3094 return READ_CONFIG_ERROR;
3097 bank->tone[j][0]->delay_send = i;
3101 cp = strchr(cp, ',');
3104 /* #extension rxnoteoff numbers... */
3105 else if (!strcmp(w[0], "rxnoteoff"))
3109 ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "%s: line %d: syntax error", name, line);
3115 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
3116 "%s: line %d: Must specify tone bank or drum set "
3117 "before assignment", name, line);
3122 ctl->cmsg(CMSG_WARNING, VERB_NORMAL,
3123 "%s: line %d: Warning: Not a drumset rxnoteoff"
3131 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
3132 "%s: line %d: extension rxnoteoff "
3133 "must be 0 or 1", name, line);
3139 if (string_to_7bit_range(cp, &j, &k))
3142 if(bank->tone[j][0] == NULL){
3143 if(alloc_tone_bank_element(&bank->tone[j][0])){
3144 ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "%s: line %d: ToneBankElement malloc error.", name, line);
3145 return READ_CONFIG_ERROR;
3148 bank->tone[j][0]->rx_note_off = i;
3152 cp = strchr(cp, ',');
3155 /* #extension playnote */
3156 else if (!strcmp(w[0], "playnote"))
3160 ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "%s: line %d: syntax error", name, line);
3166 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
3167 "%s: line %d: Must specify tone bank or drum set "
3168 "before assignment", name, line);
3173 if (i < 0 || i > 127)
3175 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
3176 "%s: line %d: extension playnote"
3177 "must be between 0 and 127", name, line);
3183 if (string_to_7bit_range(cp, &j, &k))
3186 if(bank->tone[j][0] == NULL){
3187 if(alloc_tone_bank_element(&bank->tone[j][0])){
3188 ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "%s: line %d: ToneBankElement malloc error.", name, line);
3189 return READ_CONFIG_ERROR;
3192 bank->tone[j][0]->play_note = i;
3196 cp = strchr(cp, ',');
3198 } /* #extension fc */
3199 else if (!strcmp(w[0], "fc"))
3203 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
3204 "%s: line %d: syntax error", name, line);
3210 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
3211 "%s: line %d: Must specify tone bank or drum set "
3212 "before assignment", name, line);
3217 if (i < 0 || i > 127)
3219 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
3220 "%s: line %d: extension fc "
3221 "must be between 0 and 127", name, line);
3226 for (elm = 0; elm < MAX_ELEMENT; elm++)
3227 if(bank->tone[i][elm])
3228 bank->tone[i][elm]->fc = config_parse_int16(w[2], &bank->tone[i][elm]->fcnum);
3229 } /* #extension q */
3230 else if (!strcmp(w[0], "q"))
3234 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
3235 "%s: line %d: syntax error", name, line);
3241 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
3242 "%s: line %d: Must specify tone bank or drum set "
3243 "before assignment", name, line);
3248 if (i < 0 || i > 127)
3250 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
3251 "%s: line %d: extension fc "
3252 "must be between 0 and 127", name, line);
3257 for (elm = 0; elm < MAX_ELEMENT; elm++)
3258 if(bank->tone[i][elm])
3259 bank->tone[i][elm]->reso = config_parse_int16(w[2], &bank->tone[i][elm]->resonum);
3262 else if(!strcmp(w[0], "mfx_patch"))
3266 memmove(&w[0], &w[1], sizeof(w[0]) * words);
3267 w[words] = '\0'; /* terminate the token */
3268 if (words < 2 || *w[0] < '0' || *w[0] > '9')
3272 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
3273 "%s: line %d: syntax error", name, line);
3279 memmove(&w[0], &w[1], sizeof(w[0]) * words);
3280 w[words] = '\0'; /* terminate the token */
3283 if (prog < 0 || prog > 127){
3285 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
3286 "%s: line %d: Drum number must be between ""0 and 127", name, line);
3288 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
3289 "%s: line %d: Program must be between ""%d and %d", name, line, progbase, 127 + progbase);
3294 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
3295 "%s: line %d: Must specify tone bank or drum set ""before assignment", name, line);
3299 if (config_parse_mfx_patch(w, words, mapid, origbankno, prog)) // mfx
3304 } /* #extension amp_normalize */
3305 else if (!strcmp(w[0], "amp_normalize"))
3309 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
3310 "%s: line %d: syntax error", name, line);
3316 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
3317 "%s: line %d: Must specify tone bank or drum set "
3318 "before amp_normalize", name, line);
3322 if (! strcmp(w[1], "on"))
3324 else if (! strcmp(w[1], "off"))
3328 if (k < 0 || k > 1) {
3329 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
3330 "%s: line %d: extension amp_normalize "
3331 "must be off, on, 0, 1", name, line);
3336 for(i = 0; i < (128 + MAP_BANK_COUNT); i++){
3337 ToneBank *tmpbank = tonebank[i];
3340 for (j = 0; j < 128; j++)
3341 for (elm = 0; elm < MAX_ELEMENT; elm++)
3342 if(tmpbank->tone[j][elm])
3343 tmpbank->tone[j][elm]->amp_normalize = k;
3345 for(i = 0; i < (128 + MAP_BANK_COUNT); i++){
3346 ToneBank *tmpbank = drumset[i];
3349 for (j = 0; j < 128; j++)
3350 for (elm = 0; elm < MAX_ELEMENT; elm++)
3351 if(tmpbank->tone[i][elm])
3352 tmpbank->tone[i][elm]->amp_normalize = k;
3355 else if (!strcmp(w[0], "soundfont"))
3357 int order, cutoff, isremove, reso, amp;
3362 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
3363 "%s: line %d: No soundfont file given",
3370 order = cutoff = reso = amp = -1;
3372 for (j = 2; j < words; j++)
3374 if (!strcmp(w[j], "remove"))
3379 if (!(cp = strchr(w[j], '=')))
3381 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
3382 "%s: line %d: bad patch option %s",
3389 if (!strcmp(w[j], "order"))
3391 if (k < 0 || (*cp < '0' || *cp > '9'))
3393 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
3394 "%s: line %d: order must be a digit",
3401 else if (!strcmp(w[j], "cutoff"))
3403 if (k < 0 || (*cp < '0' || *cp > '9'))
3405 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
3406 "%s: line %d: cutoff must be a digit",
3413 else if (!strcmp(w[j], "reso"))
3415 if (k < 0 || (*cp < '0' || *cp > '9'))
3417 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
3418 "%s: line %d: reso must be a digit",
3425 else if (!strcmp(w[j], "amp"))
3431 remove_soundfont(sf_file);
3433 add_soundfont(sf_file, order, cutoff, reso, amp);
3435 for(i = 0; i < 128; i++){
3436 ToneBank *tmpbank = tonebank[i];
3438 tonebank[i] = (ToneBank *)safe_malloc(sizeof(ToneBank));
3439 memset(tonebank[i], 0, sizeof(ToneBank));
3440 tmpbank = tonebank[i];
3442 for (j = 0; j < 128; j++){
3443 if(tmpbank->tone[j][0] == NULL)
3445 if(alloc_tone_bank_element(&tmpbank->tone[j][0])){
3446 ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "read_config_file: soundfont ToneBankElement malloc error.");
3447 return READ_CONFIG_ERROR;
3450 for(elm = 0; elm < MAX_ELEMENT; elm++)
3451 if(tmpbank->tone[j][elm])
3452 reinit_tone_bank_element(tmpbank->tone[j][elm]); // need instrum.c apply_bank_parameter()
3455 for(i = 0; i < 128; i++){
3456 ToneBank *tmpbank = drumset[i];
3458 drumset[i] = (ToneBank *)safe_malloc(sizeof(ToneBank));
3459 memset(drumset[i], 0, sizeof(ToneBank));
3460 tmpbank = drumset[i];
3462 for (j = 0; j < 128; j++){
3463 if(tmpbank->tone[j][0] == NULL)
3465 if(alloc_tone_bank_element(&tmpbank->tone[j][0])){
3466 ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "read_config_file: soundfont ToneBankElement malloc error.");
3467 return READ_CONFIG_ERROR;
3470 for(elm = 0; elm < MAX_ELEMENT; elm++)
3471 if(tmpbank->tone[j][elm])
3472 reinit_tone_bank_element(tmpbank->tone[j][elm]); // need instrum.c apply_bank_parameter()
3476 else if (!strcmp(w[0], "font"))
3478 int bank, preset, keynote;
3481 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
3482 "%s: line %d: no font command", name, line);
3486 if (!strcmp(w[1], "exclude"))
3490 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
3491 "%s: line %d: No bank/preset/key is given",
3498 preset = atoi(w[3]) - progbase;
3502 keynote = atoi(w[4]);
3505 if (exclude_soundfont(bank, preset, keynote))
3507 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
3508 "%s: line %d: No soundfont is given",
3513 else if (!strcmp(w[1], "order"))
3518 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
3519 "%s: line %d: No order/bank is given",
3527 preset = atoi(w[4]) - progbase;
3531 keynote = atoi(w[5]);
3534 if (order_soundfont(bank, preset, keynote, order))
3536 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
3537 "%s: line %d: No soundfont is given",
3543 else if (!strcmp(w[0], "progbase"))
3545 if (words < 2 || *w[1] < '0' || *w[1] > '9')
3547 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
3548 "%s: line %d: syntax error", name, line);
3552 progbase = atoi(w[1]);
3554 else if (!strcmp(w[0], "map")) /* map <name> set1 elem1 set2 elem2 */
3560 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
3561 "%s: line %d: syntax error", name, line);
3565 if ((arg[0] = mapname2id(w[1], &isdrum)) == -1)
3567 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
3568 "%s: line %d: Invalid map name: %s", name, line, w[1]);
3572 for (i = 2; i < 6; i++)
3573 arg[i - 1] = atoi(w[i]);
3585 for (i = 1; i < 5; i++)
3586 if (arg[i] < 0 || arg[i] > 127)
3590 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
3591 "%s: line %d: Invalid parameter", name, line);
3595 set_instrument_map(arg[0], arg[1], arg[2], arg[3], arg[4]);
3599 * Standard configurations
3601 else if (!strcmp(w[0], "dir"))
3605 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
3606 "%s: line %d: No directory given", name, line);
3610 for (i = 1; i < words; i++)
3611 add_to_pathlist(w[i]);
3613 else if (!strcmp(w[0], "source") || !strcmp(w[0], "trysource"))
3617 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
3618 "%s: line %d: No file name given", name, line);
3622 for (i = 1; i < words; i++)
3626 status = read_config_file(w[i], 0, !strcmp(w[0], "trysource"));
3629 case READ_CONFIG_SUCCESS:
3631 case READ_CONFIG_ERROR:
3634 case READ_CONFIG_RECURSION:
3635 reuse_mblock(&varbuf);
3637 return READ_CONFIG_RECURSION;
3638 case READ_CONFIG_FILE_NOT_FOUND:
3643 else if (!strcmp(w[0], "default"))
3647 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
3648 "%s: line %d: Must specify exactly one patch name",
3653 strncpy(def_instr_name, w[1], FILEPATH_MAX - 1);
3654 def_instr_name[FILEPATH_MAX - 1] = '\0';
3655 default_instrument_name = def_instr_name;
3657 /* drumset [mapid] num */
3658 else if (!strcmp(w[0], "drumset"))
3660 int newmapid, isdrum, newbankno;
3664 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
3665 "%s: line %d: No drum set number given", name, line);
3669 if (words != 2 && !isdigit(*w[1]))
3671 if ((newmapid = mapname2id(w[1], &isdrum)) == -1 || !isdrum)
3673 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
3674 "%s: line %d: Invalid drum set map name: %s", name, line, w[1]);
3679 memmove(&w[1], &w[2], sizeof w[0] * words);
3682 newmapid = INST_NO_MAP;
3683 i = atoi(w[1]) - progbase;
3684 if (i < 0 || i > 127)
3686 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
3687 "%s: line %d: Drum set must be between %d and %d",
3689 progbase, progbase + 127);
3695 i = alloc_instrument_map_bank(1, newmapid, i);
3698 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
3699 "%s: line %d: No free drum set available to map",
3710 origbankno = newbankno;
3715 if (words < 4 || *w[2] < '0' || *w[2] > '9')
3717 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
3718 "%s: line %d: syntax error", name, line);
3722 if (set_patchconf(name, line, drumset[i], &w[2], 1, newmapid, newbankno, i, 0))
3729 /* bank [mapid] num */
3730 else if (!strcmp(w[0], "bank"))
3732 int newmapid, isdrum, newbankno;
3736 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
3737 "%s: line %d: No bank number given", name, line);
3741 if (words != 2 && !isdigit(*w[1]))
3743 if ((newmapid = mapname2id(w[1], &isdrum)) == -1 || isdrum)
3745 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
3746 "%s: line %d: Invalid bank map name: %s", name, line, w[1]);
3751 memmove(&w[1], &w[2], sizeof w[0] * words);
3754 newmapid = INST_NO_MAP;
3756 if (i < 0 || i > 127)
3758 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
3759 "%s: line %d: Tone bank must be between 0 and 127",
3766 i = alloc_instrument_map_bank(0, newmapid, i);
3769 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
3770 "%s: line %d: No free tone bank available to map",
3781 origbankno = newbankno;
3786 if (words < 4 || *w[2] < '0' || *w[2] > '9')
3788 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
3789 "%s: line %d: syntax error", name, line);
3793 if (set_patchconf(name, line, tonebank[i], &w[2], 0, newmapid, newbankno, i, 0))
3801 else if(!strcmp(w[0], "add"))
3804 memmove(&w[0], &w[1], sizeof w[0] * words);
3805 w[words] = '\0'; /* terminate the token */
3806 if (words < 2 || *w[0] < '0' || *w[0] > '9')
3810 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
3811 "%s: line %d: syntax error", name, line);
3815 if (set_patchconf(name, line, bank, w, dr, mapid, origbankno, bankno, 1))
3823 if (words < 2 || *w[0] < '0' || *w[0] > '9')
3827 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
3828 "%s: line %d: syntax error", name, line);
3832 if (set_patchconf(name, line, bank, w, dr, mapid, origbankno, bankno, 0))
3842 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
3843 "Can't read %s: %s", name, strerror(errno));
3846 reuse_mblock(&varbuf);
3848 return (errcnt == 0) ? READ_CONFIG_SUCCESS : READ_CONFIG_ERROR;
3851 #ifdef SUPPORT_SOCKET
3853 #if defined(__W32__) && !defined(MAIL_NAME)
3854 #define MAIL_NAME "anonymous"
3855 #endif /* __W32__ */
3858 #define get_username() MAIL_NAME
3859 #else /* MAIL_NAME */
3861 static char *get_username(void)
3864 struct passwd *pass;
3872 if((p = getenv("USER")) != NULL)
3874 if((p = getenv("LOGIN")) != NULL)
3876 if((p = getenv("LOGNAME")) != NULL)
3879 pass = getpwuid(getuid());
3882 return pass->pw_name;
3884 #endif /* MAIL_NAME */
3886 static void init_mail_addr(void)
3890 sprintf(addr, "%s%s", get_username(), MAIL_DOMAIN);
3891 user_mailaddr = safe_strdup(addr);
3893 #endif /* SUPPORT_SOCKET */
3895 static int read_user_config_file(void)
3901 home = getenv("HOME");
3905 home = getenv("home");
3909 ctl->cmsg(CMSG_INFO, VERB_NOISY,
3910 "Warning: HOME environment is not defined.");
3915 /* timidity.cfg or _timidity.cfg or .timidity.cfg*/
3916 sprintf(path, "%s" PATH_STRING "timidity.cfg", home);
3917 status = read_config_file(path, 0, 1);
3918 if (status != READ_CONFIG_FILE_NOT_FOUND)
3921 sprintf(path, "%s" PATH_STRING "_timidity.cfg", home);
3922 status = read_config_file(path, 0, 1);
3923 if (status != READ_CONFIG_FILE_NOT_FOUND)
3927 sprintf(path, "%s" PATH_STRING ".timidity.cfg", home);
3928 status = read_config_file(path, 0, 1);
3929 if (status != READ_CONFIG_FILE_NOT_FOUND)
3934 MAIN_INTERFACE void tmdy_free_config(void)
3937 free_instrument_map();
3938 clean_up_pathlist();
3941 int set_extension_modes(char *flag)
3943 return parse_opt_E(flag);
3946 int set_ctl(char *cp)
3948 return parse_opt_i(cp);
3951 int set_play_mode(char *cp)
3953 return parse_opt_O(cp);
3956 int set_wrd(char *w)
3958 return parse_opt_W(w);
3964 int opt_evil_mode = 0;
3966 int opt_rcpcv_dll = 0;
3967 #endif /* SMFCONV */
3968 #endif /* __W32__ */
3969 static int try_config_again = 0;
3972 int opt_fast_decay = 1;
3974 int opt_fast_decay = 0;
3975 #endif /* FAST_DECAY */
3976 int32 opt_output_rate = 0;
3977 static char *opt_output_name = NULL;
3978 static StringTable opt_config_string;
3979 #ifdef SUPPORT_SOUNDSPEC
3980 double spectrogram_update_sec = 0.0;
3981 #endif /* SUPPORT_SOUNDSPEC */
3982 #if defined(AU_VOLUME_CALC)
3983 int opt_volume_calc_rms = 0;
3984 int opt_volume_calc_trim = 0;
3985 #endif /* AU_VOLUME_CALC */
3986 int opt_buffer_fragments = -1;
3987 int opt_audio_buffer_bits = -1;
3989 int opt_compute_buffer_bits = -128;
3991 MAIN_INTERFACE int set_tim_opt_short(int c, const char *optarg)
3997 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
3998 "-4 option is obsoleted. Please use -N");
4001 if (*optarg != ',' && *optarg != 'a')
4002 err += parse_opt_A(optarg);
4003 if (strchr(optarg, ','))
4004 err += parse_opt_drum_power(strchr(optarg, ',') + 1);
4005 if (strchr(optarg, 'a'))
4006 opt_amp_compensation = 1;
4009 antialiasing_allowed = 1;
4012 return parse_opt_B(optarg);
4014 return parse_opt_C(optarg);
4016 return parse_opt_c(optarg);
4018 return parse_opt_D(optarg);
4020 return parse_opt_d(optarg);
4022 return parse_opt_E(optarg);
4024 return parse_opt_e(optarg);
4026 adjust_panning_immediately = (adjust_panning_immediately) ? 0 : 1;
4029 fast_decay = (fast_decay) ? 0 : 1;
4032 return parse_opt_G(optarg);
4034 return parse_opt_g(optarg);
4036 return parse_opt_H(optarg);
4038 return parse_opt_h(optarg);
4040 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
4041 "-I option is obsoleted. Please use -Ei");
4044 return parse_opt_i(optarg);
4046 opt_realtime_playing = (opt_realtime_playing) ? 0 : 1;
4049 return parse_opt_K(optarg);
4051 return parse_opt_k(optarg);
4053 return parse_opt_L(optarg);
4055 return parse_opt_M(optarg);
4057 return parse_opt_m(optarg);
4059 return parse_opt_N(optarg);
4061 return parse_opt_n(optarg);
4063 return parse_opt_O(optarg);
4065 return parse_opt_o(optarg);
4067 return parse_opt_P(optarg);
4070 err += parse_opt_p(optarg);
4071 if (strchr(optarg, 'a'))
4072 auto_reduce_polyphony = (auto_reduce_polyphony) ? 0 : 1;
4075 return parse_opt_Q(optarg);
4077 return parse_opt_q(optarg);
4079 return parse_opt_R(optarg);
4082 return parse_opt_r(optarg);
4084 return parse_opt_S(optarg);
4086 return parse_opt_s(optarg);
4088 return parse_opt_T(optarg);
4090 return parse_opt_t(optarg);
4092 free_instruments_afterwards = 1;
4095 return parse_opt_volume_curve(optarg);
4097 return parse_opt_v(optarg);
4099 return parse_opt_W(optarg);
4102 return parse_opt_w(optarg);
4105 return parse_opt_x(optarg);
4107 return parse_opt_Y(optarg);
4109 if (strncmp(optarg, "pure", 4))
4110 return parse_opt_Z(optarg);
4112 return parse_opt_Z1(optarg + 4);
4120 MAIN_INTERFACE int set_tim_opt_short_cfg(int c, const char *optarg)
4124 return parse_opt_c(optarg);
4130 /* -------- getopt_long -------- */
4131 MAIN_INTERFACE int set_tim_opt_long(int c, const char *optarg, int index)
4133 const struct option *the_option = &(longopts[index]);
4136 if (c == '?') /* getopt_long failed parsing */
4137 parse_opt_fail(optarg);
4138 else if (c < TIM_OPT_FIRST)
4139 return set_tim_opt_short(c, optarg);
4140 if (! strncmp(the_option->name, "no-", 3))
4141 arg = "no"; /* `reverse' switch */
4145 case TIM_OPT_VOLUME:
4146 return parse_opt_A(arg);
4147 case TIM_OPT_MASTER_VOLUME:
4148 return parse_opt_master_volume(arg);
4149 case TIM_OPT_DRUM_POWER:
4150 return parse_opt_drum_power(arg);
4151 case TIM_OPT_VOLUME_COMP:
4152 return parse_opt_volume_comp(arg);
4153 case TIM_OPT_ANTI_ALIAS:
4154 return parse_opt_a(arg);
4155 case TIM_OPT_BUFFER_FRAGS:
4156 return parse_opt_B(arg);
4157 case TIM_OPT_CONTROL_RATIO:
4158 return parse_opt_C(arg);
4159 case TIM_OPT_CONFIG_FILE:
4160 return parse_opt_c(arg);
4161 case TIM_OPT_DRUM_CHANNEL:
4162 return parse_opt_D(arg);
4163 case TIM_OPT_IFACE_PATH:
4164 return parse_opt_d(arg);
4166 return parse_opt_E(arg);
4167 case TIM_OPT_MOD_WHEEL:
4168 return parse_opt_mod_wheel(arg);
4169 case TIM_OPT_PORTAMENTO:
4170 return parse_opt_portamento(arg);
4171 case TIM_OPT_VIBRATO:
4172 return parse_opt_vibrato(arg);
4173 case TIM_OPT_CH_PRESS:
4174 return parse_opt_ch_pressure(arg);
4175 case TIM_OPT_MOD_ENV:
4176 return parse_opt_mod_env(arg);
4177 case TIM_OPT_TRACE_TEXT:
4178 return parse_opt_trace_text(arg);
4179 case TIM_OPT_OVERLAP:
4180 return parse_opt_overlap_voice(arg);
4182 case TIM_OPT_OVERLAP_COUNT:
4183 return parse_opt_overlap_voice_count(arg);
4184 case TIM_OPT_MAX_CHANNEL_VOICES:
4185 return parse_opt_max_channel_voices(arg);
4187 case TIM_OPT_TEMPER_CTRL:
4188 return parse_opt_temper_control(arg);
4189 case TIM_OPT_DEFAULT_MID:
4190 return parse_opt_default_mid(arg);
4191 case TIM_OPT_SYSTEM_MID:
4192 return parse_opt_system_mid(arg);
4193 case TIM_OPT_DEFAULT_BANK:
4194 return parse_opt_default_bank(arg);
4195 case TIM_OPT_FORCE_BANK:
4196 return parse_opt_force_bank(arg);
4197 case TIM_OPT_DEFAULT_PGM:
4198 return parse_opt_default_program(arg);
4199 case TIM_OPT_FORCE_PGM:
4200 return parse_opt_force_program(arg);
4202 return parse_opt_delay(arg);
4203 case TIM_OPT_CHORUS:
4204 return parse_opt_chorus(arg);
4205 case TIM_OPT_REVERB:
4206 return parse_opt_reverb(arg);
4207 case TIM_OPT_VOICE_LPF:
4208 return parse_opt_voice_lpf(arg);
4209 case TIM_OPT_VOICE_HPF:
4210 return parse_opt_voice_hpf(arg);
4212 return parse_opt_noise_shaping(arg);
4213 #ifndef FIXED_RESAMPLATION
4214 case TIM_OPT_RESAMPLE:
4215 return parse_opt_resample(arg);
4218 return parse_opt_e(arg);
4219 case TIM_OPT_FAST_PAN:
4220 return parse_opt_F(arg);
4221 case TIM_OPT_FAST_DECAY:
4222 return parse_opt_f(arg);
4223 case TIM_OPT_SEGMENT:
4224 return parse_opt_G(arg);
4225 case TIM_OPT_SPECTROGRAM:
4226 return parse_opt_g(arg);
4227 case TIM_OPT_KEYSIG:
4228 return parse_opt_H(arg);
4230 return parse_opt_h(arg);
4231 case TIM_OPT_INTERFACE:
4232 return parse_opt_i(arg);
4233 case TIM_OPT_VERBOSE:
4234 return parse_opt_verbose(arg);
4236 return parse_opt_quiet(arg);
4238 return parse_opt_trace(arg);
4240 return parse_opt_loop(arg);
4241 case TIM_OPT_RANDOM:
4242 return parse_opt_random(arg);
4244 return parse_opt_sort(arg);
4246 case TIM_OPT_BACKGROUND:
4247 return parse_opt_background(arg);
4248 case TIM_OPT_RT_PRIO:
4249 return parse_opt_rt_prio(arg);
4250 case TIM_OPT_SEQ_PORTS:
4251 return parse_opt_seq_ports(arg);
4253 #if defined(IA_WINSYN) || defined(IA_NPSYN) || defined(IA_PORTMIDI) || \
4254 defined(IA_W32G_SYN) || defined(IA_W32GUI)
4255 case TIM_OPT_RTSYN_LATENCY:
4256 return parse_opt_rtsyn_latency(arg);
4257 case TIM_OPT_RTSYN_SKIP_AQ:
4258 return parse_opt_rtsyn_skip_aq(arg);
4259 case TIM_OPT_RTSYN_PRINT_PORTS:
4260 return parse_opt_rtsyn_print_ports(arg);
4261 #endif /* RTSYN || IA_W32GUI */
4262 case TIM_OPT_REALTIME_LOAD:
4263 return parse_opt_j(arg);
4264 case TIM_OPT_ADJUST_KEY:
4265 return parse_opt_K(arg);
4266 case TIM_OPT_VOICE_QUEUE:
4267 return parse_opt_k(arg);
4268 case TIM_OPT_PATCH_PATH:
4269 return parse_opt_L(arg);
4270 case TIM_OPT_PCM_FILE:
4271 return parse_opt_M(arg);
4273 case TIM_OPT_RESAMPLE_FILTER:
4274 return parse_opt_l(arg);
4275 case TIM_OPT_RESAMPLE_OVER_SAMPLING:
4276 return parse_opt_resample_over_sampling(arg);
4277 case TIM_OPT_PRE_RESAMPLE:
4278 return parse_opt_pre_resample(arg);
4279 case TIM_OPT_DECAY_TIME:
4280 return parse_opt_m(arg);
4281 case TIM_OPT_INTERPOLATION:
4282 return parse_opt_N(arg);
4283 case TIM_OPT_POLYPHONY_QUEUE:
4284 return parse_opt_n(arg);
4285 case TIM_OPT_OUTPUT_MODE:
4286 return parse_opt_O(arg);
4287 case TIM_OPT_OUTPUT_STEREO:
4288 if (! strcmp(the_option->name, "output-mono"))
4289 /* --output-mono == --output-stereo=no */
4291 return parse_opt_output_stereo(arg);
4292 case TIM_OPT_OUTPUT_SIGNED:
4293 if (! strcmp(the_option->name, "output-unsigned"))
4294 /* --output-unsigned == --output-signed=no */
4296 return parse_opt_output_signed(arg);
4298 case TIM_OPT_OUTPUT_BITWIDTH:
4299 if (! strcmp(the_option->name, "output-16bit"))
4301 else if (! strcmp(the_option->name, "output-24bit"))
4303 else if (! strcmp(the_option->name, "output-32bit"))
4305 else if (! strcmp(the_option->name, "output-64bit"))
4307 else if (! strcmp(the_option->name, "output-8bit"))
4309 else if (! strcmp(the_option->name, "output-f32bit"))
4311 else if (! strcmp(the_option->name, "output-float32bit"))
4313 else if (! strcmp(the_option->name, "output-f64bit"))
4315 else if (! strcmp(the_option->name, "output-float64bit"))
4317 return parse_opt_output_bitwidth(arg);
4318 case TIM_OPT_OUTPUT_FORMAT:
4319 if (! strcmp(the_option->name, "output-linear"))
4321 else if (! strcmp(the_option->name, "output-ulaw"))
4323 else if (! strcmp(the_option->name, "output-alaw"))
4325 return parse_opt_output_format(arg);
4326 case TIM_OPT_OUTPUT_SWAB:
4327 return parse_opt_output_swab(arg);
4329 case TIM_OPT_OUTPUT_DEVICE_ID:
4330 return parse_opt_output_device_id(arg);
4332 case TIM_OPT_WMME_DEVICE_ID:
4333 return parse_opt_wmme_device_id(arg);
4334 case TIM_OPT_WAVE_FORMAT_EXT:
4335 return parse_opt_wave_format_ext(arg);
4338 case TIM_OPT_WDMKS_DEVICE_ID:
4339 return parse_opt_wdmks_device_id(arg);
4340 case TIM_OPT_WDMKS_LATENCY:
4341 return parse_opt_wdmks_latency(arg);
4342 case TIM_OPT_WDMKS_FORMAT_EXT:
4343 return parse_opt_wdmks_format_ext(arg);
4344 case TIM_OPT_WDMKS_POLLING:
4345 return parse_opt_wdmks_polling(arg);
4346 case TIM_OPT_WDMKS_THREAD_PRIORITY:
4347 return parse_opt_wdmks_thread_priority(arg);
4348 case TIM_OPT_WDMKS_RT_PRIORITY:
4349 return parse_opt_wdmks_rt_priority(arg);
4350 case TIM_OPT_WDMKS_PIN_PRIORITY:
4351 return parse_opt_wdmks_pin_priority(arg);
4354 case TIM_OPT_WASAPI_DEVICE_ID:
4355 return parse_opt_wasapi_device_id(arg);
4356 case TIM_OPT_WASAPI_LATENCY:
4357 return parse_opt_wasapi_latency(arg);
4358 case TIM_OPT_WASAPI_FORMAT_EXT:
4359 return parse_opt_wasapi_format_ext(arg);
4360 case TIM_OPT_WASAPI_EXCLUSIVE:
4361 return parse_opt_wasapi_exclusive(arg);
4362 case TIM_OPT_WASAPI_POLLING:
4363 return parse_opt_wasapi_polling(arg);
4364 case TIM_OPT_WASAPI_PRIORITY:
4365 return parse_opt_wasapi_priority(arg);
4366 case TIM_OPT_WASAPI_STREAM_CATEGORY:
4367 return parse_opt_wasapi_stream_category(arg);
4368 case TIM_OPT_WASAPI_STREAM_OPTION:
4369 return parse_opt_wasapi_stream_option(arg);
4372 case TIM_OPT_PA_WMME_DEVICE_ID:
4373 return parse_opt_pa_wmme_device_id(arg);
4374 case TIM_OPT_PA_DS_DEVICE_ID:
4375 return parse_opt_pa_ds_device_id(arg);
4376 case TIM_OPT_PA_ASIO_DEVICE_ID:
4377 return parse_opt_pa_asio_device_id(arg);
4378 #ifdef PORTAUDIO_V19
4379 case TIM_OPT_PA_WDMKS_DEVICE_ID:
4380 return parse_opt_pa_wdmks_device_id(arg);
4381 case TIM_OPT_PA_WASAPI_DEVICE_ID:
4382 return parse_opt_pa_wasapi_device_id(arg);
4383 case TIM_OPT_PA_WASAPI_FLAG:
4384 return parse_opt_pa_wasapi_flag(arg);
4385 case TIM_OPT_PA_WASAPI_STREAM_CATEGORY:
4386 return parse_opt_pa_wasapi_stream_category(arg);
4387 case TIM_OPT_PA_WASAPI_STREAM_OPTION:
4388 return parse_opt_pa_wasapi_stream_option(arg);
4392 case TIM_OPT_WAVE_EXTENSIBLE:
4393 return parse_opt_wave_extensible(arg);
4394 case TIM_OPT_WAVE_UPDATE_STEP:
4395 return parse_opt_wave_update_step(arg);
4397 case TIM_OPT_FLAC_VERIFY:
4398 return parse_opt_flac_verify(arg);
4399 case TIM_OPT_FLAC_PADDING:
4400 return parse_opt_flac_padding(arg);
4401 case TIM_OPT_FLAC_COMPLEVEL:
4402 return parse_opt_flac_complevel(arg);
4404 case TIM_OPT_FLAC_OGGFLAC:
4405 return parse_opt_flac_oggflac(arg);
4406 #endif /* AU_OGGFLAC */
4407 #endif /* AU_FLAC */
4409 case TIM_OPT_OPUS_NFRAMES:
4410 return parse_opt_opus_nframes(arg);
4411 case TIM_OPT_OPUS_BITRATE:
4412 return parse_opt_opus_bitrate(arg);
4413 case TIM_OPT_OPUS_COMPLEXITY:
4414 return parse_opt_opus_complexity(arg);
4415 case TIM_OPT_OPUS_VBR:
4416 return parse_opt_opus_vbr(arg);
4417 case TIM_OPT_OPUS_CVBR:
4418 return parse_opt_opus_cvbr(arg);
4419 #endif /* AU_OPUS */
4421 case TIM_OPT_SPEEX_QUALITY:
4422 return parse_opt_speex_quality(arg);
4423 case TIM_OPT_SPEEX_VBR:
4424 return parse_opt_speex_vbr(arg);
4425 case TIM_OPT_SPEEX_ABR:
4426 return parse_opt_speex_abr(arg);
4427 case TIM_OPT_SPEEX_VAD:
4428 return parse_opt_speex_vad(arg);
4429 case TIM_OPT_SPEEX_DTX:
4430 return parse_opt_speex_dtx(arg);
4431 case TIM_OPT_SPEEX_COMPLEXITY:
4432 return parse_opt_speex_complexity(arg);
4433 case TIM_OPT_SPEEX_NFRAMES:
4434 return parse_opt_speex_nframes(arg);
4435 #endif /* AU_SPEEX */
4436 case TIM_OPT_OUTPUT_FILE:
4437 return parse_opt_o(arg);
4438 case TIM_OPT_PATCH_FILE:
4439 return parse_opt_P(arg);
4440 case TIM_OPT_POLYPHONY:
4441 return parse_opt_p(arg);
4442 case TIM_OPT_POLY_REDUCE:
4443 return parse_opt_p1(arg);
4445 return parse_opt_Q(arg);
4446 case TIM_OPT_TEMPER_MUTE:
4447 return parse_opt_Q1(arg);
4448 case TIM_OPT_PRESERVE_SILENCE:
4449 return parse_opt_preserve_silence(arg);
4450 case TIM_OPT_AUDIO_BUFFER:
4451 return parse_opt_q(arg);
4453 case TIM_OPT_RESAMPLE_QUEUE:
4454 return parse_opt_r(arg);
4456 case TIM_OPT_CACHE_SIZE:
4457 return parse_opt_S(arg);
4458 case TIM_OPT_SAMPLE_FREQ:
4459 return parse_opt_s(arg);
4460 case TIM_OPT_ADJUST_TEMPO:
4461 return parse_opt_T(arg);
4462 case TIM_OPT_CHARSET:
4463 return parse_opt_t(arg);
4464 case TIM_OPT_UNLOAD_INST:
4465 return parse_opt_U(arg);
4466 #if defined(AU_VOLUME_CALC)
4467 case TIM_OPT_VOLUME_CALC_RMS:
4468 return parse_opt_volume_calc_rms(arg);
4469 case TIM_OPT_VOLUME_CALC_TRIM:
4470 return parse_opt_volume_calc_trim(arg);
4471 #endif /* AU_VOLUME_CALC */
4472 case TIM_OPT_VOLUME_CURVE:
4473 return parse_opt_volume_curve(arg);
4474 case TIM_OPT_VERSION:
4475 return parse_opt_v(arg);
4477 return parse_opt_W(arg);
4479 case TIM_OPT_RCPCV_DLL:
4480 return parse_opt_w(arg);
4482 case TIM_OPT_CONFIG_STR:
4483 return parse_opt_x(arg);
4485 case TIM_OPT_COMPUTE_BUFFER:
4486 return parse_opt_Y(arg);
4487 case TIM_OPT_FREQ_TABLE:
4488 return parse_opt_Z(arg);
4489 case TIM_OPT_PURE_INT:
4490 return parse_opt_Z1(arg);
4491 case TIM_OPT_MODULE:
4492 return parse_opt_default_module(arg);
4494 case TIM_OPT_ADD_PLAY_TIME:
4495 return parse_opt_add_play_time(arg);
4496 case TIM_OPT_ADD_SILENT_TIME:
4497 return parse_opt_add_silent_time(arg);
4498 case TIM_OPT_EMU_DELAY_TIME:
4499 return parse_opt_emu_delay_time(arg);
4500 case TIM_OPT_LIMITER:
4501 return parse_opt_limiter(arg);
4502 case TIM_OPT_MIX_ENV:
4503 return parse_opt_mix_envelope(arg);
4504 case TIM_OPT_MOD_UPDATE:
4505 return parse_opt_modulation_update(arg);
4506 case TIM_OPT_CUT_SHORT:
4507 return parse_opt_cut_short_time(arg);
4508 case TIM_OPT_COMPUTE_THREAD_NUM:
4509 return parse_opt_compute_thread_num(arg);
4510 case TIM_OPT_TRACE_MODE_UPDATE:
4511 return parse_opt_trace_mode_update(arg);
4512 case TIM_OPT_LOAD_ALL_INSTRUMENT:
4513 return parse_opt_load_all_instrument(arg);
4514 #ifdef SUPPORT_LOOPEVENT
4515 case TIM_OPT_LOOP_REPEAT:
4516 return parse_opt_midi_loop_repeat(arg);
4517 case TIM_OPT_LOOP_FILTER:
4518 return parse_opt_midi_loop_filter(arg);
4519 #endif /* SUPPORT_LOOPEVENT */
4520 case TIM_OPT_OD_LEVEL_GS:
4521 return parse_opt_od_level_gs(arg);
4522 case TIM_OPT_OD_DRIVE_GS:
4523 return parse_opt_od_drive_gs(arg);
4524 case TIM_OPT_OD_LEVEL_XG:
4525 return parse_opt_od_level_xg(arg);
4526 case TIM_OPT_OD_DRIVE_XG:
4527 return parse_opt_od_drive_xg(arg);
4528 case TIM_OPT_OD_LEVEL_SD:
4529 return parse_opt_od_level_sd(arg);
4530 case TIM_OPT_OD_DRIVE_SD:
4531 return parse_opt_od_drive_sd(arg);
4533 #if defined(__W32__)
4534 case TIM_OPT_PROCESS_PRIORITY:
4535 return parse_opt_process_priority(arg);
4536 #if !(defined(IA_W32G_SYN) || defined(WINDRV))
4537 case TIM_OPT_PLAYER_THREAD_PRIORITY:
4538 return parse_opt_player_thread_priority(arg);
4541 case TIM_OPT_DUMMY_SETTING:
4542 return 0; //dummy call
4544 case TIM_OPT_INT_SYNTH_RATE:
4545 return parse_opt_int_synth_rate(arg);
4546 case TIM_OPT_INT_SYNTH_SINE:
4547 return parse_opt_int_synth_sine(arg);
4548 case TIM_OPT_INT_SYNTH_UPDATE:
4549 return parse_opt_int_synth_update(arg);
4552 ctl->cmsg(CMSG_FATAL, VERB_NORMAL,
4553 "[BUG] Inconceivable case branch %d", c);
4555 return 0; //dummy call
4560 MAIN_INTERFACE int set_tim_opt_long_cfg(int c, const char *optarg, int index)
4562 const struct option *the_option = &(longopts[index]);
4565 if (c == '?') /* getopt_long failed parsing */
4566 parse_opt_fail(optarg);
4567 else if (c < TIM_OPT_FIRST)
4568 return set_tim_opt_short_cfg(c, optarg);
4569 if (! strncmp(the_option->name, "no-", 3))
4570 arg = "no"; /* `reverse' switch */
4574 case TIM_OPT_CONFIG_FILE:
4575 return parse_opt_c(arg);
4577 return 0; //dummy call
4582 static inline int parse_opt_A(const char *arg)
4584 /* amplify volume by n percent */
4585 if (!arg) return amplification;
4586 return set_val_i32(&lification, atoi(arg), 0, MAX_AMPLIFICATION,
4590 static inline int parse_opt_master_volume(const char *arg)
4592 /* amplify volume by n percent */
4593 if (!arg) return output_amplification;
4594 return set_val_i32(&output_amplification, atoi(arg), 0, MAX_AMPLIFICATION,
4595 "Output Amplification");
4598 static inline int parse_opt_drum_power(const char *arg)
4601 if (!arg) return opt_drum_power;
4602 return set_val_i32(&opt_drum_power, atoi(arg), 0, MAX_AMPLIFICATION,
4606 static inline int parse_opt_volume_comp(const char *arg)
4608 /* --[no-]volume-compensation */
4610 opt_amp_compensation = y_or_n_p(arg);
4614 static inline int parse_opt_a(const char *arg)
4617 antialiasing_allowed = y_or_n_p(arg);
4621 static inline int parse_opt_B(const char *arg)
4623 /* --buffer-fragments */
4629 if (set_value(&opt_buffer_fragments, atoi(arg), 0, 4096,
4630 "Buffer Fragments (num)"))
4634 if ((p = strchr(arg, ',')) != NULL) {
4635 if (set_value(&opt_audio_buffer_bits, atoi(++p), 1, AUDIO_BUFFER_BITS,
4636 "Buffer Fragments (bit)"))
4642 static inline int parse_opt_C(const char *arg)
4645 if (set_val_i32(&control_ratio, atoi(arg), 0, MAX_CONTROL_RATIO,
4648 opt_control_ratio = control_ratio;
4652 static inline int parse_opt_c(const char *arg)
4656 if (got_a_configuration == 1)
4659 if (read_config_file(arg, 0, 0))
4661 got_a_configuration = 1;
4665 static inline int parse_opt_D(const char *arg)
4668 return set_channel_flag(&default_drumchannels, atoi(arg), "Drum channel");
4671 static inline int parse_opt_d(const char *arg)
4673 /* dynamic lib root */
4675 safe_free(dynamic_lib_root);
4676 if (!arg) arg = ".";
4677 dynamic_lib_root = safe_strdup(arg);
4680 ctl->cmsg(CMSG_WARNING, VERB_NOISY, "-d option is not supported");
4682 #endif /* IA_DYNAMIC */
4685 static inline int parse_opt_E(const char *arg)
4687 /* undocumented option --ext */
4689 if (!arg) return err;
4694 opt_modulation_wheel = 1;
4697 opt_modulation_wheel = 0;
4706 opt_nrpn_vibrato = 1;
4709 opt_nrpn_vibrato = 0;
4712 opt_channel_pressure = 1;
4715 opt_channel_pressure = 0;
4718 opt_modulation_envelope = 1;
4721 opt_modulation_envelope = 0;
4724 opt_trace_text_meta_event = 1;
4727 opt_trace_text_meta_event = 0;
4730 opt_overlap_voice_allow = 1;
4733 opt_overlap_voice_allow = 0;
4736 opt_temper_control = 1;
4739 opt_temper_control = 0;
4743 opt_drum_effect = 1;
4746 opt_drum_effect = 0;
4749 opt_insertion_effect = 1;
4752 opt_insertion_effect = 0;
4763 opt_tva_release = 1;
4768 opt_tva_release = 0;
4771 opt_delay_control = 1;
4774 opt_delay_control = 0;
4778 if (parse_opt_default_mid(arg + 1))
4783 if (parse_opt_system_mid(arg + 1))
4788 if (parse_opt_default_bank(arg + 1))
4790 while (isdigit(*(arg + 1)))
4794 if (parse_opt_force_bank(arg + 1))
4796 while (isdigit(*(arg + 1)))
4800 if (parse_opt_default_program(arg + 1))
4802 while (isdigit(*(arg + 1)) || *(arg + 1) == '/')
4806 if (parse_opt_force_program(arg + 1))
4808 while (isdigit(*(arg + 1)) || *(arg + 1) == '/')
4812 if (strncmp(arg + 1, "delay=", 6) == 0) {
4813 if (parse_opt_delay(arg + 7))
4815 } else if (strncmp(arg + 1, "chorus=", 7) == 0) {
4816 if (parse_opt_chorus(arg + 8))
4818 } else if (strncmp(arg + 1, "reverb=", 7) == 0) {
4819 if (parse_opt_reverb(arg + 8))
4821 } else if (strncmp(arg + 1, "ns=", 3) == 0) {
4822 if (parse_opt_noise_shaping(arg + 4))
4824 } else if (strncmp(arg + 1, "vlpf=", 5) == 0) {
4825 if (parse_opt_voice_lpf(arg + 6))
4827 #ifndef FIXED_RESAMPLATION
4828 } else if (strncmp(arg + 1, "resamp=", 7) == 0) {
4829 if (parse_opt_resample(arg + 8))
4834 ctl->cmsg(CMSG_ERROR,
4835 VERB_NORMAL, "-E%s: unsupported effect", arg);
4840 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
4841 "-E: Illegal mode `%c'", *arg);
4850 static inline int parse_opt_mod_wheel(const char *arg)
4852 /* --[no-]mod-wheel */
4854 opt_modulation_wheel = y_or_n_p(arg);
4858 static inline int parse_opt_portamento(const char *arg)
4860 /* --[no-]portamento */
4862 opt_portamento = y_or_n_p(arg);
4866 static inline int parse_opt_vibrato(const char *arg)
4868 /* --[no-]vibrato */
4870 opt_nrpn_vibrato = y_or_n_p(arg);
4874 static inline int parse_opt_ch_pressure(const char *arg)
4876 /* --[no-]ch-pressure */
4878 opt_channel_pressure = y_or_n_p(arg);
4882 static inline int parse_opt_mod_env(const char *arg)
4884 /* --[no-]mod-envelope */
4886 opt_modulation_envelope = y_or_n_p(arg);
4890 static inline int parse_opt_trace_text(const char *arg)
4892 /* --[no-]trace-text-meta */
4894 opt_trace_text_meta_event = y_or_n_p(arg);
4898 static inline int parse_opt_overlap_voice(const char *arg)
4900 /* --[no-]overlap-voice */
4902 opt_overlap_voice_allow = y_or_n_p(arg);
4906 static inline int parse_opt_overlap_voice_count(const char *arg)
4908 /* --overlap-voice-count */
4913 if (! val || val < 0) {
4914 ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "Voice Overlap Count: Illegal value");
4917 opt_overlap_voice_count = val;
4921 static inline int parse_opt_max_channel_voices(const char *arg)
4923 /* --max_channel_voices */
4928 if (! val || val < 4 || val > 512) {
4929 ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "Max Channel Voices: Illegal value");
4932 opt_max_channel_voices = val;
4936 static inline int parse_opt_temper_control(const char *arg)
4938 /* --[no-]temper-control */
4940 opt_temper_control = y_or_n_p(arg);
4944 static inline int parse_opt_default_mid(const char *arg)
4952 ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "Manufacture ID: Illegal value");
4955 opt_default_mid = val;
4959 static inline int parse_opt_system_mid(const char *arg)
4967 ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "Manufacture ID: Illegal value");
4970 opt_system_mid = val;
4974 static inline int parse_opt_default_bank(const char *arg)
4976 /* --default-bank */
4978 if (set_value(&default_tonebank, atoi(arg), 0, 0x7f, "Bank number"))
4980 special_tonebank = -1;
4984 static inline int parse_opt_force_bank(const char *arg)
4988 if (set_value(&special_tonebank, atoi(arg), 0, 0x7f, "Bank number"))
4993 static inline int parse_opt_default_program(const char *arg)
4995 /* --default-program */
5000 if (set_value(&prog, atoi(arg), 0, 0x7f, "Program number"))
5002 if ((p = strchr(arg, '/')) != NULL) {
5003 if (set_value(&i, atoi(++p), 1, MAX_CHANNELS, "Program channel"))
5005 default_program[i - 1] = prog;
5007 for (i = 0; i < MAX_CHANNELS; i++)
5008 default_program[i] = prog;
5012 static inline int parse_opt_force_program(const char *arg)
5014 /* --force-program */
5019 if (set_value(&def_prog, atoi(arg), 0, 0x7f, "Program number"))
5022 set_default_program(def_prog);
5023 if ((p = strchr(arg, '/')) != NULL) {
5024 if (set_value(&i, atoi(++p), 1, MAX_CHANNELS, "Program channel"))
5026 default_program[i - 1] = SPECIAL_PROGRAM;
5028 for (i = 0; i < MAX_CHANNELS; i++)
5029 default_program[i] = SPECIAL_PROGRAM;
5033 static inline int set_default_program(int prog)
5038 bank = (special_tonebank >= 0) ? special_tonebank : default_tonebank;
5039 if ((ip = play_midi_load_instrument(0, bank, prog, 0, NULL)) == NULL) // elm=0
5041 default_instrument = ip;
5045 static inline int parse_opt_delay(const char *arg)
5053 case 'd': /* disable */
5054 opt_delay_control = 0;
5057 case 'D': /* normal */
5058 opt_delay_control = 1;
5061 ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "Invalid delay parameter.");
5067 static inline int parse_opt_chorus(const char *arg)
5075 case 'd': /* disable */
5076 opt_chorus_control = 0;
5077 opt_surround_chorus = 0;
5080 case 'n': /* normal */
5082 case 's': /* surround */
5083 opt_surround_chorus = (*arg == '2' || *arg == 's') ? 1 : 0;
5084 if ((p = strchr(arg, ',')) != NULL) {
5085 if (set_value(&opt_chorus_control, atoi(++p), 0, 0x7f,
5088 opt_chorus_control = -opt_chorus_control;
5089 opt_normal_chorus_plus = 0;
5091 opt_chorus_control = 1;
5092 opt_normal_chorus_plus = 0;
5099 opt_surround_chorus = (*arg == '4' || *arg == 'W') ? 1 : 0;
5100 if ((p = strchr(arg, ',')) != NULL) {
5101 if (set_value(&opt_chorus_control, atoi(++p), 0, 0x7f,
5104 opt_chorus_control = -opt_chorus_control;
5105 opt_normal_chorus_plus = 1;
5107 opt_chorus_control = 1;
5108 opt_normal_chorus_plus = 1;
5115 opt_surround_chorus = (*arg == '6' || *arg == 'B') ? 1 : 0;
5116 if ((p = strchr(arg, ',')) != NULL) {
5117 if (set_value(&opt_chorus_control, atoi(++p), 0, 0x7f,
5120 opt_chorus_control = -opt_chorus_control;
5121 opt_normal_chorus_plus = 2;
5123 opt_chorus_control = 1;
5124 opt_normal_chorus_plus = 2;
5131 opt_surround_chorus = (*arg == '8' || *arg == 'T') ? 1 : 0;
5132 if ((p = strchr(arg, ',')) != NULL) {
5133 if (set_value(&opt_chorus_control, atoi(++p), 0, 0x7f,
5136 opt_chorus_control = -opt_chorus_control;
5137 opt_normal_chorus_plus = 3;
5139 opt_chorus_control = 1;
5140 opt_normal_chorus_plus = 3;
5146 opt_surround_chorus = ( *arg == 'H') ? 1 : 0;
5147 if ((p = strchr(arg, ',')) != NULL) {
5148 if (set_value(&opt_chorus_control, atoi(++p), 0, 0x7f,
5151 opt_chorus_control = -opt_chorus_control;
5152 opt_normal_chorus_plus = 4;
5154 opt_chorus_control = 1;
5155 opt_normal_chorus_plus = 4;
5160 opt_surround_chorus = ( *arg == 'E') ? 1 : 0;
5161 if ((p = strchr(arg, ',')) != NULL) {
5162 if (set_value(&opt_chorus_control, atoi(++p), 0, 0x7f,
5165 opt_chorus_control = -opt_chorus_control;
5166 opt_normal_chorus_plus = 5;
5168 opt_chorus_control = 1;
5169 opt_normal_chorus_plus = 5;
5173 case 'v': /* chorus VST */
5175 opt_surround_chorus = ( *arg == 'V') ? 1 : 0;
5176 if ((p = strchr(arg, ',')) != NULL) {
5177 if (set_value(&opt_chorus_control, atoi(++p), 0, 0x7f,
5180 opt_chorus_control = -opt_chorus_control;
5181 opt_normal_chorus_plus = 6;
5183 opt_chorus_control = 1;
5184 opt_normal_chorus_plus = 6;
5189 ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "Invalid chorus parameter.");
5195 static inline int parse_opt_reverb(const char *arg)
5201 /* option action opt_reverb_control
5202 * reverb=0 no reverb 0
5203 * reverb=1 old reverb 1
5204 * reverb=1,n set reverb level to n (-1 to -127)
5205 * reverb=2 "global" old reverb 2
5206 * reverb=2,n set reverb level to n (-1 to -127) - 128
5207 * reverb=3 new reverb 3
5208 * reverb=3,n set reverb level to n (-1 to -127) - 256
5209 * reverb=4 "global" new reverb 4
5210 * reverb=4,n set reverb level to n (-1 to -127) - 384
5212 * I think "global" was meant to apply a single global reverb,
5213 * without applying any reverb to the channels. The do_effects()
5214 * function in effects.c looks like a good way to do this.
5216 * This is NOT the "correct" way to implement global reverb, we should
5217 * really make a new variable just for that. But if opt_reverb_control
5218 * is already used in a similar fashion, rather than creating a new
5219 * variable for setting the channel reverb levels, then I guess
5220 * maybe this isn't so bad.... It would be nice to create new
5221 * variables for both global reverb and channel reverb level settings
5222 * in the future, but this will do for now.
5227 case 'd': /* disable */
5228 opt_reverb_control = 0;
5231 case 'n': /* normal */
5232 if ((p = strchr(arg, ',')) != NULL) {
5233 if (set_value(&opt_reverb_control, atoi(++p), 1, 0x7f,
5236 opt_reverb_control = -opt_reverb_control;
5238 opt_reverb_control = 1;
5241 case 'g': /* global */
5242 if ((p = strchr(arg, ',')) != NULL) {
5243 if (set_value(&opt_reverb_control, atoi(++p), 1, 0x7f,
5246 opt_reverb_control = -opt_reverb_control - 128;
5248 opt_reverb_control = 2;
5251 case 'f': /* freeverb */
5252 return parse_opt_reverb_freeverb(arg, 'f');
5254 case 'G': /* global freeverb */
5255 return parse_opt_reverb_freeverb(arg, 'G');
5256 case '5': /* reverb ex */
5257 if ((p = strchr(arg, ',')) != NULL) {
5258 if (set_value(&opt_reverb_control, atoi(++p), 1, 0x7f,
5261 opt_reverb_control = -opt_reverb_control - 512;
5263 opt_reverb_control = 5;
5265 case '6': /* global reverb ex */
5266 if ((p = strchr(arg, ',')) != NULL) {
5267 if (set_value(&opt_reverb_control, atoi(++p), 1, 0x7f,
5270 opt_reverb_control = -opt_reverb_control - 640;
5272 opt_reverb_control = 6;
5274 case '7': /* reverb ex2 */
5275 if ((p = strchr(arg, ',')) != NULL) {
5276 if (set_value(&opt_reverb_control, atoi(++p), 1, 0x7f,
5279 opt_reverb_control = -opt_reverb_control - 768;
5281 opt_reverb_control = 7;
5283 case '8': /* global reverb ex2 */
5284 if ((p = strchr(arg, ',')) != NULL) {
5285 if (set_value(&opt_reverb_control, atoi(++p), 1, 0x7f,
5288 opt_reverb_control = -opt_reverb_control - 896;
5290 opt_reverb_control = 8;
5293 case 'v': /* reverb VST */
5294 if ((p = strchr(arg, ',')) != NULL) {
5295 if (set_value(&opt_reverb_control, atoi(++p), 1, 0x7f,
5298 opt_reverb_control = -opt_reverb_control - 1024;
5300 opt_reverb_control = 9;
5302 case 'V': /* global reverb VST */
5303 if ((p = strchr(arg, ',')) != NULL) {
5304 if (set_value(&opt_reverb_control, atoi(++p), 1, 0x7f,
5307 opt_reverb_control = -opt_reverb_control - 1152;
5309 opt_reverb_control = 10;
5313 ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "Invalid reverb parameter.");
5319 static int parse_opt_reverb_freeverb(const char *arg, char type)
5324 if ((p = strchr(arg, ',')) != NULL)
5329 if (*p && *p != ',') {
5330 if (set_value(&opt_reverb_control, atoi(p), 1, 0x7f,
5334 opt_reverb_control = -opt_reverb_control - 256;
5336 opt_reverb_control = -opt_reverb_control - 384;
5338 opt_reverb_control = (type == 'f') ? 3 : 4;
5339 if ((p = strchr(p, ',')) == NULL)
5342 /* ranges 0..10 below determined just to reject an extreme value */
5344 if (*p && *p != ',') {
5345 if (parse_val_float_t(&freeverb_scaleroom, p, 0, 10,
5346 "Freeverb scaleroom"))
5349 if ((p = strchr(p, ',')) == NULL)
5353 if (*p && *p != ',') {
5354 if (parse_val_float_t(&freeverb_offsetroom, p, 0, 10,
5355 "Freeverb offsetroom"))
5358 if ((p = strchr(p, ',')) == NULL)
5361 /* predelay factor */
5362 if (*p && *p != ',') {
5365 if (set_val_i32(&value, atoi(p), 0, 1000,
5366 "Freeverb predelay factor"))
5368 reverb_predelay_factor = value * DIV_100;
5373 static inline int parse_opt_voice_lpf(const char *arg)
5379 case 'd': /* disable */
5383 case 'c': /* chamberlin */
5387 case 'm': /* moog */
5391 case 'b': /* ButterworthFilter */
5394 case '4': /* Resonant IIR */
5398 case '5': /* amSynth */
5402 case '6': /* 1 pole 6db/oct */
5406 case '7': /* LPF18 18db/oct */
5410 case '8': /* two first order low-pass filter */
5414 case '9': /* HPF ButterworthFilter */
5418 case 'B': /* BPF ButterworthFilter */
5422 ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "Invalid voice LPF type %s", arg);
5428 static inline int parse_opt_voice_hpf(const char *arg)
5434 case 'd': /* disable */
5438 case 'b': /* ButterworthFilter hpf */
5442 case 'c': /* lpf12-3 */
5446 case 'o': /* 1 pole 6db/oct */
5450 ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "Invalid voice HPF type %s", arg);
5456 /* Noise Shaping filter from
5457 * Kunihiko IMAI <imai@leo.ec.t.kanazawa-u.ac.jp>
5459 static inline int parse_opt_noise_shaping(const char *arg)
5461 /* --noise-shaping */
5463 if (set_value(&noise_sharp_type, atoi(arg), 0, 4, "Noise shaping type"))
5468 static inline int parse_opt_resample(const char *arg)
5474 if(num > RESAMPLE_MAX - 1){
5475 ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "Invalid resample type %s", arg);
5476 opt_resample_type = DEFAULT_RESAMPLATION_NUM;
5479 opt_resample_type = num;
5484 case 'd': /* disable */
5485 opt_resample_type = RESAMPLE_NONE;
5488 case 'l': /* linear */
5489 opt_resample_type = RESAMPLE_LINEAR;
5492 case 'c': /* cspline */
5493 opt_resample_type = RESAMPLE_CSPLINE;
5496 case 'L': /* lagrange */
5497 opt_resample_type = RESAMPLE_LAGRANGE;
5500 case 'n': /* newton */
5501 opt_resample_type = RESAMPLE_NEWTON;
5504 case 'g': /* guass */
5505 opt_resample_type = RESAMPLE_GAUSS;
5509 case 's': /* sharp */
5510 opt_resample_type = RESAMPLE_SHARP;
5513 case 'p': /* linear % */
5514 opt_resample_type = RESAMPLE_LINEAR_P;
5516 case '8': /* sine */
5517 opt_resample_type = RESAMPLE_SINE;
5519 case '9': /* square */
5520 opt_resample_type = RESAMPLE_SQUARE;
5523 ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "Invalid resample type %s", arg);
5524 opt_resample_type = DEFAULT_RESAMPLATION_NUM;
5530 static inline int parse_opt_e(const char *arg)
5537 ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "-e option is not supported");
5539 #endif /* __W32__ */
5542 static inline int parse_opt_F(const char *arg)
5545 adjust_panning_immediately = y_or_n_p(arg);
5549 static inline int parse_opt_f(const char *arg)
5552 fast_decay = y_or_n_p(arg);
5556 static inline int parse_opt_G(const char *arg)
5558 /* play just sub-segment(s) (seconds) */
5560 const char *p = arg;
5563 if (strchr(arg, 'm'))
5564 return parse_opt_G1(arg);
5565 if (time_segments == NULL) {
5566 time_segments = (TimeSegment *) safe_malloc(sizeof(TimeSegment));
5567 time_segments->type = 0;
5568 if (parse_segment(time_segments, p)) {
5569 free_time_segments();
5572 time_segments->prev = time_segments->next = NULL, sp = time_segments;
5574 for (sp = time_segments; sp->next != NULL; sp = sp->next)
5576 sp->next = (TimeSegment *) safe_malloc(sizeof(TimeSegment));
5578 if (parse_segment(sp->next, p)) {
5579 free_time_segments();
5582 sp->next->prev = sp, sp->next->next = NULL, sp = sp->next;
5584 while ((p = strchr(p, ',')) != NULL) {
5585 sp->next = (TimeSegment *) safe_malloc(sizeof(TimeSegment));
5587 if (parse_segment(sp->next, ++p)) {
5588 free_time_segments();
5591 sp->next->prev = sp, sp->next->next = NULL, sp = sp->next;
5594 for (sp = time_segments; sp != NULL; sp = sp->next) {
5597 if (sp->begin.s <= prev_end) {
5598 ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "Segments must be ordered");
5599 free_time_segments();
5601 } else if (sp->end.s != -1 && sp->begin.s >= sp->end.s) {
5602 ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "Segment time must be ordered");
5603 free_time_segments();
5606 prev_end = sp->end.s;
5611 static inline int parse_opt_G1(const char *arg)
5613 /* play just sub-segment(s) (measure) */
5615 const char *p = arg;
5616 int prev_end_meas, prev_end_beat;
5618 if (time_segments == NULL) {
5619 time_segments = (TimeSegment *) safe_malloc(sizeof(TimeSegment));
5620 time_segments->type = 1;
5621 if (parse_segment2(time_segments, p)) {
5622 free_time_segments();
5625 time_segments->prev = time_segments->next = NULL, sp = time_segments;
5627 for (sp = time_segments; sp->next != NULL; sp = sp->next)
5629 sp->next = (TimeSegment *) safe_malloc(sizeof(TimeSegment));
5631 if (parse_segment2(sp->next, p)) {
5632 free_time_segments();
5635 sp->next->prev = sp, sp->next->next = NULL, sp = sp->next;
5637 while ((p = strchr(p, ',')) != NULL) {
5638 sp->next = (TimeSegment *) safe_malloc(sizeof(TimeSegment));
5640 if (parse_segment2(sp->next, ++p)) {
5641 free_time_segments();
5644 sp->next->prev = sp, sp->next->next = NULL, sp = sp->next;
5646 prev_end_meas = prev_end_beat = -1;
5647 for (sp = time_segments; sp != NULL; sp = sp->next) {
5650 if (sp->begin.m.meas * 16 + sp->begin.m.beat
5651 <= prev_end_meas * 16 + prev_end_beat) {
5652 ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "Segments must be ordered");
5653 free_time_segments();
5655 } else if (sp->end.m.meas != -1 && sp->end.m.beat != -1
5656 && sp->begin.m.meas * 16 + sp->begin.m.beat
5657 >= sp->end.m.meas * 16 + sp->end.m.beat) {
5658 ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "Segment time must be ordered");
5659 free_time_segments();
5662 prev_end_meas = sp->end.m.meas, prev_end_beat = sp->end.m.beat;
5667 static int parse_segment(TimeSegment *seg, const char *p)
5673 else if (parse_time(&seg->begin.s, p))
5675 p = ((q = strchr(p, '-')) == NULL) ? p + strlen(p) : q + 1;
5676 if (*p == ',' || *p == '\0')
5678 else if (parse_time(&seg->end.s, p))
5683 static int parse_segment2(TimeSegment *seg, const char *p)
5688 seg->begin.m.meas = seg->begin.m.beat = 1;
5689 else if (parse_time2(&seg->begin.m, p))
5691 p = ((q = strchr(p, '-')) == NULL) ? p + strlen(p) : q + 1;
5692 if (*p == ',' || *p == 'm')
5693 seg->end.m.meas = seg->end.m.beat = -1;
5694 else if (parse_time2(&seg->end.m, p))
5699 static int parse_time(FLOAT_T *param, const char *p)
5701 const char *p1, *p2, *p3;
5705 p1 = ((p1 = strchr(p, ':')) == NULL) ? p + strlen(p) : p1;
5706 p2 = ((p2 = strchr(p, '-')) == NULL) ? p + strlen(p) : p2;
5707 p3 = ((p3 = strchr(p, ',')) == NULL) ? p + strlen(p) : p3;
5708 if ((p1 < p2 && p2 <= p3) || (p1 < p3 && p3 <= p2)) {
5709 if (set_value(&min, atoi(p), 0, 59, "Segment time (min part)"))
5711 if (parse_val_float_t(&sec, p1 + 1, 0, 59.999,
5712 "Segment time (sec+frac part)"))
5714 *param = min * 60 + sec;
5715 } else if (parse_val_float_t(param, p, 0, 3599.999, "Segment time"))
5720 static int parse_time2(Measure *param, const char *p)
5722 const char *p1, *p2, *p3;
5724 if (set_value(¶m->meas, atoi(p), 0, 999, "Segment time (measure)"))
5726 p1 = ((p1 = strchr(p, '.')) == NULL) ? p + strlen(p) : p1;
5727 p2 = ((p2 = strchr(p, '-')) == NULL) ? p + strlen(p) : p2;
5728 p3 = ((p3 = strchr(p, ',')) == NULL) ? p + strlen(p) : p3;
5729 if ((p1 < p2 && p2 <= p3) || (p1 < p3 && p3 <= p2)) {
5730 if (set_value(¶m->beat, atoi(p1 + 1), 1, 15,
5731 "Segment time (beat)"))
5738 static inline int parse_opt_g(const char *arg)
5740 #ifdef SUPPORT_SOUNDSPEC
5742 spectrogram_update_sec = atof(arg);
5743 if (spectrogram_update_sec <= 0) {
5744 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
5745 "Invalid -g argument: `%s'", arg);
5748 view_soundspec_flag = 1;
5751 ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "-g option is not supported");
5753 #endif /* SUPPORT_SOUNDSPEC */
5756 static inline int parse_opt_H(const char *arg)
5758 /* force keysig (number of sharp/flat) */
5762 if (set_value(&keysig, atoi(arg), -7, 7,
5763 "Force keysig (number of sHarp(+)/flat(-))"))
5765 opt_force_keysig = keysig;
5769 __attribute__((noreturn))
5770 #ifndef __BORLANDC__
5771 static inline int parse_opt_h(const char *arg)
5773 static int parse_opt_h(const char *arg)
5776 static char *help_list[] = {
5777 "TiMidity++ %s (C) 1999-2018 Masanao Izumo <iz@onicos.co.jp>",
5778 "The original version (C) 1995 Tuukka Toivonen <tt@cgs.fi>",
5779 "TiMidity is free software and comes with ABSOLUTELY NO WARRANTY.",
5782 "Win32 version by Davide Moretti <dave@rimini.com>",
5783 " and Daisuke Aoki <dai@y7.net>",
5785 #endif /* __W32__ */
5787 " %s [options] filename [...]",
5789 #ifndef __W32__ /*does not work in Windows */
5790 " Use \"-\" as filename to read a MIDI file from stdin",
5794 " -A n,m --volume=n, --drum-power=m",
5795 " Amplify volume by n percent (may cause clipping),",
5796 " and amplify drum power by m percent",
5797 " (a) --[no-]volume-compensation",
5798 " Toggle amplify compensation (disabled by default)",
5799 " -a --[no-]anti-alias",
5800 " Enable the anti-aliasing filter",
5801 " -B n,m --buffer-fragments=n,m",
5802 " Set number of buffer fragments(n), and buffer size(2^m)",
5803 " -C n --control-ratio=n",
5804 " Set ratio of sampling and control frequencies (0...255)",
5805 " -c file --config-file=file",
5806 " Read extra configuration file",
5807 " -D n --drum-channel=n",
5808 " Play drums on channel n",
5810 " -d path --interface-path=path",
5811 " Set dynamic interface module directory",
5812 #endif /* IA_DYNAMIC */
5813 " -E mode --ext=mode",
5814 " TiMidity sequencer extensional modes:",
5815 " mode = w/W : Enable/Disable Modulation wheel",
5816 " p/P : Enable/Disable Portamento",
5817 " v/V : Enable/Disable NRPN Vibrato",
5818 " s/S : Enable/Disable Channel pressure",
5819 " e/E : Enable/Disable Modulation Envelope",
5820 " t/T : Enable/Disable Trace Text Meta Event at playing",
5821 " o/O : Enable/Disable Overlapped voice",
5822 " z/Z : Enable/Disable Temperament control",
5823 " j/J : Enable/Disable Insertion effect",
5824 " q/Q : Enable/Disable EQ",
5825 " d/D : Enable/Disable Drumpart effect",
5826 " x/X : Enable/Disable TVA envelope control",
5827 " c/C : Enable/Disable CC#94 delay(celeste) effect",
5828 " m<HH>: Define default Manufacture ID <HH> in two hex",
5829 " M<HH>: Define system Manufacture ID <HH> in two hex",
5830 " b<n>: Use tone bank <n> as the default",
5831 " B<n>: Always use tone bank <n>",
5832 " i<n/m>: Use program <n> on channel <m> as the default",
5833 " I<n/m>: Always use program <n> on channel <m>",
5834 " F<args>: For effect. See below for effect options",
5836 #ifdef MODULATION_WHEEL_ALLOW
5840 #endif /* MODULATION_WHEEL_ALLOW */
5841 #ifdef PORTAMENTO_ALLOW
5845 #endif /* PORTAMENTO_ALLOW */
5846 #ifdef NRPN_VIBRATO_ALLOW
5850 #endif /* NRPN_VIBRATO_ALLOW */
5851 #ifdef GM_CHANNEL_PRESSURE_ALLOW
5855 #endif /* GM_CHANNEL_PRESSURE_ALLOW */
5856 #ifdef MODULATION_ENVELOPE_ALLOW
5860 #endif /* MODULATION_ENVELOPE_ALLOW */
5861 #ifdef ALWAYS_TRACE_TEXT_META_EVENT
5865 #endif /* ALWAYS_TRACE_TEXT_META_EVENT */
5866 #ifdef OVERLAP_VOICE_ALLOW
5870 #endif /* OVERLAP_VOICE_ALLOW */
5871 #ifdef TEMPER_CONTROL_ALLOW
5875 #endif /* TEMPER_CONTROL_ALLOW */
5884 " Increase thread priority (evil) - be careful!",
5886 " -F --[no-]fast-panning",
5887 " Disable/Enable fast panning (toggle on/off, default is on)",
5888 " -f --[no-]fast-decay",
5895 "fast decay mode (toggle)",
5902 #ifdef SUPPORT_SOUNDSPEC
5903 " -g sec --spectrogram=sec",
5904 " Open Sound-Spectrogram Window",
5905 #endif /* SUPPORT_SOUNDSPEC */
5906 " -H n --force-keysig=n",
5907 " Force keysig number of sHarp(+)/flat(-) (-7..7)",
5909 " Display this help message",
5910 " -i mode --interface=mode",
5911 " Select user interface (see below for list)",
5913 " --realtime-priority=n (for alsaseq only)",
5914 " Set the realtime priority (0-100)",
5915 " --sequencer-ports=n (for alsaseq only)",
5916 " Set the number of opened sequencer ports (default is 4)",
5918 #if defined(IA_WINSYN) || defined(IA_PORTMIDISYN) || defined(IA_NPSYN) || defined(IA_W32G_SYN)
5919 " --rtsyn-latency=sec (for rtsyn only)",
5920 " Set the realtime latency (sec)",
5921 " (default is 0.2 sec, minimum is 0.04 sec)",
5923 " -j --[no-]realtime-load",
5924 " Realtime load instrument (toggle on/off)",
5925 " -K n --adjust-key=n",
5926 " Adjust key by n half tone (-24..24)",
5927 " -k msec --voice-queue=msec",
5928 " Specify audio queue time limit to reduce voice",
5929 " -L path --patch-path=path",
5930 " Append dir to search path",
5931 " -l n --resample-filter=n",
5932 " n=0 : Disable filtration",
5933 #if !defined(DEFAULT_RESAMPLATION_FILTER) || (DEFAULT_RESAMPLATION_FILTER == 0)
5936 " 1 : LPFBW (Butterworth) x1",
5937 #if defined(DEFAULT_RESAMPLATION_FILTER) && (DEFAULT_RESAMPLATION_FILTER == 1)
5940 " 2 : LPFBW (Butterworth) x2",
5941 #if defined(DEFAULT_RESAMPLATION_FILTER) && (DEFAULT_RESAMPLATION_FILTER == 2)
5944 " 3 : LPFBW (Butterworth) x3",
5945 #if defined(DEFAULT_RESAMPLATION_FILTER) && (DEFAULT_RESAMPLATION_FILTER == 3)
5948 " 4 : LPFBW (Butterworth) x4",
5949 #if defined(DEFAULT_RESAMPLATION_FILTER) && (DEFAULT_RESAMPLATION_FILTER == 4)
5952 " 5 : LPFAM (24dB/oct)-2 x1",
5953 #if defined(DEFAULT_RESAMPLATION_FILTER) && (DEFAULT_RESAMPLATION_FILTER == 5)
5956 " 6 : LPFAM (24dB/oct)-2 x2",
5957 #if defined(DEFAULT_RESAMPLATION_FILTER) && (DEFAULT_RESAMPLATION_FILTER == 6)
5961 #if defined(DEFAULT_RESAMPLATION_FILTER) && (DEFAULT_RESAMPLATION_FILTER == 7)
5964 " -M name --pcm-file=name",
5965 " Specify PCM filename (*.wav or *.aiff) to be played or:",
5966 " \"auto\" : Play *.mid.wav or *.mid.aiff",
5967 " \"none\" : Disable this feature (default)",
5968 " -m msec --decay-time=msec",
5969 " Minimum time for a full volume sustained note to decay,",
5971 " -N n --interpolation=n",
5972 " Set the interpolation parameter (depends on -EFresamp option)",
5973 " Linear interpolation is used if audio queue < 99%s",
5974 " cspline, lagrange:",
5975 " Toggle 4-point interpolation (default on)",
5978 " n'th order Newton polynomial interpolation, n=1-45 odd",
5981 " n+1 point Gauss-like interpolation, n=2-32 (default 24)",
5983 " n+1 point Sharp interpolation, n=2-8 (default 6)",
5985 " n=0-100 (default 100)",
5986 " -O mode --output-mode=mode",
5987 " Select output mode and format (see below for list)",
5988 " --wave-extensible (for RIFF WAVE file only)",
5989 " Enable WAVE_FORMAT_EXTENSIBLE tag (GUID)",
5990 " --wave-update-step=n (for RIFF WAVE file only)",
5991 " Update RIFF to n KBytes per. n=0-9999 (default is 512)",
5993 " --flac-verify (for FLAC / OggFLAC only)",
5994 " Verify a correct encoding",
5995 " --flac-padding=n (for FLAC / OggFLAC only)",
5996 " Write a PADDING block of length n",
5997 " --flac-complevel=n (for FLAC / OggFLAC only)",
5998 " Set compression level n:[0..8]",
6000 " --oggflac (for Ogg FLAC only)",
6001 " Output OggFLAC stream (experimental)",
6002 #endif /* AU_OGGFLAC */
6003 #endif /* AU_FLAC */
6005 " --opus-nframes=n (for Ogg Opus only)",
6006 " Number of frames per Opus packet",
6007 " n:[120, 240, 480, 960, 1920, 2880] (default is 960)",
6008 " --opus-bitrate=n (for Ogg Opus only)",
6009 " Encoding average bit-rate n:[5-512,513-512000] (default is 128)",
6010 " --opus-complexity=n (for Ogg Opus only)",
6011 " Set encoding complexity n:[0..10] (default is 10)",
6012 " --[no-]opus-vbr (for Ogg Opus only)",
6013 " Enable variable bit-rate (VBR) (default on)",
6014 " --[no-]opus-cvbr (for Ogg Opus only)",
6015 " Enable constrained variable bit-rate (CVBR) (default on)",
6016 #endif /* AU_OPUS */
6018 " --speex-quality=n (for Ogg Speex only)",
6019 " Encoding quality n:[0..10]",
6020 " --speex-vbr (for Ogg Speex only)",
6021 " Enable variable bit-rate (VBR)",
6022 " --speex-abr=n (for Ogg Speex only)",
6023 " Enable average bit-rate (ABR) at rate bps",
6024 " --speex-vad (for Ogg Speex only)",
6025 " Enable voice activity detection (VAD)",
6026 " --speex-dtx (for Ogg Speex only)",
6027 " Enable file-based discontinuous transmission (DTX)",
6028 " --speex-complexity=n (for Ogg Speex only)",
6029 " Set encoding complexity n:[0-10]",
6030 " --speex-nframes=n (for Ogg Speex only)",
6031 " Number of frames per Ogg packet n:[0-10]",
6033 " --output-device-id=n",
6035 " --wmme-device-id=n (for Windows only)",
6036 " Number of WMME device ID (-1: Default device, 0..19: other)",
6037 " --wave-format-ext=n , --wmme-format-ext=n (for Windows only)",
6038 " WMME Enable WAVE_FORMAT_EXTENSIBLE (default is 1)",
6041 " --wdmks-device-id=n (for Windows only)",
6042 " Number of WDMKS device ID (0..19:)",
6043 " --wdmks-latency=n (for Windows only)",
6044 " WDMKS Latency ms n=1-9999 depend device (default is 20)",
6045 " --wdmks-format-ext=n (for Windows only)",
6046 " WDMKS Enable WAVE_FORMAT_EXTENSIBLE (default is 1)",
6047 " --wdmks-realtime=n (for Windows only)",
6048 " WDMKS 0:WaveCyclic 1:WaveRT (default is 0)",
6049 " supported since Windows Vista",
6050 " --wdmks-polling=n (for Windows only)",
6051 " WDMKS Flags RT 0:Event 1:Polling (default is 0)",
6052 " --wdmks_priority=n (for Windows only)",
6053 " WDMKS ThreadPriority (default is 1)",
6054 " 0:Low , 1:Normal , 2:High , 3:Exclusive",
6055 " --wdmks_priority-rt=n (for Windows only)",
6056 " WDMKS ThreadPriority RT (default is 0)",
6057 " 0:Auto(Audio) , 1:Audio , 2:Capture , 3:Distribution , 4:Games , 5:playback , 6:ProAudio , 7:WindowManager",
6060 " --wasapi-device-id=n (for Windows only)",
6061 " Number of WASAPI device ID (-1: Default device, 0..19: other)",
6062 " --wasapi-latency=n (for Windows only)",
6063 " WASAPI Latency ms n=1-9999 depend device (default is 10)",
6064 " --wasapi-format-ext=n (for Windows only)",
6065 " WASAPI Enable WAVE_FORMAT_EXTENSIBLE (default is 1)",
6066 " --wasapi-exclusive=n (for Windows only)",
6067 " WASAPI 0:Shared mode 1:Exclusive mode (default is 0)",
6068 " --wasapi-polling=n (for Windows only)",
6069 " WASAPI Flags 0:Event 1:Polling (default is 0)",
6070 " --wasapi_priority=n (for Windows only)",
6071 " WASAPI ThreadPriority (default is 0)",
6072 " 0:None , 1:Audio , 2:Capture , 3:Distribution , 4:Games , 5:playback , 6:ProAudio , 7:WindowManager",
6073 " --wasapi-stream-category=n (for Windows only)",
6074 " WASAPI StreamCategory (default is 0)",
6075 " 0:Other , 1:None , 2:None , 3:Communications , 4:Alerts , 5:SoundEffects ,",
6076 " 6:GameEffects , 7:GameMedia , 8:GameChat , 9:Speech , 10:Movie , 11:Media",
6077 " values 1,2 are deprecated on Windows 10 and not included into enumeration",
6078 " --wasapi-stream-option=n (for Windows only)",
6079 " WASAPI StreamOption 0:None 1:Raw 2:MatchFormat (default is 0)",
6080 " 1:Raw bypass WASAPI Audio Engine DSP effects, supported since Windows 8.1",
6083 " --pa-asio-device-id=n",
6084 " Number of PortAudio device ID (-2: Default device, 0..99: other)",
6086 " --pa-wmme-device-id=n (for Windows only)",
6087 " Number of PortAudio device ID (-2: Default device, 0..99: other)",
6088 " --pa-ds-device-id=n (for Windows only)",
6089 " Number of PortAudio device ID (-2: Default device, 0..99: other)",
6090 #ifdef PORTAUDIO_V19
6091 " --pa-wdmks-device-id=n (for Windows only)",
6092 " Number of PortAudio device ID (-2: Default device, 0..99: other)",
6093 " --pa-wasapi-device-id=n (for Windows only)",
6094 " Number of PortAudio device ID (-2: Default device, 0..99: other)",
6095 " --pa-wasapi-flag=n",
6099 " --add-play-time=sec (default is 0.5)",
6100 " --add-silent-time=sec (default is 0.5)",
6101 " --emu-delay-time=sec (default is 0.1)",
6102 #if defined(__W32__)
6103 " --process-priority=n (for Windows only)",
6104 #if !defined(IA_W32G_SYN)
6105 " --player-thread-priority=n (for Windows only)",
6108 " -o file --output-file=file",
6109 " Output to another file (or device/server) (Use \"-\" for stdout)",
6110 #if defined(AU_PORTAUDIO) || defined(AU_WIN32)
6111 " Set the output device no. (-1 shows available device no. list)",
6113 " -P file --patch-file=file",
6114 " Use patch file for all programs",
6115 " -p n --polyphony=n",
6116 " Allow n-voice polyphony. Optional auto polyphony reduction",
6117 " (a) --[no-]polyphony-reduction",
6118 " Toggle automatic polyphony reduction. Enabled by default",
6119 " -Q n[,...] --mute=n[,...]",
6120 " Ignore channel n (0: ignore all, -n: resume channel n)",
6121 " (t) --temper-mute=n[,...]",
6122 " Quiet temperament type n (0..3: preset, 4..7: user-defined)",
6123 " --preserve-silence",
6124 " Do not drop initial silence. Default: drop initial silence",
6125 " -q sec/n --audio-buffer=sec/n",
6126 " Specify audio buffer in seconds",
6127 " sec: Maxmum buffer, n: Filled to start (default is 5.0/100%s)",
6128 " (size of 100%s equals device buffer size)",
6129 " -R msec Pseudo reveb effect (set every instrument's release to msec)",
6130 " if n=0, n is set to 800",
6131 " -r n --resample-queue=n",
6132 " Specify audio queue time limit to reduce resample quality",
6133 " n: size of 100 equals device buffer size",
6134 " -S n --cache-size=n",
6135 " Cache size (0 means no cache)",
6136 " -s freq --sampling-freq=freq",
6137 " Set sampling frequency to freq (Hz or kHz)",
6138 " -T n --adjust-tempo=n",
6139 " Adjust tempo to n%s,",
6140 " 120=play MOD files with an NTSC Amiga's timing",
6141 " -t code --output-charset=code",
6142 " Output text language code:",
6143 " code=auto : Auto conversion by `LANG' environment variable",
6145 " ascii : Convert unreadable characters to '.' (0x2e)",
6146 " nocnv : No conversion",
6147 " 1251 : Convert from windows-1251 to koi8-r",
6151 " sjis : shift JIS",
6152 #endif /* JAPANESE */
6153 " -U --[no-]unload-instruments",
6154 " Unload instruments from memory between MIDI files",
6155 #ifdef AU_VOLUME_CALC
6156 " --volume-calc-rms",
6157 " Soundfont Volume Calc output to `root mean square' format",
6158 " --volume-calc-trim",
6159 " Trim silence samples",
6160 #endif /* AU_VOLUME_CALC */
6161 " -V power --volume-curve=power",
6162 " Define the velocity/volume/expression curve",
6163 " amp = vol^power (auto: 0, linear: 1, ideal: ~1.661, GS: ~2)",
6165 " Display TiMidity version information",
6166 " -W mode --wrd=mode",
6167 " Select WRD interface (see below for list)",
6169 " -w mode --rcpcv-dll=mode",
6170 " Windows extensional modes:",
6171 " mode=r/R : Enable/Disable rcpcv.dll",
6172 #endif /* __W32__ */
6173 " -x str --config-string=str",
6174 " Read configuration str from command line argument",
6175 " -Z file --freq-table=file",
6176 " Load frequency table (Use \"pure\" for pure intonation)",
6177 " pure<n>(m) --pure-intonation=n(m)",
6178 " Initial keysig number <n> of sharp(+)/flat(-) (-7..7)",
6179 " 'm' stands for minor mode",
6182 " Simulate behavior of specific synthesizer module by n",
6183 " n=0 : TiMidity++ Default (default)",
6184 " 1-4 : Roland SC family",
6185 " 5-15 : GS family",
6186 " 16-23 : Yamaha MU family",
6187 " 24-31 : XG family",
6188 " 32-33 : SoundBlaster family",
6189 " 56-79 : LA family",
6190 " 80-84 : KORG family",
6191 " 96-98 : SD series",
6192 " 99-111 : other systhesizer modules",
6193 " 112-127 : TiMidity++ specification purposes",
6194 " --mix-envelope=n",
6195 " --cut-short-time=msec",
6196 " --limiter=n (gain per)",
6197 #ifdef SUPPORT_LOOPEVENT
6199 " Set number of unwind repeat count",
6200 " --loop-filter=types",
6201 " Enable loop-event types:",
6202 " type=0 : Filter reset",
6203 " 1 : CC#111 - Last End of Track",
6205 " l : Mark Loop_Start - Loop_End",
6207 " All: --loop-filter=1ml2",
6208 #endif /* SUPPORT_LOOPEVENT */
6209 #ifdef ENABLE_THREAD
6210 " --compute-thread-num=n",
6211 " Set number of divide multi-threads (0..16)",
6212 " (0..1 means single-thread, default is 0)",
6213 #endif /* ENABLE_THREAD */
6215 " Set GS overdrive-amplify-level (1..400:default=100)",
6217 " Set GS overdrive-drive-level (1..400:default=100)",
6219 " Set XG overdrive-amplify-level (1..400:default=100)",
6221 " Set XG overdrive-drive-level (1..400:default=100)",
6222 #if defined(PRE_RESAMPLATION) || defined(DEFAULT_PRE_RESAMPLATION)
6223 " --pre-resample=n",
6227 void show_ao_device_info(FILE *fp);
6229 char version[64], *help_args[7], per_mark[2];
6232 ControlMode *cmp, **cmpp;
6234 PlayMode *pmp, **pmpp;
6235 WRDTracer *wlp, **wlpp;
6238 strcpy(version, (!strstr(timidity_version, "current")) ? "version " : "");
6239 strcat(version, timidity_version);
6240 strcat(version, " ");
6241 strcat(version, arch_string);
6244 help_args[0] = version;
6245 help_args[1] = program_name;
6246 help_args[2] = per_mark;
6247 help_args[3] = per_mark;
6248 help_args[4] = per_mark;
6249 help_args[5] = per_mark;
6250 help_args[6] = NULL;
6251 for (i = 0, j = 0; (h = help_list[i]) != NULL; i++) {
6252 if (strchr(h, '%')) {
6253 if (*(strchr(h, '%') + 1) != '%')
6254 fprintf(fp, h, help_args[j++]);
6256 fprintf(fp, "%s", h);
6262 fputs("Effect options (-EF, --ext=F option):" NLS
6263 " -EFdelay=d Disable delay effect (default)" NLS
6264 " -EFdelay=D Enable delay effect" NLS
6265 " -EFchorus=d Disable MIDI chorus effect control" NLS
6266 " -EFchorus=n Enable Normal MIDI chorus effect control" NLS
6267 " [,level] `level' is optional to specify chorus level [0..127]" NLS
6269 " -EFchorus=s Surround sound, chorus detuned to a lesser degree" NLS
6270 " [,level] `level' is optional to specify chorus level [0..127]" NLS
6271 " -EFreverb=d Disable MIDI reverb effect control" NLS
6272 #if !defined(REVERB_CONTROL_ALLOW) && !defined(FREEVERB_CONTROL_ALLOW)
6275 " -EFreverb=n Enable Normal MIDI reverb effect control" NLS
6276 " [,level] `level' is optional to specify reverb level [1..127]" NLS
6277 #if defined(REVERB_CONTROL_ALLOW)
6280 " -EFreverb=g Global reverb effect" NLS
6281 " [,level] `level' is optional to specify reverb level [1..127]" NLS
6282 " -EFreverb=f Enable Freeverb MIDI reverb effect control" NLS
6283 " [,level] `level' is optional to specify reverb level [1..127]" NLS
6284 #if !defined(REVERB_CONTROL_ALLOW) && defined(FREEVERB_CONTROL_ALLOW)
6287 " -EFreverb=G Global Freeverb effect" NLS
6288 " [,level] `level' is optional to specify reverb level [1..127]" NLS
6289 " -EFvlpf=d Disable voice LPF" NLS
6290 #if !defined(VOICE_MOOG_LPF_ALLOW) && !defined(VOICE_CHAMBERLIN_LPF_ALLOW)
6293 " -EFvlpf=c Enable Chamberlin resonant LPF (12dB/oct)" NLS
6294 #if defined(VOICE_CHAMBERLIN_LPF_ALLOW)
6297 " -EFvlpf=m Enable Moog resonant lowpass VCF (24dB/oct)" NLS
6298 #if defined(VOICE_MOOG_LPF_ALLOW) && !defined(VOICE_CHAMBERLIN_LPF_ALLOW)
6301 " -EFvlpf=b Enable ButterworthFilter resonant lowpass (butterworth)" NLS
6302 " -EFvlpf=i Enable Resonant IIR lowpass VCF (12dB/oct)-2" NLS
6303 " -EFvlpf=a Enable amSynth resonant lowpass VCF (24dB/oct)-2" NLS
6304 " -EFvlpf=o Enable 1 pole 6db/oct resonant lowpass VCF (6dB/oct)" NLS
6305 " -EFvlpf=e Enable resonant 3 pole lowpass VCF (18dB/oct)" NLS
6306 " -EFvlpf=t Enable two first order lowpass VCF " NLS
6307 " -EFvlpf=h Enable HPF ButterworthFilter VCF (butterworth)" NLS
6308 " -EFvlpf=B Enable BPF ButterworthFilter VCF (butterworth)" NLS
6309 " -EFns=n Enable the n'th degree (type) noise shaping filter" NLS
6310 " n:[0..4] (for 8-bit linear encoding, default is 4)" NLS
6311 " n:[0..4] (for 16-bit linear encoding, default is 4)" NLS
6312 " n:[0] (for 24-bit linear encoding, default is 0)" NLS
6313 " n:[0] (for 32-bit linear encoding, default is 0)" NLS
6314 " n:[0] (for 64-bit linear encoding, default is 0)" NLS
6315 " n:[0] (for float 32-bit linear encoding, default is 0)" NLS
6316 " n:[0] (for float 64-bit linear encoding, default is 0)" NLS, fp);
6317 #ifndef FIXED_RESAMPLATION
6318 #ifdef HAVE_STRINGIZE
6319 #define tim_str_internal(x) #x
6320 #define tim_str(x) tim_str_internal(x)
6322 #define tim_str(x) "x"
6324 fputs(" -EFresamp=d Disable resamplation", fp);
6325 if (! strcmp(tim_str(DEFAULT_RESAMPLATION), "resample_none"))
6326 fputs(" (default)", fp);
6328 fputs(" -EFresamp=l Enable Linear resample algorithm", fp);
6329 if (! strcmp(tim_str(DEFAULT_RESAMPLATION), "resample_linear"))
6330 fputs(" (default)", fp);
6332 fputs(" -EFresamp=c Enable C-spline resample algorithm", fp);
6333 if (! strcmp(tim_str(DEFAULT_RESAMPLATION), "resample_cspline"))
6334 fputs(" (default)", fp);
6336 fputs(" -EFresamp=L Enable Lagrange resample algorithm", fp);
6337 if (! strcmp(tim_str(DEFAULT_RESAMPLATION), "resample_lagrange"))
6338 fputs(" (default)", fp);
6340 fputs(" -EFresamp=n Enable Newton resample algorithm", fp);
6341 if (! strcmp(tim_str(DEFAULT_RESAMPLATION), "resample_newton"))
6342 fputs(" (default)", fp);
6344 fputs(" -EFresamp=g Enable Gauss-like resample algorithm", fp);
6345 if (! strcmp(tim_str(DEFAULT_RESAMPLATION), "resample_gauss"))
6346 fputs(" (default)", fp);
6349 fputs(" -EFresamp=s Enable Sharp resample algorithm", fp);
6350 if (! strcmp(tim_str(DEFAULT_RESAMPLATION), "resample_sharp"))
6351 fputs(" (default)", fp);
6353 fputs(" -EFresamp=p Enable LinearP resample algorithm", fp);
6354 if (! strcmp(tim_str(DEFAULT_RESAMPLATION), "resample_linear_p"))
6355 fputs(" (default)", fp);
6357 " -EFresamp affects the behavior of -N option" NLS, fp);
6360 fputs("Alternative TiMidity sequencer extensional mode long options:" NLS
6361 " --[no-]mod-wheel" NLS
6362 " --[no-]portamento" NLS
6363 " --[no-]vibrato" NLS
6364 " --[no-]ch-pressure" NLS
6365 " --[no-]mod-envelope" NLS
6366 " --[no-]trace-text-meta" NLS
6367 " --[no-]overlap-voice" NLS
6369 " --overlap-voice-count=n" NLS
6370 " --[no-]temper-control" NLS
6371 " --default-mid=<HH>" NLS
6372 " --system-mid=<HH>" NLS
6373 " --default-bank=n" NLS
6374 " --force-bank=n" NLS
6375 " --default-program=n/m" NLS
6376 " --force-program=n/m" NLS
6377 " --delay=(d|D)" NLS
6378 " --chorus=(d|n|s|w|W|b|B|t|T|h|H|e|E)[,level]" NLS
6379 " --reverb=(d|n|g|f|G)[,level]" NLS
6380 " --reverb=(f|G)[,level[,scaleroom[,offsetroom[,predelay]]]]" NLS
6381 " --voice-lpf=(d|c|m|b|i|a|o|e|t|h|B)" NLS
6382 " --noise-shaping=n" NLS, fp);
6383 #ifndef FIXED_RESAMPLATION
6384 fputs(" --resample=(d|l|c|L|n|g|s|p)" NLS, fp);
6387 fputs("Available interfaces (-i, --interface option):" NLS, fp);
6388 for (cmpp = ctl_list; (cmp = *cmpp) != NULL; cmpp++)
6389 fprintf(fp, " -i%c %s" NLS,
6390 cmp->id_character, cmp->id_name);
6392 fprintf(fp, "Supported dynamic load interfaces (%s):" NLS,
6394 memset(mark, 0, sizeof(mark));
6395 for (cmpp = ctl_list; (cmp = *cmpp) != NULL; cmpp++)
6396 mark[(int) cmp->id_character] = 1;
6397 list_dyna_interface(fp, dynamic_lib_root, mark);
6398 #endif /* IA_DYNAMIC */
6400 fputs("Interface options (append to -i? option):" NLS
6401 " `v' more verbose (cumulative)" NLS
6402 " `q' quieter (cumulative)" NLS
6403 " `t' trace playing" NLS
6404 " `l' loop playing (some interface ignore this option)" NLS
6405 " `r' randomize file list arguments before playing" NLS
6406 " `s' sorting file list arguments before playing" NLS, fp);
6408 fputs(" `D' daemonize TiMidity++ in background "
6409 "(for alsaseq only)" NLS, fp);
6412 fputs("Alternative interface long options:" NLS
6417 " --[no-]random" NLS
6418 " --[no-]sort" NLS, fp);
6420 fputs(" --[no-]background" NLS, fp);
6423 fputs("Available output modes (-O, --output-mode option):" NLS, fp);
6424 for (pmpp = play_mode_list; (pmp = *pmpp) != NULL; pmpp++)
6425 fprintf(fp, " -O%c %s" NLS,
6426 pmp->id_character, pmp->id_name);
6428 fputs("Output format options (append to -O? option):" NLS
6430 " `M' monophonic" NLS
6431 " `s' signed output" NLS
6432 " `u' unsigned output" NLS
6433 " `1' 16-bit sample width" NLS
6434 " `2' 24-bit sample width" NLS
6435 " `3' 32-bit sample width" NLS
6436 " `6' 64-bit sample width" NLS
6437 " `8' 8-bit sample width" NLS
6438 " `f' float 32-bit sample width" NLS
6439 " `D' float 64-bit sample width" NLS
6440 " `l' linear encoding" NLS
6441 " `U' U-Law encoding" NLS
6442 " `A' A-Law encoding" NLS
6443 " `x' byte-swapped output" NLS, fp);
6445 fputs("Alternative output format long options:" NLS
6446 " --output-stereo" NLS
6447 " --output-mono" NLS
6448 " --output-signed" NLS
6449 " --output-unsigned" NLS
6450 " --output-16bit" NLS
6451 " --output-24bit" NLS
6452 " --output-32bit" NLS
6453 " --output-64bit" NLS
6454 " --output-8bit" NLS
6455 " --output-f32bit" NLS
6456 " --output-float32bit" NLS
6457 " --output-f64bit" NLS
6458 " --output-float64bit" NLS
6459 " --output-linear" NLS
6460 " --output-ulaw" NLS
6461 " --output-alaw" NLS
6462 " --[no-]output-swab" NLS, fp);
6464 fputs("Available WRD interfaces (-W, --wrd option):" NLS, fp);
6465 for (wlpp = wrdt_list; (wlp = *wlpp) != NULL; wlpp++)
6466 fprintf(fp, " -W%c %s" NLS, wlp->id, wlp->name);
6470 return 0; // dummy call
6475 static inline void list_dyna_interface(FILE *fp, char *path, char *mark)
6478 char fname[NAME_MAX];
6480 if ((dir = url_dir_open(path)) == NULL)
6482 #if defined(__W32__)
6487 if(chdir(path) != 0)
6489 while (url_gets(dir, fname, sizeof(fname)) != NULL)
6490 if (strncmp(fname, "if_", 3) == 0) {
6491 void* handle = NULL;
6492 char path[NAME_MAX];
6493 snprintf(path, NAME_MAX, ".%c%s", PATH_SEP, fname);
6494 if((handle = dl_load_file(path))) {
6495 ControlMode *(* loader)(void) = NULL;
6497 for (c = 'A'; c <= 'z'; c++) {
6498 char buf[20]; /* enough */
6499 if(mark[(int)c]) continue;
6500 sprintf(buf, "interface_%c_loader", c);
6501 if((loader = dl_find_symbol(handle, buf))) {
6502 fprintf(fp, " -i%c %s" NLS, c, loader()->id_name);
6511 dummy = fchdir(cwd);
6512 dummy += close(cwd);
6517 ControlMode *dynamic_interface_module(int id_char)
6520 char fname[FILEPATH_MAX];
6521 ControlMode *ctl = NULL;
6524 ControlMode *(* inferface_loader)(void);
6526 if ((url = url_dir_open(dynamic_lib_root)) == NULL)
6529 if(chdir(dynamic_lib_root) != 0)
6531 while (url_gets(url, fname, sizeof(fname)) != NULL) {
6532 if (strncmp(fname, "if_", 3) == 0) {
6533 char path[NAME_MAX], buff[20];
6534 snprintf(path, NAME_MAX-1, ".%c%s", PATH_SEP, fname);
6535 if((handle = dl_load_file(path)) == NULL)
6537 sprintf(buff, "interface_%c_loader", id_char);
6538 if((inferface_loader = dl_find_symbol(handle, buff)) == NULL) {
6542 ctl = inferface_loader();
6543 if(ctl->id_character == id_char)
6547 dummy = fchdir(cwd);
6548 dummy += close(cwd);
6552 #endif /* IA_DYNAMIC */
6554 static inline int parse_opt_i(const char *arg)
6556 /* interface mode */
6557 ControlMode *cmp, **cmpp;
6561 for (cmpp = ctl_list; (cmp = *cmpp) != NULL; cmpp++) {
6562 if (cmp->id_character == *arg) {
6565 #if defined(IA_W32GUI) || defined(IA_W32G_SYN)
6567 cmp->trace_playing = 0;
6569 #endif /* IA_W32GUI */
6575 cmp = dynamic_interface_module(*arg);
6581 #endif /* IA_DYNAMIC */
6583 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
6584 "Interface `%c' is not compiled in.", *arg);
6595 case 't': /* toggle */
6596 cmp->trace_playing = (cmp->trace_playing) ? 0 : 1;
6599 cmp->flags ^= CTLF_LIST_LOOP;
6602 cmp->flags ^= CTLF_LIST_RANDOM;
6605 cmp->flags ^= CTLF_LIST_SORT;
6608 cmp->flags ^= CTLF_AUTOSTART;
6611 cmp->flags ^= CTLF_AUTOEXIT;
6614 cmp->flags ^= CTLF_DRAG_START;
6617 cmp->flags ^= CTLF_AUTOUNIQ;
6620 cmp->flags ^= CTLF_AUTOREFINE;
6623 cmp->flags ^= CTLF_NOT_CONTINUE;
6626 cmp->flags ^= CTLF_DAEMONIZE;
6629 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
6630 "Unknown interface option `%c'", *arg);
6636 static inline int parse_opt_verbose(const char *arg)
6639 ctl->verbosity += (arg) ? atoi(arg) : 1;
6643 static inline int parse_opt_quiet(const char *arg)
6646 ctl->verbosity -= (arg) ? atoi(arg) : 1;
6650 static inline int parse_opt_trace(const char *arg)
6654 ctl->trace_playing = y_or_n_p(arg);
6658 static inline int parse_opt_loop(const char *arg)
6662 return set_flag(&(ctl->flags), CTLF_LIST_LOOP, arg);
6665 static inline int parse_opt_random(const char *arg)
6669 return set_flag(&(ctl->flags), CTLF_LIST_RANDOM, arg);
6672 static inline int parse_opt_sort(const char *arg)
6676 return set_flag(&(ctl->flags), CTLF_LIST_SORT, arg);
6680 static inline int parse_opt_background(const char *arg)
6682 /* --[no-]background */
6684 return set_flag(&(ctl->flags), CTLF_DAEMONIZE, arg);
6687 static inline int parse_opt_rt_prio(const char *arg)
6689 /* --realtime-priority */
6691 if (set_value(&opt_realtime_priority, atoi(arg), 0, 100,
6692 "Realtime priority"))
6697 static inline int parse_opt_seq_ports(const char *arg)
6699 /* --sequencer-ports */
6701 if (set_value(&opt_sequencer_ports, atoi(arg), 1, 16,
6702 "Number of sequencer ports"))
6708 #if defined(IA_WINSYN) || defined(IA_NPSYN) || defined(IA_PORTMIDI) || \
6709 defined(IA_W32G_SYN)
6710 static inline int parse_opt_rtsyn_latency(const char *arg)
6712 /* --rtsyn-latency */
6716 if (sscanf(arg, "%lf", &latency) == EOF)
6717 latency = RTSYN_LATENCY;
6718 rtsyn_set_latency(latency);
6722 static inline int parse_opt_rtsyn_skip_aq(const char *arg)
6724 /* --rtsyn-skip-aq */
6725 rtsyn_set_skip_aq(y_or_n_p(arg));
6729 __attribute__((noreturn))
6730 static inline int parse_opt_rtsyn_print_ports(const char *arg)
6732 /* --rtsyn-print-ports */
6733 const char c = ctl->id_character;
6734 if (c == 'W' || c == 'P') {
6736 rtsyn_get_port_list();
6737 rtsyn_print_port_list();
6742 #elif defined(IA_W32GUI)
6743 static inline int parse_opt_rtsyn_latency(const char *arg)
6745 /* --rtsyn-latency */
6748 static inline int parse_opt_rtsyn_skip_aq(const char *arg)
6750 /* --rtsyn-skip-aq */
6753 static inline int parse_opt_rtsyn_print_ports(const char *arg)
6755 /* --rtsyn-print-ports */
6760 static inline int parse_opt_j(const char *arg)
6763 opt_realtime_playing = y_or_n_p(arg);
6767 static inline int parse_opt_K(const char *arg)
6771 if (set_value(&key_adjust, atoi(arg), -24, 24, "Key adjust"))
6776 static inline int parse_opt_k(const char *arg)
6778 safe_free(opt_reduce_voice_threshold);
6779 opt_reduce_voice_threshold = safe_strdup(arg ? arg : DEFAULT_REDUCE_VOICE_THRESHOLD);
6780 // reduce_voice_threshold = atoi(arg);
6784 static inline int parse_opt_L(const char *arg)
6787 add_to_pathlist(arg);
6788 try_config_again = 1;
6792 static inline int parse_opt_l(const char *arg)
6795 opt_resample_filter = atoi(arg);
6799 static inline int parse_opt_resample_over_sampling(const char *arg)
6802 opt_resample_over_sampling = atoi(arg);
6806 static inline int parse_opt_pre_resample(const char *arg)
6809 opt_pre_resamplation = atoi(arg);
6813 static inline int parse_opt_M(const char *arg)
6815 safe_free(pcm_alternate_file);
6817 pcm_alternate_file = safe_strdup(arg);
6821 static inline int parse_opt_m(const char *arg)
6824 min_sustain_time = atoi(arg);
6825 if (min_sustain_time < 0)
6826 min_sustain_time = 0;
6830 static inline int parse_opt_N(const char *arg)
6833 opt_resample_param = atoi(arg);
6837 static inline int parse_opt_n(const char *arg)
6839 safe_free(opt_reduce_polyphony_threshold);
6840 opt_reduce_polyphony_threshold = safe_strdup(arg ? arg : DEFAULT_REDUCE_POLYPHONY_THRESHOLD);
6844 static inline int parse_opt_O(const char *arg)
6847 PlayMode *pmp, **pmpp, *prev_playmode;
6851 prev_playmode = play_mode;
6852 for (pmpp = play_mode_list; (pmp = *pmpp) != NULL; pmpp++)
6853 if (pmp->id_character == *arg) {
6859 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
6860 "Playmode `%c' is not compiled in.", *arg);
6863 if (prev_playmode) {
6864 if (prev_playmode->close_output) {
6865 prev_playmode->close_output();
6867 safe_free(prev_playmode->name);
6868 prev_playmode->name = NULL;
6872 case 'S': /* stereo */
6873 pmp->encoding &= ~PE_MONO;
6876 pmp->encoding |= PE_MONO;
6879 pmp->encoding |= PE_SIGNED;
6880 pmp->encoding &= ~(PE_ULAW | PE_ALAW);
6884 pmp->encoding &= ~PE_SIGNED;
6885 // pmp->encoding &= ~(PE_ULAW | PE_ALAW); // w32g can't use ULAW ALAW
6887 case 'D': /* D for float 64-bit */
6888 pmp->encoding |= PE_F64BIT;
6889 pmp->encoding &= ~(PE_16BIT | PE_24BIT | PE_32BIT | PE_64BIT | PE_F32BIT | PE_ULAW | PE_ALAW);
6891 case '6': /* 6 for 64-bit */
6892 pmp->encoding |= PE_64BIT;
6893 pmp->encoding &= ~(PE_16BIT | PE_24BIT | PE_32BIT | PE_F32BIT | PE_F64BIT | PE_ULAW | PE_ALAW);
6895 case 'f': /* f for float 32-bit */
6896 pmp->encoding |= PE_F32BIT;
6897 pmp->encoding &= ~(PE_16BIT | PE_24BIT | PE_32BIT | PE_64BIT | PE_F64BIT | PE_ULAW | PE_ALAW);
6899 case '3': /* 3 for 32-bit */
6900 pmp->encoding |= PE_32BIT;
6901 pmp->encoding &= ~(PE_16BIT | PE_24BIT | PE_64BIT | PE_F32BIT | PE_F64BIT | PE_ULAW | PE_ALAW);
6903 case '2': /* 2 for 24-bit */
6904 pmp->encoding |= PE_24BIT;
6905 pmp->encoding &= ~(PE_16BIT | PE_32BIT | PE_64BIT | PE_F32BIT | PE_F64BIT | PE_ULAW | PE_ALAW);
6907 case '1': /* 1 for 16-bit */
6908 pmp->encoding |= PE_16BIT;
6909 pmp->encoding &= ~(PE_24BIT | PE_32BIT | PE_64BIT | PE_F32BIT | PE_F64BIT | PE_ULAW | PE_ALAW);
6912 pmp->encoding &= ~(PE_16BIT | PE_24BIT | PE_32BIT | PE_64BIT | PE_F32BIT | PE_F64BIT | PE_BYTESWAP);
6914 case 'l': /* linear */
6915 pmp->encoding &= ~(PE_ULAW | PE_ALAW);
6917 case 'U': /* uLaw */
6918 pmp->encoding |= PE_ULAW;
6919 pmp->encoding &= ~(PE_SIGNED | PE_16BIT | PE_24BIT | PE_32BIT | PE_64BIT | PE_F32BIT | PE_F64BIT | PE_ALAW | PE_BYTESWAP);
6921 case 'A': /* aLaw */
6922 pmp->encoding |= PE_ALAW;
6923 pmp->encoding &= ~(PE_SIGNED | PE_16BIT | PE_24BIT | PE_32BIT | PE_64BIT | PE_F32BIT | PE_F64BIT | PE_ULAW | PE_BYTESWAP);
6926 pmp->encoding ^= PE_BYTESWAP; /* toggle */
6927 pmp->encoding &= ~(PE_ULAW | PE_ALAW);
6930 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
6931 "Unknown format modifier `%c'", *arg);
6937 static inline int parse_opt_output_stereo(const char *arg)
6939 /* --output-stereo, --output-mono */
6942 /* I first thought --mono should be the syntax sugar to
6943 * --stereo=no, but the source said stereo should be !PE_MONO,
6944 * not mono should be !PE_STEREO. Perhaps I took a wrong
6947 play_mode->encoding &= ~PE_MONO;
6949 play_mode->encoding |= PE_MONO;
6953 static inline int parse_opt_output_signed(const char *arg)
6955 /* --output-singed, --output-unsigned */
6957 if (set_flag(&(play_mode->encoding), PE_SIGNED, arg))
6959 play_mode->encoding &= ~(PE_ULAW | PE_ALAW);
6963 static inline int parse_opt_output_bitwidth(const char *arg)
6965 /* --output-16bit, --output-24bit, --output-32bit, --output-64bit, --output-8bit, --output-float32bit, --output-float64bit */
6968 case 'f': /* float32bit */
6969 play_mode->encoding |= PE_F32BIT;
6970 play_mode->encoding &= ~(PE_16BIT | PE_24BIT | PE_32BIT | PE_64BIT | PE_F64BIT | PE_ULAW | PE_ALAW);
6972 case 'D': /* float64bit */
6973 play_mode->encoding |= PE_F64BIT;
6974 play_mode->encoding &= ~(PE_16BIT | PE_24BIT | PE_32BIT | PE_64BIT | PE_F32BIT | PE_ULAW | PE_ALAW);
6976 case '1': /* 16bit */
6977 play_mode->encoding |= PE_16BIT;
6978 play_mode->encoding &= ~(PE_24BIT | PE_32BIT | PE_64BIT | PE_F32BIT | PE_F64BIT | PE_ULAW | PE_ALAW);
6980 case '2': /* 24bit */
6981 play_mode->encoding |= PE_24BIT;
6982 play_mode->encoding &= ~(PE_16BIT | PE_32BIT | PE_64BIT | PE_F32BIT | PE_F64BIT | PE_ULAW | PE_ALAW);
6984 case '3': /* 32bit */
6985 play_mode->encoding |= PE_32BIT;
6986 play_mode->encoding &= ~(PE_16BIT | PE_24BIT | PE_64BIT | PE_F32BIT | PE_F64BIT | PE_ULAW | PE_ALAW);
6988 case '6': /* 64bit */
6989 play_mode->encoding |= PE_64BIT;
6990 play_mode->encoding &= ~(PE_16BIT | PE_24BIT | PE_32BIT | PE_F32BIT | PE_F64BIT | PE_ULAW | PE_ALAW);
6992 case '8': /* 8bit */
6993 play_mode->encoding &= ~(PE_16BIT | PE_24BIT | PE_32BIT | PE_64BIT | PE_F32BIT | PE_F64BIT);
6996 ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "Invalid output bitwidth %s", arg);
7001 static inline int parse_opt_output_format(const char *arg)
7003 /* --output-linear, --output-ulaw, --output-alaw */
7006 case 'l': /* linear */
7007 play_mode->encoding &= ~(PE_ULAW | PE_ALAW);
7009 case 'u': /* uLaw */
7010 play_mode->encoding |= PE_ULAW;
7011 play_mode->encoding &=
7012 ~(PE_SIGNED | PE_16BIT | PE_24BIT | PE_32BIT | PE_64BIT | PE_F32BIT | PE_F64BIT | PE_ALAW | PE_BYTESWAP);
7014 case 'a': /* aLaw */
7015 play_mode->encoding |= PE_ALAW;
7016 play_mode->encoding &=
7017 ~(PE_SIGNED | PE_16BIT | PE_24BIT | PE_32BIT | PE_64BIT | PE_F32BIT | PE_F64BIT | PE_ULAW | PE_BYTESWAP);
7020 ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "Invalid output format %s", arg);
7025 static inline int parse_opt_output_swab(const char *arg)
7027 /* --[no-]output-swab */
7029 if (set_flag(&(play_mode->encoding), PE_BYTESWAP, arg))
7031 play_mode->encoding &= ~(PE_ULAW | PE_ALAW);
7035 static inline int parse_opt_output_device_id(const char *arg)
7037 /* --opt-output-device-id */
7039 opt_output_device_id = atoi(arg);
7043 static inline int parse_opt_wmme_device_id(const char *arg)
7045 /* --opt-wmme-device-id */
7047 opt_wmme_device_id = atoi(arg);
7050 static inline int parse_opt_wave_format_ext(const char *arg)
7052 /* --opt-wave_format_ext */
7054 opt_wave_format_ext = atoi(arg);
7057 static inline int parse_opt_wmme_buffer_bit(const char *arg)
7059 /* --opt_wmme_buffer_bit */
7061 opt_wmme_buffer_bits = atoi(arg);
7064 static inline int parse_opt_wmme_buffer_num(const char *arg)
7066 /* --opt_wmme_buffer_num */
7068 opt_wmme_buffer_num = atoi(arg);
7073 static inline int parse_opt_wdmks_device_id(const char *arg)
7075 /* --wdmks-device-id */
7077 opt_wdmks_device_id = atoi(arg);
7080 static inline int parse_opt_wdmks_latency(const char *arg)
7082 /* --wdmks-latency */
7084 opt_wdmks_latency = atoi(arg);
7087 static inline int parse_opt_wdmks_format_ext(const char *arg)
7089 /* --wdmks-format_ext */
7091 opt_wdmks_format_ext = atoi(arg);
7094 static inline int parse_opt_wdmks_polling(const char *arg)
7096 /* --wdmks-polling */
7098 opt_wdmks_polling = atoi(arg);
7101 static inline int parse_opt_wdmks_thread_priority(const char *arg)
7103 /* --wdmks-thread-priority */
7105 opt_wdmks_thread_priority = atoi(arg);
7108 static inline int parse_opt_wdmks_pin_priority(const char *arg)
7110 /* --wdmks-pin-priority */
7112 opt_wdmks_pin_priority = atoi(arg);
7115 static inline int parse_opt_wdmks_rt_priority(const char *arg)
7117 /* --wdmks-rt-priority */
7119 opt_wdmks_rt_priority = atoi(arg);
7124 static inline int parse_opt_wasapi_device_id(const char *arg)
7126 /* --wasapi-device-id */
7128 opt_wasapi_device_id = atoi(arg);
7131 static inline int parse_opt_wasapi_latency(const char *arg)
7133 /* --wasapi-latency */
7135 opt_wasapi_latency = atoi(arg);
7138 static inline int parse_opt_wasapi_format_ext(const char *arg)
7140 /* --wasapi-format_ext */
7142 opt_wasapi_format_ext = atoi(arg);
7145 static inline int parse_opt_wasapi_exclusive(const char *arg)
7147 /* --wasapi-exclusive */
7149 opt_wasapi_exclusive = atoi(arg);
7152 static inline int parse_opt_wasapi_polling(const char *arg)
7154 /* --wasapi-polling */
7156 opt_wasapi_polling = atoi(arg);
7159 static inline int parse_opt_wasapi_priority(const char *arg)
7161 /* --wasapi-priority */
7163 opt_wasapi_priority = atoi(arg);
7166 static inline int parse_opt_wasapi_stream_category(const char *arg)
7168 /* --wasapi-stream-category */
7170 opt_wasapi_stream_category = atoi(arg);
7173 static inline int parse_opt_wasapi_stream_option(const char *arg)
7175 /* --wasapi-stream-option */
7177 opt_wasapi_stream_option = atoi(arg);
7183 static inline int parse_opt_pa_wmme_device_id(const char *arg)
7185 /* --pa-wmme-device-id */
7187 opt_pa_wmme_device_id = atoi(arg);
7190 static inline int parse_opt_pa_ds_device_id(const char *arg)
7192 /* --pa-ds-device */
7194 opt_pa_ds_device_id = atoi(arg);
7197 static inline int parse_opt_pa_asio_device_id(const char *arg)
7199 /* --pa-asio-device-id */
7201 opt_pa_asio_device_id = atoi(arg);
7204 #ifdef PORTAUDIO_V19
7205 static inline int parse_opt_pa_wdmks_device_id(const char *arg)
7207 /* --pa-wdmks-device */
7209 opt_pa_wdmks_device_id = atoi(arg);
7212 static inline int parse_opt_pa_wasapi_device_id(const char *arg)
7214 /* --pa-wasapi-device-id */
7216 opt_pa_wasapi_device_id = atoi(arg);
7219 static inline int parse_opt_pa_wasapi_flag(const char *arg)
7221 /* --pa-wasapi-flag */
7223 opt_pa_wasapi_flag = atoi(arg);
7226 static inline int parse_opt_pa_wasapi_stream_category(const char *arg)
7228 /* --pa-wasapi-stream-category */
7230 opt_pa_wasapi_stream_category = atoi(arg);
7233 static inline int parse_opt_pa_wasapi_stream_option(const char *arg)
7235 /* --pa-wasapi-stream-option */
7237 opt_pa_wasapi_stream_option = atoi(arg);
7244 extern void wave_set_option_extensible(int);
7245 extern void wave_set_option_update_step(int);
7247 static inline int parse_opt_wave_extensible(const char *arg)
7249 wave_set_option_extensible(y_or_n_p(arg));
7253 static inline int parse_opt_wave_update_step(const char *arg)
7255 wave_set_option_update_step(arg ? atoi(arg) : 0);
7262 static inline int parse_opt_flac_verify(const char *arg)
7264 flac_set_option_verify(1);
7268 static inline int parse_opt_flac_padding(const char *arg)
7271 flac_set_option_padding(atoi(arg));
7275 static inline int parse_opt_flac_complevel(const char *arg)
7278 flac_set_compression_level(atoi(arg));
7283 extern void flac_set_option_oggflac(int);
7285 static inline int parse_opt_flac_oggflac(const char *arg)
7287 flac_set_option_oggflac(1);
7290 #endif /* AU_OGGFLAC */
7291 #endif /* AU_FLAC */
7294 extern void opus_set_nframes(int);
7295 extern void opus_set_bitrate(int);
7296 extern void opus_set_complexity(int);
7297 extern void opus_set_vbr(int);
7298 extern void opus_set_cvbr(int);
7300 static inline int parse_opt_opus_nframes(const char *arg)
7302 opus_set_nframes(arg ? atoi(arg) : 1920);
7306 static inline int parse_opt_opus_bitrate(const char *arg)
7308 opus_set_bitrate(arg ? atoi(arg) : 128);
7312 static inline int parse_opt_opus_complexity(const char *arg)
7314 opus_set_complexity(arg ? atoi(arg) : 10);
7318 static inline int parse_opt_opus_vbr(const char *arg)
7320 opus_set_vbr(y_or_n_p(arg));
7324 static inline int parse_opt_opus_cvbr(const char *arg)
7326 opus_set_cvbr(y_or_n_p(arg));
7329 #endif /* AU_OPUS */
7332 extern void speex_set_option_quality(int);
7333 extern void speex_set_option_vbr(int);
7334 extern void speex_set_option_abr(int);
7335 extern void speex_set_option_vad(int);
7336 extern void speex_set_option_dtx(int);
7337 extern void speex_set_option_complexity(int);
7338 extern void speex_set_option_nframes(int);
7340 static inline int parse_opt_speex_quality(const char *arg)
7343 speex_set_option_quality(atoi(arg));
7347 static inline int parse_opt_speex_vbr(const char *arg)
7349 speex_set_option_vbr(1);
7353 static inline int parse_opt_speex_abr(const char *arg)
7356 speex_set_option_abr(atoi(arg));
7360 static inline int parse_opt_speex_vad(const char *arg)
7362 speex_set_option_vad(1);
7366 static inline int parse_opt_speex_dtx(const char *arg)
7368 speex_set_option_dtx(1);
7372 static inline int parse_opt_speex_complexity(const char *arg)
7375 speex_set_option_complexity(atoi(arg));
7379 static inline int parse_opt_speex_nframes(const char *arg)
7382 speex_set_option_nframes(atoi(arg));
7385 #endif /* AU_SPEEX */
7387 static inline int parse_opt_o(const char *arg)
7390 safe_free(opt_output_name);
7391 opt_output_name = safe_strdup(url_expand_home_dir(arg));
7395 static inline int parse_opt_P(const char *arg)
7397 /* set overriding instrument */
7399 strncpy(def_instr_name, arg, sizeof(def_instr_name) - 1);
7400 def_instr_name[sizeof(def_instr_name) - 1] = '\0';
7404 static inline int parse_opt_p(const char *arg)
7408 // safe_calloc() sizeof(Voice) < MAX_SAFE_MALLOC_SIZE
\82Å
\82 \82ê
\82Î
\82¢
\82¢
\82Í
\82¸ (win
\88È
\8aO
\82Í
\95s
\96¾
7409 if (set_value(&voices, atoi(arg), 1, MAX_VOICES, "Polyphony"))
7412 if (set_value(&voices, atoi(arg), 1,
7413 MAX_SAFE_MALLOC_SIZE / sizeof(Voice), "Polyphony"))
7416 max_voices = voices;
7420 static inline int parse_opt_p1(const char *arg)
7422 /* --[no-]polyphony-reduction */
7423 if (!arg) arg = "n";
7424 auto_reduce_polyphony = y_or_n_p(arg);
7428 static inline int parse_opt_Q(const char *arg)
7430 const char *p = arg;
7433 if (strchr(arg, 't'))
7434 /* backward compatibility */
7435 return parse_opt_Q1(arg);
7436 if (set_channel_flag(&quietchannels, atoi(arg), "Quiet channel"))
7438 while ((p = strchr(p, ',')) != NULL)
7439 if (set_channel_flag(&quietchannels, atoi(++p), "Quiet channel"))
7444 static inline int parse_opt_Q1(const char *arg)
7448 const char *p = arg;
7451 if (set_value(&prog, atoi(arg), 0, 7, "Temperament program number"))
7453 temper_type_mute |= 1 << prog;
7454 while ((p = strchr(p, ',')) != NULL) {
7455 if (set_value(&prog, atoi(++p), 0, 7, "Temperament program number"))
7457 temper_type_mute |= 1 << prog;
7462 static inline int parse_opt_preserve_silence(const char *arg)
7464 opt_preserve_silence = 1;
7468 static inline int parse_opt_q(const char *arg)
7470 char *max_buff = NULL;
7471 char *fill_buff = NULL;
7473 max_buff = safe_strdup(arg);
7474 fill_buff = strchr(max_buff, '/');
7476 if (fill_buff != max_buff) {
7477 safe_free(opt_aq_max_buff);
7478 opt_aq_max_buff = max_buff;
7481 safe_free(opt_aq_fill_buff);
7483 opt_aq_fill_buff = safe_strdup(++fill_buff);
7488 static inline int parse_opt_R(const char *arg)
7490 /* I think pseudo reverb can now be retired... Computers are
7491 * enough fast to do a full reverb, don't they?
7493 if (!arg) arg = "-1";
7494 if (atoi(arg) == -1) /* reset */
7497 if (set_val_i32(&modify_release, atoi(arg), 0, MAX_MREL,
7500 if (modify_release == 0)
7501 modify_release = DEFAULT_MREL;
7506 static inline int parse_opt_r(const char *arg)
7508 safe_free(opt_reduce_quality_threshold);
7509 opt_reduce_quality_threshold = safe_strdup((arg) ? arg : DEFAULT_REDUCE_QUALITY_THRESHOLD);
7510 // reduce_quality_threshold = atoi(arg);
7514 static inline int parse_opt_add_play_time(const char *arg)
7517 add_play_time = atoi(arg);
7518 if(add_play_time < 0)
7523 static inline int parse_opt_add_silent_time(const char *arg)
7526 add_silent_time = atoi(arg);
7527 if(add_silent_time < 0)
7528 add_silent_time = 0;
7532 static inline int parse_opt_emu_delay_time(const char *arg)
7535 emu_delay_time = atoi(arg);
7536 if(emu_delay_time < 0)
7541 static inline int parse_opt_mix_envelope(const char *arg)
7544 opt_mix_envelope = atoi(arg);
7545 if (opt_mix_envelope < 0)
7546 opt_mix_envelope = 0;
7550 static inline int parse_opt_modulation_update(const char *arg)
7553 opt_modulation_update = atoi(arg);
7554 if (opt_modulation_update < 0)
7555 opt_modulation_update = 0;
7559 static inline int parse_opt_cut_short_time(const char *arg)
7562 opt_cut_short_time = atoi(arg);
7563 if (opt_cut_short_time < 0)
7564 opt_cut_short_time = 0;
7568 static inline int parse_opt_limiter(const char *arg)
7571 opt_limiter = atoi(arg);
7572 if (opt_limiter < 0)
7577 static inline int parse_opt_compute_thread_num(const char *arg)
7580 compute_thread_num = atoi(arg);
7584 static inline int parse_opt_trace_mode_update(const char *arg)
7586 #ifdef USE_TRACE_TIMER
7588 trace_mode_update_time = atoi(arg);
7589 set_trace_mode_update_time();
7594 static inline int parse_opt_load_all_instrument(const char *arg)
7597 opt_load_all_instrument = atoi(arg);
7601 static inline int parse_opt_int_synth_rate(const char *arg)
7604 opt_int_synth_rate = atoi(arg);
7607 static inline int parse_opt_int_synth_sine(const char *arg)
7610 opt_int_synth_sine = atoi(arg);
7613 static inline int parse_opt_int_synth_update(const char *arg)
7616 opt_int_synth_update = atoi(arg);
7620 #ifdef SUPPORT_LOOPEVENT
7621 static inline int parse_opt_midi_loop_repeat(const char *arg)
7623 opt_midi_loop_repeat = (arg) ? atoi(arg) : 0;
7624 opt_use_midi_loop_repeat = (opt_midi_loop_repeat >= 1) ? 1 : 0;
7628 static inline int parse_opt_midi_loop_filter(const char *arg)
7631 if (!arg) return err;
7632 opt_use_midi_loop_repeat = 0;
7638 opt_use_midi_loop_repeat = 0;
7642 /* Control change #111 */
7643 opt_use_midi_loop_repeat |= LF_CC111_TO_EOT;
7648 opt_use_midi_loop_repeat |= LF_MARK_A_TO_B;
7652 /* Mark `Loop_Start'-`Loop_End'*/
7653 opt_use_midi_loop_repeat |= LF_MARK_S_TO_E;
7657 /* Control change #2 - CC#4 */
7658 opt_use_midi_loop_repeat |= LF_CC2_TO_CC4;
7662 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
7663 "--loop-filter: Illegal mode `%c'", *arg);
7671 #endif /* SUPPORT_LOOPEVENT */
7673 static inline int parse_opt_od_level_gs(const char *arg)
7676 if (set_value(&level, arg ? atoi(arg) : 100, 1, 400, "GS OD Level adjust"))
7678 otd.gsefx_CustomODLv = level / 100.0;
7682 static inline int parse_opt_od_drive_gs(const char *arg)
7685 if (set_value(&level, arg ? atoi(arg) : 100, 1, 400, "GS OD Drive adjust"))
7687 otd.gsefx_CustomODDrive = level / 100.0;
7691 static inline int parse_opt_od_level_xg(const char *arg)
7694 if (set_value(&level, arg ? atoi(arg) : 100, 1, 400, "XG OD Level adjust"))
7696 otd.xgefx_CustomODLv = level / 100.0;
7700 static inline int parse_opt_od_drive_xg(const char *arg)
7703 if (set_value(&level, arg ? atoi(arg) : 100, 1, 400, "XG OD Drive adjust"))
7705 otd.xgefx_CustomODDrive = level / 100.0;
7709 static inline int parse_opt_od_level_sd(const char *arg)
7712 if (set_value(&level, arg ? atoi(arg) : 100, 1, 400, "SD OD Level adjust"))
7714 otd.sdefx_CustomODLv = level / 100.0;
7718 static inline int parse_opt_od_drive_sd(const char *arg)
7721 if (set_value(&level, arg ? atoi(arg) : 100, 1, 400, "SD OD Drive adjust"))
7723 otd.sdefx_CustomODDrive = level / 100.0;
7728 static inline int parse_opt_process_priority(const char *arg)
7730 processPriority = (arg) ? (DWORD)atoi(arg) : NORMAL_PRIORITY_CLASS;
7734 #if !(defined(IA_W32G_SYN) || defined(WINDRV))
7735 static inline int parse_opt_player_thread_priority(const char *arg)
7737 PlayerThreadPriority = (arg) ? (DWORD)atoi(arg) : THREAD_PRIORITY_NORMAL;
7741 static inline int parse_opt_GUI_thread_priority(const char *arg)
7743 GUIThreadPriority = (arg) ? (DWORD)atoi(arg) : THREAD_PRIORITY_NORMAL;
7746 #endif /* !IA_W32G_SYN */
7747 #endif /* __W32__ */
7749 static inline int parse_opt_S(const char *arg)
7754 suffix = arg[strlen(arg) - 1];
7769 allocate_cache_size = atof(arg) * figure;
7773 static inline int parse_opt_s(const char *arg)
7778 if (!arg) arg = "44.1";
7779 if ((freq = atoi(arg)) < 1000)
7780 freq = atof(arg) * 1000 + 0.5;
7781 return set_val_i32(&opt_output_rate, freq, MIN_OUTPUT_RATE, MAX_OUTPUT_RATE, "Resampling frequency");
7784 static inline int parse_opt_T(const char *arg)
7789 if (!arg) arg = "100";
7790 if (set_value(&adjust, atoi(arg), 10, 400, "Tempo adjust"))
7792 tempo_adjust = 100.0 / adjust;
7796 static inline int parse_opt_t(const char *arg)
7798 if (!arg) arg = OUTPUT_TEXT_CODE;
7799 safe_free(output_text_code);
7800 output_text_code = safe_strdup(arg);
7804 static inline int parse_opt_U(const char *arg)
7806 if (!arg) arg = "n";
7807 free_instruments_afterwards = y_or_n_p(arg);
7811 #if defined(AU_VOLUME_CALC)
7812 static inline int parse_opt_volume_calc_rms(const char *arg)
7814 opt_volume_calc_rms = 1;
7818 static inline int parse_opt_volume_calc_trim(const char *arg)
7820 opt_volume_calc_trim = 1;
7823 #endif /* AU_VOLUME_CALC */
7826 static inline int parse_opt_volume_curve(const char *arg)
7829 if (!(atof(arg) >= 0)) {
7830 ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "Volume curve power must be >= 0", *arg);
7833 if (atof(arg) != 0) {
7834 init_user_vol_table(atof(arg));
7835 opt_user_volume_curve = atof(arg);
7837 opt_user_volume_curve = 0;
7841 __attribute__((noreturn))
7842 static inline int parse_opt_v(const char *arg)
7844 const char *version_list[] = {
7845 #if defined(__BORLANDC__) || defined(__MRC__) || defined(__WATCOMC__) || defined(__DMC__)
7852 (strcmp(timidity_version, "current")) ? "version " : "",
7853 timidity_version, " ", arch_string, NLS,
7856 "Copyright (C) 1999-2018 Masanao Izumo <iz@onicos.co.jp>", NLS,
7857 "Copyright (C) 1995 Tuukka Toivonen <tt@cgs.fi>", NLS,
7860 "Win32 version by Davide Moretti <dmoretti@iper.net>", NLS,
7861 " and Daisuke Aoki <dai@y7.net>", NLS,
7863 #endif /* __W32__ */
7864 "This program is distributed in the hope that it will be useful,", NLS,
7865 "but WITHOUT ANY WARRANTY; without even the implied warranty of", NLS,
7866 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the", NLS,
7867 "GNU General Public License for more details.", NLS,
7869 FILE *fp = open_pager();
7872 #if defined(__BORLANDC__) || defined(__MRC__)
7873 if (strcmp(timidity_version, "current"))
7874 version_list[1] = "version ";
7875 version_list[2] = timidity_version;
7877 for (i = 0; i < sizeof(version_list) / sizeof(char *); i++)
7878 fputs(version_list[i], fp);
7883 static inline int parse_opt_W(const char *arg)
7885 WRDTracer *wlp, **wlpp;
7888 if (*arg == 'R') { /* for WRD reader options */
7889 put_string_table(&wrd_read_opts, arg + 1, strlen(arg + 1));
7892 for (wlpp = wrdt_list; (wlp = *wlpp) != NULL; wlpp++)
7893 if (wlp->id == *arg) {
7895 safe_free(wrdt_open_opts);
7896 wrdt_open_opts = safe_strdup(arg + 1);
7899 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
7900 "WRD Tracer `%c' is not compiled in.", *arg);
7905 static inline int parse_opt_w(const char *arg)
7919 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
7920 "-w%c option is not supported", *arg);
7922 #endif /* SMFCONV */
7924 ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "-w: Illegal mode `%c'", *arg);
7928 #endif /* __W32__ */
7930 static inline int parse_opt_x(const char *arg)
7932 StringTableNode *st;
7935 if ((st = put_string_table(&opt_config_string,
7936 arg, strlen(arg))) != NULL)
7937 expand_escape_string(st->string);
7941 static inline int parse_opt_Y(const char *arg)
7943 /* --compute-buffer */
7945 if (set_value(&opt_compute_buffer_bits, atoi(arg), -5, AUDIO_BUFFER_BITS - 1,
7946 "Compute Buffer (bit)"))
7951 static inline void expand_escape_string(char *s)
7957 for (t = s; *s; s++)
7994 static inline int parse_opt_Z(const char *arg)
7996 /* load frequency table */
7997 return load_table(arg);
8000 static inline int parse_opt_Z1(const char *arg)
8002 /* --pure-intonation */
8005 opt_pure_intonation = 1;
8007 if (set_value(&keysig, atoi(arg), -7, 7,
8008 "Initial keysig (number of #(+)/b(-)[m(minor)])"))
8010 opt_init_keysig = keysig;
8011 if (strchr(arg, 'm'))
8012 opt_init_keysig += 16;
8017 static inline int parse_opt_default_module(const char *arg)
8020 opt_default_module = atoi(arg);
8021 if (opt_default_module < 0)
8022 opt_default_module = 0;
8027 __attribute__((noreturn))
8028 static inline int parse_opt_fail(const char *arg)
8030 /* getopt_long failed to recognize any options */
8031 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
8032 "Could not understand option : try --help");
8036 static inline int set_value(int *param, int i, int low, int high, const char *name)
8040 if (set_val_i32(&val, i, low, high, name))
8046 static inline int set_val_i32(int32 *param,
8047 int32 i, int32 low, int32 high, const char *name)
8049 if (i < low || i > high) {
8050 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
8051 "%s must be between %ld and %ld", name, low, high);
8058 static int parse_val_float_t(FLOAT_T *param,
8059 const char *arg, FLOAT_T low, FLOAT_T high, const char *name)
8064 value = strtod(arg, &errp);
8066 /* only when nothing was parsed */
8067 ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "Invalid %s", name);
8070 return set_val_float_t(param, value, low, high, name);
8073 static inline int set_val_float_t(FLOAT_T *param,
8074 FLOAT_T i, FLOAT_T low, FLOAT_T high, const char *name)
8076 if (i < low || i > high) {
8077 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
8078 "%s must be between %.1f and %.1f", name, low, high);
8085 static inline int set_channel_flag(ChannelBitMask *flags, int32 i, const char *name)
8088 FILL_CHANNELMASK(*flags);
8090 } else if (abs(i) > MAX_CHANNELS) {
8091 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
8092 "%s must be between (-)1 and (-)%d, or 0",
8093 name, MAX_CHANNELS);
8097 SET_CHANNELMASK(*flags, i - 1);
8099 UNSET_CHANNELMASK(*flags, -i - 1);
8103 static inline int y_or_n_p(const char *arg)
8123 static inline int set_flag(int32 *fields, int32 bitmask, const char *arg)
8128 *fields &= ~bitmask;
8132 static inline FILE *open_pager(void)
8134 #if ! defined(__MACOS__) && defined(HAVE_POPEN) && defined(HAVE_ISATTY) \
8135 && ! defined(IA_W32GUI) && ! defined(IA_W32G_SYN)
8138 if (isatty(1) && (pager = getenv("PAGER")) != NULL)
8139 return popen(pager, "w");
8144 static inline void close_pager(FILE *fp)
8146 #if ! defined(__MACOS__) && defined(HAVE_POPEN) && defined(HAVE_ISATTY) \
8147 && ! defined(IA_W32GUI) && ! defined(IA_W32G_SYN)
8153 static void interesting_message(void)
8156 "TiMidity++ %s%s %s -- MIDI to WAVE converter and player" NLS
8157 "Copyright (C) 1999-2018 Masanao Izumo <iz@onicos.co.jp>" NLS
8158 "Copyright (C) 1995 Tuukka Toivonen <tt@cgs.fi>" NLS
8161 "Win32 version by Davide Moretti <dmoretti@iper.net>" NLS
8162 " and Daisuke Aoki <dai@y7.net>" NLS
8164 #endif /* __W32__ */
8165 "This program is free software; you can redistribute it and/or modify" NLS
8166 "it under the terms of the GNU General Public License as published by" NLS
8167 "the Free Software Foundation; either version 2 of the License, or" NLS
8168 "(at your option) any later version." NLS
8170 "This program is distributed in the hope that it will be useful," NLS
8171 "but WITHOUT ANY WARRANTY; without even the implied warranty of" NLS
8172 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the" NLS
8173 "GNU General Public License for more details." NLS
8175 "You should have received a copy of the GNU General Public License" NLS
8176 "along with this program; if not, write to the Free Software" NLS
8177 "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA" NLS
8178 NLS, (strcmp(timidity_version, "current")) ? "version " : "",
8184 /* -------- functions for getopt_long ends here --------- */
8187 static RETSIGTYPE sigterm_exit(int sig)
8192 /* NOTE: Here, fprintf is dangerous because it is not re-enterance
8193 * function. It is possible coredump if the signal is called in printf's.
8196 dummy = write(2, "Terminated sig=0x", 17);
8197 s[0] = "0123456789abcdef"[(sig >> 4) & 0xf];
8198 s[1] = "0123456789abcdef"[sig & 0xf];
8200 dummy += write(2, s, 3);
8205 #endif /* HAVE_SIGNAL */
8207 static void timidity_arc_error_handler(const char *error_message)
8209 extern int open_file_noise_mode;
8210 if(open_file_noise_mode)
8211 ctl->cmsg(CMSG_WARNING, VERB_NORMAL, "%s", error_message);
8214 static PlayMode null_play_mode = {
8219 {0,0,0,0,0}, /* extra_param */
8220 "Null output device", /* id_name */
8221 '\0', /* id_character */
8222 NULL, /* open_output */
8223 NULL, /* close_output */
8224 NULL, /* output_data */
8229 MAIN_INTERFACE void timidity_start_initialize(void)
8232 static int drums[] = DEFAULT_DRUMCHANNELS;
8233 static int is_first = 1;
8234 #if defined(__FreeBSD__) && !defined(__alpha__)
8236 #elif defined(__NetBSD__) || defined(__OpenBSD__)
8240 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
8241 fpexp = fpgetmask();
8242 fpsetmask(fpexp & ~(FP_X_INV|FP_X_DZ));
8245 if(!output_text_code)
8246 output_text_code = safe_strdup(OUTPUT_TEXT_CODE);
8247 if(!opt_aq_max_buff)
8248 opt_aq_max_buff = safe_strdup("20.0");
8249 if(!opt_aq_fill_buff)
8250 opt_aq_fill_buff = safe_strdup("200%");
8252 if(!opt_reduce_voice_threshold)
8253 opt_reduce_voice_threshold = safe_strdup("0");
8254 if(!opt_reduce_quality_threshold)
8255 opt_reduce_quality_threshold = safe_strdup("0");
8256 if(!opt_reduce_polyphony_threshold)
8257 opt_reduce_polyphony_threshold = safe_strdup("0");
8259 /* Check the byte order */
8261 #ifdef LITTLE_ENDIAN
8262 if(*(char *)&i != 1)
8264 if(*(char *)&i == 1)
8267 fprintf(stderr, "Byte order is miss configured.\n");
8271 for(i = 0; i < MAX_CHANNELS; i++)
8273 memset(&(channel[i]), 0, sizeof(Channel));
8276 CLEAR_CHANNELMASK(quietchannels);
8277 CLEAR_CHANNELMASK(default_drumchannels);
8279 for(i = 0; drums[i] > 0; i++)
8280 SET_CHANNELMASK(default_drumchannels, drums[i] - 1);
8281 #if MAX_CHANNELS > 16
8282 for(i = 16; i < MAX_CHANNELS; i++)
8283 if(IS_SET_CHANNELMASK(default_drumchannels, i & 0xF))
8284 SET_CHANNELMASK(default_drumchannels, i);
8287 if(program_name == NULL)
8288 program_name = "TiMidity";
8289 uudecode_unquote_html = 1;
8291 for(i = 0; i < MAX_CHANNELS; i++)
8293 default_program[i] = DEFAULT_PROGRAM;
8294 special_program[i] = -1;
8295 memset(channel[i].drums, 0, sizeof(channel[i].drums));
8297 arc_error_handler = timidity_arc_error_handler;
8299 if(play_mode == NULL) play_mode = &null_play_mode;
8301 if(is_first) /* initialize once time */
8303 got_a_configuration = 0;
8305 #ifdef SUPPORT_SOCKET
8307 if(url_user_agent == NULL)
8310 (char *)safe_malloc(10 + strlen(timidity_version));
8311 strcpy(url_user_agent, "TiMidity-");
8312 strcat(url_user_agent, timidity_version);
8314 #endif /* SUPPORT_SOCKET */
8316 for(i = 0; url_module_list[i]; i++)
8317 url_add_module(url_module_list[i]);
8318 init_string_table(&opt_config_string);
8320 init_freq_table_tuning();
8321 init_freq_table_pytha();
8322 init_freq_table_meantone();
8323 init_freq_table_pureint();
8324 init_freq_table_user();
8328 init_gm2_pan_table();
8329 init_attack_vol_table();
8330 init_sb_vol_table();
8331 init_modenv_vol_table();
8332 init_def_vol_table();
8333 init_gs_vol_table();
8334 init_perceived_vol_table();
8335 init_gm2_vol_table();
8336 #ifdef SUPPORT_SOCKET
8337 url_news_connection_cache(URL_NEWS_CONN_CACHE);
8338 #endif /* SUPPORT_SOCKET */
8339 for(i = 0; i < NSPECIAL_PATCH; i++)
8340 special_patch[i] = NULL;
8342 int_rand(-1); /* initialize random seed */
8343 int_rand(42); /* the 1st number generated is not very random */
8344 ML_RegisterAllLoaders ();
8350 MAIN_INTERFACE int timidity_pre_load_configuration(void)
8356 char local[FILEPATH_MAX] = { 0 };
8357 const char cfgname[] = CONFIG_FILE_NAME_P;
8359 #if defined(IA_W32GUI) || defined(IA_W32G_SYN)
8360 extern char *ConfigFile;
8361 int firstStartup = 0;
8362 if (!ConfigFile[0]) {
8364 GetWindowsDirectoryA(ConfigFile, FILEPATH_MAX - strlen(cfgname) - 1);
8365 strlcat(ConfigFile, cfgname, sizeof(local));
8367 strlcpy(local, ConfigFile, sizeof(local) - 1);
8368 if ((check = open(local, 0)) >= 0)
8371 if (!read_config_file(local, 0, 0)) {
8372 got_a_configuration = 1;
8378 /* First, try read configuration file which is in the
8379 * TiMidity directory.
8381 if (GetModuleFileNameA(NULL, local, FILEPATH_MAX - strlen(cfgname) - 1))
8383 local[FILEPATH_MAX - strlen(cfgname) - 1] = '\0';
8384 if ((strp = pathsep_strrchr(local)) != NULL)
8387 strlcat(local, cfgname, sizeof(local));
8388 if ((check = open(local, 0)) >= 0)
8391 if (!read_config_file(local, 0, 0)) {
8392 #if defined(IA_W32GUI) || defined(IA_W32G_SYN)
8394 strlcpy(ConfigFile, local, FILEPATH_MAX - 1);
8397 got_a_configuration = 1;
8402 #if !defined(IA_W32GUI) && !defined(IA_W32G_SYN)
8403 /* Next, try read system configuration file.
8404 * Default is C:\WINDOWS\TIMIDITY.CFG
8406 GetWindowsDirectoryA(local, FILEPATH_MAX - strlen(cfgname) - 1);
8407 strlcat(local, cfgname, sizeof(local));
8408 if ((check = open(local, 0)) >= 0)
8411 if (!read_config_file(local, 0, 0)) {
8412 got_a_configuration = 1;
8420 if (!read_config_file(CONFIG_FILE, 0, 0))
8421 got_a_configuration = 1;
8422 #endif /* __W32__ */
8424 /* Try read configuration file which is in the
8425 * $HOME (or %HOME% for DOS) directory.
8426 * Please setup each user preference in $HOME/.timidity.cfg
8427 * (or %HOME%/timidity.cfg for DOS)
8429 if (read_user_config_file()) {
8430 ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
8431 "Error: Syntax error in ~/." CONFIG_FILE_NAME);
8438 MAIN_INTERFACE int timidity_post_load_configuration(void)
8442 /* If we're going to fork for daemon mode, we need to fork now, as
8443 certain output libraries (pulseaudio) become unhappy if initialized
8444 before forking and then being used from the child. */
8446 if (ctl->id_character == 'A' && (ctl->flags & CTLF_DAEMONIZE))
8452 case 0: // child is the daemon
8454 case -1: // error status return
8456 default: // no error, doing well
8457 if ((pidf = fopen( "/var/run/timidity.pid", "w" )) != NULL )
8459 fprintf( pidf, "%d\n", pid );
8466 if(play_mode == &null_play_mode)
8470 output_id = getenv("TIMIDITY_OUTPUT_ID");
8471 #ifdef TIMIDITY_OUTPUT_ID
8472 if(output_id == NULL)
8473 output_id = TIMIDITY_OUTPUT_ID;
8474 #endif /* TIMIDITY_OUTPUT_ID */
8475 if(output_id != NULL)
8477 for(i = 0; play_mode_list[i]; i++)
8478 if(play_mode_list[i]->id_character == *output_id)
8480 if (! play_mode_list[i]->detect ||
8481 play_mode_list[i]->detect()) {
8482 play_mode = play_mode_list[i];
8489 if (play_mode == &null_play_mode) {
8490 /* try to detect the first available device */
8491 for(i = 0; play_mode_list[i]; i++) {
8492 /* check only the devices with detect callback */
8493 if (play_mode_list[i]->detect) {
8494 if (play_mode_list[i]->detect()) {
8495 play_mode = play_mode_list[i];
8502 if (play_mode == &null_play_mode) {
8503 fprintf(stderr, "Couldn't open output device" NLS);
8507 /* apply changes made for null play mode to actual play mode */
8508 if(null_play_mode.encoding != 0) {
8509 play_mode->encoding = apply_encoding(play_mode->encoding, null_play_mode.encoding);
8511 if(null_play_mode.rate != 0) {
8512 play_mode->rate = null_play_mode.rate;
8516 if(!got_a_configuration)
8518 if(try_config_again && !read_config_file(CONFIG_FILE, 0, 0))
8519 got_a_configuration = 1;
8522 if(opt_config_string.nstring > 0)
8524 char **config_string_list;
8526 config_string_list = make_string_array(&opt_config_string);
8527 if(config_string_list != NULL)
8529 for(i = 0; config_string_list[i]; i++)
8531 if(!read_config_file(config_string_list[i], 1, 0))
8532 got_a_configuration = 1;
8536 free(config_string_list[0]);
8537 free(config_string_list);
8541 if(!got_a_configuration)
8547 MAIN_INTERFACE void timidity_init_player(void)
8549 initialize_resampler_coeffs();
8551 /* Allocate voice[] */
8552 free_voice_pointer();
8553 init_voice_pointer();
8555 /* Set play mode parameters */
8556 if(opt_output_rate != 0)
8557 play_mode->rate = opt_output_rate;
8558 else if(play_mode->rate == 0)
8559 play_mode->rate = DEFAULT_RATE;
8562 COPY_CHANNELMASK(drumchannels, default_drumchannels);
8563 COPY_CHANNELMASK(drumchannel_mask, default_drumchannel_mask);
8566 if(opt_buffer_fragments != -1)
8568 if(play_mode->flag & PF_BUFF_FRAGM_OPT)
8569 play_mode->extra_param[0] = opt_buffer_fragments;
8571 ctl->cmsg(CMSG_WARNING, VERB_NORMAL,
8572 "%s: -B option is ignored", play_mode->id_name);
8575 opt_buffer_fragments = 64;
8578 if(opt_audio_buffer_bits != -1)
8580 audio_buffer_bits = opt_audio_buffer_bits;
8583 opt_audio_buffer_bits = audio_buffer_bits;
8585 if(opt_compute_buffer_bits != -128)
8587 compute_buffer_bits = opt_compute_buffer_bits;
8590 opt_compute_buffer_bits = compute_buffer_bits;
8592 init_output(); // div_playmode_rate
8605 #ifdef SUPPORT_SOUNDSPEC
8606 if(view_soundspec_flag)
8609 soundspec_setinterval(spectrogram_update_sec);
8611 #endif /* SOUNDSPEC */
8616 void timidity_init_reduce_queue(void)
8618 double time1,time2,time3,base;
8620 base = aq_get_dev_queuesize() / 2;
8622 base = AUDIO_BUFFER_SIZE;
8624 #ifdef REDUCE_QUALITY_TIME_TUNING
8625 time1 = atof(opt_reduce_quality_threshold);
8629 time1 = REDUCE_QUALITY_TIME_TUNING;
8630 else if(!strchr(opt_reduce_quality_threshold, '%'))
8631 time1 = time1 * play_mode->rate / base * 100;
8632 reduce_quality_threshold = (int)time1;
8634 #ifdef REDUCE_VOICE_TIME_TUNING
8635 time2 = atof(opt_reduce_voice_threshold);
8639 time2 = REDUCE_VOICE_TIME_TUNING;
8640 else if(!strchr(opt_reduce_voice_threshold, '%'))
8641 time2 = time2 * play_mode->rate / base * 100;
8642 reduce_voice_threshold = (int)time2;
8644 #ifdef REDUCE_POLYPHONY_TIME_TUNING
8645 time3 = atof(opt_reduce_polyphony_threshold);
8649 time3 = REDUCE_POLYPHONY_TIME_TUNING;
8650 else if(!strchr(opt_reduce_polyphony_threshold, '%'))
8651 time3 = time3 * play_mode->rate / base * 100;
8652 reduce_polyphony_threshold = (int)time3;
8656 void timidity_init_aq_buff(void)
8658 double time1, /* max buffer */
8659 time2, /* init filled */
8660 base; /* buffer of device driver */
8662 if(!IS_STREAM_TRACE)
8663 return; /* Ignore */
8665 time1 = atof(opt_aq_max_buff);
8666 time2 = atof(opt_aq_fill_buff);
8667 base = (double)aq_get_dev_queuesize() * div_playmode_rate;
8669 if(strchr(opt_aq_max_buff, '%'))
8671 time1 = base * (time1 - 100) * DIV_100;
8672 if(time1 < 0) time1 = 0;
8674 if(strchr(opt_aq_fill_buff, '%'))
8675 time2 = base * time2 * DIV_100;
8677 aq_set_soft_queue(time1, time2);
8678 timidity_init_reduce_queue();
8681 MAIN_INTERFACE int timidity_play_main(int nfiles, char **files)
8683 int need_stdin = 0, need_stdout = 0;
8685 int output_fail = 0;
8687 #if (defined(__W32__) && !defined(__W32G__)) && defined(FORCE_TIME_PERIOD)
8689 #endif /* (__W32__ && !__W32G__) && FORCE_TIME_PERIOD */
8691 if(nfiles == 0 && !strchr(INTERACTIVE_INTERFACE_IDS, ctl->id_character))
8696 play_mode->name = opt_output_name;
8697 if(!strcmp(opt_output_name, "-")){
8700 setmode( fileno(stdout), O_BINARY );
8705 for(i = 0; i < nfiles; i++)
8706 if (!strcmp(files[i], "-")){
8709 setmode( fileno(stdin), O_BINARY );
8713 if(ctl->open(need_stdin, need_stdout))
8715 fprintf(stderr, "Couldn't open %s (`%c')" NLS,
8716 ctl->id_name, ctl->id_character);
8717 if(play_mode->close_output)
8719 play_mode->close_output();
8721 safe_free(play_mode->name);
8722 play_mode->name = NULL;
8726 if(wrdt->open(wrdt_open_opts))
8728 fprintf(stderr, "Couldn't open WRD Tracer: %s (`%c')" NLS,
8729 wrdt->name, wrdt->id);
8730 if(play_mode->close_output)
8732 play_mode->close_output();
8734 safe_free(play_mode->name);
8735 play_mode->name = NULL;
8740 #ifdef BORLANDC_EXCEPTION
8743 #endif /* BORLANDC_EXCEPTION */
8747 signal(SIGTERM, sigterm_exit);
8749 SetConsoleCtrlHandler(handler, TRUE);
8751 ctl->cmsg(CMSG_INFO, VERB_DEBUG_SILLY,
8752 "Initialize for Critical Section");
8753 InitializeCriticalSection(&critSect);
8756 if(!SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_ABOVE_NORMAL))
8757 ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "Error raising thread priority");
8759 #if defined(__W32__)
8760 #ifndef BELOW_NORMAL_PRIORITY_CLASS /* VC6.0 doesn't support them. */
8761 #define BELOW_NORMAL_PRIORITY_CLASS 0x4000
8762 #define ABOVE_NORMAL_PRIORITY_CLASS 0x8000
8763 #endif /* BELOW_NORMAL_PRIORITY_CLASS */
8764 if( processPriority == IDLE_PRIORITY_CLASS ||
8765 processPriority == BELOW_NORMAL_PRIORITY_CLASS ||
8766 processPriority == NORMAL_PRIORITY_CLASS ||
8767 processPriority == ABOVE_NORMAL_PRIORITY_CLASS ||
8768 processPriority == HIGH_PRIORITY_CLASS ||
8769 processPriority == REALTIME_PRIORITY_CLASS)
8770 if(!SetPriorityClass(GetCurrentProcess(), processPriority))
8771 ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "Error changing process priority");
8772 #if !(defined(IA_W32G_SYN) || defined(WINDRV))
8773 if( PlayerThreadPriority == THREAD_PRIORITY_IDLE ||
8774 PlayerThreadPriority == THREAD_PRIORITY_LOWEST ||
8775 PlayerThreadPriority == THREAD_PRIORITY_BELOW_NORMAL ||
8776 PlayerThreadPriority == THREAD_PRIORITY_NORMAL ||
8777 PlayerThreadPriority == THREAD_PRIORITY_ABOVE_NORMAL ||
8778 PlayerThreadPriority == THREAD_PRIORITY_HIGHEST ||
8779 PlayerThreadPriority == THREAD_PRIORITY_TIME_CRITICAL)
8780 if(!SetThreadPriority(GetCurrentThread(), PlayerThreadPriority))
8781 ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "Error changing thread priority");
8787 signal(SIGINT, sigterm_exit);
8788 signal(SIGTERM, sigterm_exit);
8790 signal(SIGPIPE, sigterm_exit); /* Handle broken pipe */
8791 #endif /* SIGPIPE */
8792 #endif /* HAVE_SIGNAL */
8796 /* Open output device */
8797 ctl->cmsg(CMSG_INFO, VERB_DEBUG_SILLY,
8798 "Open output: %c, %s",
8799 play_mode->id_character,
8800 play_mode->id_name);
8802 if (play_mode->flag & PF_PCM_STREAM) {
8803 play_mode->extra_param[1] = aq_calc_fragsize();
8804 ctl->cmsg(CMSG_INFO, VERB_DEBUG_SILLY,
8805 "requesting fragment size: %d",
8806 play_mode->extra_param[1]);
8808 #if !defined ( IA_W32GUI ) && !defined ( IA_W32G_SYN )
8809 if(play_mode->open_output() < 0)
8811 ctl->cmsg(CMSG_FATAL, VERB_NORMAL,
8812 "Couldn't open %s (`%c')",
8813 play_mode->id_name, play_mode->id_character);
8818 #endif /* IA_W32GUI */
8821 control_ratio = play_mode->rate / CONTROLS_PER_SECOND;
8822 if(control_ratio < 1)
8824 else if (control_ratio > MAX_CONTROL_RATIO)
8825 control_ratio = MAX_CONTROL_RATIO;
8827 if(!opt_load_all_instrument)
8828 init_load_soundfont();
8832 timidity_init_aq_buff();
8834 if(allocate_cache_size > 0)
8835 resamp_cache_reset();
8838 set_default_program(def_prog);
8839 if (*def_instr_name)
8840 set_default_instrument(def_instr_name);
8842 if(ctl->flags & CTLF_LIST_RANDOM)
8843 randomize_string_list(files, nfiles);
8844 else if(ctl->flags & CTLF_LIST_SORT)
8845 sort_pathname(files, nfiles);
8847 #if (defined(__W32__) && !defined(__W32G__)) && defined(FORCE_TIME_PERIOD)
8848 if (timeGetDevCaps(&tcaps, sizeof(TIMECAPS)) != TIMERR_NOERROR)
8849 tcaps.wPeriodMin = 10;
8850 timeBeginPeriod(tcaps.wPeriodMin);
8851 #endif /* (__W32__ && !__W32G__) && FORCE_TIME_PERIOD */
8853 /* Return only when quitting */
8854 ctl->cmsg(CMSG_INFO, VERB_DEBUG_SILLY,
8855 "pass_playing_list() nfiles=%d", nfiles);
8857 retval=ctl->pass_playing_list(nfiles, files);
8859 #if (defined(__W32__) && !defined(__W32G__)) && defined(FORCE_TIME_PERIOD)
8860 timeEndPeriod(tcaps.wPeriodMin);
8861 #endif /* (__W32__ && !__W32G__) && FORCE_TIME_PERIOD */
8868 #endif /* XP_UNIX */
8870 if (play_mode->close_output)
8871 play_mode->close_output();
8872 safe_free(play_mode->name);
8873 play_mode->name = NULL;
8877 DeleteCriticalSection (&critSect);
8880 #ifdef BORLANDC_EXCEPTION
8882 fprintf(stderr, "\nError!!!\nUnexpected Exception Occured!\n");
8883 if(play_mode->fd != -1)
8885 play_mode->purge_output();
8886 play_mode->close_output();
8890 DeleteCriticalSection (&critSect);
8893 #endif /* BORLANDC_EXCEPTION */
8895 #ifdef SUPPORT_SOUNDSPEC
8896 if(view_soundspec_flag)
8898 #endif /* SUPPORT_SOUNDSPEC */
8900 free_archive_files();
8901 #ifdef SUPPORT_SOCKET
8902 url_news_connection_cache(URL_NEWS_CLOSE_CACHE);
8903 #endif /* SUPPORT_SOCKET */
8909 int w32gSecondTiMidity(int opt, int argc, char **argv);
8910 int w32gSecondTiMidityExit(void);
8911 int w32gLoadDefaultPlaylist(void);
8912 int w32gSaveDefaultPlaylist(void);
8913 extern int volatile save_playlist_once_before_exit_flag;
8914 #endif /* IA_W32GUI */
8917 #if defined ( IA_W32GUI ) || defined ( IA_W32G_SYN )
8918 static int CoInitializeOK = 0;
8922 #if !defined(KBTIM_SETUP) && !defined(WINDRV_SETUP)
8924 #if !defined(ANOTHER_MAIN) || defined(__W32__)
8925 #ifdef __W32__ /* Windows */
8926 #if defined(IA_W32GUI) && !defined(__CYGWIN32__) && !defined(__MINGW32__) \
8927 || defined(IA_W32G_SYN) /* _MSC_VER, _BORLANDC_, __WATCOMC__ */
8928 int win_main(int argc, char **argv)
8929 #else /* Cygwin, MinGW or console */
8930 int __cdecl main(int argc, char **argv)
8933 int main(int argc, char **argv)
8939 char *files_nbuf = NULL;
8942 #if defined(DANGEROUS_RENICE) && !defined(__W32__) && !defined(main)
8944 * THIS CODES MUST EXECUTE BEGINNING OF MAIN FOR SECURITY.
8945 * DON'T PUT ANY CODES ABOVE.
8947 #include <sys/resource.h>
8950 extern int setpriority(int which, id_t who, int prio);
8951 extern int setreuid(int ruid, int euid);
8955 if (setpriority(PRIO_PROCESS, 0, DANGEROUS_RENICE) < 0) {
8956 perror("setpriority");
8957 fprintf(stderr, "Couldn't set priority to %d.", DANGEROUS_RENICE);
8962 #if defined(REDIRECT_STDOUT)
8963 memcpy(stdout, fopen(REDIRECT_STDOUT, "a+"), sizeof(FILE));
8964 printf("TiMidity++ start\n");
8969 #if defined(IA_W32GUI) && !defined(WIN32GCC) || defined(IA_W32G_SYN)
8971 #elif defined(TIMIDITY_LEAK_CHECK)
8972 _CrtSetDbgFlag(CRTDEBUGFLAGS);
8978 HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
8980 if (hStdOut != INVALID_HANDLE_VALUE)
8984 if (GetConsoleMode(hStdOut, &mode))
8986 SetConsoleMode(hStdOut, mode | 0x0004 /* ENABLE_VIRTUAL_TERMINAL_PROCESSING */);
8992 #endif /* __W32__ */
8993 #if !defined(KBTIM) && !defined(WINDRV)
8994 OverrideSFSettingLoad();
8995 #endif /* KBTIM WINVSTI */
8996 #if defined(VST_LOADER_ENABLE) && defined(TIM_CUI) && defined(TWSYNSRV)
8997 if (hVSTHost == NULL) {
8999 hVSTHost = LoadLibrary("timvstwrap_x64.dll");
9001 hVSTHost = LoadLibrary("timvstwrap.dll");
9003 if (hVSTHost != NULL) {
9004 ((vst_open)GetProcAddress(hVSTHost, "vstOpen"))();
9009 #if defined(__W32__) && !defined(WINDRV)
9010 (void)w32_reset_dll_directory();
9014 static int maincnt = 0;
9016 if (maincnt++ > 0) {
9019 } while (argv[0][0] == '-');
9020 ctl->pass_playing_list(argc, argv);
9027 dynamic_lib_root = safe_strdup(SHARED_LIB_PATH);
9028 dl_init(argc, argv);
9030 #endif /* IA_DYNAMIC */
9031 if ((program_name = pathsep_strrchr(argv[0])))
9034 program_name = argv[0];
9035 if (strncmp(program_name, "timidity", 8) == 0)
9038 else if (strncasecmp(program_name, "kmidi", 5) == 0)
9040 #endif /* IA_KMIDI */
9042 else if (strncasecmp(program_name, "tkmidi", 6) == 0)
9044 #endif /* IA_TCLTK */
9046 else if (strncasecmp(program_name, "gtkmidi", 6) == 0)
9050 else if (strncasecmp(program_name, "xmmidi", 6) == 0)
9052 #endif /* IA_MOTIF */
9054 else if (strncasecmp(program_name, "xawmidi", 7) == 0)
9058 else if (strncasecmp(program_name, "xskinmidi", 9) == 0)
9060 #endif /* IA_XSKIN */
9062 else if (strncasecmp(program_name, "twsync", 6) == 0) /* twsync*.exe */
9064 else if (strncasecmp(program_name, "tmidisyn", 8) == 0) /* tmidisyn*.exe */
9066 else if (strncasecmp(program_name, "tmidis~", 7) == 0) /* tmidis~1.exe */
9068 #endif /* IA_WINSYN */
9069 if (argc == 1 && !strchr(INTERACTIVE_INTERFACE_IDS, ctl->id_character)) {
9070 interesting_message();
9073 timidity_start_initialize();
9074 #if defined (IA_W32GUI) || defined (IA_W32G_SYN)
9075 if (CoInitialize(NULL) == S_OK)
9079 /* Secondary TiMidity Execute */
9080 /* FirstLoadIniFile(); */
9081 if (w32gSecondTiMidity(SecondMode, argc, argv) == FALSE) {
9082 w32gSecondTiMidityExit();
9085 w32g_free_playlist();
9086 w32g_uninitialize();
9091 for (c = 1; c < argc; c++)
9092 if (is_directory(argv[c])) {
9095 p = (char *) safe_malloc(strlen(argv[c]) + 2);
9100 #endif /* IA_W32GUI || IA_W32G_SYN */
9101 #if defined(IA_WINSYN) || defined(IA_PORTMIDISYN) || defined(IA_NPSYN) || defined(IA_W32G_SYN)
9102 opt_sf_close_each_file = 0;
9104 optind = longind = 0;
9106 while ((c = getopt_long(argc, argv, optcommands, longopts, &longind)) > 0)
9107 if ((err = set_tim_opt_long_cfg(c, optarg, longind)) != 0)
9110 if (got_a_configuration != 1){
9111 if ((err = timidity_pre_load_configuration()) != 0)
9114 optind = longind = 0;
9115 while ((c = getopt_long(argc, argv, optcommands, longopts, &longind)) > 0)
9116 if ((err = set_tim_opt_long(c, optarg, longind)) != 0)
9118 err += timidity_post_load_configuration();
9119 /* If there were problems, give up now */
9120 if (err || (optind >= argc && !strchr(INTERACTIVE_INTERFACE_IDS, ctl->id_character))) {
9121 if (!got_a_configuration) {
9123 char config1[1024], config2[1024];
9125 memset(config1, 0, sizeof(config1));
9126 memset(config2, 0, sizeof(config2));
9127 #if defined(IA_W32GUI) || defined(IA_W32G_SYN)
9129 extern char *ConfigFile;
9131 strncpy(config1, ConfigFile, sizeof(config1) - 1);
9133 #else /* !IA_W32GUI && !IA_W32G_SYN */
9134 GetWindowsDirectory(config1, 1023 - 13);
9135 strcat(config1, "\\TIMIDITY.CFG");
9137 if (GetModuleFileName(NULL, config2, 1023)) {
9140 config2[1023] = '\0';
9141 if (strp = strrchr(config2, '\\')) {
9143 strncat(config2, "TIMIDITY.CFG",
9144 sizeof(config2) - strlen(config2) - 1);
9147 ctl->cmsg(CMSG_FATAL, VERB_NORMAL,
9148 "%s: Can't read any configuration file.\n"
9149 "Please check %s or %s", program_name, config1, config2);
9151 ctl->cmsg(CMSG_FATAL, VERB_NORMAL,
9152 "%s: Can't read any configuration file.\n"
9153 "Please check " CONFIG_FILE, program_name);
9154 #endif /* __W32__ */
9156 ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "Try %s -h for help", program_name);
9157 /* Try to continue if it is Windows version */
9158 #if !defined(IA_W32GUI) && !defined(IA_W32G_SYN)
9159 return 1; /* problems with command line */
9162 timidity_init_player();
9164 load_all_instrument();
9166 #ifdef MULTI_THREAD_COMPUTE
9167 #if defined(__W32__) && ( defined(IA_W32G_SYN) )
9168 set_compute_thread_priority(syn_ThreadPriority);
9170 begin_compute_thread();
9172 nfiles = argc - optind;
9173 files = argv + optind;
9175 && ctl->id_character != 'r' && ctl->id_character != 'A'
9176 && ctl->id_character != 'W' && ctl->id_character != 'N'
9177 && ctl->id_character != 'P')
9178 files = expand_file_archives(files, &nfiles);
9180 files_nbuf = files[0];
9181 #if !defined(IA_W32GUI) && !defined(IA_W32G_SYN) && !defined(IA_WINSYN)
9182 if (dumb_error_count)
9186 w32gLoadDefaultPlaylist();
9187 main_ret = timidity_play_main(nfiles, files);
9189 if (save_playlist_once_before_exit_flag) {
9190 save_playlist_once_before_exit_flag = 0;
9191 w32gSaveDefaultPlaylist();
9193 w32gSecondTiMidityExit();
9196 w32g_free_playlist();
9197 w32g_uninitialize();
9199 #elif defined(__W32__)
9201 main_ret = timidity_play_main(nfiles, files);
9206 w32g_uninitialize();
9207 #endif /* IA_W32G_SYN */
9210 main_ret = timidity_play_main(nfiles, files);
9211 #endif /* IA_W32GUI */
9213 #ifdef MULTI_THREAD_COMPUTE
9214 terminate_compute_thread();
9216 #ifdef SUPPORT_SOCKET
9217 safe_free(url_user_agent);
9218 url_user_agent = NULL;
9219 safe_free(url_http_proxy_host);
9220 url_http_proxy_host = NULL;
9221 safe_free(url_ftp_proxy_host);
9222 url_ftp_proxy_host = NULL;
9223 safe_free(user_mailaddr);
9224 user_mailaddr = NULL;
9227 safe_free(dynamic_lib_root);
9228 dynamic_lib_root = NULL;
9230 safe_free(pcm_alternate_file);
9231 pcm_alternate_file = NULL;
9232 safe_free(opt_output_name);
9233 opt_output_name = NULL;
9234 safe_free(opt_aq_max_buff);
9235 opt_aq_max_buff = NULL;
9236 safe_free(opt_aq_fill_buff);
9237 opt_aq_fill_buff = NULL;
9238 safe_free(opt_reduce_voice_threshold);
9239 opt_reduce_voice_threshold = NULL;
9240 safe_free(opt_reduce_quality_threshold);
9241 opt_reduce_quality_threshold = NULL;
9242 safe_free(opt_reduce_polyphony_threshold);
9243 opt_reduce_polyphony_threshold = NULL;
9244 safe_free(output_text_code);
9245 output_text_code = NULL;
9246 safe_free(wrdt_open_opts);
9247 wrdt_open_opts = NULL;
9249 && ctl->id_character != 'r' && ctl->id_character != 'A'
9250 && ctl->id_character != 'W' && ctl->id_character != 'N'
9251 && ctl->id_character != 'P') {
9252 safe_free(files_nbuf);
9258 free_audio_bucket();
9259 free_instruments(0);
9268 free_global_mblock();
9270 //free_reverb_buffer();
9271 free_effect_buffers();
9282 free_voice_pointer();
9283 uninitialize_resampler_coeffs();
9284 for (i = 0; i < MAX_CHANNELS; i++)
9285 free_drum_effect(i);
9286 #if defined(VST_LOADER_ENABLE) && defined(TIM_CUI) && defined(TWSYNSRV)
9288 // only load , no save
9289 // (vst_close)GetProcAddress(hVSTHost, "vstClose")();
9290 FreeLibrary(hVSTHost);
9294 #if (defined(IA_W32GUI) || defined(IA_W32G_SYN)) && \
9295 defined(__GNUC__) && !defined(SUPPORT_WINMAIN)
9296 if (RestartTimidity) {
9297 PROCESS_INFORMATION pi;
9299 char path[MAX_PATH];
9302 RestartTimidity = 0;
9303 ZeroMemory(&pi, sizeof(pi));
9304 ZeroMemory(&si, sizeof(si));
9307 GetModuleFileNameA(NULL, path, MAX_PATH);
9309 //ArgvToCmdLine(); // ToDo
9310 params = (char*) safe_malloc(strlen(path) + 3 + strlen(cmdline) + 1);
9311 strcpy(params, "\"");
9312 strcat(params, path);
9313 strcat(params, "\"" " ");
9314 strcat(params, cmdline);
9315 if (CreateProcessA(NULL, params, NULL, NULL, TRUE,
9316 CREATE_DEFAULT_ERROR_MODE, NULL, NULL, &si, &pi) == FALSE)
9317 MessageBoxA(NULL, "Restart Error.", "TiMidity++ Win32GUI", MB_OK | MB_ICONEXCLAMATION);
9318 CloseHandle(pi.hProcess);
9319 CloseHandle(pi.hThread);
9322 #endif /* (IA_W32GUI || IA_W32G_SYN) && __GNUC__ && !SUPPORT_WINMAIN */
9325 #endif /* !ANOTHER_MAIN || __W32__ */
9328 static void w32_exit(void)
9334 #if defined(IA_W32GUI) || defined(IA_W32G_SYN) || defined(TIM_CUI) || defined(TWSYNSRV)
9335 #ifdef MULTI_THREAD_COMPUTE
9336 terminate_compute_thread();
9339 #ifdef SUPPORT_SOCKET
9340 safe_free(url_user_agent);
9341 url_user_agent = NULL;
9342 safe_free(url_http_proxy_host);
9343 url_http_proxy_host = NULL;
9344 safe_free(url_ftp_proxy_host);
9345 url_ftp_proxy_host = NULL;
9346 safe_free(user_mailaddr);
9347 user_mailaddr = NULL;
9350 safe_free(dynamic_lib_root);
9351 dynamic_lib_root = NULL;
9353 safe_free(pcm_alternate_file);
9354 pcm_alternate_file = NULL;
9355 safe_free(opt_output_name);
9356 opt_output_name = NULL;
9357 safe_free(opt_aq_max_buff);
9358 opt_aq_max_buff = NULL;
9359 safe_free(opt_aq_fill_buff);
9360 opt_aq_fill_buff = NULL;
9361 safe_free(opt_reduce_voice_threshold);
9362 opt_reduce_voice_threshold = NULL;
9363 safe_free(opt_reduce_quality_threshold);
9364 opt_reduce_quality_threshold = NULL;
9365 safe_free(opt_reduce_polyphony_threshold);
9366 opt_reduce_polyphony_threshold = NULL;
9367 safe_free(output_text_code);
9368 output_text_code = NULL;
9369 safe_free(wrdt_open_opts);
9370 wrdt_open_opts = NULL;
9373 free_audio_bucket();
9374 free_instruments(0);
9382 free_global_mblock();
9384 //free_reverb_buffer();
9385 free_effect_buffers();
9396 free_voice_pointer();
9397 uninitialize_resampler_coeffs();
9398 for (i = 0; i < MAX_CHANNELS; i++)
9399 free_drum_effect(i);
9401 #ifdef VST_LOADER_ENABLE
9403 // only load , no save
9404 // ((vst_close) GetProcAddress(hVSTHost, "vstClose"))();
9405 FreeLibrary(hVSTHost);
9410 #endif /* __W32__ */
9413 #endif /* KBTIM_SETUP */