FreqForEverChange.c

/*______________________________________________________*/
/*                        C Shell                       */
/*                          by                          */
/*                  RICHARD P. COLLYER                  */
/*                       09/02/87                       */
/*______________________________________________________*/
 
#include    <CType.h>
#include    <Quickdraw.h>
#include    <Windows.h>
#include    <OSUtils.h>
#include    <Controls.h>
#include    <desk.h>
#include    <dialogs.h>
#include    <Events.h>
#include    <Memory.h>
#include    <Menus.h>
#include    <Notification.h>
#include    <OSEvents.h>
#include    <Packages.h>
#include    <Palettes.h>
#include    <Printing.h>
#include    <Files.h>
#include    <Resources.h>
#include    <SANE.h>
#include    <SegLoad.h>
#include    <Sound.h>
#include    <SoundInput.h>
#include    <Slots.h>
#include    <ToolUtils.h>
#include    <StdIO.h>
#include    <math.h>
#include    <StandardFile.h>
 
extern _DataInit();
 
#define TRUE            0xFF
#define FALSE           0
#define VERSION         1
#define SR_BIT          0
 
#define appleID         128         
#define appleMenu       0
#define aboutMeCommand  1
 
#define fileID          129
#define startCommand    1
#define printCommand    3
#define quitCommand     5
 
#define editID          130
 
#define aboutMeDLOG     128
#define okButton        1
#define authorItem      2
#define languageItem    3
 
long                Tick, WhereBoard;
int                 yieldTime, err, numcolor, offLeft, offTop, offRight, offBottom;
Rect                screenRect, BaseRect, TotalRect, minRect;
WindowPtr           whichWindow, myWindow;
CTabHandle          mycolors;
PaletteHandle       srcPalette;
MenuHandle          mymenu1, mymenu2, mymenu0;
EventRecord         myEvent;
Boolean             DoneFlag, Color, CPU20, FPU, Sys6, Memboard;
GDHandle            theGDevice;
SysEnvRec           theWorld;
OSErr               OSys;
SpBlockPtr          mySpBlockPtr;
SpBlock             mySpBlock;
 
#ifdef powerc
   QDGlobals    qd;
#endif
 
/*______________________________________________________*/
/*                What ever You want                    */
/*______________________________________________________*/
void start()
{
    Handle          SoundData;
    SndChannelPtr   chan;
    OSErr           err;
    SndCommand      mycmd;
    KeyMap          myKeys;
    
    SoundData = GetResource ('snd ', 100);
    if (ResError() != noErr || SoundData == nil)
        Debugger();
    HLock (SoundData);
            
    mycmd.cmd = soundCmd;
    mycmd.param1 = 0;
    mycmd.param2 = (long) *SoundData;
    
    chan = nil;
    err = SndNewChannel (&chan, sampledSynth, 0, nil);
    if (err != noErr)
        Debugger();
    
    err = SndDoImmediate (chan, &mycmd);
    if (err != noErr)
        Debugger();
 
    mycmd.cmd = freqCmd;
    mycmd.param1 = 0;
    mycmd.param2 = 60;
    
    err = SndDoCommand (chan, &mycmd, FALSE);
    if (err != noErr)
        Debugger();
 
    do {
        GetKeys (myKeys);
        if (((myKeys[3] >> 6) & 1) != FALSE) {
            mycmd.cmd = freqCmd;
            mycmd.param1 = 0;
            mycmd.param2 += 1;
    
            err = SndDoImmediate (chan, &mycmd);
            if (err != noErr)
                Debugger();
            }
            
        if (((myKeys[3] >> 5) & 1) != FALSE) {
            mycmd.cmd = freqCmd;
            mycmd.param1 = 0;
            mycmd.param2 -= 1;
    
            err = SndDoImmediate (chan, &mycmd);
            if (err != noErr)
                Debugger();
            }
            
        } while (((myKeys[0] >> 20) & 1) == FALSE);
    
    mycmd.cmd = quietCmd;
    mycmd.param1 = 0;
    mycmd.param2 = 0;
    
    err = SndDoImmediate (chan, &mycmd);
    if (err != noErr)
        Debugger();
 
    err = SndDisposeChannel (chan,FALSE);
    if (err != noErr)
        Debugger();
        
    HUnlock (SoundData);
    return;
}
 
/*______________________________________________________*/
/*                 About Prog Dialog                    */
/*______________________________________________________*/
void showAboutMeDialog()
{
    GrafPtr     savePort;
    DialogPtr   theDialog;
    short       itemHit;
 
    GetPort(&savePort);
    theDialog = GetNewDialog(aboutMeDLOG, nil, (WindowPtr) -1);
    SetPort(theDialog);
 
    do {
        ModalDialog(nil, &itemHit);
    } while (itemHit != okButton);
 
    CloseDialog(theDialog);
 
    SetPort(savePort);
    return;
}
 
/*______________________________________________________*/
/*                 Do Menu Function                     */
/*______________________________________________________*/
void doCommand(mResult)
    long    mResult;
{
    int                     theMenu, theItem;
    char                    daName[256];
    GrafPtr                 savePort;
 
    theItem = LoWord(mResult);
    theMenu = HiWord(mResult);
    
    switch (theMenu) {
/*______________________________________________________*/
/*                    Do Apple Menu                     */
/*______________________________________________________*/
        case appleID:
            if (theItem == aboutMeCommand)
                showAboutMeDialog();
            else {
                GetItem(mymenu0, theItem, daName);
                GetPort(&savePort);
                (void) OpenDeskAcc(daName);
                SetPort(savePort);
            }
            break;
/*______________________________________________________*/
/*                     Do File Menu                     */
/*______________________________________________________*/
        case fileID:
            switch (theItem) {
                case startCommand:
                    start();
                    break;
                case printCommand:
                    break;
                case quitCommand:
                    DoneFlag = TRUE;
                    break;
                default:
                    break;
                }
            break;
/*______________________________________________________*/
/*                     Do Edit Menu                     */
/*______________________________________________________*/
        case editID:
            switch (theItem) {
                default:
                    break;
                }
            break;
        default:
            break;
        }
    HiliteMenu(0);
    return;
}
 
 
#ifdef powerc
   QDGlobals    qd;
#endif
 
/*______________________________________________________*/
/*               Initialization traps                   */
/*______________________________________________________*/
void init()
{
    UnloadSeg(_DataInit);
    InitGraf(&qd.thePort);
    FlushEvents(everyEvent, 0);
    InitWindows();
    InitDialogs(nil);
    InitCursor();
    MaxApplZone();
/*______________________________________________________*/
/*            If not right Machine then stop            */
/*______________________________________________________*/
    OSys = SysEnvirons(VERSION,&theWorld);
    if(!theWorld.hasColorQD)
        Color = TRUE;
    else
        Color = FALSE;
        
    if(theWorld.processor >= env68020)
        CPU20 = TRUE;
    else
        CPU20 = FALSE;
        
    if(!theWorld.hasFPU)
        FPU = TRUE;
    else
        FPU = FALSE;
        
    if(theWorld.systemVersion < 0x0600)
        Sys6 = FALSE;
    else
        Sys6 = TRUE;
                    
/*______________________________________________________*/
/*                    Set menus                         */
/*______________________________________________________*/
    mymenu0 = GetMenu(appleID);
    AddResMenu(mymenu0, 'DRVR');
    InsertMenu(mymenu0,0);
    mymenu1 = newmenu(129,"File");
    appendmenu(mymenu1,"Start;-;Print;-;Quit");
    InsertMenu(mymenu1,0);
    mymenu2 = newmenu(130,"Edit");
    InsertMenu(mymenu2,0);
    DrawMenuBar();
 
/*______________________________________________________*/
/*                  Init variables                      */
/*______________________________________________________*/
    DoneFlag = FALSE;
    yieldTime = 0;
    return;
}
 
main()
{
    Boolean     track;
    long        growResult;
/*______________________________________________________*/
/*                   Main Event loop                    */
/*______________________________________________________*/
    init();
    for ( ;; ) {
        if (DoneFlag) {
            ExitToShell();
            }
        if (WaitNextEvent(everyEvent, &myEvent, yieldTime, nil)) {
            switch (myEvent.what) {
                case mouseDown:
                    switch (FindWindow(myEvent.where, &whichWindow)) {
                        case inSysWindow:
                            SystemClick(&myEvent, whichWindow);
                            break;
                        case inMenuBar:
                            doCommand(MenuSelect(myEvent.where));
                            break;
                        case inContent:
                            break;
                        case inDrag:
                            DragWindow (whichWindow, myEvent.where, &TotalRect);
                            EraseRect (&whichWindow->portRect);
                            DrawGrowIcon (whichWindow);
                            break;
                        case inGrow:
                            growResult = GrowWindow (whichWindow, myEvent.where,
                                                    &minRect);
                            SizeWindow(whichWindow, LoWord(growResult), 
                                    HiWord(growResult), TRUE);
                            EraseRect (&whichWindow->portRect);
                            DrawGrowIcon (whichWindow);
                            break;
                        case inGoAway:
                            track = TrackGoAway (whichWindow, myEvent.where);
                            if (track)
                                CloseWindow (whichWindow);
                            break;
                        case inZoomIn:
                            track = TrackBox (whichWindow, myEvent.where, inZoomIn);
                            if (track) {
                                ZoomWindow (whichWindow, inZoomIn, TRUE);
                                EraseRect (&whichWindow->portRect);
                                DrawGrowIcon (whichWindow);
                                }
                            break;
                        case inZoomOut:
                            track = TrackBox (whichWindow, myEvent.where, inZoomOut);
                            if (track) {
                                ZoomWindow (whichWindow, inZoomOut, TRUE);
                                EraseRect (&whichWindow->portRect);
                                DrawGrowIcon (whichWindow);
                                }
                            break;
                        default:
                            break;
                        }
                    break;
                case keyDown:
                    break;
                case autoKey:
                    break;
                case updateEvt:
                    if ((WindowPtr) myEvent.message == myWindow) {
                        BeginUpdate((WindowPtr) myWindow);
                        EndUpdate((WindowPtr) myWindow);
                        }
                    break;
                case diskEvt:
                    break;
                case activateEvt:
                    break;
                case app4Evt:
                    if ((myEvent.message << 31) == 0) { /* Suspend */
                        yieldTime = 30;
                        HideWindow((WindowPtr) myWindow);
                        }
                    else { /* Resume */
                        yieldTime = 0;
                        ShowWindow((WindowPtr) myWindow);
                        SetPort((WindowPtr) myWindow);
                        }
                    break;
                default:
                    break;
                }
            }
        }
}