static long midimsg(COMMNG self, UINT msg, long param) { CMMIDI midi; COMFLAG flag; midi = (CMMIDI)(self + 1); switch(msg) { case COMMSG_MIDIRESET: midireset(midi); return(1); case COMMSG_SETFLAG: flag = (COMFLAG)param; if ((flag) && (flag->size == sizeof(_COMFLAG) + sizeof(midi->mch)) && (flag->sig == COMSIG_MIDI)) { CopyMemory(midi->mch, flag + 1, sizeof(midi->mch)); midisetparam(midi); return(1); } break; case COMMSG_GETFLAG: flag = (COMFLAG)_MALLOC(sizeof(_COMFLAG) + sizeof(midi->mch), "MIDI FLAG"); if (flag) { flag->size = sizeof(_COMFLAG) + sizeof(midi->mch); flag->sig = COMSIG_MIDI; flag->ver = 0; flag->param = 0; CopyMemory(flag + 1, midi->mch, sizeof(midi->mch)); return((long)flag); } break; case COMMSG_MIMPIDEFFILE: mimpidef_load(&midi->def, (OEMCHAR *)param); return(1); case COMMSG_MIMPIDEFEN: midi->def_en = (param)?TRUE:FALSE; return(1); } return(0); }
static INTPTR midimsg(COMMNG self, UINT msg, INTPTR param) { CMMIDI midi; COMFLAG flag; midi = (CMMIDI)(self + 1); switch (msg) { case COMMSG_MIDIRESET: midireset(midi); return 1; case COMMSG_SETFLAG: flag = (COMFLAG)param; if ((flag) && (flag->size == sizeof(_COMFLAG) + sizeof(midi->mch)) && (flag->sig == COMSIG_MIDI)) { CopyMemory(midi->mch, flag + 1, sizeof(midi->mch)); midisetparam(midi); return 1; } break; case COMMSG_GETFLAG: flag = (COMFLAG)_MALLOC(sizeof(_COMFLAG) + sizeof(midi->mch), "MIDI FLAG"); if (flag) { flag->size = sizeof(_COMFLAG) + sizeof(midi->mch); flag->sig = COMSIG_MIDI; flag->ver = 0; flag->param = 0; CopyMemory(flag + 1, midi->mch, sizeof(midi->mch)); return (INTPTR)flag; } break; } return 0; }
int main(int argc, char **argv) { int ch; int example = 0; int gmreset = 0; char *file = NULL; FILE *f; const char *errstr; struct sigaction sa; struct itimerval it; while ((ch = getopt(argc, argv, "?d:f:glmqt:vx")) != -1) { switch (ch) { case 'f': file = optarg; break; case 'g': gmreset = 1; break; case 'm': showmeta = 1; break; case 'q': play = 0; break; case 't': tempo = 60 * 1000000 / strtonum(optarg, 40, 240, &errstr); if (errstr) errx(1, "tempo is %s: %s", errstr, optarg); break; case 'v': verbose++; break; case 'x': example = 1; break; case '?': default: usage(); } } argc -= optind; argv += optind; hdl = mio_open(file, MIO_OUT, 0); if (hdl == NULL) errx(1, "failed to open MIDI output"); if (gmreset) midireset(); sa.sa_flags = SA_RESTART; sa.sa_handler = sigalrm; sigfillset(&sa.sa_mask); if (sigaction(SIGALRM, &sa, NULL) < 0) err(1, "sigaction"); it.it_interval.tv_sec = it.it_value.tv_sec = 0; it.it_interval.tv_usec = it.it_value.tv_usec = 1000; if (setitimer(ITIMER_REAL, &it, NULL) < 0) err(1, "setitimer"); if (example) playdata(sample, sizeof sample, "<Gubben Noa>"); else if (argc == 0) playfile(stdin, "<stdin>"); else while (argc--) { f = fopen(*argv, "r"); if (f == NULL) err(1, "%s", *argv); else { playfile(f, *argv); fclose(f); } argv++; } exit(0); }