Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Cool Keyboard
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
exploitmonkey




PostPosted: Wed Dec 29, 2004 8:00 pm   Post subject: Cool Keyboard

This is the code for a simple keyboard I made.... an criticism would be good.... graphics soon to come

%>>>>CODE

loop
var chars : array char of boolean
Input.KeyDown (chars)
if chars ('q') then
sound (100, 100)

elsif chars ('w') then
sound (200, 100)

elsif chars ('e') then
sound (300, 100)

elsif chars ('r') then
sound (400, 100)

elsif chars ('t') then
sound (500, 100)

elsif chars ('y') then
sound (600, 100)

elsif chars ('u') then
sound (700, 100)

elsif chars ('i') then
sound (800, 100)

elsif chars ('o') then
sound (900, 100)

elsif chars ('p') then
sound (1000, 100)

elsif chars ('a') then
sound (1100, 100)

elsif chars ('s') then
sound (1200, 100)

elsif chars ('d') then
sound (1300, 100)

elsif chars ('f') then
sound (1400, 100)

elsif chars ('g') then
sound (1500, 100)

elsif chars ('h') then
sound (1600, 100)

elsif chars ('j') then
sound (1700, 100)

elsif chars ('k') then
sound (1800, 100)

elsif chars ('l') then
sound (1900, 100)

elsif chars ('z') then
sound (2000, 100)

elsif chars ('x') then
sound (2100, 100)

elsif chars ('c') then
sound (2200, 100)

elsif chars ('v') then
sound (2300, 100)

elsif chars ('b') then
sound (2400, 100)

elsif chars ('n') then
sound (2500, 100)

elsif chars ('m') then
sound (2600, 100)


end if

end loop


%>>>>>END CODE
Sponsor
Sponsor
Sponsor
sponsor
Delos




PostPosted: Wed Dec 29, 2004 9:55 pm   Post subject: (No subject)

Ok...

1)
Use [code] tags. Or feel the burn from the flames hurled at you by many people.

2)
You're idea is interesting...a little trite, but interesting.
Try this though:
You can either stick w/ your current Input.KeyDown() method of input, or use a getch. Either way.
Pass your character input to a variable. Take the ord() of it. From there, you'll have a discernable number (integer). Use that and some simple arithmetic to compute the resultant sound() values.
This will shorten your code considerably.
cool dude




PostPosted: Thu Dec 30, 2004 11:23 am   Post subject: (No subject)

instead of using all the keys on the keyboard u could have done just one interval of the piano/keyboard and for example to play the note c u will press c on the keyboard. this will make it just like the piano and u could actually play a song. but this is pretty good too.
Andy




PostPosted: Thu Dec 30, 2004 11:35 am   Post subject: (No subject)

wow.. two people commented on this program, and none of them noted the biggest error. i have no idea why turing does not recognize this error.. notice how he declared the variable inside the loop. in any high level programming language, this will not be acceptable. you cannot declare the variable with the same name over and over again.
Tony




PostPosted: Thu Dec 30, 2004 1:33 pm   Post subject: (No subject)

Delos wrote:
Pass your character input to a variable. Take the ord() of it. From there, you'll have a discernable number (integer). Use that and some simple arithmetic to compute the resultant sound() values.

although a good idea, you will have difficulty with keyboard layout that's not in alphabetical order. on a QWERT keyboard, the ord() values are respectivly

81 87 69 82 84

if there's a function to match them to 1,2,3,4,5 type of of an ordered list... let me know Wink
cool dude




PostPosted: Thu Dec 30, 2004 2:14 pm   Post subject: (No subject)

dodge_tomahawk wrote:
wow.. two people commented on this program, and none of them noted the biggest error. i have no idea why turing does not recognize this error.. notice how he declared the variable inside the loop. in any high level programming language, this will not be acceptable. you cannot declare the variable with the same name over and over again.


i did notice that but i ignored that because it worked both ways. but it is true u should always have the variables declared outside the loop.
we64




PostPosted: Thu Dec 30, 2004 6:43 pm   Post subject: (No subject)

Yeah, true about the variables. But I guess he is just doing it because he can.. why not take the advantage of turing anyways... lol..
Delos




PostPosted: Thu Dec 30, 2004 7:08 pm   Post subject: (No subject)

tony wrote:
Delos wrote:
Pass your character input to a variable. Take the ord() of it. From there, you'll have a discernable number (integer). Use that and some simple arithmetic to compute the resultant sound() values.

although a good idea, you will have difficulty with keyboard layout that's not in alphabetical order. on a QWERT keyboard, the ord() values are respectivly

81 87 69 82 84

if there's a function to match them to 1,2,3,4,5 type of of an ordered list... let me know Wink


Did I mention that I just glanced at the code and didn't actually consider what it was used for? Laughing
Sponsor
Sponsor
Sponsor
sponsor
Andy




PostPosted: Fri Dec 31, 2004 11:56 am   Post subject: (No subject)

but its less efficient.. you're basicly formating that memory allocation when you can just replace what ever is inside it
BPhelmet




PostPosted: Fri Dec 31, 2004 2:51 pm   Post subject: (No subject)

pretty interesting, sounds freaky
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 10 Posts ]
Jump to:   


Style:  
Search: