AutoHotkey Community

It is currently May 26th, 2012, 10:28 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 11 posts ] 
Author Message
PostPosted: September 1st, 2009, 7:04 am 
Offline

Joined: September 21st, 2008, 6:34 am
Posts: 16
ok so heres my script.

Code:
tempo := 120 ;default tempo
newValue := 4 ;default new value
newTempo := 120 ;default new tempo

; Gui, sub-command [, Param2, Param3, Param4]


Gui, Add, Text, x95 y15, Base Tempo:
Gui, Add, Edit, x165 y13 vtempo, 120
Gui, Add, Text, x88 y40, New Beat Value:
Gui, Add, Edit, x172 y36 vnewValue w25, 4
Gui, show, W300 H100, Rhythmic Modulation Assistant
gui, add, button, x95 y60 gupdateValues, What's my tempo?

^!r::
reload
return

updateValues:
   gui, submit, nohide
   nameNewValue(newValue)
   newTempo := (60 / ( ( (60 / tempo)*4) / newValue ) )
   msgbox Giving the %newValueName% the beat, our new tempo should be %newTempo% bpm.
return

!^y::
test := 3 / 3
msgbox %test%
return

isDivisible(value, divisor)
{
msgbox is %value% divided by %divisor% an integer?
if (value / divisor) is integer
   {
      msgBox yes, %value% is evenly divisible by %divisor%.
      return, true
   }
else if (value / divisor) is not integer {
   msgBox no, %value% is not evenly divisible by %divisor%.
   return, false
   }
}

nameNewValue(newValue) {

if (isDivisible(newValue, 3) = true)
   rhythType := "triplet"
   
if (isDivisible(newValue, 4))
   rhythType := ""
   
if (isDivisible(newValue, 5) = true)
   rhythType := "quintuplet"
   
if (isDivisible(newValue, 7) = true)
   rhythType := "septuplet"

else
   rhythType := "tuplet"

global newValueName := rhythType
   
}


particular trouble spot is my isdivisible function.

Code:
isDivisible(value, divisor)
{
msgbox is %value% divided by %divisor% an integer?
if (value / divisor) is integer
   {
      msgBox yes, %value% is evenly divisible by %divisor%.
      return, true
   }
else if (value / divisor) is not integer {
   msgBox no, %value% is not evenly divisible by %divisor%.
   return, false
   }
}


Why is it returning true all the time? What am I doing wrong?

_________________
Composer
http://www.joshuaevensen.com


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 1st, 2009, 7:24 am 
Offline
User avatar

Joined: May 24th, 2009, 5:35 am
Posts: 2099
Location: Iowa, USA
Documentation wrote:
if var is type
if var is not type


Example:
Code:
var := value / divisor

if var is integer ; -or-  if !mod(value, divisor)
   ...
else
   ...

_________________
Image
Recommended: AutoHotkey_L
Basic Webpage Controls


Last edited by jethrow on September 1st, 2009, 7:45 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 1st, 2009, 7:35 am 
Offline

Joined: September 21st, 2008, 6:34 am
Posts: 16
so...

Code:
isDivisible(value, divisor)
{
msgbox is %value% divided by %divisor% an integer?

var := value / divisor

if var is integer
      msgBox yes, %value% is evenly divisible by %divisor%.
else
   msgBox no, %value% is not evenly divisible by %divisor%.
}


?

If that's right, it still isn't working.

_________________
Composer
http://www.joshuaevensen.com


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 1st, 2009, 7:56 am 
Offline
User avatar

Joined: May 24th, 2009, 5:35 am
Posts: 2099
Location: Iowa, USA
Yeah, you're right :oops:. I think the issue is with the number format after dividing (see SetFormat). I'd just use:
Code:
if !mod(value, divisor) ; it's divisible

_________________
Image
Recommended: AutoHotkey_L
Basic Webpage Controls


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 1st, 2009, 2:04 pm 
Offline

Joined: October 7th, 2006, 4:50 pm
Posts: 3157
Location: MN, USA
AHK Help File wrote:
True divide (/): Unlike EnvDiv, true division yields a floating point result even when both inputs are integers. For example, 3/2 yields 1.5 rather than 1, and 4/2 yields 2.0 rather than 2.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 1st, 2009, 3:23 pm 
Offline

Joined: April 8th, 2009, 8:23 pm
Posts: 3036
Location: Rio de Janeiro - RJ - Brasil
Code:
If !mod( mod(value,divisor) , 1 )
  Msgbox integer!

OR
Code:
Result := mod( value , divisor ) + 0
If Result is integer
  Msgbox integer!

_________________
"Read the manual. Read it again. Search the forum.
Try something before asking. Show what you've tried.
"
Image
Antonio França
My stuff: Google Profile


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 1st, 2009, 4:31 pm 
Offline

Joined: September 21st, 2008, 6:34 am
Posts: 16
It works now, guys! Thanks!

My little app is done.

http://joshuaevensen.com/Etc/RhythmicMo ... istant.exe

_________________
Composer
http://www.joshuaevensen.com


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 1st, 2009, 5:43 pm 
@joshua alias conchfeld
Interesting music! Same parts reminds me a little at David Sylvian :D

*switch topic*
Would you mind to provide code instead of an compiled exe? Just in case you're interested to get bancrupt for the reason of millions of downloads of your app :D


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 1st, 2009, 6:23 pm 
Offline

Joined: September 21st, 2008, 6:34 am
Posts: 16
Its too niche to get millions of downloads haha, but I will post code. Here.

Code:
tempo := 120 ;default tempo
newValue := 4 ;default new value
newTempo := 120 ;default new tempo

; Gui, sub-command [, Param2, Param3, Param4]


Gui, Add, Text, x95 y15, Base Tempo:
Gui, Add, Edit, x165 y13 vtempo, 120
Gui, Add, Text, x88 y40, New Beat Value:
Gui, Add, Edit, x172 y36 vnewValue w25, 4
Gui, show, W300 H120, Rhythmic Modulation Assistant
gui, add, button, x95 y60 gupdateValues, What's my tempo?
Gui, Add, Text, x2 y90, (NOTE: if you get too ridiculous, the note types will be wrong.)

^!r::
reload
return

updateValues:
   gui, submit, nohide
   nameNewValue(newValue)
   newTempo := (60 / ( ( (60 / tempo)*4) / newValue ) )
   msgbox If our new beat is a %newValueName%, our new tempo should be %newTempo% bpm.
return

!^y::
test := 3 / 3
msgbox %test%
return

isDivisible(value, divisor)
{
;msgbox is %value% divided by %divisor% an integer?

if !mod(value, divisor)
      return true
else
   return false
}

nameNewValue(newValue) {

if (isDivisible(newValue, 3) = true)
   rhythType := "triplet"
else if (isDivisible(newValue, 4))
   rhythType := ""
else if (isDivisible(newValue, 5) = true)
   rhythType := "quintuplet"
else if (isDivisible(newValue, 7) = true)
   rhythType := "septuplet"
else
   rhythType := newValue . "tuplet"

if newValue between 0 and 3
   rhythClass := "half note "
else if newValue between 4 and 7
   rhythClass := "quarter note "
else if newValue between 9 and 15
   rhythClass := "eighth note "
else if newValue between 16 and 31
   rhythClass := "sixteenth note "
else if newValue between 32 and 63
   rhythClass := "thirty second note "
   
global newValueName := rhythClass . rhythType
   
}


Glad you dig the music, man. Cool.

_________________
Composer
http://www.joshuaevensen.com


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 1st, 2009, 6:38 pm 
Offline
User avatar

Joined: May 24th, 2009, 5:35 am
Posts: 2099
Location: Iowa, USA
Just some thoughts:
Code:
isDivisible(value, divisor) {
   Return  mod(value, divisor) ? false : true
}


Code:
rhythType := !mod(newValue, 3) ? "triplet" : (!mod(newValue, 4) ? "" : (!mod(newValue, 5) ? "quintuplet" : (!mod(newValue, 7) ? "septuplet" : newValue . "tuplet")))

_________________
Image
Recommended: AutoHotkey_L
Basic Webpage Controls


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 1st, 2009, 6:55 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
I was just about to say for that function you only need to specify one possible result; the script will assume the other result if the defined is not true:

Code:
isDivisible(value, divisor) {
  if !Mod(value, divisor)
    return true
}


But to that end, creating a function to perform the same action as an already existing function is kind of redundant, no?

Code:
nameNewValue(newValue) {
  if !Mod(newValue,3)
    rhythType := "triplet"
  else if !Mod(newValue,4)
    rhythType := ""
  else if !Mod(newValue,5)
    rhythType := "quintuplet"
  else if !Mod(newValue,7)
    rhythType := "septuplet"
  else
    rhythType := newValue "tuplet"

  if newValue between 0 and 3
    rhythClass := "half note "
  else if newValue between 4 and 7
    rhythClass := "quarter note "
  else if newValue between 9 and 15
    rhythClass := "eighth note "
  else if newValue between 16 and 31
    rhythClass := "sixteenth note "
  else if newValue between 32 and 63
    rhythClass := "thirty second note "
  return newValueName := rhythClass rhythType
}

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: AndyJenk, Bing [Bot], JSLover, Miguel, patgenn123, rbrtryn and 69 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group