home *** CD-ROM | disk | FTP | other *** search
- program PlayChristmasCarol (input, output, SongFromDisk);
-
- { Xmassong Version 1.10 (C) 1985 Michael Glowacki
- Available in the Public Domain
-
- This program will play the Christmas carol stored in SONGFILE.DAT
- which is necessary to run this program. Updates will be readily available as
- they are created. Enjoy this simple program and give a copy to your friends.
-
- MJG }
-
-
- type NoteRecord = record
- C,CF,D,DF,E,F,FF,G,GF,A,AF,B: integer;
- end;
- SingleNote = record
- Octave : integer;
- NoteName : integer;
- NoteLength : real; {in whole notes}
- end; {NoteRecord}
- Song = array[1..136] of SingleNote;
- SongFile = file of Song;
-
- const MillisecondsPerWholeNote = 1500; { 1.5 seconds }
- Notes: NoteRecord =
- (C:1;CF:2;D:3;DF:4;E:5;F:6;FF:7;G:8;GF:9;A:10;AF:11;B:12);
-
- var ChristmasSong : Song;
- SongFromDisk : SongFile;
- WhichNote : integer;
- Reply : char;
-
- function ConvertToMs (Length : real) : integer;
- {This function converts the Length of the note (in whole notes) to ms.}
-
- begin
- ConvertToMs:= round(Length*MillisecondsPerWholeNote);
- end; { ConvertToMs }
-
- procedure Play (Octave, Note, Duration : integer);
- { Play Note in Octave Duration milliseconds }
- { Frequency computed by first computing C in }
- { Octave then increasing frequency by Note-1 }
- { times the twelfth root of 2. (1.059463994) }
- { }
- { If Duration is zero Note will be played }
- { until you activate procedure NoSound }
-
- var
- Frequency: real;
- I: integer;
- begin
- if (Note < 13) and (Note > 0)
- then begin
- Frequency:=32.625;
- { Compute C in Octave }
- for I:=1 to Octave do Frequency:=Frequency*2;
- { Increase frequency Note-1 times }
- for I:=1 to Note-1 do Frequency:=Frequency*1.059463094;
- if Duration<>0 then
- begin
- Sound(Round(Frequency));
- Delay(Duration);
- NoSound;
- end else Sound(Round(Frequency))
- end
- else Delay(Duration);
- end;
-
- procedure GetSong (var XmasSong : Song; var ThisFile : SongFile);
- begin
- assign(ThisFile, 'SONGFILE.DAT');
- reset(ThisFile);
- read(ThisFile, XmasSong);
- close(ThisFile);
- end; { GetSong }
-
- begin {PlayChristmasCarol}
- writeln('Xmassong Version 1.10 (C) 1985 Michael Glowacki ');
- writeln(' Available in the Public Domain');
- GotoXY(11,7);
- writeln('This program requires that SONGFILE.DAT is on the current disk drive.');
- write('Is that file on this disk drive? ');
- readln(Reply);
- writeln;
- if (Reply = 'y') or (Reply = 'Y')
- then begin
- GetSong(ChristmasSong, SongFromDisk);
- WhichNote:= 1;
- writeln(' God Rest Ye, Merry Gentlemen');
- repeat
- with ChristmasSong[WhichNote]
- do begin
- Play(Octave, NoteName, ConvertToMs(NoteLength));
- end;
- WhichNote:= WhichNote + 1;
- until (WhichNote > 137);
- end; {if Reply = 'Y'}
- end. {PlayChristmasCarol}