home *** CD-ROM | disk | FTP | other *** search
/ The Best of Mecomp Multimedia 2 / MECOMP-CD-II.iso / amiga / datatypes / mididt / source / playmidi.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-10-04  |  2.8 KB  |  114 lines

  1. /*
  2. ** $PROJECT: playmidi
  3. **
  4. ** $VER: playmidi.c 1.0 (11.9.97)
  5. **
  6. ** Copyright 1997 by Martin Gierich.
  7. ** Inspired by playsound.c written by David N. Junod.
  8. **
  9. ** Minimal player for midi music using midi.datatype (CLI only).
  10. **
  11. ** Calling template: NAME/A,VOLUME/N/K,CYCLES/N/K,CLUSTER/K
  12. ** NAME - name of file to play
  13. ** VOLUME - main playback volume
  14. ** CYCLES - number of repeats
  15. ** CLUSTER - name of CAMD cluster for midi playback
  16. **
  17. ** $TABSIZE: 3
  18. */
  19.  
  20. #include <string.h>
  21. #include <exec/types.h>
  22. #include <datatypes/soundclass.h>
  23. #include <datatypes/midiclass.h>
  24.  
  25. #include <proto/exec.h>
  26. #include <proto/dos.h>
  27. #include <proto/datatypes.h>
  28.  
  29. /*****************************************************************************/
  30.  
  31. /* Disable CTRL-C handling */
  32. #ifdef __SASC
  33. void __regargs __chkabort(void) { }
  34. void __regargs _CXBRK(void) { }
  35. #endif
  36.  
  37. /*****************************************************************************/
  38.  
  39. /* Define command line arguments for ReadArgs() */
  40. #define TEMPLATE "NAME/A,VOLUME/N,CYCLES/N,CLUSTER/K"
  41. enum
  42. {
  43.     OPT_NAME,
  44.     OPT_VOL,
  45.     OPT_CYC,
  46.     OPT_CLU,
  47.     NUM_OPTS
  48. };
  49.  
  50. /*****************************************************************************/
  51.  
  52. int main (int argc, char **argv)
  53. {
  54.     /* Argument parsing variables */
  55.     ULONG options[NUM_OPTS];
  56.     struct RDArgs *rdargs;
  57.  
  58.     /* Object variable */
  59.     Object *obj;
  60.  
  61.     /* Parse arguments */
  62.     memset (options, 0, sizeof(options));
  63.     if (rdargs = ReadArgs(TEMPLATE, (LONG *)options, NULL))
  64.     {
  65.  
  66.         /* Clear signal to be used, so we can recognize end of playback */
  67.         SetSignal(0L, SIGBREAKF_CTRL_C);
  68.  
  69.         /* Open the midi object */
  70.         if (obj = NewDTObject (
  71.             /* Set the source file name */
  72.             (APTR) options[OPT_NAME],
  73.             /* Say that the source is a file */
  74.             DTA_SourceType,    DTST_FILE,
  75.             /* We will only accept music (midi) DataTypes */
  76.             DTA_GroupID,    GID_MUSIC,
  77.             /* Set attributes from the commandline */
  78.             SDTA_Volume,    options[OPT_VOL] ? *(LONG*) options[OPT_VOL] : 64,
  79.             SDTA_Cycles,    options[OPT_CYC] ? *(LONG*) options[OPT_CYC] : 1,
  80.             options[OPT_CLU] ? MDTA_Cluster : DTA_Dummy, (APTR) options[OPT_CLU],
  81.             /* We want to be notified when the music stops playing, so
  82.              * we provide a signal task and a signal (CTRL-C) */
  83.             SDTA_SignalTask,(ULONG) FindTask (NULL),
  84.             SDTA_SignalBit,    (ULONG) SIGBREAKF_CTRL_C,
  85.             /* Start playing immediately */
  86.             DTA_Immediate,    TRUE,
  87.             /* No more attributes */
  88.             TAG_DONE))
  89.         {
  90.  
  91.             Printf("Playing midi file %s.\n", options[OPT_NAME]);
  92.  
  93.             /* Wait till the datatype tells us that it is all over */
  94.             Wait(SIGBREAKF_CTRL_C);
  95.  
  96.             /* Get rid of the object */
  97.             DisposeDTObject(obj);
  98.         }
  99.         else
  100.             /* Show a failure message */
  101.             if (!IoErr())
  102.                 Printf("Error: No music file.\n",IoErr());
  103.             PrintFault (IoErr (), "Error");
  104.  
  105.     /* Free the allocated memory after ReadArgs */
  106.     FreeArgs (rdargs);
  107.     }
  108.     else
  109.         /* Show a failure message */
  110.         PrintFault (IoErr (), "Error");
  111.  
  112.     return(0);
  113. }
  114.