
-----------------------------------
PianoGirl
Sun Jan 23, 2005 5:28 pm

Help with Piano Program - I really need 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:


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 "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 ">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:



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 "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 "