home *** CD-ROM | disk | FTP | other *** search
- /***********************************************************/
- /* */
- /* Amiga C Encyclopedia (ACE) V3.0 Amiga C Club (ACC) */
- /* ------------------------------- ------------------ */
- /* */
- /* Book: ACM Sound Amiga C Club */
- /* Chapter: EasySound Tulevagen 22 */
- /* File: Play.c 181 41 LIDINGO */
- /* Author: Anders Bjerin SWEDEN */
- /* Date: 92-05-07 */
- /* Version: 1.00 */
- /* */
- /* Copyright 1992, Anders Bjerin - Amiga C Club (ACC) */
- /* */
- /* Registered members may use this program freely in their */
- /* own commercial/noncommercial programs/articles. */
- /* */
- /***********************************************************/
-
- /* This program can be either used from Workbench or the CLI. */
- /* If run from the CLI you give it one or more file names */
- /* containing sampled sound data, and this program will play */
- /* all the sound effects after each other. */
- /* */
- /* This program can also be used from Workbench. The user can */
- /* now simply duble click on the icons he/she wants to play. */
- /* Note that these icons must have been given this program's */
- /* name as default tool name, or else they do not know which */
- /* program should be started when double clicked on. You can */
- /* set the default tool name with help of the "Info" program */
- /* which can be started from the Workbench menus. Give the */
- /* field "Default Tool" the string "SYS:Utilities/Play" if */
- /* you have placed this program in the "Utilities" directory */
- /* on your system disk. */
- /* */
- /* This program can also be used to play sound files which */
- /* have not been prepared with a default tool name. The user */
- /* simply clicks once on this program's icon, and while */
- /* holding one of the SHIFT keys pressed clicks once on each */
- /* sound file he/she want to play. When all files have been */
- /* selected he/she simply double clicks on the last icon. */
- /* This program will then automatically be started and the */
- /* selected files played. */
- /* */
- /* This program is a good example of how to precess the */
- /* Workbench arguments. */
-
-
-
- /* This program must be linked with the EasySound module. */
-
-
- /* Include some important header files: */
- #include <exec/types.h> /* Declares CPTR, BOOL and STRPTR. */
- #include <libraries/dos.h> /* File lock etc... */
- #include <workbench/startup.h> /* Can be used from Workbench. */
- #include "EasySound.h" /* Declares LEFT0, LEFT1, RIGHT0, etc. */
-
-
- /* Pointers to the sound effect: */
- struct SoundInfo *sound;
-
-
-
- /* External global pointer to the Workbench data: */
- /* (Is automatically declared and defined in the */
- /* start up module.) */
- extern struct WBStartup *WBenchMsg;
-
-
- /* Declare the function(s) in this module: */
- void main
- (
- int argc,
- char *argv[]
- );
-
-
- void main
- (
- int argc,
- char *argv[]
- )
- {
- /* Counter: */
- int counter;
-
- /* Number of arguments: */
- int num_arg;
-
- /* Pointer to the workbench arguments: */
- struct WBArg *our_wbarg;
-
- /* From Workbench? */
- BOOL from_workbench;
-
- /* Temporary file name pointer: */
- STRPTR file_name;
-
- /* Pointer to the "old" directory (lock): */
- struct FileLock *old_dir = NULL;
-
-
-
- /* Started from Workbench or CLI? */
- if( argc == 0 )
- {
- /* Program started from Workbench! */
-
- /* Get a pointer to the fisrt argument: */
- our_wbarg = WBenchMsg->sm_ArgList;
-
- /* Set number of arguments: */
- num_arg = WBenchMsg->sm_NumArgs;
-
- /* From Workbench: */
- from_workbench = TRUE;
- }
- else
- {
- /* Started from CLI! */
-
- /* Set the number of arguments: (Makes it */
- /* easier since we now only have to check */
- /* one variable.) */
- num_arg = argc;
-
- /* From CLI: */
- from_workbench = FALSE;
- }
-
-
-
- /* If there is only one arguemnt the program has */
- /* been started without any selected sound files. */
- /* Tell the user how to use this program: */
- if( num_arg == 1 )
- {
- /* Started from Workbench or the CLI? */
- if( from_workbench )
- {
- /* Started from workbench. Tell the user how to */
- /* use this program from Workbench: */
- printf( "Instruction:\n1. Click once on this icon\n" );
- printf( "2. Press any of the shift keys and\n hold it down.\n" );
- printf( "3. Click once on each file to play.\n" );
- printf( "4. Double click on the last icon.\n" );
-
- /* Wait fifteen seconds before we quit. The small */
- /* window will be immediately closed when our */
- /* program terminates, and we must therefore give */
- /* the user some time to read the instructions: */
- Delay( 15 * 50 );
- }
- else
- {
- /* Started from CLI. Tell the user how to */
- /* use this program from CLI: */
- printf( "Usage: Play <sound 1> <sound 2> ...\n" );
- }
- }
-
-
-
- /* Set counter: */
- counter = 1;
-
- /* As long as there are arguments left */
- /* we stay in the while loop: */
- while( counter < num_arg )
- {
- if( from_workbench )
- {
- /* Program started from Workbench! */
-
- /* Go to next argument: (We skip the first argument since */
- /* it is contains the program name, which we definitly */
- /* should not try to play!) */
- our_wbarg++;
-
- /* Get one argument: */
- file_name = our_wbarg->wa_Name;
-
- /* Change directory to where the sound file is: */
- /* (Note that we have to save the old "lock" so */
- /* we later can restore the current directory.) */
- old_dir = (struct FileLock *)
- CurrentDir( our_wbarg->wa_Lock );
- }
- else
- {
- /* Started from CLI! */
- file_name = argv[ counter ];
- }
-
-
-
- /* Prepare the sound: */
- sound = ESPrepareSound( file_name );
-
- /* OK? */
- if( sound )
- {
- /* Sound successfully prepared! */
- printf( "Playing \"%s\"!\n", file_name );
-
- /* Lets play it: */
- ESPlaySound( sound, MAXVOLUME, RIGHT1, SOUND_PRI_EFFECT,
- NORMALRATE, ONCE, 0, 0, WAIT );
-
- /* Make sure that the sound effect has stopped: */
- ESStopSound( RIGHT1 );
-
- /* Remove the sound:*/
- ESRemoveSound( sound );
- }
- else
- {
- /* ERROR! */
- printf( "Could not load sound \"%s\"!\n", file_name );
- }
-
-
-
- /* If we have changed current directory, restore it: */
- if( old_dir )
- CurrentDir( old_dir );
-
- /* Increase counter: */
- counter++;
- }
-
-
-
- /* The End! */
- exit( 0 );
- }
-