 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
feejo
Joined: 16 Jun 2007 Posts: 245
|
Posted: Tue Aug 28, 2007 9:18 pm Post subject: SoundBeep |
|
|
When I press up it should change de sound, but it just stop.
| Code: | Loop
SoundBeep, x, 1
UP:: x:=+1
DOWN:: x:=-1
msgbox, %x%
Return
#ù::Pause ;will pause the script when / is pushed |
|
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6856 Location: Pacific Northwest, US
|
Posted: Tue Aug 28, 2007 9:24 pm Post subject: |
|
|
feejo,
this is the second script of yours that has hotkeys "inside" the loop. This is not correct.
Here is what AHK sees for your script.
| Code: |
Loop
SoundBeep, x, 1
UP:: x:=+1
DOWN:: x:=-1
#ù::Pause ;will pause the script when / is pushed
|
the up and down keys make x -1 or +1, but it never adds.
try this:
| Code: |
Settimer, beep, 25
x=250
Return
beep:
Soundbeep, x, 24
Return
Up::
x++
Return
Down::
x--
Return
#ù::
SetTimer, beep, off
Return
|
you still need to add error checking to make sure you don't make x go too high or too low. _________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM |
|
| Back to top |
|
 |
feejo
Joined: 16 Jun 2007 Posts: 245
|
Posted: Tue Aug 28, 2007 9:48 pm Post subject: |
|
|
| Ya but if the retrun appear before the hotkey it dose not affect the script until it is presses (I think) |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6856 Location: Pacific Northwest, US
|
Posted: Tue Aug 28, 2007 10:27 pm Post subject: |
|
|
Hotkey definitions should not be in a loop. AHK doesn't work that way. _________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM |
|
| Back to top |
|
 |
Trikster
Joined: 15 Jul 2007 Posts: 1224 Location: Enterprise, Alabama
|
Posted: Tue Aug 28, 2007 11:13 pm Post subject: |
|
|
@ fe,
You are correct. A return is like a pause in a script. So if there is a return before and after the hotkey, it will only be executed by pressing the keys. And only that action set to the hotkey will be done. _________________ ScriptPad | ~dieom | dieom | izwian2k7 | Ian | God |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6856 Location: Pacific Northwest, US
|
Posted: Tue Aug 28, 2007 11:16 pm Post subject: |
|
|
even if there is not a return before and after, it will only be executed when he hits the hotkey (* the way he had it) _________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM |
|
| Back to top |
|
 |
Z Gecko Guest
|
Posted: Tue Aug 28, 2007 11:28 pm Post subject: |
|
|
when using SoundBeep, why not play real-notes instead of every possible frequency?
| Code: | x:=tonecalc()
lenght=1000
soundplay=1
Settimer, beep, -1
Return
beep:
setbatchlines -1
loop
{
if soundplay = 1
Soundbeep, x, length
}
Return
Up::
x:=tonecalc(x, "up")
Return
Down::
x:=tonecalc(x, "down")
Return
Left::
x:=tonecalc(x, "octavedown")
return
Right::
x:=tonecalc(x, "octaveup")
return
^p::
soundplay := soundplay = 1 ? 0 : 1
Return
tonecalc(freq = 440, operation = "set", hilimit = 13824, lolimit = 27)
{
if freq > %hilimit%
freq:= hilimit
if freq < %lolimit%
freq:= lolimit
x := freq
if operation = up
x*=1.059463
if operation = down
x/=1.059463
if operation = octaveup
x*=2
if operation = octavedown
x/=2
if x > %hilimit%
x:= freq
if x < %lolimit%
x:= freq
return x
}
|
|
|
| Back to top |
|
 |
feejo
Joined: 16 Jun 2007 Posts: 245
|
Posted: Wed Aug 29, 2007 6:08 pm Post subject: |
|
|
| Thanks, |
|
| Back to top |
|
 |
feejo
Joined: 16 Jun 2007 Posts: 245
|
Posted: Thu Aug 30, 2007 9:06 am Post subject: |
|
|
Can you explain your script line by line?
| Code: | x:=tonecalc()
lenght=1000
soundplay=1
Settimer, beep, -1
Return
beep:
setbatchlines -1
loop
{
if soundplay = 1
Soundbeep, x, length
}
Return
Up::
x:=tonecalc(x, "up")
Return
Down::
x:=tonecalc(x, "down")
Return
Left::
x:=tonecalc(x, "octavedown")
return
Right::
x:=tonecalc(x, "octaveup")
return
^p::
soundplay := soundplay = 1 ? 0 : 1
Return
tonecalc(freq = 440, operation = "set", hilimit = 13824, lolimit = 27)
{
if freq > %hilimit%
freq:= hilimit
if freq < %lolimit%
freq:= lolimit
x := freq
if operation = up
x*=1.059463
if operation = down
x/=1.059463
if operation = octaveup
x*=2
if operation = octavedown
x/=2
if x > %hilimit%
x:= freq
if x < %lolimit%
x:= freq
return x
}
|
engunneer |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6856 Location: Pacific Northwest, US
|
Posted: Thu Aug 30, 2007 5:21 pm Post subject: |
|
|
it is just doing standard math on musical notes with an upper and lower limit. What part do you not understand? _________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM |
|
| Back to top |
|
 |
feejo
Joined: 16 Jun 2007 Posts: 245
|
Posted: Thu Aug 30, 2007 7:34 pm Post subject: |
|
|
Cause I am trying to understand what
tonecalc() is
x:=tonecalc(x, "up") |
|
| Back to top |
|
 |
Z Gecko Guest
|
Posted: Thu Aug 30, 2007 8:15 pm Post subject: |
|
|
well, tonecalc is a function.
this function will alway returns a number.
tonecalc() will return 440 because i defined default values for every var that can be passed to the function:
| Code: | tonecalc(freq = 440, operation = "set", hilimit = 13824, lolimit = 27)
{
...
} |
same goes for tonecalc(440) , tonecalc(440, "set") , tonecalc( , "set")
x:=tonecalc(x, "up") will set x to a value one note above the previous value of x.
down, octaveup and octavedown act similar.
BTW: 440Hz = A4 = concert pitch A = Kammerton A |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|