home *** CD-ROM | disk | FTP | other *** search
/ Da Capo / da_capo_vol1.bin / programs / amiga / edit / octamedv2 / programmers / examples / example2.c < prev    next >
C/C++ Source or Header  |  1993-03-13  |  2KB  |  69 lines

  1. /* This program loads a module, and plays it. Uses medplayer.library, and
  2.    octaplayer.library if required. Could be used as a small replacement of
  3.    (Octa)MEDPlayer. */
  4.  
  5. #include <exec/types.h>
  6. #include <libraries/dos.h>
  7. #include <proto/exec.h>
  8. #include <proto/dos.h>
  9. /* These two must be included in this order. */
  10. #include "libproto.h"
  11. #include "modplayer.h"
  12.  
  13. void main(argc,argv)
  14. int argc;
  15. char *argv[];
  16. {
  17.     struct MMD0 *sng;
  18.     register struct Library *MEDPlayerBase = 0L,*OctaPlayerBase = 0L;
  19.     if(argc < 2) {
  20.         printf("Usage: example2 <song>\n");
  21.         return;
  22.     }
  23.     MEDPlayerBase = OpenLibrary("medplayer.library",0);
  24.     if(!MEDPlayerBase) {
  25.         printf("Can't open medplayer.library!\n");
  26.         return;
  27.     }
  28.     printf("Loading...\n");
  29.     sng = LoadModule(argv[1]);
  30.     if(!sng) {
  31.         printf("Load error (DOS error #%d).\n",IoErr());
  32.         goto exit;
  33.     }
  34.     /* Now, test if it's 5 - 8 channel module */
  35.     if(sng->song->flags & FLAG_8CHANNEL) {
  36.         OctaPlayerBase = OpenLibrary("octaplayer.library",0);
  37.         if(!OctaPlayerBase) {
  38.             printf("Can't open octaplayer.library!\n");
  39.             goto exit;
  40.         }
  41.         if(GetPlayer8()) {
  42.             printf("Resource allocation failed.\n");
  43.             goto exit;
  44.         }
  45.         PlayModule8(sng);
  46.     } else {
  47.         register long count,midi = 0;
  48.     /* Check if it's a MIDI song. We check the MIDI channel of
  49.     each instrument. */
  50.            for(count = 0; count < 63; count++)
  51.             if(sng->song->sample[count].midich) midi = 1;
  52.         if(GetPlayer(midi)) {
  53.             printf("Resource allocation failed.\n");
  54.             goto exit;
  55.         }
  56.         PlayModule(sng);
  57.     }
  58.     printf("Press Ctrl-C to quit.\n");
  59.     Wait(SIGBREAKF_CTRL_C);
  60. exit:
  61.     FreePlayer();
  62.     UnLoadModule(sng);
  63.     CloseLibrary(MEDPlayerBase);
  64.     if(OctaPlayerBase) {
  65.         FreePlayer8();
  66.         CloseLibrary(OctaPlayerBase);
  67.     }
  68. }
  69.