📄 wildmidi.c
字号:
{"rate",1,0,'r'}, {"master_volume",1,0,'m'}, {"config_file",1,0,'c'}, {"wavout",1,0,'o'}, {"linear_vol",0,0,'l'}, {"reverb",0,0,'b'}, {"midi_test",0,0,'t'}, {"test_bank",1,0,'k'}, {"test_patch",1,0,'p'}, {"expensive",0,0,'e'}, {"device",1,0,'d'}, {NULL,0,NULL,0}};voiddo_help (void) { printf(" -v --version Display version\n"); printf(" -h --help This help.\n");#ifndef _WIN32 printf(" -d D --device=D Use device D for audio output instead\n"); printf(" of the default\n");#endif printf("Software Wavetable Options\n"); printf(" -o W --wavout=W Saves the output to W in wav format\n"); printf(" at 44100Hz 16 bit stereo\n"); printf(" -l --linear_vol Use linear volume adjustments\n"); printf(" -r N --rate=N output at N samples per second\n"); printf(" -c P --config_file=P P is the path and filename to your timidity.cfg\n"); printf(" Defaults to /etc/timidity.cfg\n\n"); printf(" -m V --master_volume=V Sets the master volumes, default is 100\n"); printf(" range is 0-127 with 127 being the loudest\n");}voiddo_version (void) { printf("WildMidi %s Open Source Midi Sequencer\n",WILDMIDI_VERSION); printf("Copyright (C) 2001-2004 Chris Ison wildcode@users.sourceforge.net\n\n"); printf("WildMidi comes with ABSOLUTELY NO WARRANTY\n"); printf("This is free software, and you are welcome to redistribute it\n"); printf("under the terms and conditions of the GNU General Public License version 2.\n"); printf("For more information see COPYING\n\n");}voiddo_syntax (void) { printf("wildmidi [options] filename.mid\n\n");}intmain (int argc, char **argv) { struct _WM_Info * wm_info = NULL; int i; int option_index = 0; unsigned long int mixer_options = 0; static char *config_file = NULL; void *midi_ptr = NULL; unsigned char master_volume = 100; int output_result = 0; char * output_buffer = NULL; unsigned long int perc_play = 0; unsigned long int pro_mins = 0; unsigned long int pro_secs = 0; unsigned long int apr_mins = 0; unsigned long int apr_secs = 0; unsigned char modes[4] = {0}; unsigned long int count_diff; unsigned char ch; unsigned char test_midi = 0; unsigned char test_count = 0; unsigned char *test_data = NULL; unsigned char test_bank = 0; unsigned char test_patch = 0; static char *spinner="|/-\\"; static int spinpoint = 0;#ifndef _WIN32 int my_tty; struct termios _tty; tcflag_t _res_oflg = _tty.c_oflag; tcflag_t _res_lflg = _tty.c_lflag;#define raw() (_tty.c_lflag &= ~(ICANON | ICRNL | ISIG), \ _tty.c_oflag &= ~ONLCR, tcsetattr(my_tty, TCSANOW, &_tty))#define savetty() ((void) tcgetattr(my_tty, &_tty), \ _res_oflg = _tty.c_oflag, _res_lflg = _tty.c_lflag)#define resetty() (_tty.c_oflag = _res_oflg, _tty.c_lflag = _res_lflg,\ (void) tcsetattr(my_tty, TCSADRAIN, &_tty))#endif do_version(); while (1) { i = getopt_long (argc, argv, "vho:lr:c:m:btk:p:ed:", long_options, &option_index); if (i == -1) break; switch (i) { case 'v': // Version return 0; case 'h': // help do_syntax(); do_help(); return 0; case 'r': // SoundCard Rate rate = atoi(optarg); break;#ifdef EPERIMENT_626 case 'b': // Reverb mixer_options ^= WM_MO_REVERB; break;#endif case 'm': // Master Volume master_volume = (unsigned char)atoi(optarg); break; case 'o': // Wav Output strcpy(wav_file,optarg); break; case 'c': // Config File config_file = malloc (strlen(optarg)+1); strcpy(config_file,optarg); break; case 'd': // Output device pcmname = malloc (strlen(optarg)+1); strcpy(pcmname,optarg); break; case 'e': // Expensive Interpolation mixer_options |= WM_MO_EXPENSIVE_INTERPOLATION; break; case 'l': // linear volume mixer_options |= WM_MO_LINEAR_VOLUME; break; case 't': // play test midis test_midi = 1; break; case 'k': // set test bank test_bank = (unsigned char)atoi(optarg); break; case 'p': // set test patch test_patch = (unsigned char)atoi(optarg); break; default: printf ("Unknown Option -%o ??\n", i); return 0; } } if (!config_file) { config_file = malloc(sizeof(TIMIDITY_CFG)+1); strncpy (config_file, TIMIDITY_CFG, sizeof(TIMIDITY_CFG)); config_file[sizeof(TIMIDITY_CFG)] = '\0'; } if ((optind < argc) || (test_midi)) { printf("Initializing Sound System\n"); if (wav_file[0] != '\0') { if (open_wav_output() == -1) { return 0; } } else {#if (defined _WIN32) || (defined __CYGWIN__) if (open_mm_output() == -1) {#else#ifdef HAVE_ALSA if (open_alsa_output() == -1) {#else if (open_oss_output() == -1) {#endif#endif return 0; } } printf("Initializing %s\n\n", WildMidi_GetString(WM_GS_VERSION)); printf(" + Volume up e Better resampling n Next Midi\n"); printf(" - Volume down l Linear volume q Quit\n\n"); if (WildMidi_Init (config_file, rate, mixer_options) == -1) { return 0; } WildMidi_MasterVolume(master_volume); output_buffer = malloc(16384); if (output_buffer == NULL) { printf("Not enough ram, exiting\n"); WildMidi_Shutdown(); return 0; }#ifndef _WIN32 my_tty = fileno(stdin); if (isatty(my_tty)) { savetty(); raw(); fcntl(0, F_SETFL, FNONBLOCK); }#endif while ((optind < argc) || (test_midi)) { if (!test_midi) { char * real_file = strrchr(argv[optind], '/'); if (real_file == NULL) { real_file = strrchr(argv[optind], '\\'); } midi_ptr = WildMidi_Open (argv[optind]); if (midi_ptr == NULL) { optind++; continue; } wm_info = WildMidi_GetInfo(midi_ptr); printf ("\rPlaying "); if (real_file != NULL) { printf("%s \n", (real_file+1)); } else { printf("%s \n", argv[optind]); } optind++; } else { if (test_count == midi_test_max) { break; } test_data = malloc(midi_test[test_count].size); memcpy(test_data, midi_test[test_count].data, midi_test[test_count].size); test_data[25] = test_bank; test_data[28] = test_patch; midi_ptr = WildMidi_OpenBuffer(test_data, 633); wm_info = WildMidi_GetInfo(midi_ptr); test_count++; printf ("\rPlaying test midi no. %i\n", test_count); } apr_mins = wm_info->approx_total_samples / (rate * 60); apr_secs = (wm_info->approx_total_samples % (rate * 60)) / rate; if (midi_ptr == NULL) { fprintf(stderr,"\rSkipping %s\n",argv[optind]); optind++; continue; } mixer_options = wm_info->mixer_options; WildMidi_LoadSamples(midi_ptr); while (1) { count_diff = wm_info->approx_total_samples - wm_info->current_sample; if (count_diff == 0) break; ch = 0;#ifdef _WIN32 if (_kbhit()) { ch = _getch(); putch(ch); } #else if (read(my_tty, &ch, 1) != 1) ch = 0; #endif if (ch) { switch (ch) { case 'l': WildMidi_SetOption(midi_ptr, WM_MO_LINEAR_VOLUME, ((mixer_options & WM_MO_LINEAR_VOLUME) ^ WM_MO_LINEAR_VOLUME)); mixer_options ^= WM_MO_LINEAR_VOLUME; break;#ifdef EXPERIMENT_626 case 'r': WildMidi_SetOption(midi_ptr, WM_MO_REVERB, ((mixer_options & WM_MO_REVERB) ^ WM_MO_REVERB)); mixer_options ^= WM_MO_REVERB; break;#endif case 'e': WildMidi_SetOption(midi_ptr, WM_MO_EXPENSIVE_INTERPOLATION, ((mixer_options & WM_MO_EXPENSIVE_INTERPOLATION) ^ WM_MO_EXPENSIVE_INTERPOLATION)); mixer_options ^= WM_MO_EXPENSIVE_INTERPOLATION; break; case 'n': goto NEXTMIDI; case 'q': printf("\n"); WildMidi_Close(midi_ptr); WildMidi_Shutdown(); printf("Shutting down Sound System\n"); close_output();#ifndef _WIN32 if (isatty(my_tty)) resetty();#endif printf("\r\n"); exit (0); case '-': if (master_volume > 0) { master_volume--; WildMidi_MasterVolume(master_volume); } break; case '+': if (master_volume < 127) { master_volume++; WildMidi_MasterVolume(master_volume); } break; } } if (count_diff < 4096) { output_result = WildMidi_GetOutput (midi_ptr, output_buffer, (count_diff * 4)); } else { output_result = WildMidi_GetOutput (midi_ptr, output_buffer, 16384); } wm_info = WildMidi_GetInfo(midi_ptr); perc_play = (wm_info->current_sample * 100) / wm_info->approx_total_samples; pro_mins = wm_info->current_sample / (rate * 60); pro_secs = (wm_info->current_sample % (rate * 60)) / rate; { int mode_count = 0; if (mixer_options & WM_MO_LINEAR_VOLUME) { modes[mode_count++] = 'l'; } if (mixer_options & WM_MO_REVERB) { modes[mode_count++] = 'r'; } if (mixer_options & WM_MO_EXPENSIVE_INTERPOLATION) { modes[mode_count++] = 'e'; } if (mode_count !=3) { do { modes[mode_count++] = ' '; } while (mode_count != 3); } modes[3] = '\0'; } fprintf(stderr, "\r"); fprintf(stderr, "\t [Approx %2lum %2lus Total] [%s] [%3i] [%2lum %2lus Processed] [%2lu%%] %c ", apr_mins, apr_secs, modes, master_volume, pro_mins, pro_secs, perc_play, spinner[spinpoint++%4]); if (output_result == 0) break; send_output (output_buffer, output_result); }NEXTMIDI: fprintf(stderr, "\n\r"); if (WildMidi_Close(midi_ptr) == -1) { printf ("oops\n"); } memset(output_buffer, 0, 16384); send_output (output_buffer, 16384); } memset(output_buffer, 0, 16384); send_output (output_buffer, 16384); send_output (output_buffer, 16384);#ifdef _WIN32 Sleep(5);#else usleep(5000);#endif if (WildMidi_Shutdown() == -1) printf("oops\n"); printf("Shutting down Sound System\n"); close_output();#ifndef _WIN32 if (isatty(my_tty)) resetty();#endif } else { printf("ERROR: No midi file given\n"); do_syntax(); return 0; } if (output_buffer != NULL) free(output_buffer); printf("\r"); return 0;}//============================//============================//============================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -