/* ** TRIM -- Copy MIDI data from the standard input to the standard output, ** trimming off blank time at the beginning and end. ** The output has TCIP commands repositioned logically. ** Example: 'trim -h fum' deletes only the leading silence. */ #include #include main(argc, argv) char *argv[]; { int head = 0, tail = 0, stat; long now, ptcwme, offset, lastwhen, lasttcwme; MCMD *mp; while (--argc > 0) { if (argv[argc][0] == '-') { switch (argv[argc][1]) { case 'h': head++; break; case 't': tail++; break; default: goto syntax; } } else { syntax: fprintf(stderr, "Usage: %s [-h] [-t] when; stat = mp->cmd[0]; if (stat == RT_TCWME) { ptcwme = now - offset; if (ptcwme == lasttcwme) ptcwme = -1L; continue; } if (head) { offset = now; head = 0; ptcwme = -1L; } if (ptcwme >= 0) { Rt_tcwme.when = ptcwme; putmcmd(stdout, &Rt_tcwme); lasttcwme = ptcwme; ptcwme = -1L; } mp->when -= offset; putmcmd(stdout, mp); lastwhen = mp->when; } if (ptcwme == lastwhen) { Rt_tcwme.when = ptcwme; putmcmd(stdout, &Rt_tcwme); } }