int main(int argc, char **argv) { int argi, i; char *arg, *nextarg; PmError perr; PtError pterr; PmDeviceID dev = -1; int list = 0; for (argi = 1; argi < argc; argi++) { arg = argv[argi]; nextarg = argv[argi+1]; if (arg[0] == '-') { if (!strcmp(arg, "-l")) { list = 1; } else if (!strcmp(arg, "-i") && nextarg) { dev = atoi(nextarg); argi++; } else { fprintf(stderr, "Invalid invocation.\n"); exit(1); } } } PSF(perr, Pm_Initialize, ()); PTSF(pterr, Pt_Start, (1, dump, NULL)); /* list devices */ if (list) { int ct = Pm_CountDevices(); PmDeviceID def = Pm_GetDefaultInputDeviceID(); const PmDeviceInfo *devinf; for (i = 0; i < ct; i++) { devinf = Pm_GetDeviceInfo(i); printf("%d%s: %s%s %s\n", i, (def == i) ? "*" : "", (devinf->input) ? "I" : "", (devinf->output) ? "O" : "", devinf->name); } } /* choose device */ if (dev == -1) { fprintf(stderr, "Warning: Using default device.\n"); dev = Pm_GetDefaultInputDeviceID(); } /* open it for input */ PSF(perr, Pm_OpenInput, (&stream, dev, NULL, 1024, NULL, NULL)); PSF(perr, Pm_SetFilter, (stream, PM_FILT_ACTIVE | PM_FILT_SYSEX)); while (1) Pt_Sleep(1<<31); return 0; }
int main(int argc, char **argv) { FILE *f; PmError perr; MfFile *pf; int ti; MfTrack *track; MfEvent *cur; int redux; if (argc < 4) { fprintf(stderr, "Use: hreducevel <file> <output file> <range reduction>\n"); return 1; } redux = atoi(argv[3]); PSF(perr, Mf_Initialize, ()); /* open it for input */ SF(f, fopen, NULL, (argv[1], "rb")); /* and read it */ PSF(perr, Mf_ReadMidiFile, (&pf, f)); fclose(f); /* redux it */ for (ti = 0; ti < pf->trackCt; ti++) { track = pf->tracks[ti]; cur = track->head; while (cur) { if (Pm_MessageType(cur->e.message) == MIDI_NOTE_ON) { uint8_t vel = Pm_MessageData2(cur->e.message); vel = 127 - (127-vel)/redux; cur->e.message = Pm_Message( Pm_MessageStatus(cur->e.message), Pm_MessageData1(cur->e.message), vel); } cur = cur->next; } } /* write it out */ SF(f, fopen, NULL, (argv[2], "wb")); PSF(perr, Mf_WriteMidiFile, (f, pf)); fclose(f); return 0; }
int main(int argc, char **argv) { FILE *f; PmError perr; PtError pterr; MfFile *pf; int argi, i; char *arg, *nextarg, *file; PmDeviceID dev = -1; int list = 0; file = NULL; for (argi = 1; argi < argc; argi++) { arg = argv[argi]; nextarg = argv[argi+1]; if (arg[0] == '-') { if (!strcmp(arg, "-l")) { list = 1; } else if (!strcmp(arg, "-o") && nextarg) { dev = atoi(nextarg); argi++; } else { fprintf(stderr, "Invalid invocation.\n"); exit(1); } } else { file = arg; } } PSF(perr, Pm_Initialize, ()); PSF(perr, Mf_Initialize, ()); PTSF(pterr, Pt_Start, (1, play, NULL)); /* list devices */ if (list) { int ct = Pm_CountDevices(); PmDeviceID def = Pm_GetDefaultInputDeviceID(); const PmDeviceInfo *devinf; for (i = 0; i < ct; i++) { devinf = Pm_GetDeviceInfo(i); printf("%d%s: %s%s %s\n", i, (def == i) ? "*" : "", (devinf->input) ? "I" : "", (devinf->output) ? "O" : "", devinf->name); } } /* choose device */ if (dev == -1) { fprintf(stderr, "No device selected.\n"); exit(1); } /* open it for input */ PSF(perr, Pm_OpenOutput, (&ostream, dev, NULL, 1024, NULL, NULL, 0)); /* open it for input */ f = fopen(file, "rb"); if (f == NULL) { perror(file); exit(1); } /* and read it */ PSF(perr, Mf_ReadMidiFile, (&pf, f)); fclose(f); /* now start running */ stream = Mf_OpenStream(pf); Mf_StartStream(stream, Pt_Time()); /* FIXME: I sure hope this doesn't get reordered >_> */ ready = 1; while (1) Pt_Sleep(1<<30); return 0; }
{ NETF(angles[2]), 0 }, { NETF(angles2[0]), 0 }, { NETF(angles2[2]), 0 }, { NETF(constantLight), 32 }, { NETF(frame), 16 } }; int bg_numEntityStateFields = ARRAY_LEN(bg_entityStateFields); // playerState_t fields #define PSF(x) (size_t)&((playerState_t*)0)->x, 1 #define PSA(x) (size_t)&((playerState_t*)0)->x, ARRAY_LEN( ((playerState_t*)0)->x ) vmNetField_t bg_playerStateFields[] = { { PSF(commandTime), 32 }, { PSF(origin[0]), 0 }, { PSF(origin[1]), 0 }, { PSF(bobCycle), 8 }, { PSF(velocity[0]), 0 }, { PSF(velocity[1]), 0 }, { PSF(viewangles[1]), 0 }, { PSF(viewangles[0]), 0 }, { PSF(weaponTime), -16 }, { PSF(origin[2]), 0 }, { PSF(velocity[2]), 0 }, { PSF(legsTimer), 8 }, { PSF(pm_time), -16 }, { PSF(eventSequence), 16 }, { PSF(torsoAnim), 8 }, { PSF(movementDir), 4 },
static int devopen(FILE * f, const char * name, int oflags, const char * mde) { struct fnarg fna = {0}; const char * t; const char * s=name; int len; int fnftlen; int rv, rsn; struct exsbuff exs; struct exsbuff * pexs; int exsl=sizeof(exs); int nofile = 0; /* assume file exists */ int zero = 0; /* For SFS plist */ static const char blanks[10] = " "; static const char noc[] = "NOCOMMIT"; static const int nocl = sizeof(noc) - 1; const char * mode = mde; enum intent intent; #if DEBUG __WERROR("Opening %s for mode %s", name, mode); #endif switch (name[0]) { case '/': s += strspn(s, "/"); t=strpbrk(s, "/:"); if (!t) return _seterr(EINVAL, EINVAL, _einv_rsn_bad_fn_onesl, "Leading slash, but no further slash or colon.", name); len = t - s; if ('/' == *t) /* Mode letter and maybe number */ { if (2 < len) return _seterr(EINVAL, EINVAL, _einv_rsn_bad_fn_modelong, "File mode longer than two characters.", name); fna.mode = toupper(0xff & s[0]); fna.moden = 2 == len ? s[1] : ' '; s = t + 1; break; } /* ':' File pool */ if (8 < len) return _seterr(EINVAL, EINVAL, _einv_rsn_bad_fn_fplong, "File pool name longer than 8 characters.", name); memcpy(fna.filepool, s, len); s = t; /* Fall through */ case '~': /* File space */ t = strchr(++s, '/'); if (!t) return _seterr(EINVAL, EINVAL, _einv_rsn_bad_fn_fpfsunterm, "File space name not terminated with forward slash (/).", name); len = t - s; if (len) { if (8<len) return _seterr(EINVAL, EINVAL, _einv_rsn_bad_fn_fslong, "File space name longer than 8 characters.", name); memcpy(fna.filespace, s, len); } for (;;) /* Look for directory levels */ { s += strspn(s, "/"); t = strchr(s, '/'); if (!t) break; if (fna.alen) fna.dir[fna.alen++] = '.'; len = t - s; if (sizeof(fna.dir) < fna.alen + len) return _seterr(EINVAL, EINVAL, _einv_rsn_bad_fn_fslong, "Directory path too long.", name); memcpy(fna.dir + fna.alen, s, len); fna.alen += len; s=t + 1; } break; case '.': return _seterr(EINVAL, EINVAL, _einv_rsn_bad_fn_leaddot, "File name omitted.", name); default: fna.mode = (O_RDONLY & f->oflags) ? '*' : 'A'; } t = strchr(s, '.'); if (!t) return _seterr(EINVAL, EINVAL, _einv_rsn_bad_fn_noft, "File type omitted.", name); len = t - s; fnftlen = strlen(s); if (17 < fnftlen) return _seterr(EINVAL, EINVAL, _einv_rsn_bad_fn_fnftlong, "File name and type too long.", name); memcpy(fna.fid, s, fnftlen); fna.fid[len] = ' '; fna.fidlen = fnftlen; fna.fid[fna.fidlen++] = ' '; #define PSF(x...) fna.fidlen += sprintf(fna.fid + fna.fidlen, x) if (fna.filepool[0]) { PSF("%s:", fna.filepool); if (!fna.filespace[0]) return _seterr(EINVAL, EINVAL, _einv_rsn_bad_fn_fsmissing, "File space not specified.", name); } if (fna.alen) PSF("%s.%s", fna.filespace, fna.dir); else PSF("%c", fna.mode); if (fna.moden) PSF(" %c", fna.moden); #if DEBUG __WERROR("%d >%s<", fna.fidlen, fna.fid); #endif #undef PDF /*********************************************************************/ /* Now look for the file. If user wants caseless, he will have to */ /* do the uppercasing. We in turn make no noise. */ /* */ /* Aw, c'm on. If it is read, look for uppercase. */ /*********************************************************************/ exs.exstype = 0; /* Assume not old */ rsn = 0; nofile = 0; tocsl(8, "DMSEXIST", &rv, &rsn, fna.fid, &fna.fidlen, &exs, &exsl, noc, &nocl); if (rv && 90220 == rsn && (O_RDONLY & oflags) && islower(0xff & fna.fid[0])) { int i; for (i = 0; fna.fidlen > i; i++) { fna.fid[i] = toupper(0xff & fna.fid[i]); } tocsl(8, "DMSEXIST", &rv, &rsn, fna.fid, &fna.fidlen, &exs, &exsl, noc, &nocl); } if (rv) { if (90220 == rsn) nofile = 1; else { char bfr[256]; sprintf(bfr, "DMSEXIST reason %d file '%.*s'", rsn, fna.fidlen, fna.fid); return _seterr(EINVAL, EINVAL, _einv_rsn_bad_dmsexist, "CMS error locating file", bfr); } } else { #define M(x, y) f->x = exs.exsf ## y M(recform, recf); M(lrecl, recl); M(numrecs, recs); M(numblks, blks); #undef M } /*********************************************************************/ /* Figure operation intent and set the keyword accordingly. */ /*********************************************************************/ if (nofile) { if (O_RDONLY & f->oflags) return ENOENT; intent = int_create; /* If it ain't there, surely we create */ } else { if (O_EXCL & f->oflags) return EEXISTS; if (O_RDONLY & f->oflags) intent = int_read; else if (O_TRUNC & f->oflags) intent = int_replace; else intent = int_update; } #define POP(x...) fna.optlen += sprintf(fna.opt + fna.optlen, x) POP("%s", sfsint[intent]); /* Intent */ #if DEBUG __WERROR("%d %s", fna.optlen, fna.opt); #endif /*********************************************************************/ /* Process remaining part of mode string. */ /* */ /* It may be a comma and lrecl=nnn, and SFS open options which */ /* should not include new/read/replace, as we construct that word */ /* from the standard type. */ /*********************************************************************/ s = mode; while (s && *s) { if (0==strncasecmp(s, "lrecl=", 6)) { int got=0; int lrecl; sscanf(s+6, "%d %n", &lrecl, &got); if (0==got) return _seterr(EINVAL, EINVAL, _einv_rsn_bad_lrecl, "Record length missing.", s); if (nofile) f->lrecl = lrecl; else s += 6 + got; } else if (0==strncasecmp(s, "recfm=", 6)) { char recfm = toupper(0xff & s[6]); if ('F' != recfm && 'V' != recfm) return _seterr(EINVAL, EINVAL, _einv_rsn_bad_recfm, "Record format not valid.", s); if (!nofile && recfm != f->recform) { char bfr[2] = {f->recform}; return _seterr(EINVAL, EINVAL, _einv_rsn_recfm_diff, "Record format not same as existing file.", bfr); } if (!(O_RDONLY & f->oflags)) POP(" %c", recfm); s += 7; } else return _seterr(EINVAL, EINVAL, _einv_rsn_bad_mode, "Unrecognised mode string.", s); if (*s && ',' != *s++) return _seterr(EINVAL, EINVAL, _einv_rsn_bad_mode_del, "Comma expected in mode string.", s); } /* Supply defaults if create */ if (int_create == intent) { if (!f->recform) { f->recform = 'V'; POP(" %c", f->recform); } if (!f->lrecl) { /* Setting the LRECL for V files is for the write function */ /* to know when to cut a record; SFS will ignore the record */ /* length? */ if ('F' == f->recform) f->lrecl = 80; else if (O_BINARY & f->oflags) f->lrecl = 255; } } if (sizeof(fna.opt) - fna.optlen <= len) return _seterr(EINVAL, EINVAL, _einv_rsn_long_opt, "Option string too long.", s); #if DEBUG __WERROR("fd %d mode '%s' options %d '%-*.*s' open flag %x", f->fd, mde, fna.optlen, fna.optlen, fna.optlen, fna.opt, f->oflags); #endif #undef POP /*********************************************************************/ /* And finally. */ /*********************************************************************/ tocsl(15, "DMSOPEN ", &rv, &rsn, fna.fid, &fna.fidlen, fna.opt, &fna.optlen, f->token, &zero, /* Work unit */ &zero, /* Wu error */ &zero, /* Wu error length */ &zero, /* User data */ &zero, /* User data length */ blanks, /* Create date */ blanks, /* Create time */ &f->lrecl /* Explicit record length */ ); switch (rv) { case 0: break; case 4: break; case 8: switch (rsn) { case 90310: __sayf("fd %d %s bad keyword in list '%s'", f->fd, name, fna.opt); break; default: goto error; } return EINVAL; default: error: __sayf("DMSOPEN fd %d rc=%d reason=%d.", f->fd, rv, rsn); return EINVAL; } if (!fna.mode) f->blksize = 0x1000; else { if (0) __sayf("FIXME " __FILE__ ".%d", __LINE__); } pexs = f->accwork = malloc(sizeof(struct exsbuff)); if (!f) return ENOMEM; *pexs = exs; return 0; }