home *** CD-ROM | disk | FTP | other *** search
- { *********************************** }
- { A Program to tune your fiddle. }
- { by Stephen H. Tuell }
- { Kaneohe, Hawaii }
- { February 1990 }
- { *********************************** }
-
- Program Mfiddle;
- uses
- Crt, Dos, Graph,mousu;
- const WIDTH = 20 ; { Line +/- WIDTH pixels will activate tone. }
- var
- GraphDriver : integer; { The Graphics device driver }
- GraphMode : integer; { The Graphics mode value }
- MaxX, MaxY : word; { The maximum resolution of the screen }
- ErrorCode : integer; { Reports any graphics errors }
- MaxColor : word; { The maximum color value available }
- OldExitProc : Pointer; { Saves exit procedure address }
-
- { Initialize graphics and report any errors that may occur }
- procedure Initialize;
- var
- InGraphicsMode : boolean; { Flags initialization of graphics mode }
- PathToDriver : string; { Stores the DOS path to *.BGI & *.CHR }
- begin
- { When using Crt and graphics, turn off Crt's memory-mapped writes }
- DirectVideo := FALSE;
- PathToDriver := '';
- repeat
- {$IFDEF Use8514} { check for Use8514 $DEFINE }
- GraphDriver := IBM8514;
- GraphMode := IBM8514Hi;
- {$ELSE}
- GraphDriver := Detect; { use autodetection }
- {$ENDIF}
-
- InitGraph(GraphDriver, GraphMode, PathToDriver);
- ErrorCode := GraphResult; { preserve error return }
- if ErrorCode <> grOK then { error? }
- begin
- Writeln('Graphics error: ', GraphErrorMsg(ErrorCode));
- if ErrorCode = grFileNotFound then { Can't find driver file }
- begin
- Writeln('Enter full path to BGI driver or type <Ctrl-Break> to quit:');
- Readln(PathToDriver);
- Writeln;
- end
- else
- Halt(1); { Some other error: terminate }
- end;
- until ErrorCode = grOK;
- Randomize; { Init random number generator }
- MaxColor := GetMaxColor; { Get the maximum allowable drawing color }
- MaxX := GetMaxX; { Get screen resolution values }
- MaxY := GetMaxY;
- end; { Initialize }
-
- { Abort with message if no mouse driver present }
- Procedure DetectMouse;
- Begin
- ClrScr;
- ResetMouse;
- If NOT MousePresent then
- Begin
- WriteLn('Mouse driver not present.');
- WriteLn('Terminating program.');
- Halt;
- End;
- ClrScr;
- End;
-
- { Converts an integer to a string for use with OutText, OutTextXY }
- function Int2Str(L : LongInt) : string;
- var
- S : string;
- begin
- Str(L, S);
- Int2Str := S;
- end; { Int2Str }
-
- { This function returns true if mouse is within the rectangle defined by
- x1,y1,x2,y2 }
- Function mouseinside(x1,y1,x2,y2:word):Boolean;
- begin
- GetButtonStatus;
- mouseinside:=(mousex>=x1) AND (mousex <=X2) AND (Mousey>=y1) AND (Mousey<=y2);
- end;
-
- { This function returns true if mouse is within XWIDTH pixels of xposition X
- AND mouse is within YWIDTH pixels of yposition Y}
- Function mousenear(x,xwidth,y,ywidth:word):Boolean;
- begin
- GetButtonStatus;
- Mousenear:=(mousex>=(x-xwidth)) AND (mousex <=(x+xwidth))
- AND (mousey>=(y-ywidth)) AND (mousey <=(y+ywidth)) ;
- end;
-
- Begin
- Nosound;
- { If no mouse driver installed, abort program with error message. }
- Detectmouse;
- { Initialize graphics }
- Initialize;
- setBkColor(BLUE);
- setColor(YELLOW);
- { Initialize mouse driver }
- resetmouse;
- SetGraphicsCursor(PointingHandCurs);
- { Make Quit box }
- Rectangle(450,100,549,120);
- SetFillStyle(SolidFill,Red);
- FloodFill(451,101,Yellow);
- SetTextStyle(TriplexFont,HorizDir,1);
- outtextxy(481,100,'QUIT');
- { Put up Program Boiler Plate }
- SetTextStyle(SansSerifFont,HorizDir,4);
- SetlineStyle(SolidLn,0,ThickWidth);
- Setcolor(Brown);
- Line(410,45,600,45);
- SetfillStyle(SolidFill,Green);
- bar3d(420,265,600,395,20,TRUE);
- Setcolor(White);
- Outtextxy(430,280,'Use Mouse ');
- Outtextxy(430,310,'to select');
- Outtextxy(430,340,'a string.');
- SetFillStyle(SolidFill,Red);
- outtextxy(410,10,'Fiddle Tuner');
- { Draw the strings }
- Setcolor(yellow);
- line(70,50,70,400);
- line(170,50,170,400);
- line(270,50,270,400);
- line(370,50,370,400);
- { Label the strings }
- SetTextStyle(TriplexFont,HorizDir,4);
- outtextxy( 60,415,'G');
- outtextxy(160,415,'D');
- outtextxy(260,415,'A');
- outtextxy(360,415,'E');
- { Poll the strings and play the notes }
- SetMouseCursorPos(580,315);
- ShowMouseCursor;
- Repeat
- if mousenear(70,WIDTH,225,175) then sound(196)
- else if mousenear(170,WIDTH,225,175) then sound(294)
- else if mousenear(270,WIDTH,225,175) then sound(440)
- else if mousenear(370,WIDTH,225,175) then sound(659)
- else nosound;
- until mouseinside(450,100,549,120) ; { Quit if in the Quit Box }
- nosound; { Turn off the sound }
- textmode(2);
- end.