home *** CD-ROM | disk | FTP | other *** search
/ ftp.4front-tech.com / ftp.4front-tech.com.tar / ftp.4front-tech.com / ossfree / snd-util-3.8.tar.gz / snd-util-3.8.tar / sndkit / fm / wbset.c < prev   
C/C++ Source or Header  |  1980-01-01  |  3KB  |  149 lines

  1. /*
  2.  * wbset.c
  3.  * 
  4.  * Setup loader for the WaveBlaster board using the Linux Sound Driver.
  5.  * 
  6.  * Copyright by Hannu Savolainen 1993
  7.  * 
  8.  * Redistribution and use in source and binary forms, with or without
  9.  * modification, are permitted provided that the following conditions are
  10.  * met: 1. Redistributions of source code must retain the above copyright
  11.  * notice, this list of conditions and the following disclaimer. 2.
  12.  * Redistributions in binary form must reproduce the above copyright notice,
  13.  * this list of conditions and the following disclaimer in the documentation
  14.  * and/or other materials provided with the distribution.
  15.  * 
  16.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
  17.  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19.  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
  20.  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  21.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  22.  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  23.  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  24.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  25.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  26.  * SUCH DAMAGE.
  27.  * 
  28.  */
  29. #include <stdio.h>
  30. #include <stdlib.h>
  31. #include <unistd.h>
  32. #include <fcntl.h>
  33. #include <sys/soundcard.h>
  34.  
  35. /*
  36.  * You have to change the CBK_PATH
  37.  */
  38. #ifndef CBK_PATH
  39. #define CBK_PATH    "/C/waveblst/wbpanel/"
  40. #endif
  41.  
  42. #define BUFLEN 1024
  43. int fd;
  44. int mididev;
  45.  
  46. void
  47. dump(int cbkfd)
  48. {
  49.   int i, tmp, n, p;
  50.   unsigned char buf[BUFLEN], obuf[4 * BUFLEN] =
  51.   {0};
  52.  
  53.   while ((n = read (cbkfd, buf, BUFLEN)) > 0)
  54.     {
  55.       p = 0;
  56.  
  57.       for (i = 0; i < n; i++)
  58.     {
  59.       obuf[p + 0] = SEQ_MIDIPUTC;
  60.       obuf[p + 1] = buf[i];
  61.       obuf[p + 2] = mididev;
  62.       obuf[p + 3] = 0;
  63.       p += 4;
  64.     }
  65.  
  66.       if (write (fd, obuf, p) != p)
  67.       {
  68.           perror("/dev/sequencer");
  69.           exit(-1);
  70.       }
  71.  
  72.     }
  73. }
  74.  
  75. main (int argc, char *argv[])
  76. {
  77.   int i, tmp, n, p;
  78.   struct midi_info info;
  79.  
  80.   int cbkfd;    /* Sysex file */
  81.   char cbk_name[1024];
  82.  
  83.   if (argc !=3)
  84.   {
  85.       fprintf(stderr, "usage: %s <setupname>.cgs <bankname>.cbk\n", argv[0]);
  86.       exit(-1);
  87.   }
  88.  
  89.   if ((fd = open ("/dev/sequencer", O_WRONLY, 0)) == -1)
  90.     {
  91.       perror ("/dev/sequencer");
  92.       exit (-1);
  93.     }
  94.  
  95. /*
  96.  * First locate the SB16 midi interface. The WaveBlaster is sitting there.
  97.  */
  98.  
  99.   if (ioctl(fd, SNDCTL_SEQ_NRMIDIS, &n)==-1)
  100.     {
  101.       perror ("/dev/sequencer");
  102.       exit (-1);
  103.     }
  104.  
  105.   mididev = -1;
  106.  
  107.   for (i=0;i<n && mididev == -1;i++)
  108.   {
  109.     info.device = i;
  110.     if (ioctl(fd, SNDCTL_MIDI_INFO, &info)==-1)
  111.     {
  112.       perror ("/dev/sequencer");
  113.       exit (-1);
  114.     }
  115.  
  116.     if (info.dev_type == SNDCARD_SB16MIDI) mididev=i;
  117.   }
  118.  
  119.   if (mididev == -1)
  120.   {
  121.       fprintf(stderr, "%s: SB16 Midi device not found\n");
  122.       exit(-1);
  123.   }
  124.  
  125.   sprintf(cbk_name, CBK_PATH "%s.cgs", argv[2]);
  126.  
  127.   if ((cbkfd = open (cbk_name, O_RDONLY, 0)) == -1)
  128.     {
  129.       perror (cbk_name);
  130.       exit (-1);
  131.     }
  132.  
  133.    dump(cbkfd);
  134.    close(cbkfd);
  135.  
  136.   sprintf(cbk_name, CBK_PATH "%s.cbk", argv[2]);
  137.  
  138.   if ((cbkfd = open (cbk_name, O_RDONLY, 0)) == -1)
  139.     {
  140.       perror (cbk_name);
  141.       exit (-1);
  142.     }
  143.  
  144.    dump(cbkfd);
  145.    close(cbkfd);
  146.  
  147.    exit(0);
  148. }
  149.