mdPanic(3dm)

mdPanic - flush MIDI output and transmit (obsolete)

Showing IRIX 6.5.30 (default release). Unchanged since IRIX 6.5.

NAME
     mdPanic - flush MIDI output and transmit (obsolete)

SYNOPSIS
     #include <dmedia/midi.h>

     int mdPanic(MDport port)

DESCRIPTION
     mdPanic is an obsolete routine which sends ALL NOTES OFF and RESET ALL
     CONTROLLERS messages on all channels.

     The following program illustrates the prefered method of silencing stuck
     notes (the code is also available in
     /usr/share/src/dmedia/midi/simple/panic.c if the MIDI example code is
     installed).

     #include <stdio.h>
     #include <dmedia/midi.h>

     long long stamp = 0;

     char *usage = "Usage: panic [-f] [-a | interface name]"

     /*
      * Transmit ALL NOTES OFF, ALL SOUND OFF, and RESET ALL CONTROLLERS
      * messages on all 16 channels.
      */
     void
     send_control_messages(MDport port)
     {
          int channel, byte;
          MDevent ev;
          char data_byte[] = { MD_RESETALLCONTROLLERS, MD_ALLNOTESOFF,
                         MD_ALLSOUNDOFF };

          for (channel = 0; channel < 16; channel++) {
               for (byte = 0; byte < 3; byte++) {
                    ev.stamp = stamp++;
                    ev.msg[0] = MD_CONTROLCHANGE | channel;
                    ev.msg[1] = data_byte[byte];
                    ev.msg[2] = 0;
                    mdSend(port, &ev, 1);
               }
          }
     }


     /*
      * Transmit explicit NOTE OFF events on all channels.
      */
     void
     send_note_off_events(MDport port)
     {
          int channel, note;
          MDevent ev;

          for (channel = 0; channel < 16; channel++) {
               for (note = 0; note < 128; note++) {
                    ev.stamp = stamp++;
                    ev.msg[0] = MD_NOTEOFF;
                    ev.msg[1] = note;
                    ev.msg[2] = 0;
                    mdSend(port, &ev, 1);
               }
          }
     }

     void
     main(int argc, char **argv)
     {
          int  num_interfaces;
          MDport    port;

          /* First initialize the MIDI library */
          num_interfaces = mdInit();
          if (num_interfaces == 0) {
               fprintf(stderr, "panic: no interfaces configured0);
               exit(1);
          }

          /* Open the port */
          outport = mdOpenOutPort(name);
          if (outport == NULL) {
               fprintf(stderr, "panic: Could not open interface0);
               exit(1);
          }

          /* Transmit 1 event every millisecond */
          mdSetStampMode(outport, MD_RELATIVETICKS);
          mdSetDivision(outport, 1);
          mdSetTempo(outport, 1000);

          send_note_off_events(outport);
          send_control_messages(outport);

          /* Wait for messages to go out */
          while (mdTellNow(outport) < stamp) ;
     }