Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sound on keypress?? 1

Status
Not open for further replies.

defboyuk

Technical User
Jan 6, 2006
14
GB
hi i am trying to create something that acts as a kind of midi keyboard but using a conventional ascii keyboard. I have so far worked out how to call up sounds on keypress using this:

on keydown me
if "1" = the key then
sound(2).play(member("edgyrockguitar"))
else if "2" = the key then
sound(3).play(member("ambientguitar 3"))

and so on

i want to know if it is possible to keep a sound playing for the length of the keypress (i.e. like on an organ)

any ideas?????

much appreciated
 
Hey I'm no expert but

I think if you can figure out how to get the sound to loop on keyDown then stop looping on keyUp that may be the best way to do it?

perhaps:

on keydown me
if "1" = the key then
sound(2).play(member("edgyrockguitar"))
repeat/loop??
end if
end

on keyUp me
if "1" = the key then
sound(2).stop(member("edgyrockguitar"))
end if
end

Sorry i couldnt be anymore specific, someone else will no doubt reply, but im only a beginner but theoretically i think thats the right sort of idea...

Peter Butler
Tandokuno Design
 
Yay ^_^

Thanks for the input, im sure that will help!!

Useful thing to learn too i didnt know you could do that >_>

Peter Butler
Tandokuno Design
 
do i need to check the loop box for the sound member??? i dont have the sounds on the score either they are all in the ast and im calling them with that code. I tried this:

on keydown me
if "1" = the key then
sound(2).play(member("edgyrockguitar"))

end if
end

on keyUp me
if "2"= the key then
sound(2).stop(member("edgyrockguitar"))
end if
end

but it doesnt work it replays the sound from the start on every press and the loop/repeat idea that goes below the .play section doesnt work either (script error)????>?
 
Try:

[tt]--
on startMovie
sound(2).queue([#member: member("edgyrockguitar"), #loopCount: 0])
end startMovie

on keyDown
if the key = "1" then
sound(2).play()
end if
end

on keyUp
if the key = "1" then
sound(2).pause()
end if
end
--[/tt]

Kenneth Kawamoto
 
--sound(2).queue([#member: member("edgyrockguitar"), #loopCount: 0])

variable used beor assigned a value

:-(
 
The following is the better way of doing this. I've verified it works fine on MX.

[tt]-- Movie script
on startMovie
sound(2).queue([#member: member("edgyrockguitar"), #loopCount: 0])
the keyDownScript = "handleMousedown"
the keyUpScript = "handleKeyUp"
end startMovie

on handleMousedown
if the key = "1" then
sound(2).play()
end if
end handleMousedown

on handleKeyUp
if the key = "1" then
sound(2).pause()
end if
end handleKeyUp
--[/tt]

Kenneth Kawamoto
 
Your saying this works on its own in mx - ive imported the script into a new file and it is still saying that in the first section (starting sound(2).queue...) there is a variable used before assigned value so how did you get it working?????????
 
That's very interesting. I've just done copy & paste the script and it's fine - it's standard Lingo anyway.

Funny thing is that there are no variables in that line. Do you see the words "sound", "queue", "member" and "loopCount" all in green? Then they are not variables.

May be your Director itself is the problem. If you type in "put version" in the message window do you get "8.5.1"? If not, update.

Kenneth Kawamoto
 
10.1? That's Director 10 (a.k.a. "MX 2004").

Anyway I tested on D10 and the script works fine (however, "the key" should be "_key.key" in D10).

If you copy & paste [tt]sound(2).queue([#member: member("edgyrockguitar"), #loopCount: 0])[/tt] into Message window and press return, do you get the same error?

Kenneth Kawamoto
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top