home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1998 / MacHack 1998.toast / The Hacks! / Talking KeyBoard / Source / AppleEvents / aerecord.c < prev    next >
Encoding:
Text File  |  1998-06-06  |  5.3 KB  |  190 lines  |  [TEXT/CWIE]

  1. // Program Author: Paul Baxter
  2. //    pbaxter@assistivetech.com
  3. //
  4. //
  5. #include <Speech.h>
  6. #include <Ctype.h>
  7. #include <DeskBus.h>
  8. #include <Retrace.h>
  9.  
  10. #include "pref.h"
  11. #include "globals.h"
  12. #include "aeevents.h"
  13. #include "aerecord.h"
  14. #include "aeutils.h"
  15. #include "aetoken.h"
  16.  
  17. // * ****************************************************************************** *
  18. // *    IssueQuitCommand
  19. // *                            Issue a quit command
  20. // * ****************************************************************************** *
  21. void IssueQuitCommand(void)
  22. {
  23.     AppleEvent    myAppleEvent;
  24.     AppleEvent    defReply;
  25.     OSErr         myErr = noErr;
  26.     OSErr         ignoreErr;
  27.     AEAddressDesc selfAddr;
  28.  
  29.     if (HasAppleEvents()) {
  30.         myAppleEvent.dataHandle = nil;
  31.         selfAddr.dataHandle     = nil;
  32.                             
  33.         myErr = MakeSelfAddress(&selfAddr);
  34.  
  35.         //    Build event
  36.         
  37.         if (myErr == noErr) 
  38.             myErr  = AECreateAppleEvent(kCoreEventClass, kAEQuitApplication, &selfAddr,
  39.                                             kAutoGenerateReturnID, kAnyTransactionID, &myAppleEvent);
  40.         //    send the event
  41.  
  42.         if (myErr==noErr) 
  43.             myErr  = AESend(&myAppleEvent, &defReply, kAENoReply+kAEAlwaysInteract,
  44.                                         kAENormalPriority, kAEDefaultTimeout, nil, nil);
  45.                         
  46.         if (myAppleEvent.dataHandle) 
  47.             ignoreErr = AEDisposeDesc(&myAppleEvent);
  48.  
  49.         if (selfAddr.dataHandle) 
  50.             ignoreErr = AEDisposeDesc(&selfAddr);
  51.     }
  52.     return;
  53. }
  54.  
  55.  
  56. // * ****************************************************************************** *
  57. // *    IssueSetVoice
  58. // *                            Issue an AppleEvent to change the voice
  59. // * ****************************************************************************** *
  60. OSErr IssueSetVoice(void)
  61. {
  62.     AEDesc            StringDesc;
  63.     AEAddressDesc    theAddress;
  64.     OSErr            err = noErr;
  65.  
  66.     if (HasAppleEvents()) {
  67.         err = MakeSelfAddress(&theAddress);
  68.         if (err==noErr)
  69.             err = PutPStringToDescriptor(&StringDesc, (**gPrefs).voice);
  70.  
  71.         if (err==noErr)
  72.             err  = SendAESetAppProp(typeVoiceProperty, &StringDesc, &theAddress);
  73.     }
  74.     return err;
  75. }
  76.  
  77. // * ****************************************************************************** *
  78. // *    IssueSetSpeakChars
  79. // *                        Issue an AppleEvent to speak chars
  80. // * ****************************************************************************** *
  81. OSErr IssueSetSpeakChars(void)
  82. {
  83.     AEDesc            LongDesc;
  84.     AEAddressDesc    theAddress;
  85.     OSErr            err = noErr;
  86.  
  87.     if (HasAppleEvents()) {
  88.         err = MakeSelfAddress(&theAddress);
  89.         if (err==noErr)
  90.             err = PutLongIntToDescriptor(&LongDesc, (**gPrefs).speakChars);
  91.  
  92.         if (err==noErr)
  93.             err  = SendAESetAppProp(typeSpeakCharProperty, &LongDesc, &theAddress);
  94.     }
  95.     return err;
  96. }
  97.  
  98. // * ****************************************************************************** *
  99. // *    IssueSetSpeakWords
  100. // *                            Issue an AppleEvent to speak words
  101. // * ****************************************************************************** *
  102. OSErr IssueSetSpeakWords(void)
  103. {
  104.     AEDesc            LongDesc;
  105.     AEAddressDesc    theAddress;
  106.     OSErr            err = noErr;
  107.  
  108.     if (HasAppleEvents()) {
  109.         err = MakeSelfAddress(&theAddress);
  110.         if (err==noErr)
  111.             err = PutLongIntToDescriptor(&LongDesc,  (**gPrefs).speakWords);
  112.  
  113.         if (err==noErr)
  114.             err  = SendAESetAppProp(typeSpeakWordProperty, &LongDesc, &theAddress);
  115.     }
  116.     return err;
  117. }
  118.  
  119. // * ****************************************************************************** *
  120. // *    IssueSetSpeakSentences
  121. // *                            Issue an AppleEvent to speak sentences
  122. // * ****************************************************************************** *
  123. OSErr IssueSetSpeakSentences(void)
  124. {
  125.     AEDesc            LongDesc;
  126.     AEAddressDesc    theAddress;
  127.     OSErr            err = noErr;
  128.  
  129.     if (HasAppleEvents()) {
  130.         err = MakeSelfAddress(&theAddress);
  131.         if (err==noErr)
  132.             err = PutLongIntToDescriptor(&LongDesc, (**gPrefs).speakSentence);
  133.  
  134.         if (err==noErr)
  135.             err  = SendAESetAppProp(typeSpeakSentenceProperty, &LongDesc, &theAddress);
  136.     }
  137.     return err;
  138. }
  139.  
  140. // * ****************************************************************************** *
  141. // *    SendAESetAppProp
  142. // *            Creates a property object from an object,
  143. // *            a property type and its data and sends it to
  144. // *            the requested address, and cleans up zapping params too
  145. // * ****************************************************************************** *
  146. OSErr SendAESetAppProp(DescType theProp, AEDesc *theData, AEAddressDesc *toWhom)
  147. {
  148.     AEDesc        propObjSpec;
  149.     AEDesc        nullDesc = {typeNull, NULL};
  150.     AEDesc        theObj;
  151.     AppleEvent    myAppleEvent;
  152.     AppleEvent    defReply;
  153.     OSErr        myErr;
  154.     OSErr        ignoreErr;
  155.  
  156.     myErr = AECreateDesc(typeType, (Ptr)&theProp, sizeof(theProp), &theObj);
  157.  
  158.     if (myErr==noErr)
  159.         myErr = CreateObjSpecifier(cProperty, &nullDesc, formPropertyID,
  160.                                         &theObj, true, &propObjSpec);    
  161.     if (myErr==noErr)
  162.         myErr = AECreateAppleEvent(kAECoreSuite, kAESetData, toWhom, 0, 0, &myAppleEvent);
  163.  
  164.     // add prop obj spec to the event
  165.     if (myErr==noErr)
  166.         myErr = AEPutParamDesc(&myAppleEvent, keyDirectObject, &propObjSpec);
  167.     
  168.     // add prop data to the event    
  169.     if (myErr==noErr)
  170.         myErr = AEPutParamDesc(&myAppleEvent,keyAEData, theData);
  171.  
  172.     // send event
  173.     if (myErr==noErr)
  174.         myErr = AESend(&myAppleEvent, &defReply, kAENoReply+kAEAlwaysInteract,
  175.                                     kAENormalPriority, kAEDefaultTimeout, nil, nil);
  176.  
  177.     if (myAppleEvent.dataHandle)
  178.         ignoreErr = AEDisposeDesc(&myAppleEvent);
  179.  
  180.     if (&propObjSpec.dataHandle)
  181.       ignoreErr = AEDisposeDesc(&propObjSpec);
  182.  
  183.     if (theData->dataHandle)
  184.         ignoreErr = AEDisposeDesc(theData);
  185.  
  186.     if (toWhom->dataHandle)
  187.         ignoreErr = AEDisposeDesc(toWhom);
  188.  
  189.     return(myErr);
  190. }