/* * $Id$ */ #include #include #include #include #include #include SEQ_DEFINEBUF (2048); SEQ_PM_DEFINES; int seqfd, dev = 0; unsigned char buf[100]; int bufp; /* LRU list for free operators */ unsigned char free_list[256]; int fhead=0, ftail=0, flen=0; /* LRU list for still playing notes */ unsigned char note_list[256]; int nhead=0, ntail=0, nlen=0; unsigned char oper_note[32]; int pgm = 0; int num_voices; int bender = 0; /* Initially off */ void seqbuf_dump () { if (_seqbufptr) if (write (seqfd, _seqbuf, _seqbufptr) == -1) { perror ("write /dev/sequencer"); exit (-1); } _seqbufptr = 0; } void stop_note(int note, int velocity) { int i, op; op=255; for (i=0;i255) { #if 0 fprintf(stderr, "Note list overflow %d, %d, %d\n", nlen, nhead, ntail); #endif nlen=0; /* Overflow -> hard reset */ } nlen++; ntail = (ntail+1) % 256; oper_note[free] = note; SEQ_SET_PATCH(dev, free, pgm); SEQ_PITCHBEND(dev, free, bender); SEQ_START_NOTE(dev, free, note, velocity); SEQ_DUMPBUF(); } void channel_pressure(int ch, int pressure) { int i; for (i=0;i> 7); */ pitch_bender(ch, value); bufp=1; break; case 0xc0: /* Pgm change */ if (bufp < 2) break; /* printf("Pgm change %d %d\n", ch, buf[1]); */ pgm = buf[1]; if (PM_LOAD_PATCH(dev, 0, pgm) < 0) if (errno != ESRCH) /* No such process */ perror("PM_LOAD_PATCH"); bufp=0; break; case 0xd0: /* Channel pressure */ if (bufp < 2) break; /* printf("Channel pressure %d %d\n", ch, buf[1]); */ channel_pressure(ch, buf[1]); bufp=1; break; default: bufp=0; } } int main (int argc, char *argv[]) { int i, n, max_voice = 999; struct synth_info info; unsigned char ev[4], *p; if (argc >= 2) dev = atoi(argv[1]); for (i=0;i<16;i++) oper_note[i] = 255; if ((seqfd = open ("/dev/sequencer", O_RDWR, 0)) == -1) { perror ("open /dev/sequencer"); exit (-1); } if (argc >= 3) { int d = dev; ioctl(seqfd, SNDCTL_FM_4OP_ENABLE, &d); } info.device = dev; if (ioctl(seqfd, SNDCTL_SYNTH_INFO, &info)==-1) { perror ("info /dev/sequencer"); exit (-1); } num_voices = info.nr_voices; if (num_voices>max_voice)num_voices = max_voice; fprintf(stderr, "Output to synth device %d (%s)\n", dev, info.name); fprintf(stderr, "%d voices available\n", num_voices); for (i=0;i