home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / sound / sampplay / intsnd.lha / playsound.c < prev    next >
C/C++ Source or Header  |  1993-01-20  |  2KB  |  87 lines

  1. #include <stdio.h>
  2. #include <Intuition/Intuition.h>
  3. #include <string.h>
  4. #include <exec/types.h>
  5. #include "filewindow.h"
  6. #include "easysound.h"
  7.  
  8. extern USHORT FileWindow();
  9.  
  10. struct IntuitionBase *IntuitionBase;
  11. struct IntuiMessage *your_message;
  12.  
  13.  
  14. /*POINTER TO SOUND*/
  15. CPTR TheSoundFile;
  16. char MyMessage[50];
  17. void CloseAll();
  18.  
  19. void main()
  20. {
  21.   /* Declare variable to use for FileWindow */
  22.   USHORT operation;
  23.   UBYTE file[TOTAL_LENGTH];
  24.   int Done=1;
  25.   BOOL ok=FALSE;
  26.   char MyTitle[50]="Play What File";
  27.   
  28.   /* Open Intuiton libarary */
  29.   if ( (IntuitionBase = (struct IntuitionBase *)
  30.         OpenLibrary("intuition.library",33)) == NULL)
  31.      {
  32.        printf("Can't open intuition library");
  33.        exit();
  34.      }
  35.   while(Done==1)
  36.   {
  37.     /* Open File Window (requester)*/
  38.     operation=FileWindow(
  39.                          MyTitle,      /*Title*/
  40.              NULL,                   /*extension*/
  41.                  0,0,                    /*x,y positon */
  42.                      NULL,                   /*screen (Workbench)*/
  43.                  file                    /*file with path*/
  44.                 );
  45.     /* What does user want to do? */
  46.     switch(operation)
  47.     {
  48.       case LOAD:   Done--; strcpy(MyMessage,"Gaget should not work"); break;
  49.       case SAVE:   /* Prepare And Play Sound File */
  50.                    StopSound(LEFT1);
  51.            StopSound(RIGHT1);
  52.                    TheSoundFile = PrepareSound(file);
  53.                    if ( !TheSoundFile )
  54.                      strcpy(MyTitle,"Can't prepare sound");
  55.            else
  56.            {
  57.                      ok=PlaySound (TheSoundFile, MAXVOLUME, LEFT1, NORMALRATE, 1 );
  58.                      ok=PlaySound (TheSoundFile, MAXVOLUME, RIGHT1, NORMALRATE, 1);  
  59.                      if(ok==FALSE)
  60.                        strcpy(MyTitle,"Not played succesfully");
  61.                      else
  62.                strcpy(MyTitle,"Play What File");
  63.            }
  64.            break;
  65.       case CANCEL: 
  66.       case QUIT:   Done--; strcpy(MyMessage,"Done"); break;
  67.       case PANIC: 
  68.       default:    Done--; strcpy(MyMessage,"ERROR");break;
  69.     }
  70.   }
  71.   CloseAll(MyMessage);
  72. }
  73.  
  74. void CloseAll()
  75. {
  76.   printf("%s\n",MyMessage);
  77.   StopSound(LEFT1);
  78.   StopSound(RIGHT1);
  79.   if (TheSoundFile)
  80.     RemoveSound(TheSoundFile);
  81.   if (IntuitionBase)
  82.     CloseLibrary(IntuitionBase);
  83.   exit();
  84. }
  85.  
  86.  
  87.