home *** CD-ROM | disk | FTP | other *** search
- /*
- ** $PROJECT: playmidi
- **
- ** $VER: playmidi.c 1.0 (11.9.97)
- **
- ** Copyright 1997 by Martin Gierich.
- ** Inspired by playsound.c written by David N. Junod.
- **
- ** Minimal player for midi music using midi.datatype (CLI only).
- **
- ** Calling template: NAME/A,VOLUME/N/K,CYCLES/N/K,CLUSTER/K
- ** NAME - name of file to play
- ** VOLUME - main playback volume
- ** CYCLES - number of repeats
- ** CLUSTER - name of CAMD cluster for midi playback
- **
- ** $TABSIZE: 3
- */
-
- #include <string.h>
- #include <exec/types.h>
- #include <datatypes/soundclass.h>
- #include <datatypes/midiclass.h>
-
- #include <proto/exec.h>
- #include <proto/dos.h>
- #include <proto/datatypes.h>
-
- /*****************************************************************************/
-
- /* Disable CTRL-C handling */
- #ifdef __SASC
- void __regargs __chkabort(void) { }
- void __regargs _CXBRK(void) { }
- #endif
-
- /*****************************************************************************/
-
- /* Define command line arguments for ReadArgs() */
- #define TEMPLATE "NAME/A,VOLUME/N,CYCLES/N,CLUSTER/K"
- enum
- {
- OPT_NAME,
- OPT_VOL,
- OPT_CYC,
- OPT_CLU,
- NUM_OPTS
- };
-
- /*****************************************************************************/
-
- int main (int argc, char **argv)
- {
- /* Argument parsing variables */
- ULONG options[NUM_OPTS];
- struct RDArgs *rdargs;
-
- /* Object variable */
- Object *obj;
-
- /* Parse arguments */
- memset (options, 0, sizeof(options));
- if (rdargs = ReadArgs(TEMPLATE, (LONG *)options, NULL))
- {
-
- /* Clear signal to be used, so we can recognize end of playback */
- SetSignal(0L, SIGBREAKF_CTRL_C);
-
- /* Open the midi object */
- if (obj = NewDTObject (
- /* Set the source file name */
- (APTR) options[OPT_NAME],
- /* Say that the source is a file */
- DTA_SourceType, DTST_FILE,
- /* We will only accept music (midi) DataTypes */
- DTA_GroupID, GID_MUSIC,
- /* Set attributes from the commandline */
- SDTA_Volume, options[OPT_VOL] ? *(LONG*) options[OPT_VOL] : 64,
- SDTA_Cycles, options[OPT_CYC] ? *(LONG*) options[OPT_CYC] : 1,
- options[OPT_CLU] ? MDTA_Cluster : DTA_Dummy, (APTR) options[OPT_CLU],
- /* We want to be notified when the music stops playing, so
- * we provide a signal task and a signal (CTRL-C) */
- SDTA_SignalTask,(ULONG) FindTask (NULL),
- SDTA_SignalBit, (ULONG) SIGBREAKF_CTRL_C,
- /* Start playing immediately */
- DTA_Immediate, TRUE,
- /* No more attributes */
- TAG_DONE))
- {
-
- Printf("Playing midi file %s.\n", options[OPT_NAME]);
-
- /* Wait till the datatype tells us that it is all over */
- Wait(SIGBREAKF_CTRL_C);
-
- /* Get rid of the object */
- DisposeDTObject(obj);
- }
- else
- /* Show a failure message */
- if (!IoErr())
- Printf("Error: No music file.\n",IoErr());
- PrintFault (IoErr (), "Error");
-
- /* Free the allocated memory after ReadArgs */
- FreeArgs (rdargs);
- }
- else
- /* Show a failure message */
- PrintFault (IoErr (), "Error");
-
- return(0);
- }
-