Retired Document
Important: This sample code may not represent best practices for current development. The project may use deprecated symbols and illustrate technologies and techniques that are no longer recommended.
BufferPlay.c
/* |
File: BufferPlay.c |
Contains: |
Written by: RICHARD P. COLLYER |
Copyright: Copyright © 1991-1999 by Apple Computer, Inc., All Rights Reserved. |
You may incorporate this Apple sample source code into your program(s) without |
restriction. This Apple sample source code has been provided "AS IS" and the |
responsibility for its operation is yours. You are not permitted to redistribute |
this Apple sample source code as "Apple sample source code" after having made |
changes. If you're going to re-distribute the source, we require that you make |
it clear in the source that the code was descended from Apple sample source |
code, but that you've made changes. |
Change History (most recent first): |
8/2/1999 Karl Groethe Updated for Metrowerks Codewarror Pro 2.1 |
Fixed Menu bug |
*/ |
#include <Fonts.h> |
#include <Quickdraw.h> |
#include <Windows.h> |
#include <desk.h> |
#include <Memory.h> |
#include <Menus.h> |
#include <OSEvents.h> |
#include <Resources.h> |
#include <SegLoad.h> |
#include <Sound.h> |
#include <ToolUtils.h> |
#include <Processes.h> |
#ifdef applec |
extern _DataInit(); |
#endif |
#define TRUE 0xFF |
#define FALSE 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 |
int yieldTime, err; |
MenuHandle mymenu1, mymenu0; |
EventRecord myEvent; |
Boolean DoneFlag; |
WindowPtr whichWindow; |
short GlobalFlag; |
pascal void CallBack(SndChannelPtr chan, SndCommand cmd); |
void start(); |
void showAboutMeDialog(); |
void doCommand(long mResult); |
void init(); |
/*______________________________________________________*/ |
/* What ever You want */ |
/*______________________________________________________*/ |
pascal void CallBack(SndChannelPtr chan, SndCommand cmd) |
{ |
#pragma unused (chan) |
#pragma unused (cmd) |
#ifndef powerc |
long myA5; |
myA5 = SetA5 (cmd.param2); |
#endif |
GlobalFlag = TRUE; |
#ifndef powerc |
myA5 = SetA5 (myA5); |
#endif |
return; |
} |
/*______________________________________________________*/ |
/* What ever You want */ |
/*______________________________________________________*/ |
void start() |
{ |
Handle Sound; |
SndChannelPtr chan; |
SndCommand mycmd; |
SndCallBackUPP myCallBackUPP; |
GlobalFlag = FALSE; |
Sound = GetResource ('snd ', 100); |
if (ResError() != noErr || Sound == nil) |
Debugger(); |
/* create a UPP for our sound callback */ |
myCallBackUPP = NewSndCallBackProc(CallBack); |
chan = nil; |
err = SndNewChannel (&chan, sampledSynth, initNoInterp + initMono, myCallBackUPP); |
if (err != noErr) |
Debugger(); |
do { |
mycmd.cmd = bufferCmd; |
mycmd.param1 = 0; |
mycmd.param2 = (long) *Sound; |
err = SndDoCommand (chan, &mycmd, FALSE); |
if (err != noErr) |
Debugger(); |
mycmd.cmd = callBackCmd; |
mycmd.param1 = 0; |
mycmd.param2 = SetCurrentA5(); |
err = SndDoCommand (chan, &mycmd, FALSE); |
if (err != noErr) |
Debugger(); |
do{ |
}while (GlobalFlag == FALSE); |
GlobalFlag = FALSE; |
} while (!Button()); |
err = SndDisposeChannel (chan,FALSE); |
if (err != noErr) |
Debugger(); |
DisposeRoutineDescriptor(myCallBackUPP); |
return; |
} |
/*______________________________________________________*/ |
/* About Prog Dialog */ |
/*______________________________________________________*/ |
void showAboutMeDialog() |
{ |
return; |
} |
/*______________________________________________________*/ |
/* Do Menu Function */ |
/*______________________________________________________*/ |
void doCommand(mResult) |
long mResult; |
{ |
int theMenu, theItem; |
Str255 daName; |
GrafPtr savePort; |
theItem = LoWord(mResult); |
theMenu = HiWord(mResult); |
switch (theMenu) { |
/*______________________________________________________*/ |
/* Do Apple Menu */ |
/*______________________________________________________*/ |
case appleID: |
if (theItem == aboutMeCommand) |
showAboutMeDialog(); |
else { |
GetMenuItemText(mymenu0, theItem, daName); |
GetPort(&savePort); |
(void) OpenDeskAcc((ConstStr255Param)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; |
} |
/*______________________________________________________*/ |
/* Initialization traps */ |
/*______________________________________________________*/ |
void init() |
{ |
#ifdef applec |
UnloadSeg(_DataInit); |
#endif |
InitGraf(&qd.thePort); |
InitFonts(); |
FlushEvents(everyEvent, 0); |
InitWindows(); |
InitMenus(); |
TEInit(); |
InitDialogs(nil); |
InitCursor(); |
/*_____________________________________________________*/ |
/* Set menus */ |
/*______________________________________________________*/ |
SetMenuBar (GetNewMBar (128)); |
mymenu0 = GetMenuHandle (128); |
AppendResMenu(mymenu0, 'DRVR'); |
mymenu1 = GetMenuHandle(129); |
DrawMenuBar(); |
/*______________________________________________________*/ |
/* Init variables */ |
/*______________________________________________________*/ |
DoneFlag = FALSE; |
yieldTime = 0; |
return; |
} |
main() |
{ |
/*______________________________________________________*/ |
/* 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; |
default: |
break; |
} |
break; |
case 15: |
if ((myEvent.message << 31) == 0) { /* Suspend */ |
yieldTime = 30; |
} |
else { /* Resume */ |
yieldTime = 0; |
} |
break; |
default: |
break; |
} |
} |
} |
} |
Copyright © 2003 Apple Computer, Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2003-03-14