{  1: } {******************************************************************************}
{  2: } { 									      File: PlayItGS.p                                                    
{  3: } {
{  4: } {								A Steve Wehrmann Demo Program
{  5: } {
{  6: } { 							Copyright 1990  by GS---> Specific, Inc
{  7: } {
{  8: } { 								All Rights Reserved World Wide
{  9: } {						"  Except Those Already Reserved by Parik Rao  "
{ 10: } {				  " This Source Code Demonstrates The New (User ?) ToolKit " 
{ 11: } {                                            Written For The Music {Created by}
{ 12: } {                                         SoundSmith(C) 1989 Huibert Aalgers
{ 13: } {
{ 14: } {******************************************************************************}
{ 15: } 
{ 16: } 
{ 17: } PROGRAM PlayItGS;
{ 18: } 	Uses 
{ 19: } 			Types, GSOS,TMLUtils,Locator,Memory,MiscTool,QuickDraw,Events,			  { Tool 6 }
{ 20: } 			Desk,IntMath,TextTool,Controls,Windows,Menus,LineEdit,Dialogs,
{ 21: } 			QDAux,Print,Scrap,StdFile,Fonts,Lists,Sound,NoteSyn,NoteSeq,Midi,
{ 22: } 			Ace,Resources,TextEdit, SoundSmith,TheIcon,About;
{ 23: } 	Const
{ 24: } 			kAppleMenuID		= 1;
{ 25: } 			kAboutItem			= 301;
{ 26: } 
{ 27: } 			kFileMenuID 		  	= 2;
{ 28: } 			kCloseItem			= 255;
{ 29: } 			kQuitItem			  	= 262;
{ 30: } 			kEditMenuID 		  	= 3;
{ 31: } 			kUndoItem			= 250;
{ 32: } 			kCutItem 			  	= 251;
{ 33: } 			kCopyItem			= 252;
{ 34: } 			kPasteItem			= 253;
{ 35: } 			kClearItem			= 254;
{ 36: } 
{ 37: } 	Type
{ 38: } 		
{ 39: } 		ToolListRec	= Record
{ 40: } 								TSnum 			: Integer;
{ 41: } 								MinVersion 	: Integer;
{ 42: } 				  			   End;
{ 43: } 		ToolList   	= Array[1..33] of ToolListRec;
{ 44: } 		ToolListPtr	= ^ToolList;
{ 45: } 		NewLoadRec	= Record
{ 46: } 							Ldummy			: Integer;
{ 47: } 							LscreenMode 		: Integer;
{ 48: } 							Lfiller   			: Integer;
{ 49: } 							LdPage    			: Handle;
{ 50: } 							LNumTools 		: Integer;
{ 51: } 							LToolList 		: ToolListPtr;
{ 52: } 				   		   End;
{ 53: } 	Var
{ 54: } 		gDone					: Boolean;
{ 55: } 		MyMemoryID ,
{ 56: } 		SongMemoryID		: Integer;
{ 57: } 		gStartStopRec		: NewLoadRec;
{ 58: } 		MyToolList		  	: ToolList;
{ 59: } 		LoadID			  	: Handle;
{ 60: } 		gMainEvent			: EventRecord;
{ 61: } 		gReplyRec			: SFReplyRec2;
{ 62: } 		nameC1OutputStr	: ResultBuf255Hndl;
{ 63: } 		pathC1OutputStr	      : ResultBuf255Hndl;
{ 64: } 		AppleMenuStr,
{ 65: } 		FileMenuStr,			 
{ 66: } 		EditMenuStr			: Str255;
{ 67: } 		TypeList      			: SFTypeList2;
{ 68: } 		MyLoadSongRec		: LoadSongRec;
{ 69: } 		TheSongToPlay		: GSString255Ptr;
{ 70: } 		ToolsZeroPage		: Handle;
{ 71: } 		MainWindow			: WindowPtr;
{ 72: } 		MyWColors			: WindColor;
{ 73: } 		IsSongPlaying		: Boolean;
{ 74: } 		IsSongLoaded,		
{ 75: } 		IsSongPaused,		
{ 76: } 		PauseIsEnabled,
{ 77: } 		PlayIsEnabled		: Boolean;
{ 78: } 		TheError				: Integer;
{ 79: }   		VolCtl, 			
{ 80: }   		LoadBtn,				
{ 81: }   		CompactBtn,			
{ 82: }   		PlayBtn,					
{ 83: }   		PauseBtn,				
{ 84: }   		StopBtn				: CtlRecHndl;	
{ 85: }   		CurrValue 			: Integer;		
{ 86: }   		LastValue 			: Integer;		
{ 87: }  		TheFile				: Str255;
{ 88: }  		VolumeBeforePause  : Integer;
{ 89: }  		NewBtnTitle	   : Str255;
{ 90: }  	Procedure SetTheVolume(NewVolume : Integer); Forward;
{ 91: }  	Procedure DoQuit; forward;
{ 92: } 	Procedure HandleMenu(CodeWord : LongInt); forward;
{ 93: } 	Procedure CheckTheControls; Forward;
{ 94: } 	Function AskUser: Boolean; forward;
{ 95: } 	Procedure MainEventLoop; forward;
{ 96: } 	Procedure SetUpMenu; forward;
{ 97: } 	Function NewLoadTools(ID : Integer; Dummy : Integer;
{ 98: } 		       Var LR : NewLoadRec):Handle; Tool $01,$18;
{ 99: } 		       
{100: } 	Procedure UnloadTools(Dummy : Integer; LD : Handle); Tool $01,$19;
{101: } 	Function AlertWindow2 (stringType: Integer;
{102: }                       subStrPtr,
{103: }                       alertStrPtr: Ptr): Integer;  tool 14,89;
{104: }   
{105: }   
{106: }  Procedure StartUp;
{107: } 	Var
{108: } 		BaseDP	: Integer;
{109: } 		
{110: }   	Begin
{111: }     		TLStartUp;                   
{112: }     		MyMemoryID := MMStartUp;     
{113: }     		SongMemoryID := GetNewID($5000);
{114: }     		
{115: }     		MTStartUp;                   
{116: } 
{117: }    		with gStartStopRec do Begin
{118: }       		lDummy := 0;
{119: }       		lScreenMode := $80;
{120: }       		lFiller := 0;
{121: }       		ldPage  := Nil;
{122: }       		lnumTools := 16;
{123: }       		lToolList := @MyToolList;
{124: }       	End;
{125: }     		MyToolList[ 1].TSNum := $1E;  
{126: }    		MyToolList[ 1]. MinVersion := $0100;
{127: }     		MyToolList[ 2].TSNum := $04;  
{128: }     		MyToolList[ 2]. MinVersion := $0300;
{129: }     		MyToolList[ 3].TSNum := $12;  
{130: }     		MyToolList[ 3]. MinVersion := $0201;
{131: }     		MyToolList[ 4].TSNum := $06;  
{132: }     		MyToolList[ 4]. MinVersion := $0300;
{133: }     		MyToolList[ 5].TSNum := 27; 
{134: }     		MyToolList[ 5]. MinVersion := $0300;
{135: }     		MyToolList[ 6].TSNum := 14; 
{136: }     		MyToolList[ 6]. MinVersion := $0300;
{137: }     		MyToolList[ 7].TSNum := 16; 
{138: }     		MyToolList[ 7]. MinVersion := $0300;
{139: }     		MyToolList[ 8].TSNum := 15; 
{140: }     		MyToolList[ 8]. MinVersion := $0300;
{141: }     		MyToolList[ 9].TSNum := $1C;
{142: }     		MyToolList[ 9]. MinVersion := $0300;
{143: }     		MyToolList[10].TSNum := 20; 
{144: }     		MyToolList[10]. MinVersion := $0300;
{145: }     		MyToolList[11].TSNum := 21; 
{146: }     		MyToolList[11]. MinVersion := $0101;
{147: }     		MyToolList[12].TSNum := 22; 
{148: }     		MyToolList[12]. MinVersion := $0101;
{149: }     		MyToolList[13].TSNum := 05; 
{150: }     		MyToolList[13]. MinVersion := $0101;
{151: }     		MyToolList[14].TSNum := 23; 
{152: }     		MyToolList[14]. MinVersion := $0101;
{153: }     		MyToolList[15].TSNum := $08;  
{154: }     		MyToolList[15]. MinVersion := $0100;
{155: }     		LoadId := NewLoadTools (myMemoryId,0,gStartStopRec); 
{156: }    		LoadOneTool(69,$0100);
{157: }    		ToolsZeroPage := NewHandle(2*256,MyMemoryID,$C018,Ptr(0));
{158: }    		If _ToolErr <> NoError Then Begin
{159: }    		gDone := True;
{160: }    		Exit(StartUp);
{161: }    		End;
{162: }     		BaseDP := LoWord(LongInt(ToolsZeroPage^));
{163: }     		SoundStartUp(BaseDP);
{164: }     		SSStartUp(BaseDP + $0100);
{165: } 
{166: }   	End;
{167: } Procedure ShutDown;
{168: }   	Begin
{169: }     		SSShutDown;
{170: }     		SoundShutDown;
{171: }     		UnLoadTools (0,LoadID);
{172: }     		MTShutDown;
{173: }     		MMShutDown(MyMemoryID);
{174: }     		TLShutDown;
{175: }   	End; 
{176: }  Procedure DrawVolumeInfo;
{177: }  	Var
{178: }  		String2	: Str255;
{179: }  		R			: Rect;
{180: }  	Begin
{181: }  		SetPort(MainWindow);
{182: }   		SetTextFace(OutlineMask);
{183: }  		MoveTo(85,38);
{184: }  		DrawString('Volume');
{185: }  		SetTextFace(PlainMask);
{186: }  		SetRect(R,160,29,210,40);
{187: }  		FrameRect(r);
{188: }  		SetRect(R,161,30,209,39);
{189: }  		EraseRect(R);
{190: }  		String2:=Int2String(CurrValue);
{191: }  		MoveTo(174,38);
{192: }  		DrawString(String2);
{193: }  	End;
{194: } Procedure DrawFileInfo(TheFileLoaded : Str255);
{195: } 	Var
{196: } 		CurrentSelection : Str255;
{197: } 		Place				  : Integer;
{198: } 		R					  : Rect;
{199: } 		String2			  : Str255;
{200: } 	Begin
{201: } 		 If (IsSongloaded = False) And (IsSongPlaying = False) Then
{202: } 		 Begin
{203: } 			Setport(MainWindow);
{204: } 			SetRect(R,5,0,290,27);
{205: } 			EraseRect(R);
{206: } 		End;
{207: } 		If  (IsSongloaded = True) And (IsSongPlaying = True) Then
{208: } 		 Begin
{209: } 			SetPort(MainWindow);
{210: } 			CurrentSelection := 'Currently Playing';
{211: } 			Place	:= 150  - (StringWidth(CurrentSelection) Div 2);
{212: } 			MoveTo(Place,12);
{213: } 			DrawString(CurrentSelection);
{214: } 			String2 := Concat('-==   ',TheFileLoaded,'   ==-');
{215: } 			Place	:= 150  - (StringWidth(String2) Div 2);
{216: } 			MoveTo(Place,24);
{217: } 			DrawString(String2);		
{218: } 		End; 
{219: } 	End;
{220: } Procedure CreateMainWindow ;
{221: } 	Var
{222: } 		wRec : ParamList;
{223: } 		R		: Rect;
{224: } 	Begin
{225: } 
{226: } 				with wRec do
{227: } 					Begin
{228: } 						 paramlength	:= sizeof( ParamList);
{229: } 						 wFrameBits		:= $80C0;
{230: } 						 wTitle	 		:= @'         PlayItGS         ';
{231: } 						 wRefCon			:= 0;
{232: } 						 wZoom.top			:= 0;
{233: } 						 wZoom.left		:= 0;
{234: } 						 wZoom.bottom		:= 0;
{235: } 						 wZoom.right		:= 0;
{236: } 						 wColor			:= @MyWColors;
{237: } 						 wYOrigin			:= 0;
{238: } 						 wXOrigin			:= 0;
{239: } 						 wDataH			:= 200;
{240: } 						 wDataW			:= 640;
{241: } 						 wMaxH				:= 200;
{242: } 						 wMaxW				:= 640;
{243: } 						 wScrollVer		:= 0;
{244: } 						 wScrollHor		:= 0;
{245: } 						 wPageVer			:= 0;
{246: } 						 wPageHor			:= 0;
{247: } 						 wInfoRefCon		:= 0;
{248: } 						 wInfoHeight		:= 0;
{249: } 						 wFrameDefProc	:= nil;
{250: } 						 wInfoDefProc		:= Nil;
{251: } 						 wContDefProc		:=Nil;
{252: } 						 wPosition.top	:=	50;
{253: } 						 wPosition.left	:=	170;
{254: } 						 wPosition.bottom	:=	150;
{255: } 						 wPosition.right	:=	470;
{256: } 						 wPlane	:= WindowPtr(-1);
{257: } 						 wStorage	:= nil;
{258: } 					End;
{259: } 				MainWindow := NewWindow(WRec);
{260: }   			SetPort(MainWindow);
{261: }  			SetRect(R,55,42,236,55);
{262: }   			CurrValue := 125;
{263: }   
{264: }   			VolCtl:= NewControl(MainWindow,r,Nil,$0004 + $0008+$0010,CurrValue,	
{265: } 		 					10,255,ProcPtr($06000000),0,Nil);
{266: }  			SetRect(r,0,0,80,13);
{267: }  			OffsetRect(r,55,60);
{268: }   			LoadBtn := NewControl(MainWindow,r,@'Load..',$0003,0,0,0,nil,0,nil);
{269: }   			OffsetRect(r,100,0);
{270: }   			PlayBtn   := NewControl(MainWindow,r,@'Play...',$0003,0,0,0,nil,0,nil);
{271: }   			SetRect(r,0,0,80,13);
{272: } 			OffsetRect(r,55,80);
{273: }   			PauseBtn   := NewControl(MainWindow,r,@'Pause...',$0003,0,0,0,nil,0,nil);
{274: }  			OffsetRect(r,100,0);
{275: }   			CompactBtn   := NewControl(MainWindow,r,@'Compact...',$0003,0,0,0,nil,0,nil);
{276: } 			ShowWindow(MainWindow);
{277: } 			DrawVolumeInfo;
{278: } 	End;
{279: } 
{280: } {$LongGlobals+}
{281: } Procedure TrackValue(thePart : Integer;	theCtl : CtlRecHndl);
{282: } Begin
{283: }    CurrValue :=	GetCtlValue(theCtl);
{284: }    Case	thePart	of
{285: }       5	: {up arrow}
{286: } 	Begin
{287: } 	  If CurrValue > 1 Then
{288: } 	    SetCtlValue(CurrValue - 1,theCtl);
{289: } 	    SetTheVolume(CurrValue);
{290: } 	End;
{291: }       6	: {down	arrow}
{292: } 	Begin
{293: } 	  If CurrValue < 255 Then
{294: } 	    SetCtlValue(CurrValue + 1,theCtl);
{295: } 	    SetTheVolume(CurrValue);
{296: } 	End;
{297: }       7	: {page	up}
{298: } 	Begin
{299: } 	    CurrValue := CurrValue - 10;
{300: } 	    If CurrValue < 0 Then CurrValue := 1;
{301: } 	    SetCtlValue(CurrValue,theCtl);
{302: } 	    SetTheVolume(CurrValue);
{303: } 	End;
{304: }       8	: {page	down}
{305: } 	Begin
{306: } 	    CurrValue := CurrValue + 10;
{307: } 	    If CurrValue > 255 Then CurrValue := 255;
{308: } 	    SetCtlValue(CurrValue,theCtl);
{309: } 	    SetTheVolume(CurrValue);
{310: } 	End;
{311: }     End;
{312: }  	SetTheVolume(CurrValue);
{313: }  	DrawVolumeInfo;
{314: } End;
{315: } {$LongGlobals-}
{316: } Function  AskUser: Boolean; 
{317: } 		
{318: } 	Var
{319: } 		prompt		: Str255;
{320: } 
{321: } 	Begin
{322: } 		AskUser := False;
{323: } 		prompt := 'Load  which SoundSmith  File :';
{324: } 
{325: } 		gReplyRec.nameDesc := refIsNewHandle;
{326: } 		gReplyRec.pathDesc := refIsNewHandle;
{327: } 
{328: } 
{329: } 		SFGetFile2(120, 40, refIsPointer, Ref(@prompt), nil, @TypeList, gReplyRec);
{330: } 
{331: } 		If gReplyRec.good Then AskUser := True;
{332: } 	End; 
{333: } 
{334: }  Procedure DoErrorWindow(gErrorNum : Integer);
{335: }  	Var
{336: }  			Dummy : Integer;
{337: }  	Begin
{338: }  			Dummy := ErrorWindow(1,Nil,gErrorNum);
{339: }  	End;
{340: } Procedure SetUpDefaults;
{341: } 	Begin
{342: } 		TurnOffSong;
{343: } 		HUnLockAll(SongMemoryID);
{344: } 		DisposeAll(SongMemoryID);
{345: } 		HLockAll(SongMemoryID);
{346: } 		IsSongLoaded 	:= False;
{347: } 		IsSongPlaying 	:= False;
{348: } 		IsSongPaused	:= False;
{349: } 		PauseIsEnabled	:= False;
{350: } 		PlayIsEnabled	:= False;
{351: }   		CurrValue 		:=131;		
{352: }   		LastValue 		:=CurrValue;		
{353: }  		TheFile			:= '';
{354: }  		VolumeBeforePause  := CurrValue;
{355: }  		SetCtlValue(CurrValue,VolCtl);
{356: }  		NewBtnTitle := ' Pause ';
{357: } 		SetCtlTitle(NewBtnTitle,PauseBtn);
{358: } 		CheckTheControls;
{359: } 	End;
{360: } Procedure SetTheVolume(NewVolume : Integer);
{361: } 	Var
{362: } 		OldVolume : Integer;
{363: } 	Begin
{364: } 		If OldVolume = NewVolume Then Exit(SetTheVolume);
{365: } 		SetVolume(NewVolume);
{366: } 		OldVolume := NewVolume;
{367: } 	End;
{368: } Procedure DoOpen;
{369: } 
{370: } 	Var
{371: } 		nameC1OutputStr	  	: ResultBuf255Hndl;
{372: } 		pathC1OutputStr	  		: ResultBuf255Hndl;
{373: } 		TheFileName	  		: String255Hndl;
{374: } 	Begin 
{375: } 		HideWindow(MainWindow);
{376: } 		SetUpDefaults;
{377: } 		If AskUser Then Begin
{378: } 		nameC1OutputStr := ResultBuf255Hndl(gReplyRec.nameRef.refIsNewHandle);
{379: } 		pathC1OutputStr := ResultBuf255Hndl(gReplyRec.pathRef.refIsNewHandle);
{380: } 		TheSongToPlay :=  @pathC1OutputStr^^.BufString;
{381: } 		TheFileName	:= String255Hndl(NewHandle(nameC1OutputStr^^.BufString.
{382: } 		                 		    Length + 1,MyMemoryID,AttrNoCross + AttrLocked,Ptr(0)));
{383: } 		GS2Pstring(NameC1OutputStr^^.BufString,TheFileName^^);  
{384: } 		DisposeHandle(Handle(nameC1OutputStr));
{385: } 		DisposeHandle(Handle(pathC1OutputStr));
{386: } 		With MyLoadSongRec do Begin
{387: } 			SongName := TheSongToPlay;
{388: } 			MemoryID := SongMemoryID;
{389: } 			MemoryType := $4118;
{390: } 		End;
{391: } 		TheFile := Concat('',TheFileName^^,'');
{392: } 		DoInfo(TheFile);
{393: } 		LoadSong(MyLoadSongRec);
{394: } 		If _ToolErr <> NoError Then Begin
{395: } 			TheError	:= _ToolErr;
{396: } 			CloseDialog(InfoDialog);
{397: } 			DisposeHandle(Handle(TheFileName));
{398: } 			HideWindow(MainWindow);
{399: } 			DoErrorWindow(TheError);
{400: } 			ShowWindow(MainWindow);
{401: } 			IsSongLoaded := False;
{402: } 			Exit(DoOpen);
{403: } 		End;
{404: } 		CloseDialog(InfoDialog);
{405: } 		DisposeHandle(Handle(TheFileName));
{406: } 		IsSongLoaded := True;
{407: } 		End;
{408: } 		ShowWindow(MainWindow);
{409: } 	End;
{410: } Procedure DoPlay;
{411: } 	Var
{412: } 		PlayIt	: LongInt;
{413: } 		Dummy		: Integer;
{414: } 		AlertStr	: Str255;
{415: } 	Begin
{416: } 		If (isSongLoaded = True) Then Begin
{417: } 			IsSongPlaying := True;
{418: } 			DrawFileInfo(TheFile);
{419: } 			HideControl(PlayBtn);
{420: } 			ShowControl(PauseBtn);
{421: } 			PlayIsEnabled := False;
{422: } 			PauseIsEnabled := True;
{423: } 			CurrValue := GetCtlValue(VolCtl);
{424: } 			SetTheVolume(CurrValue);
{425: } 			PlayIt	:= $00000000;
{426: } 			PlaySong(PlayIt);
{427: } 			End;
{428: } 	End;
{429: } Procedure DoPause;
{430: } 	Var
{431: } 		PauseValue : Integer;
{432: } 	Begin
{433: } 		If IsSongPaused Then Begin
{434: } 			SetCtlValue(VolumeBeforePause,VolCtl);
{435: } 			SetTheVolume(VolumeBeforePause);
{436: } 			PauseSong($0000);
{437: } 			NewBtnTitle := ' Pause ';
{438: } 			SetCtlTitle(NewBtnTitle,PauseBtn);
{439: } 			IsSongPaused := False;
{440: } 		Exit(DoPause);
{441: } 		End;
{442: } 		VolumeBeforePause := GetCtlValue(VolCtl);
{443: } 		NewBtnTitle := 'Continue';
{444: } 		SetCtlTitle(NewBtnTitle,PauseBtn);
{445: } 		PauseSong($ffff);
{446: } 		IsSongPaused := True;
{447: } 	End;
{448: } 
{449: } Procedure DoCompact;
{450: } 		Var
{451: }   			size: LongInt;
{452: }   			id: Integer;
{453: }  			h: Handle;
{454: }   			oldcur: CursorPtr;
{455: } 		Begin
{456: }   			oldcur := GetCursorAdr;
{457: }  		 	WaitCursor;  
{458: }     			HiliteControl(1,CompactBtn);
{459: }     			id := GetNewID($5000);
{460: }     			size := TotalMem;
{461: }     			Repeat
{462: }       			Repeat
{463: }         				h := NewHandle(size,id,0,nil)
{464: }       			Until h=nil;
{465: }       			size := size div 2;
{466: }     			Until size=0;
{467: }     			DisposeAll(id);
{468: }     			DeleteID(id);
{469: }     			HiliteControl(0,CompactBtn);
{470: }     			InitCursor;
{471: } 	End;
{472: } 
{473: } Procedure CheckTheControls;
{474: } 	Begin
{475: } 		If IsSongLoaded = False Then Begin
{476: } 			HideControl(PlayBtn);
{477: } 			HideControl(PauseBtn);
{478: } 			PlayIsEnabled := False;
{479: } 			PauseIsEnabled := False;
{480: } 		End;
{481: } 		If (IsSongLoaded = True) And (IsSongPlaying = False) Then Begin
{482: } 		ShowControl(PlayBtn);
{483: } 		playIsEnabled := True;
{484: } 		End;
{485: } 	End;
{486: } Procedure DoQuit;
{487: } 	Var
{488: } 		AlertStr   : Str255;
{489: } 		ItemHit     : Integer;
{490: } 	Begin
{491: } 		HideWindow(MainWindow);
{492: } 	     	alertStr := concat ('24/', 'Do You Really Want To Quit ? ', '/^Okay/No Way\0');
{493: }      		ItemHit := AlertWindow2 (0, nil, @alertStr[1]);
{494: } 		If ItemHit = 0 Then
{495: } 		gDone := True
{496: } 		else ShowWindow(MainWindow);
{497: } 		
{498: } 	End; 
{499: } 
{500: } Procedure Initialize;
{501: } 	Begin
{502: } 		TypeList.numEntries := 1;
{503: } 		TypeList.fileTypeEntries[1].flags := $8000;
{504: } 		TypeList.fileTypeEntries[1].fileType := $00D5;
{505: } 		TypeList.fileTypeEntries[1].auxType := $00000007;
{506: } 		with MyWColors do Begin
{507: }     				FrameColor := $0000;
{508: }     				TitleColor := $0f00;
{509: }     				TBarColor  := $020f;
{510: }     				GrowColor  := $f0f0;
{511: }     				InfoColor  := $00f0;
{512: } 		End;
{513: } 	End;
{514: } Procedure DoClose (theWindow  : GrafPortPtr);
{515: }   	Begin
{516: }     		If (theWindow = nil) or (TheWindow = MainWindow) Then exit;
{517: }     		ClosEndAbyWinPtr (theWindow);
{518: }     		If _ToolErr <> NoError Then Begin                   
{519: }     		CloseWindow   (theWindow);              
{520: }     	End;
{521: }  End;    
{522: } 
{523: } Procedure HandleMenu(CodeWord : LongInt);
{524: } 		
{525: } 	Var
{526: } 		theMenu			  : Integer;
{527: } 		theItem			  : Integer;
{528: } 		theWindow			  : WindowPtr;
{529: } 		result				  : Boolean;
{530: } 		dummy				  : Integer;
{531: } 		Begin
{532: } 		theMenu := HiWrd(CodeWord);
{533: } 		theItem := LoWrd(CodeWord);
{534: } 		If TheItem <> 0 Then Begin
{535: } 		Case theItem of
{536: } 			kAboutItem: Begin 
{537: } 								HideWindow(mainwindow);
{538: } 								DoAbout;
{539: } 								ShowWindow(MainWindow);
{540: } 							End;
{541: } 			kCloseItem:DoClose(FrontWindow);
{542: } 			kQuitItem: DoQuit;
{543: } 			kUndoItem: ;
{544: } 			kCutItem: ;
{545: } 			kCopyItem: ;
{546: } 			kPasteItem: ;
{547: } 			kClearItem: ;
{548: } 			
{549: } 			Otherwise
{550: } 				Begin
{551: } 					If theItem < 249 Then 
{552: } 					dummy := OpenNDA(TheItem);
{553: } 					
{554: } 				End;
{555: } 			End;
{556: } 		HiliteMenu(False, theMenu);
{557: } 	End;
{558: } End; 
{559: } Procedure SetUpMenu;
{560: } 	Var
{561: } 		Height : Integer;
{562: } 
{563: } 	Begin
{564: } 	
{565: } 		AppleMenuStr := Concat('>>@\XN1\0',
{566: } 					'==About PlayItGS\N301*Aa\0',
{567: } 					'==-\N301D\0.');
{568: } 		FileMenuStr := Concat('>>  File   \N2\0',
{569: } 					'==Close\N255*Ww\0',
{570: } 					'==-\n302D\0',
{571: } 					'==Quit\N262*Qq\0.');
{572: } 		EditMenuStr := Concat('>>  Edit  \N3\0',
{573: } 					'==Undo\N250D\0',
{574: } 					'==-\N303D\0',
{575: } 					'==Cut\N251*Xx\0',
{576: } 					'==Copy\N252*Cc\0',
{577: } 					'==Paste\N253*Vv\0',
{578: } 					'==Clear\N254\0.');
{579: } 				
{580: }    		SetMTitleStart(10);
{581: }    		InsertMenu(NewMenu(@EditMenuStr[1]),0);	
{582: }    		InsertMenu(NewMenu(@FileMenuStr[1]),0);	
{583: }    		InsertMenu(NewMenu(@AppleMenuStr[1]),0);	
{584: }    		FixAppleMenu(kAppleMenuID);	
{585: }    		Height := FixMenuBar;			
{586: }    		DrawMenuBar;					
{587: } 	End; 
{588: } Procedure MainEventLoop;
{589: } 	
{590: } 		Var
{591: } 			Code			  : Integer;
{592: } 			TheWindow		  : WindowPtr;
{593: } 			R,LimitRect		: Rect;
{594: } 			Part				: Integer;
{595: } 			TheControl	 : CtlRecHndl;
{596: } 		Begin
{597: } 			gDone := False;
{598: } 			Repeat
{599: } 			  SystemTask;
{600: } 			  CheckTheControls;
{601: } 			    gMainEvent.what := 0;
{602: } 				If GetNextEvent(everyevent, gMainEvent) Then Begin
{603: } 				  Case gMainEvent.what of
{604: } 					mouseDownEvt: Begin
{605: } 						code := FindWindow(theWindow, gMainEvent.where.h,
{606: } 													 gMainEvent.where.v);
{607: } 						Case code of
{608: } 							wInDesk: ;
{609: } 							wInMenuBar:
{610: } 							 Begin
{611: } 								MenuSelect(gMainEvent, GetSysBar);
{612: } 								HandleMenu(gMainEvent.wmTaskData);
{613: } 							 End;
{614: } 							wInContent:
{615: } 							 Begin
{616: } 							 	If TheWindow <> FrontWindow Then SelectWindow(TheWindow);
{617: } 								Part := FindControl(TheControl,gMainEvent.where.h,
{618: } 												gMainEvent.where.v,TheWindow);
{619: } 								If Part <> 0 Then
{620: } 								If theControl <> Nil Then Begin
{621: } 						 		If TheControl = LoadBtn Then 
{622: } 						 		Begin
{623: } 									HiliteControl(1,LoadBtn);
{624: } 									HiliteControl(0,LoadBtn);
{625: } 						 		DoOpen;
{626: } 						 		End;
{627: } 						 		If TheControl = PlayBtn Then 
{628: } 						 		Begin
{629: } 						 			HiliteControl(1,PlayBtn);
{630: } 						 			HiliteControl(0,PlayBtn);
{631: } 						 			If Not IsSongPlaying Then
{632: } 						 			DoPlay;
{633: } 						 		End;
{634: } 						 		If TheControl = PauseBtn Then 
{635: } 						 		Begin
{636: } 						 			HiliteControl(1,PauseBtn);
{637: } 						 			HiliteControl(0,PauseBtn);
{638: } 						 			DoPause;
{639: } 						 		End;
{640: } 						 		If TheControl = CompactBtn Then 
{641: } 						 		Begin
{642: } 						 		DoCompact;
{643: } 						 		End;
{644: } 						 Part := TrackControl( gMainEvent.where.h,
{645: } 								gMainEvent.where.v,@TrackValue,VolCtl);
{646: } 								CurrValue := GetCtlValue(VolCtl);
{647: } 								If CurrValue <> LastValue Then Begin
{648: } 								LastValue := CurrValue;
{649: } 								SetTheVolume(LastValue);
{650: } 								DrawVolumeInfo;
{651: } 								End;
{652: } 						
{653: } 							End;
{654: } 						
{655: } 						End;
{656: } 					wInDrag:
{657: } 						Begin
{658: } 						SetRect(LimitRect,4,26,639,199);
{659: } 						DragWindow(0,gMainEvent.where.h,
{660: } 							gMainEvent.where.v,8,@LimitRect,MainWindow);
{661: } 						End;
{662: } 					otherwise 				
{663: } 					If code < 0 Then 
{664: } 					SystemClick(gMainEvent, theWindow, code);				
{665: } 				End;
{666: } 				End; 
{667: } 						
{668: } 				mouseUpEvt: ;
{669: } 				keyDownEvt: 
{670: } 							 Begin
{671: } 								MenuKey(gMainEvent, GetSysBar);
{672: } 								HandleMenu(gMainEvent.wmTaskData);
{673: } 							 End;
{674: } 
{675: } 				autoKeyEvt: ;
{676: } 				updateEvt: Begin
{677: } 								SetPort(MainWindow);
{678: } 								BeginUpDate(WindowPtr(gMainEvent.message));
{679: } 								DrawControls(WindowPtr(gMainEvent.message));
{680: } 								CurrValue := GetCtlValue(VolCtl);
{681: } 								DrawFileInfo(TheFile);
{682: } 								DrawVolumeInfo;
{683: } 								EndUpDate(WindowPtr(gMainEvent.message));
{684: } 							  End;
{685: } 				activateEvt:Begin
{686: } 								SetPort(MainWindow);
{687: } 								If Odd(gMainEvent.ModIfiers) Then Begin
{688: } 									HiliteControl(0,VolCtl);
{689: } 									HiliteControl(0,LoadBtn);
{690: } 									HiliteControl(0,PlayBtn);
{691: } 									HiliteControl(0,CompactBtn);
{692: } 									HiliteControl(0,PauseBtn);
{693: } 									DrawControls(MainWindow);
{694: } 									DrawFileInfo(TheFile);
{695: } 									DrawVolumeInfo;
{696: } 								End Else
{697: } 								Begin
{698: } 									HiliteControl(1,VolCtl);
{699: } 									HiliteControl(1,LoadBtn);
{700: } 									HiliteControl(1,PlayBtn);
{701: } 									HiliteControl(1,CompactBtn);
{702: } 									HiliteControl(1,PauseBtn);
{703: } 								End;
{704: } 								
{705: } 							     End;		
{706: } 				End;
{707: } 			End;
{708: } 			Until gDone;
{709: } 		End; 
{710: } 
{711: } 	Begin
{712: } 			StartUp;
{713: } 			Initialize;
{714: } 			CreateIcon;
{715: } 			SetUpMenu;
{716: } 			InitCursor;
{717: } 			CreateMainWindow;
{718: } 			SetUpDefaults;
{719: } 			MainEventLoop;
{720: } 			
{721: } 			ShutDown;
{722: } 	End.
{723: } 	End.
