AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

SoundBeep

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
feejo



Joined: 16 Jun 2007
Posts: 245

PostPosted: Tue Aug 28, 2007 9:18 pm    Post subject: SoundBeep Reply with quote

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
View user's profile Send private message
engunneer



Joined: 30 Aug 2005
Posts: 6856
Location: Pacific Northwest, US

PostPosted: Tue Aug 28, 2007 9:24 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
feejo



Joined: 16 Jun 2007
Posts: 245

PostPosted: Tue Aug 28, 2007 9:48 pm    Post subject: Reply with quote

Ya but if the retrun appear before the hotkey it dose not affect the script until it is presses (I think)
Back to top
View user's profile Send private message
engunneer



Joined: 30 Aug 2005
Posts: 6856
Location: Pacific Northwest, US

PostPosted: Tue Aug 28, 2007 10:27 pm    Post subject: Reply with quote

Question

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
View user's profile Send private message Visit poster's website
Trikster



Joined: 15 Jul 2007
Posts: 1224
Location: Enterprise, Alabama

PostPosted: Tue Aug 28, 2007 11:13 pm    Post subject: Reply with quote

@ 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
View user's profile Send private message
engunneer



Joined: 30 Aug 2005
Posts: 6856
Location: Pacific Northwest, US

PostPosted: Tue Aug 28, 2007 11:16 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Z Gecko
Guest





PostPosted: Tue Aug 28, 2007 11:28 pm    Post subject: Reply with quote

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

PostPosted: Wed Aug 29, 2007 6:08 pm    Post subject: Reply with quote

Thanks,
Back to top
View user's profile Send private message
feejo



Joined: 16 Jun 2007
Posts: 245

PostPosted: Thu Aug 30, 2007 9:06 am    Post subject: Reply with quote

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
View user's profile Send private message
engunneer



Joined: 30 Aug 2005
Posts: 6856
Location: Pacific Northwest, US

PostPosted: Thu Aug 30, 2007 5:21 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
feejo



Joined: 16 Jun 2007
Posts: 245

PostPosted: Thu Aug 30, 2007 7:34 pm    Post subject: Reply with quote

Cause I am trying to understand what
tonecalc() is
x:=tonecalc(x, "up")
Back to top
View user's profile Send private message
Z Gecko
Guest





PostPosted: Thu Aug 30, 2007 8:15 pm    Post subject: Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group