home *** CD-ROM | disk | FTP | other *** search
/ Black Art of 3D Game Programming / Black_Art_of_3D_Game_Programming.iso / source / borland / chap_6 / mididemo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-10  |  4.7 KB  |  193 lines

  1.  
  2. // MIDIDEMO.C - MIDI Music Demo
  3.  
  4. // I N C L U D E S ///////////////////////////////////////////////////////////
  5.  
  6. #include <io.h>
  7. #include <conio.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <dos.h>
  11. #include <bios.h>
  12. #include <fcntl.h>
  13. #include <memory.h>
  14. #include <malloc.h>
  15. #include <math.h>
  16. #include <string.h>
  17.  
  18. // include our the sound library
  19.  
  20. #include "black3.h"
  21. #include "black6.h"
  22.  
  23. // M A I N ///////////////////////////////////////////////////////////////////
  24.  
  25. void main(int argc, char **argv)
  26. {
  27.  
  28. char filename[16];  // the .XMI extended midi filename
  29.  
  30. int done=0,    // main loop exit flag
  31.     loaded=0,  // tracks if a file has been loaded
  32.     sequence,  // sequence of XMI extended midi file to be played
  33.     select;    // the users input
  34.  
  35. music song;    // the music structure
  36.  
  37. // main event loop
  38.  
  39. while(!done)
  40.      {
  41.      // print out menu
  42.  
  43.      printf("\n\nExtended MIDI Menu\n");
  44.      printf("\n1. Load Extended MIDI file.");
  45.      printf("\n2. Play Sequence.");
  46.      printf("\n3. Stop Sequence.");
  47.      printf("\n4. Resume Sequence.");
  48.      printf("\n5. Unload Extended MIDI File from Memory.");
  49.      printf("\n6. Print Status.");
  50.      printf("\n7. Exit Program.");
  51.  
  52.      printf("\n\nSelect One ?");
  53.  
  54.      // get input
  55.  
  56.      scanf("%d",&select);
  57.  
  58.      // what does user want to do?
  59.  
  60.      switch(select)
  61.            {
  62.            case 1:  // Load Extended MIDI file
  63.                 {
  64.                 printf("\nEnter Filename of song ?");
  65.                 scanf("%s",filename);
  66.  
  67.                 // if a song is already loaded then delete it
  68.  
  69.                 if (loaded)
  70.                    {
  71.                    // stop music and unload sound
  72.  
  73.                    Music_Stop();
  74.                    Music_Unload((music_ptr)&song);
  75.  
  76.                    } // end if loaded
  77.  
  78.                 // load the new file
  79.  
  80.                 if (Music_Load(filename,(music_ptr)&song))
  81.                    {
  82.                    printf("\nMusic file successfully loaded...");
  83.  
  84.                    // flag that a file is loaded
  85.  
  86.                    loaded = 1;
  87.  
  88.                    }
  89.                 else
  90.                    {
  91.                    // error
  92.  
  93.                    printf("\nSorry, the file %s couldn't be loaded!",filename);
  94.  
  95.                    } // end else
  96.  
  97.                 } break;
  98.  
  99.            case 2: // Play Sequence
  100.                 {
  101.                 // make sure a midi file has been loaded
  102.  
  103.                 if (loaded)
  104.                    {
  105.                    printf("\nWhich Sequence 0..n ?");
  106.                    scanf("%d",&sequence);
  107.  
  108.                    // play the requested sequence
  109.  
  110.                    Music_Play((music_ptr)&song,sequence);
  111.  
  112.                    } // end if loaded
  113.                 else
  114.                    printf("\nYou must first load an extended MIDI file.");
  115.  
  116.                 } break;
  117.  
  118.            case 3: // Stop Sequence
  119.                 {
  120.                 // make sure a midi file has been loaded
  121.  
  122.                 if (loaded)
  123.                     Music_Stop();
  124.                 else
  125.                    printf("\nYou must first load an extended MIDI file.");
  126.  
  127.                 } break;
  128.  
  129.            case 4: // Resume Sequence
  130.                 {
  131.                 // make sure a midi file has been loaded
  132.  
  133.                 if (loaded)
  134.                     Music_Resume();
  135.                 else
  136.                    printf("\nYou must first load an extended MIDI file.");
  137.  
  138.                 } break;
  139.  
  140.            case 5: // Unload Extended MIDI File from Memory
  141.                 {
  142.                 // make sure a midi file has been loaded
  143.  
  144.                 if (loaded)
  145.                    {
  146.                    Music_Stop();
  147.                    Music_Unload((music_ptr)&song);
  148.                    loaded=0;
  149.                    }
  150.                 else
  151.                    printf("\nYou must first load an extended MIDI file.");
  152.  
  153.                 } break;
  154.  
  155.            case 6: // Print Status
  156.                 {
  157.  
  158.                 printf("\nMIDIPAK Status = %d",Music_Status());
  159.  
  160.                 } break;
  161.  
  162.            case 7: // Exit Program
  163.                 {
  164.                 // delete music and stop
  165.  
  166.                 if (loaded)
  167.                    {
  168.                    Music_Stop();
  169.                    Music_Unload((music_ptr)&song);
  170.                    loaded=0;
  171.                    }
  172.  
  173.                 done=1;
  174.  
  175.                 } break;
  176.  
  177.            default:
  178.                   {
  179.                   printf("\nInvalid Selection!");
  180.                   } break;
  181.  
  182.            } // end switch
  183.  
  184.      } // end while
  185.  
  186. // unload file if there is one
  187.  
  188. if (loaded)
  189.    Music_Unload((music_ptr)&song);
  190.  
  191. } // end main
  192.  
  193.