home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format 119 / af119sub.adf / SamEd.lzx / SamEd / Developers / General.c < prev    next >
C/C++ Source or Header  |  2001-06-09  |  6KB  |  185 lines

  1. /*-----------------------------------------------------------------------------
  2.  
  3. General.c v1.0  22.10.98 Matthew Hampton;
  4.  
  5. -----------------------------------------------------------------------------*/
  6.  
  7.  
  8. #include <muistd.h>
  9. #include <exec/exec.h>
  10. #include "extproc.h"
  11. #include "waveeditclass.c"
  12.  
  13. void cleanup(void);     /*quit function*/
  14. void Edit_Data(void);
  15.  
  16. #define ID_DO   1
  17.  
  18. static struct interface{
  19.     APTR app;
  20.     APTR win;
  21.     
  22.     APTR wave;
  23.     APTR doit;
  24.     APTR exit;
  25. } App;
  26. struct MUI_CustomClass *wave_mcc;
  27.  
  28.  
  29. EPP_HANDLE epph;            /*for use with EP_ functions*/
  30. struct sam_info *sample;    /*pointer to a sam_info structure, for collecting data*/
  31. BYTE signal;                /*a signal number, for auto quit (we quit when SamEd quits)*/
  32.  
  33.  
  34. LONG main(int argc, char *argv[])
  35. {
  36.     if (argc <3) return(0);
  37.     if (atol(argv[1]) != PROC_MAGIC) return(0); /*make sure SamEd launched us*/
  38.  
  39.     init();
  40.  
  41.     if (!(epph = EP_NewPort (atol(argv[2]))))   /*create a new message port*/
  42.         cleanup();
  43.  
  44.     if (-1 == (signal = EP_AllocQSig (epph) ))  /*allocate the auto quit signal*/
  45.         cleanup();
  46.  
  47.  
  48.     /*create the MUI interface*/
  49.  
  50.     if (!(wave_mcc = MUI_CreateCustomClass(NULL,MUIC_Area,NULL,sizeof(struct WaveData),WaveDispatcher)))
  51.         cleanup();
  52.  
  53.     App.app = ApplicationObject,
  54.     MUIA_Application_Title      , "General ExtProc",
  55.     MUIA_Application_Version    , "$VER: 1.00 (17.10.98)",
  56.     MUIA_Application_Copyright  , "©1998, Matthew Hampton",
  57.     MUIA_Application_Author     , "Hampy",
  58.     MUIA_Application_Description, "ExtProc for SamED",
  59.     MUIA_Application_Base       , "GENEP",
  60.  
  61.     SubWindow, App.win = WindowObject,
  62.         MUIA_Window_Title, "General",
  63.         MUIA_Window_ID   , MAKE_ID('G','E','N','E'),
  64.  
  65.         WindowContents, VGroup,
  66.             Child, App.wave = NewObject(wave_mcc->mcc_Class, NULL,
  67.                     TextFrame,
  68.                     MUIA_Waveform_Draw, WDM_LINE | WDM_HGRID | WDM_VGRID,
  69.                     TAG_DONE),
  70.             Child, HGroup,
  71.                 Child, RectangleObject, MUIA_Weight, 25, End,
  72.                 Child, App.doit     = SimpleButton("Do"),
  73.                 Child, RectangleObject, MUIA_Weight, 25, End,
  74.                 Child, App.exit     = SimpleButton("Exit"),
  75.                 Child, RectangleObject, MUIA_Weight, 25, End,
  76.                 End,
  77.             End,
  78.         End,
  79.     End;
  80.  
  81.     if(!App.app) cleanup();
  82.  
  83.     /*return ids (yuk), keep things simple*/
  84.     DoMethod(App.doit,MUIM_Notify,MUIA_Pressed,FALSE,App.app,2,MUIM_Application_ReturnID,ID_DO);
  85.     DoMethod(App.exit,MUIM_Notify,MUIA_Pressed,FALSE,App.app,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  86.     DoMethod(App.win,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,App.app,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  87.  
  88.     set(App.win,MUIA_Window_Open,TRUE);
  89.  
  90.     ULONG sigs = 0, ret = 0;
  91.     ULONG quitsig = 1L << signal;    /*use signal bit number to make a mask*/
  92.  
  93.     while (TRUE)    /*repeat until break*/
  94.     {
  95.         ret = DoMethod(App.app,MUIM_Application_NewInput,&sigs);
  96.  
  97.         /*check signals for MUI, CTRL_C, and quitsig*/
  98.         if (sigs)
  99.         {
  100.             sigs = Wait(sigs | SIGBREAKF_CTRL_C | quitsig);
  101.             if (sigs & SIGBREAKF_CTRL_C) break;
  102.             if (sigs & quitsig) break;
  103.         }
  104.  
  105.         /*check for return id's*/
  106.         if (ret)
  107.         {
  108.             if (ret == MUIV_Application_ReturnID_Quit) break;      /*quit if cancelled*/
  109.  
  110.             if (ret == ID_DO)
  111.             {
  112.                 Edit_Data();
  113.             }
  114.         }
  115.     }
  116.     cleanup();  /*quit*/
  117. }
  118.  
  119.  
  120. /*cleanup all system allocations, tell samed we have quit*/
  121. void cleanup(void)
  122. {
  123.     EP_Quit (epph);         /*tell SamEd we have quit*/
  124.  
  125.     EP_DeletePort (epph);   /*delete the message port*/
  126.  
  127.     EP_DeallocQSig (signal);/*deallocte the autoquit signal*/
  128.  
  129.     /*close the MUI application*/
  130.     if (App.app)
  131.     {
  132.         set(App.win,MUIA_Window_Open,FALSE);
  133.         MUI_DisposeObject(App.app);          /* dispose all objects. */
  134.         MUI_DeleteCustomClass(wave_mcc); /* delete the custom class. */
  135.         fail(NULL,NULL);
  136.     }
  137.     else
  138.         fail(NULL,"could not open interface (MUI)");
  139. }
  140.  
  141. void Edit_Data(void)
  142. {
  143.     if (EP_Lock (epph))         /*first aquire the lock*/
  144.     {
  145.         if (EP_GetSample(epph, &sample, NULL, NULL))    /*set up a pointer to the data*/
  146.         {
  147.             /*the length is in bytes but GET / SET_LEVEL offset in samples, so convert to samples*/
  148.             ULONG length = Bytes_To_Sams (sample->length, sample->type);
  149.  
  150.             for (ULONG n =0; n < length; n++)   /*edit the whole sample*/
  151.             {
  152.                 LONG lev = GET_LEVEL (sample->waveform, n, sample->type, 0);
  153.                 lev *= lev; lev = lev /90 -180;
  154.                 SET_LEVEL (sample->waveform, n, lev, sample->type, 0);
  155.             }
  156.         }
  157.  
  158.         EP_Unlock(epph);
  159.     }
  160. }
  161.  
  162. /*if you need to set up new sample data use code similar to this*/
  163.  
  164. void New_Data(struct sam_info *sample, BYTE *new_wave, ULONG new_len, ULONG new_type)
  165. {
  166.     ULONG new_len_bytes = Sams_To_Bytes (new_len, new_type);
  167.  
  168.     if (new_wave = AllocMem (new_len_bytes, MEMF_CLEAR | MEMF_PUBLIC))
  169.     {
  170.         if (sample->length)
  171.             FreeMem (sample->waveform, sample->length);
  172.  
  173.         sample->waveform = new_wave;
  174.         sample->length = new_len_bytes;
  175.         sample->type = new_type;
  176.         sample->loop_begin = 0;
  177.         sample->loop_length = 0;
  178.         sample->loop = FALSE;
  179.         sample->def_freq = 16000;
  180.         sample->def_vol = 65536;
  181.         sample->file_type = 0;      /*Indicates type in sample attributes window, 0 = RAW. No other
  182.                                     values should be used.*/
  183.     }
  184. }
  185.