
-----------------------------------
Harblkipz
Thu Nov 06, 2008 4:38 pm

Piano
-----------------------------------
Hello Compsci,

I want to make a piano program in Turing. I have the base for my program, I just need help with one thing.

Here's my code, just as a start.

var chars : array char of boolean
loop
    Input.KeyDown (chars)
    
    if chars ('a') then
         Music.Play ( "2c" )
    else
        put "" ..
    end if
    if chars ('s') then
        Music.Play ( "2e" )
    else
        put "" ..
    end if
    if chars ('d') then
        Music.Play ( "2d" )
    else
        put "" ..
    end if
    if chars ('f') then
        Music.Play ( "2f" )
    else
        put "" ..
    end if
end loop


When I hit a note, then another, there is this huge delay, is there any way to fix that? Thanks!

-----------------------------------
pavol
Thu Nov 06, 2008 4:51 pm

RE:Piano
-----------------------------------
Vertico is right, you don't need the put "" part, as a matter of fact you don't even need the else clause of your if statements. 
What I think is that simply calling Music.Play() alone takes a while to execute and that's what is  causing the delays in your program.


...strange Vertico's post no longer exists lol :?

-----------------------------------
Harblkipz
Thu Nov 06, 2008 5:58 pm

RE:Piano
-----------------------------------
Still doesn't stop the delay, i should of been more specific.
What I want it to do is, when i hit one note, if I hit another right after it either plays both, or the newly hit note. What ever is easier.

-----------------------------------
Insectoid
Thu Nov 06, 2008 6:06 pm

RE:Piano
-----------------------------------
Is Turing even capable of playing more than one note at a time?

-----------------------------------
S_Grimm
Thu Nov 06, 2008 9:09 pm

RE:Piano
-----------------------------------
nope. at least not to my knowledge. when i tried to write this program myself, i couldn't get it to play more than one note at a time.

-----------------------------------
Harblkipz
Thu Nov 06, 2008 9:09 pm

RE:Piano
-----------------------------------
I hope so, if not then we can scrap this thread.

-----------------------------------
S_Grimm
Thu Nov 06, 2008 9:11 pm

RE:Piano
-----------------------------------
like i said, (and if someone can prove me wrong, please do) I couldn't get this program to play more than one note at a time when i tried (that was almost a year ago.)

-----------------------------------
Harblkipz
Fri Nov 07, 2008 9:46 pm

RE:Piano
-----------------------------------
That sucks. I remember I did this in my engineering class last year with a breadboard. I thought it would be neat with just a keyboard but I guess I forgot Turing couldn't do that. Thanks anyways guys. :]

-----------------------------------
SNIPERDUDE
Sun Nov 09, 2008 7:35 pm

RE:Piano
-----------------------------------
You can, using  a process.  But I wouldn't because of the unreliability of these (the timing is not reliable) and should be avoided whenever possible.

-----------------------------------
sriyegna
Tue Mar 09, 2010 4:48 pm

RE:Piano
-----------------------------------
could you please elaborate sniperdude?

im building a similar program, cept with more keys :)

and its very annoying to have to wait for the whole delay. id like to make it smooth. So, could you please elaborate on your process theory?

-----------------------------------
Turing_Gamer
Tue Mar 09, 2010 6:11 pm

Re: Piano
-----------------------------------
You can do it easily by using frequencies but not so much piano. It is practically impossible. You can use intstr but the max it can do is a whole note and the least it can do is I believe 8. Not much variety so sorry cant help you

-----------------------------------
SNIPERDUDE
Sat Mar 13, 2010 11:18 pm

RE:Piano
-----------------------------------
processes are similar to procedures, but when called will run alongside the rest of your program (where in a procedure it will finish executing the contents before moving on).  This means if you put a part you want to play alongside your current melody, you would put one of them in a process.

But like I said the problem with using a process in Turing is the timings of when it will execute is very hard to manage, especially with varying computer speeds.  Try it out anyway for this purpose, but keep in mind you should use procs whenever possible.
