Piano Playing Program - I really need some help tonight
Author |
Message |
PianoGirl
|
Posted: Sun Jan 23, 2005 5:10 pm Post subject: Piano Playing Program - I really need some help tonight |
|
|
In short, my program is pretty damn stupid. Unfortunately, we need to test these things in class tomorrow and I have have something working...
Basically, my program will play all the notes I want it to, but not at the same time. I know this has to do with the getch command. Perhaps this program could work with Input. Keydown, but unfortunately I have Turing 4.0.1 on my home computer (4.0.5 at school)
If anyone would be able to tell me if there is a way to get to play the notes at the same time, I would REALLY appreciate it. Here is my code:
code: |
function checkNote (x : string (1)) : string
% Purpose: Tells the program which note is associated with each key
% on the keyboard
% Down 1 octave:
if x = " " then % space - C
result "<c"
elsif x = chr (122) then % z - D
result "<d"
elsif x = chr (120) then % x - E
result "<e"
elsif x = chr (99) then % c - F
result "<f"
elsif x = chr (118) then % v - G
result "<g"
elsif x = chr (98) then % b - A
result "<a"
elsif x = chr (110) then % n - B
result "<b"
elsif x = chr (97) then % a - C#
result "<c+"
elsif x = chr (115) then % s - D#
result "<d+"
elsif x = chr (102) then % f - F#
result "<f+"
elsif x = chr (103) then % g - G#
result "<g+"
elsif x = chr (104) then % h - A#
result "<a+"
% Up 1 octave:
elsif x = chr (106) then % j - C
result "c"
elsif x = chr (107) then % k - D
result "d"
elsif x = chr (108) then % l - E
result "e"
elsif x = chr (59) then % ; - F
result "f"
elsif x = chr (39) then % ' - G
result "g"
elsif x = chr (10) then % enter - A
result "a"
elsif x = chr (211) then % delete - B
result "b"
elsif x = chr (105) then % i - C#
result "c+"
elsif x = chr (111) then % o - D#
result "d+"
elsif x = chr (91) then % [ - F#
result "f+"
elsif x = chr (93) then % ] - G#
result "g+"
elsif x = chr (92) then % \ - A#
result "a+"
% Down 2 octaves:
elsif x = chr (96) then % ` - C
result "<<c"
elsif x = chr (49) then % 1 - D
result "<<d"
elsif x = chr (50) then % 2 - E
result "<<e"
elsif x = chr (51) then % 3 - F
result "<<f"
elsif x = chr (52) then % 4 - G
result "<<g"
elsif x = chr (53) then % 5 - A
result "<<a"
elsif x = chr (54) then % 6 - B
result "<<b"
elsif x = chr (187) then % F1 - #C
result "<<c+"
elsif x = chr (188) then % F2 - #D
result "<<d+"
elsif x = chr (189) then % F3 - #F
result "<<f+"
elsif x = chr (190) then % F4 - #G
result "<<g+"
elsif x = chr (191) then % F5 - #A
result "<<a+"
% Up 2 octaves:
elsif x = chr (55) then % 7 - C
result ">c"
elsif x = chr (56) then % 8 - D
result ">d"
elsif x = chr (57) then % 9 - E
result ">e"
elsif x = chr (48) then % 0 - F
result ">f"
elsif x = chr (45) then % - - G
result ">g"
elsif x = chr (61) then % = - A
result ">a"
elsif x = chr (8) then % backspace - B
result ">b"
elsif x = chr (192) then % F6 - #C
result ">c+"
elsif x = chr (193) then % F7 - #D
result ">d+"
elsif x = chr (195) then % F9 - #F
result ">f+"
elsif x = chr (196) then % F10 - #G
result ">g+"
elsif x = chr (197) then % F11 - #A
result ">a+"
% Down 3 octaves:
elsif x = chr (90) then % Z - C
result "<<<c"
elsif x = chr (88) then % X - D
result "<<<d"
elsif x = chr (67) then % C - E
result "<<<e"
elsif x = chr (86) then % V - F
result "<<<f"
elsif x = chr (66) then % B - G
result "<<<g"
elsif x = chr (78) then % N - A
result "<<<a"
elsif x = chr (77) then % M - B
result "<<<b"
elsif x = chr (83) then % S - #C
result "<<<c+"
elsif x = chr (68) then % D - #D
result "<<<d+"
elsif x = chr (71) then % G - #F
result "<<<f+"
elsif x = chr (72) then % H - #G
result "<<<g+"
elsif x = chr (74) then % J - #A
result "<<<a+"
% Up 3 octaves:
elsif x = chr (81) then % Q - C
result ">>c"
elsif x = chr (87) then % W - D
result ">>d"
elsif x = chr (69) then % E - E
result ">>e"
elsif x = chr (82) then % R - F
result ">>f"
elsif x = chr (84) then % T - G
result ">>g"
elsif x = chr (89) then % Y - A
result ">>a"
elsif x = chr (85) then % U - B
result ">>b"
elsif x = chr (64) then % @ - #C
result ">>c+"
elsif x = chr (35) then % # - #D
result ">>d+"
elsif x = chr (37) then % % - #F
result ">>f+"
elsif x = chr (94) then % ^ - #G
result ">>g+"
elsif x = chr (38) then % & - #A
result ">>a+"
elsif x = chr (27) then % Esc - Exit
result "exit"
else
result "x" % No note will be played
end if
end checkNote
process doNote (notes:string,duration : int)
var timeBegin := Time.Elapsed
loop
Music.Play (notes)
exit when Time.Elapsed - timeBegin >= duration
end loop
end doNote
% Driver Program
var x: string(1)
loop
getch(x)
fork doNote(checkNote(x), 125)
end loop
|
The best thing that I have been able to come up with is using arrays where if you press a certain key, the next notes after that you can play one note - six notes at one time. The problem with this is that I don't know how to alternate (to play six notes, then five note, then one and so one). Its also not very smoothe.
Here is an example of that:
code: |
function checkNote (x : string (1)) : string
% Purpose: Tells the program which note is associated with each
% key on the keyboard
% Down 1 octave:
if x = " " then % space - C
result "<c"
elsif x = chr (122) then % z - D
result "<d"
elsif x = chr (120) then % x - E
result "<e"
elsif x = chr (99) then % c - F
result "<f"
elsif x = chr (118) then % v - G
result "<g"
elsif x = chr (98) then % b - A
result "<a"
elsif x = chr (110) then % n - B
result "<b"
elsif x = chr (97) then % a - C#
result "<c+"
elsif x = chr (115) then % s - D#
result "<d+"
elsif x = chr (102) then % f - F#
result "<f+"
elsif x = chr (103) then % g - G#
result "<g+"
elsif x = chr (104) then % h - A#
result "<a+"
% Up 1 octave:
elsif x = chr (106) then % j - C
result "c"
elsif x = chr (107) then % k - D
result "d"
elsif x = chr (108) then % l - E
result "e"
elsif x = chr (59) then % ; - F
result "f"
elsif x = chr (39) then % ' - G
result "g"
elsif x = chr (10) then % enter - A
result "a"
elsif x = chr (211) then % delete - B
result "b"
elsif x = chr (105) then % i - C#
result "c+"
elsif x = chr (111) then % o - D#
result "d+"
elsif x = chr (91) then % [ - F#
result "f+"
elsif x = chr (93) then % ] - G#
result "g+"
elsif x = chr (92) then % \ - A#
result "a+"
% Down 2 octaves:
elsif x = chr (96) then % ` - C
result "<<c"
elsif x = chr (49) then % 1 - D
result "<<d"
elsif x = chr (50) then % 2 - E
result "<<e"
elsif x = chr (51) then % 3 - F
result "<<f"
elsif x = chr (52) then % 4 - G
result "<<g"
elsif x = chr (53) then % 5 - A
result "<<a"
elsif x = chr (54) then % 6 - B
result "<<b"
elsif x = chr (187) then % F1 - #C
result "<<c+"
elsif x = chr (188) then % F2 - #D
result "<<d+"
elsif x = chr (189) then % F3 - #F
result "<<f+"
elsif x = chr (190) then % F4 - #G
result "<<g+"
elsif x = chr (191) then % F5 - #A
result "<<a+"
% Up 2 octaves:
elsif x = chr (55) then % 7 - C
result ">c"
elsif x = chr (56) then % 8 - D
result ">d"
elsif x = chr (57) then % 9 - E
result ">e"
elsif x = chr (48) then % 0 - F
result ">f"
elsif x = chr (45) then % - - G
result ">g"
elsif x = chr (61) then % = - A
result ">a"
elsif x = chr (8) then % backspace - B
result ">b"
elsif x = chr (192) then % F6 - #C
result ">c+"
elsif x = chr (193) then % F7 - #D
result ">d+"
elsif x = chr (195) then % F9 - #F
result ">f+"
elsif x = chr (196) then % F10 - #G
result ">g+"
elsif x = chr (197) then % F11 - #A
result ">a+"
% Down 3 octaves:
elsif x = chr (90) then % Z - C
result "<<<c"
elsif x = chr (88) then % X - D
result "<<<d"
elsif x = chr (67) then % C - E
result "<<<e"
elsif x = chr (86) then % V - F
result "<<<f"
elsif x = chr (66) then % B - G
result "<<<g"
elsif x = chr (78) then % N - A
result "<<<a"
elsif x = chr (77) then % M - B
result "<<<b"
elsif x = chr (83) then % S - #C
result "<<<c+"
elsif x = chr (68) then % D - #D
result "<<<d+"
elsif x = chr (71) then % G - #F
result "<<<f+"
elsif x = chr (72) then % H - #G
result "<<<g+"
elsif x = chr (74) then % J - #A
result "<<<a+"
% Up 3 octaves:
elsif x = chr (81) then % Q - C
result ">>c"
elsif x = chr (87) then % W - D
result ">>d"
elsif x = chr (69) then % E - E
result ">>e"
elsif x = chr (82) then % R - F
result ">>f"
elsif x = chr (84) then % T - G
result ">>g"
elsif x = chr (89) then % Y - A
result ">>a"
elsif x = chr (85) then % U - B
result ">>b"
elsif x = chr (64) then % @ - #C
result ">>c+"
elsif x = chr (35) then % # - #D
result ">>d+"
elsif x = chr (37) then % % - #F
result ">>f+"
elsif x = chr (94) then % ^ - #G
result ">>g+"
elsif x = chr (38) then % & - #A
result ">>a+"
elsif x = chr (27) then % Esc - Exit
result "exit"
else
result "x" % No note will be played
end if
end checkNote
procedure recordNotes (notes : string)
var saveFile : int
open : saveFile, "saveFile.txt", put
var arrayName : array 1 .. 100000 of string
for i : 1 .. upper (notes)
arrayName (i) := notes
put : saveFile, arrayName (i)
end for
end recordNotes
process doNote (notes:string,duration : int)
var timeBegin := Time.Elapsed
loop
Music.Play (notes)
exit when Time.Elapsed - timeBegin >= duration
end loop
end doNote
% Driver Program
var sixNotes : array 1 .. 6 of string
var fiveNotes : array 1 .. 5 of string
var fourNotes : array 1 .. 4 of string
var threeNotes : array 1 .. 3 of string
var twoNotes : array 1 .. 2 of string
var oneNote : string
var x : string (1)
loop
getch (x)
% Plays six notes at one time
if x = chr (121) then %y
loop
for six : 1 .. 6
getch (x)
sixNotes (six) := checkNote (x)
end for
for six : 1 .. 6
fork doNote (sixNotes (six), 125)
end for
end loop
% Plays five notes at one time
elsif x = chr (116) then %t
loop
for five : 1 .. 5
getch (x)
fiveNotes (five) := checkNote (x)
end for
for five : 1 .. 5
fork doNote (fiveNotes (five), 125)
end for
end loop
% Plays four notes at one time
elsif x = chr (114) then % r
loop
for four : 1 .. 4
getch (x)
fourNotes (four) := checkNote (x)
end for
for four : 1 .. 4
fork doNote (fourNotes (four), 125)
end for
end loop
% Plays three notes at one time
elsif x = chr (101) then %e
loop
for i : 1 .. 3
getch (x)
threeNotes (i) := checkNote (x)
end for
for i : 1 .. 3
fork doNote (threeNotes (i), 125)
end for
end loop
% Plays two notes at one time
elsif x = chr (119) then %w
loop
for b : 1 .. 2
getch (x)
twoNotes (b) := checkNote (x)
end for
for b : 1 .. 2
fork doNote (twoNotes (b), 125)
end for
end loop
% Plays one at one time
elsif x = chr (113) then %q
loop
getch (x)
oneNote := checkNote (x)
fork doNote (checkNote (x), 125)
end loop
else
end if
end loop
|
Please help me, I'm completely out of ideas. Thanks very much,
- Julie |
|
|
|
|
|
Sponsor Sponsor
|
|
|
|
|