home *** CD-ROM | disk | FTP | other *** search
- /*
- * dlog.c - handle dialogs for the critic
- *
- */
-
- #include <memory.h>
- #include <quickdraw.h>
- #include <font.h>
- #include <window.h>
- #include <osutil.h>
- #include <menu.h>
- #include <event.h>
- #include <textedit.h>
- #include <dialog.h>
- #include <desk.h>
- #include <control.h>
- #include <toolutil.h>
- #define watchCursor 4 /* Should be in TOOLUTIL.H but isn't. */
- #include <resource.h>
- #include <segment.h>
- #include <packages.h>
- #include <stdio.h>
-
- #include "critic.h"
- #include "speech.h"
-
- /*
- * Voice setup dialog stuff.
- * VP_DLOG is the resource ID of the setup dialog;
- * all other VP_ values are item IDs within that dialog.
- * Ranges come next, followed by default values.
- */
-
- #define VP_DLOG 258 /* resource ID of our setup dialog */
-
- #define VP_OK 1 /* OK button */
- #define VP_CAN 2 /* CANCEL button */
- #define VP_MALE 5 /* male voice */
- #define VP_FEM 6 /* female voice */
- #define VP_NAT 7 /* "natural" inflection */
- #define VP_MONO 8 /* monotonic ("robotic") inflection */
- #define VP_PITCH 11 /* base pitch field */
- #define VP_RATE 14 /* speaking rate field */
-
- #define RATMIN 85 /* mininum valid speaking rate (wpm) */
- #define RATMAX 425 /* maximum "" */
- #define RATWID 3 /* max width of the rate field */
-
- #define PITMIN 65 /* minimum valid base pitch (hz) */
- #define PITMAX 500 /* maximum "" */
- #define PITWID 3 /* max width of the pitch field */
-
- #define INFLDEF Natural /* default inflection */
- #define SEXDEF Male /* default gender */
- #define RATDEF 180 /* default speaking rate */
- #define PITDEF 80 /* default base pitch */
-
- static Sex gender; /* current gender */
- static FOMode inflect; /* current inflection Mode */
- static int pitch; /* current base pitch */
- static int rate; /* current speaking rate */
-
-
- /*
- * voicedfl() - set a default voice
- */
-
- voicedfl()
- {
- gender = SEXDEF;
- inflect = INFLDEF;
- pitch = PITDEF;
- rate = RATDEF;
-
- voiceset(gender, inflect, pitch, rate);
- }
-
- /*
- * setupvoice() - perform the "voice parameters" dialog
- */
-
- setupvoice()
- {
- /*
- * edited values of the fields
- */
-
- int ratedt; /* rate value */
- char rats[10]; /* rate string (pascal) */
- int pitedt; /* pitch value */
- char pits[10]; /* pitch string (pascal)*/
- int infledt; /* inflection item */
- int genedt; /* gender item */
-
- int itemhit;
- DialogPtr setupptr;
- int itemtype;
- ControlHandle item;
- Rect itembox;
-
- /*
- * init the "edited" values
- */
-
- ratedt = rate;
- itoa(ratedt, rats);
- ctop(rats);
-
- pitedt = pitch;
- itoa(pitedt, pits);
- ctop(pits);
-
- infledt = (inflect == Natural ? VP_NAT : VP_MONO);
- genedt = (gender == Male ? VP_MALE : VP_FEM);
-
- /*
- * open the dialog & set the fields to their initial values
- */
-
- setupptr = GetNewDialog(VP_DLOG, NULL, (long) -1);
- radioswitch(setupptr, infledt, infledt);
- radioswitch(setupptr, genedt, genedt);
- GetDItem(setupptr, VP_RATE, &itemtype, &item, &itembox);
- SetIText(item, rats);
- GetDItem(setupptr, VP_PITCH, &itemtype, &item, &itembox);
- SetIText(item, pits);
-
- itemhit = VP_MALE; /* (just to keep the loop going) */
- while (itemhit != VP_OK && itemhit != VP_CAN) {
- /*
- * carry out the dialog; get an item selection.
- */
- ModalDialog(NULL, &itemhit);
-
- /*
- * take care of the buttons
- */
-
- switch(itemhit) {
- case VP_RATE:
- justdigs(setupptr, itemhit, RATWID);
- break;
- case VP_PITCH:
- justdigs(setupptr, itemhit, PITWID);
- break;
- case VP_MALE:
- case VP_FEM:
- /* not implemented -- do nothing */
- break;
- case VP_NAT:
- case VP_MONO:
- infledt = radioswitch(setupptr, itemhit, infledt);
- break;
- }
- }
-
- if (itemhit == VP_OK) {
-
- /*
- * update and verify the string field values
- */
-
- GetDItem(setupptr, VP_RATE, &itemtype, &item, &itembox);
- GetIText(item, rats);
- ptoc(rats);
- ratedt = atoi(rats);
- if (ratedt < RATMIN) ratedt = RATMIN;
- if (ratedt > RATMAX) ratedt = RATMAX;
- itoa(ratedt, rats);
- ctop(rats);
- SetIText(item, rats);
-
-
- GetDItem(setupptr, VP_PITCH, &itemtype, &item, &itembox);
- GetIText(item, pits);
- ptoc(pits);
- pitedt = atoi(pits);
- if (pitedt < PITMIN) pitedt = PITMIN;
- if (pitedt > PITMAX) pitedt = PITMAX;
- itoa(pitedt, pits);
- ctop(pits);
- SetIText(item, pits);
-
- /*
- * store the selected values
- */
-
- rate = ratedt;
- pitch = pitedt;
-
- gender = (genedt == VP_MALE ? Male : Female);
- inflect = (infledt == VP_NAT ? Natural : Robotic);
- voiceset(gender, inflect, pitch, rate);
- }
-
- /*
- * release storage and remove dialog
- */
-
- DisposDialog(setupptr);
- }
-
- /*
- * radioswitch() - turn one radio button off & another one on,
- * returning the item ID of the new "on" button.
- */
-
- int
- radioswitch(ptr, oncontrl, offcontrl)
- DialogPtr ptr;
- int oncontrl, offcontrl; /* items to turn on and off, respectively */
- {
- int itemtype;
- ControlHandle item;
- Rect itembox;
-
- GetDItem(ptr, offcontrl, &itemtype, &item, &itembox);
- SetCtlVal(item, 0);
- GetDItem(ptr, oncontrl, &itemtype, &item, &itembox);
- SetCtlVal(item, 1);
- return(oncontrl);
- }
-
-
- /*
- * justdigs() - restrict the contents of an EditText item to just the given
- * number of digits. I.E., throw out non-digit characters & characters
- * beyond the end of the field.
- * The field must be less than 100 characters wide.
- */
-
- justdigs(ptr, field, width)
- DialogPtr ptr;
- int field; /* # of the dialog item to modify */
- int width; /* max # of digits in the field */
- {
- int itemtype;
- ControlHandle item;
- Rect itembox;
- static char buf[100];
- char *src, *dst; /* pointers for removing non-digits */
-
- GetDItem(ptr, field, &itemtype, &item, &itembox);
- GetIText(item, buf);
- ptoc(buf);
-
- dst = &buf[0];
- for (src = &buf[0]; (*dst = *src); ++src) {
- if (*dst >= 0 && *dst <= '9') ++dst;
- }
- buf[width] = '\0';
-
- ctop(buf);
- SetIText(item, buf);
- }
-
-
- /*
- * itoa() - integer to ascii string
- */
-
- itoa(val, dest)
- int val; /* the integer to convert */
- char *dest; /* where to put the string */
- {
- int isneg; /* "it's a negative number" */
- char rightstr[21]; /* the right-justified string */
- char *p;
-
- isneg = 0;
- if (val < 0) {
- isneg = 1;
- val = -val;
- if (val < 0) {
- /* it's the most negative number, -0 */
- val = 0;
- }
- }
-
- p = &rightstr[21];
- *(--p) = '\0';
- do {
- *(--p) = (char) (val % 10) + '0';
- val /= 10;
- } while (val > 0);
-
- if (isneg) {
- *dest++ = '-';
- }
- while (*dest++ = *p++)
- ;
- }
-