home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Mother of All Windows Books
/
CD-MOM.iso
/
cd_mom
/
newsletr
/
vbz
/
vbz1-3
/
dll_src.exe
/
WINPLAY.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1993-02-25
|
4KB
|
167 lines
library WINPLAY;
{This is a Windows implementation of the BASIC PLAY}
{command. To use it, you must first open the sound}
{queue with OpenSound}
{by Jonathan Zuck}
{Copyright 1991-3 Jonathan Zuck & User Friendly, Inc.}
{$R WINPLAY}
uses WinProcs, WinTypes, Strings;
Const
A = 65; P = 80;
NoteArr: Array[A..P] OF Integer =
(10,12,1,3,5,6,8,0,0,0,0,0,0,0,0,0);
Var {These are values that should remain between calls}
hLastCall:Integer;
Tempo:Integer;
Music:Integer;
Octave:Integer;
Length:Integer;
Var {These are temporary values for the SendNote Proc}
NewNote, NewAccent,
ForeGround:Bool;
Pitch, NoteLength, Dots:Integer;
El: Integer;
procedure SendNote;forward;
function GetNumber (Song:PChar):Integer;forward;
procedure Play (Song:PChar);export;
Var
hCaller:Integer;
Begin
hCaller := GetCurrentTask;
if hCaller <> hLastCall then
begin
hLastCall := hCaller;
Tempo := 120;
Music := 0;
Octave := 3;
Length := 4;
ForeGround := TRUE;
end;
Dots := 0;
NewNote := FALSE;
NewAccent := TRUE;
NoteLength := 0;
AnsiUpper (Song);
El := 0;
While Song[El] <> #0 do
Begin
case Song[El] of
'A'..'G', 'P':
begin
SendNote;
Pitch := NoteArr[Ord(Song[El])];
NewNote := TRUE;
end;
'+', '#':
Inc (Pitch);
'-':
Dec (Pitch);
'.':
Inc (Dots);
'1'..'9':
NoteLength := GetNumber (Song);
'>':
begin
SendNote;
Inc (Octave);
end;
'<':
begin
SendNote;
Dec (Octave);
end;
'M':
begin
SendNote;
Inc (El);
case Song[El] of
'N':
Music := S_NORMAL;
'S':
Music := S_STACCATO;
'L':
Music := S_LEGATO;
'F':
ForeGround := TRUE;
'B':
ForeGround := FALSE;
end;
NewAccent := TRUE;
end;
'N':
begin
SendNote;
Inc (El);
Pitch := GetNumber (Song);
NewNote := TRUE;
end;
'O':
begin
SendNote;
Inc (El);
Octave := GetNumber (Song);
end;
'T':
begin
SendNote;
Inc (El);
Tempo := GetNumber (Song);
NewAccent := TRUE;
end;
'L':
begin
SendNote;
Inc (El);
Length := GetNumber (Song);
end;
end;
Inc (El);
end;
SendNote;
if ForeGround then WaitSoundState (0);
End;
procedure SendNote;
Begin
If NewAccent then SetVoiceAccent (1, Tempo, 1, Music, 0);
If NewNote then
begin
If Pitch > 0 then Pitch := (Pitch + (Octave * 12)) - 1;
If NoteLength = 0 then NoteLength := Length;
While SetVoiceNote (1, Pitch, NoteLength, Dots) <> 0 Do;
StartSound;
NoteLength := 0;
Dots := 0;
end;
NewNote := FALSE;
NewAccent := FALSE;
End;
function GetNumber (Song:PChar):Integer;
Var
Temp:Integer;
Begin
Temp := Ord(Song[El]) - 48; {Convert to number}
While (Song[El+1] >= '0') and (Song[El+1] <= '9') do
begin
Temp := (Temp * 10) + (Ord(Song[El+1]) - 48);
Inc (El);
end;
GetNumber := Temp;
End;
Exports
Play resident;
Begin
hLastCall := 0;
End.