home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 9 / FreshFishVol9-CD2.bin / bbs / util / muispeechtoy-0.01.lha / MUISpeechToy / src / Main.c < prev    next >
C/C++ Source or Header  |  1994-07-03  |  7KB  |  293 lines

  1. #include <libraries/mui.h>
  2. #include <libraries/locale.h>
  3.  
  4. #include <clib/locale_protos.h>
  5. #include <clib/muimaster_protos.h>
  6. #include <clib/alib_protos.h>
  7. #include <clib/dos_protos.h>
  8. #include <clib/exec_protos.h>
  9.  
  10. #include <devices/narrator.h>
  11.  
  12. #include <stdlib.h>
  13. #include <stdio.h>
  14.  
  15. #include "speak.h"
  16.  
  17. //#define CATCOMP_CODE
  18. #define CATCOMP_BLOCK
  19. #include "speakstrings.h"
  20. //#undef CATCOMP_CODE
  21. #undef CATCOMP_BLOCK
  22.  
  23. #define DEFAULT_STR        "Hey, I am the M.U.I. Speechtoy, brought to you by Y.E.T."
  24.  
  25. BYTE audio_chn[4] = {3,5,10,12};
  26.  
  27. enum ids {  RET_DUMMY,
  28.             RET_TEXT,
  29.             RET_HEIGHT,
  30.             RET_SPEED,
  31.             RET_VOLUME,
  32.             RET_SEX,
  33.             RET_KIND,
  34.             RET_PERTUB,
  35.             RET_ENTHU,
  36.             RET_SPEAK, };
  37.  
  38. struct LocaleBase *     LocaleBase;
  39. struct Library *         MUIMasterBase;
  40. struct MsgPort *        SpeakMP;
  41.  
  42. struct Locale *            locale = NULL;
  43. struct Catalog *        Catalog = NULL;
  44.  
  45.  
  46. struct narrator_rb *     SpeakIO;
  47. struct ObjApp *         App    = NULL;
  48.  
  49. int PITCH    = 120;
  50. int SPEED    = 120;
  51. int VOLUME    = 64;
  52. int SEX        = MALE;
  53. int KIND    = ROBOTICF0;
  54. int ENTHU   = 0;
  55. int PERTUB  = 0;
  56.  
  57. void main(int argc,char **argv);
  58.  
  59. /****************************************************************/
  60.  
  61. int wbmain(struct WBStartup *wb_startup)
  62. {
  63.  
  64.     main(0, NULL);
  65. }
  66.  
  67.  
  68. /****************************************************************/
  69.  
  70. char * MyTranslate(char * str)
  71. {
  72.     char ph_buf[255];
  73.  
  74.     Translate(str , strlen(str) , (APTR) ph_buf , 255);
  75.         
  76.     return ph_buf;
  77. }
  78.  
  79. /****************************************************************/
  80.  
  81. void Speak(char *str)
  82. {
  83.     static char ph_buf[255];
  84.  
  85.     Translate(str , strlen(str) , (APTR) ph_buf , 255);
  86.  
  87.     setstring( App->STR_PHONEME , ph_buf);
  88.  
  89.     set( App->STR_TEXT , MUIA_String_BufferPos , 0);
  90.     set( App->STR_PHONEME , MUIA_String_BufferPos , 0);
  91.  
  92.  
  93.     SpeakIO->message.io_Command    = CMD_WRITE;
  94.     SpeakIO->message.io_Offset    = 0;
  95.     SpeakIO->message.io_Data    = ph_buf;
  96.     SpeakIO->message.io_Length    = strlen( ph_buf );
  97.  
  98.     SpeakIO->ch_masks            = audio_chn;
  99.     SpeakIO->nm_masks            = sizeof(audio_chn);
  100.     SpeakIO->rate                = SPEED;
  101.     SpeakIO->pitch                = PITCH;
  102.     SpeakIO->volume                = VOLUME;
  103.     SpeakIO->sex                = SEX;
  104.     SpeakIO->mode                = KIND;
  105.     SpeakIO->F0enthusiasm        = ENTHU;
  106.     SpeakIO->F0perturb            = PERTUB;
  107.     
  108.     DoIO((struct IORequest *) SpeakIO);
  109. }
  110.  
  111. /****************************************************************/
  112.  
  113. void init(void)
  114. {
  115.     if (!(MUIMasterBase =  OpenLibrary(MUIMASTER_NAME,MUIMASTER_VMIN)))
  116.     {
  117.         exit(0);
  118.     }
  119.     
  120.     SpeakMP = CreateMsgPort();
  121.     SpeakIO = (struct narrator_rb *) CreateExtIO(SpeakMP,sizeof(struct narrator_rb));
  122.     SpeakIO->flags = NDF_NEWIORB;
  123.                 
  124.     OpenDevice("narrator.device",0,(struct IORequest *) SpeakIO,NULL);
  125. }
  126.  
  127. /****************************************************************/
  128.  
  129. void main(int argc,char **argv)
  130. {
  131.     BOOL    running = TRUE;
  132.     ULONG    signal;
  133.  
  134.     LocaleBase = (struct LocaleBase *) OpenLibrary("locale.library",37);
  135.  
  136.     if (LocaleBase != NULL)
  137.     {
  138.         struct TagItem tags[3];
  139.     
  140.         locale = OpenLocale(NULL);
  141.  
  142.         if (strcmp(locale->loc_LanguageName,"deutsch.language"))   // Builtin language != locale Language
  143.         {
  144.             tags[0].ti_Tag  = OC_BuiltInLanguage;
  145.             tags[0].ti_Data = (ULONG) "deutsch";    
  146.  
  147.             tags[1].ti_Tag  = OC_Version;
  148.             tags[1].ti_Data = (ULONG) 1;
  149.  
  150.             tags[2].ti_Tag  = OC_BuiltInCodeSet;    // Default, requested from Commodore
  151.             tags[2].ti_Data = (ULONG) 0;
  152.  
  153.             Catalog=OpenCatalogA(NULL,"muispeechtoy.catalog",tags);
  154.  
  155.          }
  156.     }    
  157.  
  158.     init();
  159.  
  160.     App = CreateApp();
  161.  
  162.     DoMethod(App->WIN_MAIN, MUIM_Notify, MUIA_Window_CloseRequest, TRUE, App->App, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
  163.     
  164.     setstring( App->STR_TEXT , DEFAULT_STR);
  165.     setstring( App->STR_PHONEME , MyTranslate(DEFAULT_STR));
  166.  
  167.     set( App->STR_TEXT , MUIA_String_BufferPos , 0);
  168.     set( App->STR_PHONEME , MUIA_String_BufferPos , 0);
  169.  
  170.     set( App->STR_TEXT , MUIA_String_BufferPos , 0);
  171.  
  172.     setslider( App->SL_SPEED,  SPEED);
  173.     setslider( App->SL_HEIGHT, PITCH);
  174.     setslider( App->SL_VOLUME, VOLUME);
  175.     setslider( App->SL_ENTHUSIASMUS, ENTHU);
  176.     setslider( App->SL_PERTUBATION, PERTUB);
  177.  
  178.  
  179.  
  180.     DoMethod(App->WIN_MAIN,MUIM_Window_SetCycleChain,
  181.                 App->CY_SEX,
  182.                 App->CY_KIND,
  183.                 App->SL_HEIGHT,
  184.                 App->SL_SPEED,
  185.                 App->SL_VOLUME,
  186.                 App->SL_ENTHUSIASMUS,
  187.                 App->SL_PERTUBATION,
  188.                 App->STR_TEXT,
  189.                 App->STR_PHONEME,
  190.                 App->BT_SPEAK,
  191.                 NULL);
  192.  
  193.     DoMethod( App->STR_TEXT, MUIM_Notify,MUIA_String_Acknowledge,MUIV_EveryTime,App->App,2,MUIM_Application_ReturnID,RET_TEXT);
  194.     DoMethod( App->BT_SPEAK, MUIM_Notify,MUIA_Pressed,FALSE,App->App,2,MUIM_Application_ReturnID,RET_SPEAK);
  195.     DoMethod( App->SL_HEIGHT,MUIM_Notify,MUIA_Slider_Level,MUIV_EveryTime,App->App,2,MUIM_Application_ReturnID,RET_HEIGHT);
  196.     DoMethod( App->SL_SPEED, MUIM_Notify,MUIA_Slider_Level,MUIV_EveryTime,App->App,2,MUIM_Application_ReturnID,RET_SPEED);
  197.     DoMethod( App->SL_VOLUME,MUIM_Notify,MUIA_Slider_Level,MUIV_EveryTime,App->App,2,MUIM_Application_ReturnID,RET_VOLUME);
  198.     DoMethod( App->SL_ENTHUSIASMUS,MUIM_Notify,MUIA_Slider_Level,MUIV_EveryTime,App->App,2,MUIM_Application_ReturnID,RET_ENTHU);
  199.     DoMethod( App->SL_PERTUBATION,MUIM_Notify,MUIA_Slider_Level,MUIV_EveryTime,App->App,2,MUIM_Application_ReturnID,RET_PERTUB);
  200.     DoMethod( App->CY_SEX,   MUIM_Notify,MUIA_Cycle_Active,MUIV_EveryTime,App->App,2,MUIM_Application_ReturnID,RET_SEX);
  201.     DoMethod( App->CY_KIND,  MUIM_Notify,MUIA_Cycle_Active,MUIV_EveryTime,App->App,2,MUIM_Application_ReturnID,RET_KIND);
  202.  
  203.  
  204.     set( App->WIN_MAIN, MUIA_Window_Open, TRUE );
  205.  
  206.     
  207.     while (running)
  208.     {
  209.         switch (DoMethod(App->App,MUIM_Application_Input,&signal))    
  210.         {
  211.             case RET_SPEAK:
  212.                 char *x;
  213.                 get(App->STR_TEXT,MUIA_String_Contents,&x);
  214.                 Speak(x);
  215.                 break;
  216.  
  217.             case RET_SEX:
  218.                 get(App->CY_SEX,MUIA_Cycle_Active,&SEX);
  219.                 break;
  220.  
  221.             case RET_KIND:
  222.                 get(App->CY_KIND,MUIA_Cycle_Active,&KIND);
  223.                 break;
  224.  
  225.             case RET_SPEED:
  226.                 get(App->SL_SPEED,MUIA_Slider_Level,&SPEED);
  227.                 break;
  228.  
  229.             case RET_HEIGHT:
  230.                 get(App->SL_HEIGHT,MUIA_Slider_Level,&PITCH);
  231.                 break;
  232.  
  233.             case RET_VOLUME:
  234.                 get(App->SL_VOLUME,MUIA_Slider_Level,&VOLUME);
  235.                 break;
  236.  
  237.             case RET_PERTUB:
  238.                 get(App->SL_PERTUBATION,MUIA_Slider_Level,&PERTUB);
  239.                 break;
  240.  
  241.             case RET_ENTHU:
  242.                 get(App->SL_ENTHUSIASMUS,MUIA_Slider_Level,&ENTHU);
  243.                 break;
  244.  
  245.  
  246.             case RET_TEXT:
  247.                 char *x;
  248.                 get(App->STR_TEXT,MUIA_String_Contents,&x);
  249.                 setstring( App->STR_PHONEME , MyTranslate(x));
  250.                 set( App->STR_TEXT , MUIA_String_BufferPos , 0);
  251.                 set( App->STR_PHONEME , MUIA_String_BufferPos , 0);
  252.                 break;
  253.  
  254.             case MUIV_Application_ReturnID_Quit:
  255.                 running = FALSE;
  256.                         break;
  257.         }
  258.     }        
  259.  
  260.     if (running && signal) Wait(signal);
  261.  
  262.  
  263.     CloseDevice((struct IORequest *) SpeakIO);
  264.     DeleteIORequest((struct IORequest *) SpeakIO);
  265.     DeleteMsgPort(SpeakMP);
  266.  
  267.     DisposeApp(App);
  268.     CloseLibrary(MUIMasterBase);
  269.     CloseLibrary((struct Library *) LocaleBase);
  270. }
  271.  
  272. STRPTR GetString(LONG stringNum)
  273. {
  274.     LONG   *l;
  275.     UWORD  *w;
  276.     STRPTR  builtIn;
  277.  
  278.     l = (LONG *)CatCompBlock;
  279.  
  280.     while (*l != stringNum)
  281.     {
  282.         w = (UWORD *)((ULONG)l + 4);
  283.         l = (LONG *)((ULONG)l + (ULONG)*w + 6);
  284.     }
  285.     builtIn = (STRPTR)((ULONG)l + 6);
  286.  
  287.  
  288.     if (LocaleBase)
  289.         return(GetCatalogStr(Catalog,stringNum,builtIn));
  290.  
  291.     return(builtIn);
  292. }
  293.