Skip to content

Instantly share code, notes, and snippets.

@tuankiet65
Created February 6, 2013 09:50
Show Gist options
  • Save tuankiet65/4721496 to your computer and use it in GitHub Desktop.
Save tuankiet65/4721496 to your computer and use it in GitHub Desktop.
program music;
uses crt;
var n, author, tone, path, tmp: string;
t: text;
hz, time, i: longint;
begin
clrscr;
write('Enter input path: ');
readln(path);
assign(t, path);
{$I-}
reset(t);
while IOResult<>0 do begin
writeln('File not found');
write('Please enter input path: ');
readln(path);
assign(t, path);
reset(t);
end;
{$I+}
while not eof(t) do begin
readln(t, tmp);
if pos('<author>', tmp)<>0 then begin
author:=tmp;
delete(author, 1, 8);
delete(author, pos('</author>', author), length(author));
end;
if pos('<name>', tmp)<>0 then begin
n:=tmp;
delete(n, 1, 6);
delete(n, pos('</name>', n), length(n));
end;
if pos('<music>', tmp)<>0 then break;
end;
writeln('Now playing song name ', n, ' by ', author);
while tmp<>'</music>' do begin
readln(t, tmp);
while i<>length(tmp) do begin
if tmp[i]=' ' then delete(tmp, i, 1) else i:=i+1;
end;
if pos('<whole>', tmp)<>0 then begin
time:=4000;
delete(tmp, 1, 7);
delete(tmp, pos('</whole>', tmp), length(tmp));
end;
if pos('<half>', tmp)<>0 then begin
time:=2000;
delete(tmp, 1, 6);
delete(tmp, pos('</half>', tmp), length(tmp));
end;
if pos('<quarter>', tmp)<>0 then begin
time:=1000;
delete(tmp, 1, 9);
delete(tmp, pos('</quarter>', tmp), length(tmp));
end;
if pos('<eighth>', tmp)<>0 then begin
time:=500;
delete(tmp, 1, 8);
delete(tmp, pos('</eighth>', tmp), length(tmp));
end;
if pos('<sixteenth>', tmp)<>0 then begin
time:=250;
delete(tmp, 1, 11);
delete(tmp, pos('</sixteenth>', tmp), length(tmp));
end;
case tmp of
'Do': hz:=131;
'Re': hz:=147;
'Mi': hz:=165;
'Fa': hz:=175;
'Sol': hz:=196;
'La': hz:=220;
'Si': hz:=247;
'Doo': hz:=262;
end;
sound(hz);
delay(time);
end;
nosound;
readln;
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment