home *** CD-ROM | disk | FTP | other *** search
/ Dave Lowe: The Developer …nd Blaster Series Disk 1 / Lowe_TheDeveloperKitForSoundBlasterSeriesDisk1.img / C / MSC / MIDI / MIDIOUT.C < prev   
Encoding:
C/C++ Source or Header  |  1991-10-30  |  2.7 KB  |  70 lines

  1. /* ------------------------------------------------------------------------ */
  2. /*  @@ Source Documentation                        *** MSC/TC Version ***   */
  3. /*                                                                          */
  4. /*  Copyright (c) Creative Technology Pte Ltd, 1991. All rights reserved.   */
  5. /*                                                                          */
  6. /*   TITLE       : MIDIOUT.C                                                */
  7. /*                                                                          */
  8. /*   DESCRIPTION :                                                          */
  9. /*       This program demostrates how to use the SBK MIDI interface         */
  10. /*       functions to play a 'C major scale'. It calls the MIDI low         */
  11. /*       level interface functions to send the MIDI commands to MIDI        */
  12. /*       keyboard.                                                          */
  13. /*                                                                          */
  14. /*       The program checks BLASTER environment for the Card settings.      */
  15. /*       It also performs test base on BLASTER environment settings to      */
  16. /*       ensure they are tally with the hardware settings on the Card.      */
  17. /*                                                                          */
  18. /* ------------------------------------------------------------------------ */
  19.  
  20. #include <stdio.h>
  21. #include <sbc.h>
  22. #include <sbmidi.h>
  23.  
  24.  
  25. /* Look up table for MIDI value of a 'scale' starts from 'middle C' */
  26.  
  27. unsigned char  NoteNum[] = { 60, 62, 64, 65, 67, 69, 71, 72 } ;
  28.  
  29.  
  30.  
  31. #pragma loop_opt(off)
  32. main ()
  33. {
  34.     unsigned int   i, j, note;
  35.     unsigned char  pnum;
  36.  
  37.  
  38.     /* Retrieve the BLASTER environment settings */
  39.     if ( ! GetEnvSetting() )
  40.     {
  41.         if (sbc_check_card() & 4)
  42.         {
  43.             for ( pnum= 0; pnum < 5; pnum++ )
  44.             {
  45.                 /* program change command */
  46.                 sbmidi_out_shortmsg( 0xC0, pnum, 0 );
  47.  
  48.                 /* play the Middle C scale */
  49.                 for ( note=0; note < 8; note++ )
  50.                 {
  51.                     /* Note On command */
  52.                     sbmidi_out_shortmsg( 0x90, NoteNum[note], 0x40 );
  53.  
  54.                     /* delay loop */
  55.                     for (i=0; i<100; i++)
  56.                         for (j=0; j < 1000; j++);
  57.  
  58.                     /* Note Off command */
  59.                     sbmidi_out_shortmsg( 0x80, NoteNum[note], 0x40 );
  60.                 }
  61.             }
  62.         }
  63.         else
  64.             printf("Sound Blaster Card not found or wrong I/O settings.\n") ;
  65.     }
  66.     else
  67.         printf("BLASTER environment not set or incomplete or invalid.\n");
  68. }
  69. #pragma loop_opt()
  70.