home *** CD-ROM | disk | FTP | other *** search
/ Chestnut's Multimedia Mania / MM_MANIA.ISO / midi / cmtcmu / moxctest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-28  |  1.9 KB  |  81 lines

  1. /* moxctest.c -- a test program illustrating moxc */
  2. /*
  3.  * this program plays a short figure on every keydown
  4.  */
  5.  
  6. #include "cmtprog.h"
  7.  
  8. mainscore()
  9. begin
  10.     int r;
  11.  
  12.     /*
  13.      * turning on continuous controller messages (DX7 aftertouch messages)
  14.      * will REALLY load the cpu, so only use this if you need it!
  15.      */
  16. /*    midi_cont(true);    */
  17.  
  18.     /*
  19.      * play a note with a random pitch:
  20.      */
  21.     note(r = random(0, 100), 20);
  22.  
  23.     /*
  24.      * cause mainscore to run every 2 seconds
  25.      */
  26.     cause(200, mainscore);
  27.  
  28.     printf("random(0, 100) = %d\n", r);
  29. end
  30.  
  31.  
  32. keyup(c, k)    /* this gets called whenever a key goes up */
  33. begin        /* turn off all the notes turned on by keydown */
  34.     cause(40, midi_note, c, k+1, 0);
  35.     cause(70, midi_note, c, k-1, 0);
  36.     cause(95, midi_note, c, k+2, 0);
  37.     cause(115, midi_note, c, k-2, 0);
  38.     cause(130, midi_note, c, k+3, 0);
  39.     cause(140, midi_note, c, k-3, 0);
  40.     cause(145, midi_note, c, k+4, 0);
  41. end
  42.  
  43. keydown(c, k, v)    /* this is called when a keyboard note is pressed */
  44. begin            /* schedule a short phrase transposed by k */
  45.     cause(40, midi_note, c, k+1, v);
  46.     cause(70, midi_note, c, k-1, v);
  47.     cause(95, midi_note, c, k+2, v);
  48.     cause(115, midi_note, c, k-2, v);
  49.     cause(130, midi_note, c, k+3, v);
  50.     cause(140, midi_note, c, k-3, v);
  51.     cause(145, midi_note, c, k+4, v);
  52. end
  53.  
  54. ctrlchange(chan, ctrl, value)
  55. begin
  56.     printf("ctrlchange: chan %d, ctrl %d, value %d\n", chan, ctrl, value);
  57. end
  58.  
  59. bendchange(chan, value)
  60. begin
  61.     printf("bendchange: chan %d, value %d\n", chan, value);
  62. end
  63.  
  64. peddown(c)
  65. begin
  66.     printf("peddown, chan %d\n", c);
  67. end
  68.  
  69. pedup(c)
  70. begin
  71.     printf("pedup, chan %d\n", c);
  72. end
  73.  
  74. asciievent(c)
  75. {
  76.     if (c == 'q') quit();
  77.     else if (c == 'n') midi_thru(true);
  78.     else if (c == 'f') midi_thru(false);
  79.     else printf("Type q to quit.\n");
  80. }
  81.