home *** CD-ROM | disk | FTP | other *** search
/ ftp.ee.lbl.gov / 2014.05.ftp.ee.lbl.gov.tar / ftp.ee.lbl.gov / bmd-1.0beta.tar.Z / bmd-1.0beta.tar / bmd-1.0beta / app / mtools / mw.c < prev    next >
C/C++ Source or Header  |  1991-08-21  |  2KB  |  117 lines

  1. /*
  2.  * Copyright (c) 1991 Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms are permitted
  6.  * provided that the above copyright notice and this paragraph are
  7.  * duplicated in all such forms and that any documentation,
  8.  * advertising materials, and other materials related to such
  9.  * distribution and use acknowledge that the software was developed
  10.  * by the University of California, Lawrence Berkeley Laboratory,
  11.  * Berkeley, CA.  The name of the University may not be used to
  12.  * endorse or promote products derived from this software without
  13.  * specific prior written permission.
  14.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  15.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  16.  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  17.  */
  18. #include <stdio.h>
  19. #include <sys/types.h>
  20. #include <sys/file.h>
  21. #include <sys/ioctl.h>
  22. #include <sundev/midi.h>
  23.  
  24. usage()
  25. {
  26.     printf("usage: mw b1 [ b2 b3 ... ]\n");
  27.     exit(1);
  28. }
  29.  
  30. w(fd, p)
  31.     int fd;
  32.     struct midi_msg *p;
  33. {
  34.     int cc;
  35.  
  36.     cc = write(fd, (caddr_t)p, sizeof(*p));
  37.     if (cc < 0) {
  38.         perror("write");
  39.         exit(1);
  40.     }
  41.     printf("wrote %d bytes\n", cc);
  42. }
  43.  
  44. xm(fd, t, c, v)
  45. {
  46.     struct midi_msg mm;
  47.  
  48.     mm.mm_time = t;
  49.     mm.mm_data[0] = c;
  50.     mm.mm_data[1] = v;
  51.     mm.mm_data[2] = 0x20;
  52.     w(fd, &mm);
  53. }
  54.  
  55. on(fd, t, v)
  56. {
  57.     xm(fd, t, 0x90, v);
  58. }
  59.  
  60. off(fd, t, v)
  61. {
  62.     xm(fd, t, 0x80, v);
  63. }
  64.  
  65. mute(fd, t)
  66. {
  67.     int i, cc;
  68.     struct midi_msg m;
  69.  
  70.     m.mm_time = t;
  71.     for (i = 0; i < 16; ++i) {
  72.         m.mm_data[0] = 0xb0 | i;
  73.         w(fd, &m);
  74.     }
  75. }
  76.  
  77. extern char *optarg;
  78.  
  79. main(argc, argv)
  80.     int argc;
  81.     char **argv;
  82. {
  83.     int fd, c;
  84.     int port = 1;
  85.     u_long t;
  86.     char *dev = "/dev/midi0";
  87.  
  88.     while ((c = getopt(argc, argv, "p:")) != -1) {
  89.         switch(c) {
  90.  
  91.         case 'p':
  92.             port = atoi(optarg);
  93.             break;
  94.  
  95.         default:
  96.             usage();
  97.         }
  98.     }
  99.     fd = midi_open(O_WRONLY, port);
  100.     
  101.     on(fd, 100, 0x3c);
  102.     off(fd, 1100, 0x3c);
  103. #ifdef notdef
  104.     if (ioctl(fd, BMDPAUSE, 0) < 0) {
  105.         perror("BMDPAUSE");
  106.         exit(1);
  107.     }
  108. #endif
  109.     mute(fd, 1500);
  110. #ifdef notdef
  111.     (void)ioctl(fd, BMDRESUME, 0);
  112. #endif
  113.     close(fd);
  114.  
  115.     exit(0);
  116. }
  117.