Sign in to follow this  
Followers 0
MvGulik

Adlib timing behavior. (AdlibUnRegister())

16 posts in this topic

#1 ·  Posted (edited)

Think it would be more intuitive (and usefull) if AdlibUnRegister() would completely reset things.

Ergo: This code would than actually be counting from the new AdlibRegister() timepoint. Instead of (kinda) behaving like there was no AdlibUnRegister() call at all.

#AutoIt3Wrapper_AU3Check_Stop_OnWarning=y
#AutoIt3Wrapper_AU3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7

Global Const $iRatio = 100 ;; 1000
Global Const $sAdlib = 'AdlibFunc'
Global $iTimer = 0

$iTimer = TimerInit()

AdlibRegister($sAdlib, 4 * $iRatio)
Sleep((4 * 5 * $iRatio) + $iRatio)
AdlibUnRegister($sAdlib)
Exit

#cs    result:
AdlibFunc(), 409.264650422213 (+4)
AdlibFunc(), 799.788431372549 (+4)
AdlibFunc(), 1207.94519428939 (+4)
AdlibFunc(), 1616.18206347503 (+4)
AdlibFunc(), 2013.64021504222 (+4)
#ce

Func AdlibFunc()
    DebugOut('AdlibFunc(), ' & TimerDiff($iTimer))
    AdlibUnRegister($sAdlib)
    sleep(3*$iRatio) ;; some simulated processing time.
    AdlibRegister($sAdlib, 4 * $iRatio)
EndFunc

Func DebugOut($sMsg)
    ConsoleWrite($sMsg & @CRLF)
EndFunc

[3.3.8.1/3.3.9.4]

---

GOTO message to skip confusing parts. (That would be message #10) (using stupid full http link, as forum post-editor is bugged to no end.)

Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Inside the Adlib Function therez no need to Unregister or ReRegister.

The script waits till the Function completes

Hope that helps

Phoenix XL

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites

Inside the Adlib Function therez no need to Unregister or ReRegister.

The script waits till the Function completes

Hope that helps

Phoenix XL

Nope, Not really helping (yet).

Why do you say "... there is no need ..." ?.. I main I know there is no need, or better in my case "no use" for it, as there is no change in the default behavior.

But that's also my point, it would be nice if there would be a use for it.

I though about the fact that I'm doing the additional adlib-registering inside the adlib call, but did not follow trough on that thought. (mainly because I think there will be no difference, or effect, by doing so. ... will test later)


"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Share this post


Link to post
Share on other sites

What do you mean by reset? I can't see what you're trying to accomplish without a concrete example.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

If I read the OP code "as is" I think the more logical output/behavior would be something like:

AdlibFunc(), 400.~ (+4)...[*$ratio]
AdlibFunc(), 1100.~ (+3+4)
AdlibFunc(), 1800.~ (+3+4)
AdlibFunc(), 2500.~ (+3+4)
AdlibFunc(), 3200.~ (+3+4)

instead of

AdlibFunc(), 400.~ (+4)
AdlibFunc(), 800.~ (+4)
AdlibFunc(), 1200.~ (+4)
AdlibFunc(), 1600.~ (+4)
AdlibFunc(), 2000.~ (+4)

Which makes more sense to me if the code would use the names AdlibPauseCallback() and AdlibUnPauseCallback() for the adlib-register calls inside the AdlibFunc() function.

[corrections...][+codetags]

Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Think it would be more intuitive (and usefull) if AdlibUnRegister() would completely reset things.

Ergo: This code would than actually be counting from the new AdlibRegister() timepoint. Instead of (kinda) behaving like there was no AdlibUnRegister() call at all.

I didn't know this was the case. In the help file it says:

Re-registering an already existing Adlib function will update it with a new time.

Have you tested that?

Edited by czardas

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Yep. works as expected.

But had wrong expectation. (stupid typo-bug fixed)(re-digesting result ...)

#AutoIt3Wrapper_AU3Check_Stop_OnWarning=y
#AutoIt3Wrapper_AU3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7

#cs    result:
AdlibFunc(), 400 ... (+4)
AdlibFunc(), 900 ... (+5)
AdlibFunc(), 1500 ... (+6)
#ce

Global Const $iRatio = 100 ;; 1000
Global Const $sAdlib = 'AdlibFunc'
Global $iTimer = 0, $iCounter = 4

$iTimer = TimerInit()

AdlibRegister($sAdlib, 4 * $iRatio)
do
until $iCounter > 6
AdlibUnRegister($sAdlib)
Exit

Func AdlibFunc()
    DebugOut('AdlibFunc(), ' & _TimerDiffRound($iTimer))
    $iCounter += 1
    AdlibRegister($sAdlib, $iCounter * $iRatio)
EndFunc
Func _TimerDiffRound($time)
    Return Round(TimerDiff($time)/$iRatio)*$iRatio
EndFunc

Func DebugOut($sMsg)
    ConsoleWrite($sMsg & @CRLF)
EndFunc

[bug fixed]

Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Darn(2) ... back to the drawing board.

#AutoIt3Wrapper_AU3Check_Stop_OnWarning=y
#AutoIt3Wrapper_AU3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7

#cs    result:
AdlibFunc(), 400
AdlibFunc(), 1100
AdlibFunc(), 1800
AdlibFunc(), 2500
AdlibFunc(), 3200
#ce

Global Const $iRatio = 100 ;; 1000
Global Const $sAdlib = 'AdlibFunc'
Global $fExit = False, $fAdlibReReg = False, $iTimer = 0
AdlibRegister('setExit', 36 * $iRatio)

$iTimer = TimerInit()

AdlibRegister($sAdlib, 4 * $iRatio)
Do
    If $fAdlibReReg Then
        AdlibUnRegister($sAdlib)
        AdlibRegister($sAdlib, 4 * $iRatio)
        $fAdlibReReg = False
    EndIf
Until $fExit
AdlibUnRegister($sAdlib)
Exit

Func AdlibFunc()
    DebugOut('AdlibFunc(), ' & Round(TimerDiff($iTimer)/$iRatio)*$iRatio )
    sleep(3*$iRatio) ;; some simulated processing time.
    $fAdlibReReg = True
EndFunc
Func SetExit()
    $fExit = True
EndFunc

Func DebugOut($sMsg)
    ConsoleWrite($sMsg & @CRLF)
EndFunc

---

For completion. #7 test tested outside adlib call. (no difference to result at #7) (+stupid typo-bug fix.)

#AutoIt3Wrapper_AU3Check_Stop_OnWarning=y
#AutoIt3Wrapper_AU3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7

#cs    result:
AdlibFunc(), 400 .. (+4)
AdlibFunc(), 900 .. (+5)
AdlibFunc(), 1500 .. (+6)
#ce

Global Const $iRatio = 100 ;; 1000
Global Const $sAdlib = 'AdlibFunc'
Global $fAdlibReReg = False, $iTimer = 0, $iCounter = 4

$iTimer = TimerInit()

AdlibRegister($sAdlib, 4 * $iRatio)
Do
    If $fAdlibReReg Then
        $iCounter += 1
        AdlibRegister($sAdlib, $iCounter * $iRatio)
        $fAdlibReReg = False
    EndIf
until $iCounter > 6
AdlibUnRegister($sAdlib)
Exit

Func AdlibFunc()
    DebugOut('AdlibFunc(), ' & _TimerDiffRound($iTimer))
    $fAdlibReReg = True
EndFunc
Func _TimerDiffRound($time)
    Return Round(TimerDiff($time)/$iRatio)*$iRatio
EndFunc

Func DebugOut($sMsg)
    ConsoleWrite($sMsg & @CRLF)
EndFunc

---

On Hold: (something I don't get(yet) is bugging me ...)

Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

I just ran a test on this. AdLibRegister appears to reset the time as expected, so I'm not sure what this is about.

AdlibRegister("MyAdlib", 2000)

Dim $iTimer = TimerInit()

Sleep(8100)
; 2 seconds
; 4 seconds
; 6 seconds
; 8 seconds

AdlibUnRegister("MyAdlib")
Sleep(1000) ; Following results should now return odd numbers
AdlibRegister("MyAdlib", 2000)

Sleep(8100)
; 11 seconds
; 13 seconds
; 15 seconds
; 17 seconds

Func MyAdlib()
    ConsoleWrite(Round(TimerDiff($iTimer)/1000) & " seconds" & @LF)
EndFunc

There's a few miliseconds processing time, but the rounded results turn from even to odd (on my machine) after re-registering the adlib.

The only thing I don't get is why this function is called adlib. To me this sounds like ad libitum (ad lib) meaning free rhythm, at your leisure - ie not accurate timing - quite the opposite of the function's description.

to play the passage in free time rather than in strict or "metronomic" tempo (a practice known as rubato when not expressly indicated by the composer);

Edited by czardas

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Taking my time ... But your right that Adlib works as expected, when your using the adlib-reg's outside its own adlib-call scoop.

But when you use the additional AdlibRegister() commands inside its own adlib-call. It works a little differently.

The new adlib starting time-point will not be based on the moment the additional AdlibRegister() was issued. But it will be based on the start-time of the adlib-call (your currently are in).

Considering changing stuff on something, while using it, is generally not a good thing. (adlib or otherwise.) I think a general note about this in doc might not be bad thing.

Code used to check. (bug free I hope :D )

#AutoIt3Wrapper_AU3Check_Stop_OnWarning=y
#AutoIt3Wrapper_AU3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
;; Adlib re-reg call made outside own adlib call.

#cs    result: no additional 3sec simulated adlib-call work time.
AdlibFunc(), 400 .. (+4)
AdlibFunc(), 900 .. (+5)
AdlibFunc(), 1500 .. (+6)
#ce
#cs    result: with additional 3sec simulated adlib-call work time.
AdlibFunc(), 400 .. (+4)
AdlibFunc(), 1200 .. (+3+5)
AdlibFunc(), 2100 .. (+3+6)
#ce

Global Const $iRatio = 100 ;; 1000
Global Const $sAdlib = 'AdlibFunc'
Global $fAdlibReReg = False, $iTimer = 0, $iCounter = 0

$iCounter = 4
$iTimer = TimerInit()
AdlibRegister($sAdlib, $iCounter * $iRatio)
Do
    If $fAdlibReReg Then
        $iCounter += 1
        sleep(3*$iRatio) ;; some simulated processing time. (here or in AdlibFunc() Adlib-call.)
        AdlibRegister($sAdlib, $iCounter * $iRatio)
        $fAdlibReReg = False
    EndIf
until $iCounter > 6
AdlibUnRegister($sAdlib)
Exit

Func AdlibFunc()
    DebugOut('AdlibFunc(), ' & _TimerDiffRound($iTimer))
    $fAdlibReReg = True
EndFunc
Func _TimerDiffRound($time)
    Return Round(TimerDiff($time)/$iRatio)*$iRatio
EndFunc

Func DebugOut($sMsg)
    ConsoleWrite($sMsg & @CRLF)
EndFunc

#AutoIt3Wrapper_AU3Check_Stop_OnWarning=y
#AutoIt3Wrapper_AU3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
;; Adlib re-reg call made inside own adlib call.

#cs    result: no additional 3sec simulated adlib-call work time.
AdlibFunc(), 400 ... (+4)
AdlibFunc(), 900 ... (+5)
AdlibFunc(), 1500 ... (+6)
#ce
#cs    result: with additional 3sec simulated adlib-call work time.
AdlibFunc(), 400 ... (+4)
AdlibFunc(), 900 ... (+5)
AdlibFunc(), 1500 ... (+6)
#ce

Global Const $iRatio = 100 ;; 1000
Global Const $sAdlib = 'AdlibFunc'
Global $iTimer = 0, $iCounter = 0

$iCounter = 4
$iTimer = TimerInit()
AdlibRegister($sAdlib, $iCounter * $iRatio)
do
until $iCounter > 6
AdlibUnRegister($sAdlib)
Exit

Func AdlibFunc()
    DebugOut('AdlibFunc(), ' & _TimerDiffRound($iTimer))
    $iCounter += 1
    sleep(3*$iRatio) ;; some simulated processing time.
    AdlibRegister($sAdlib, $iCounter * $iRatio) ;; this one is not taking in account the fact that its delayed by the 3sec sleep.
EndFunc
Func _TimerDiffRound($time)
    Return Round(TimerDiff($time)/$iRatio)*$iRatio
EndFunc

Func DebugOut($sMsg)
    ConsoleWrite($sMsg & @CRLF)
EndFunc

NTS: Recheck AdlibUnRegister(). (seems all AdlibRegister() related at this point.)

[+code comment]

Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

I get what you're saying, but I'm not sure of the cause. I wonder if this could be related to variable scope - I think it's a reasonable assumption, but without access to the source code it will always be guesswork.

Edited by czardas

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

I can confirm MvGulik's findings.

Global $bCorrupted = False, $iTimer = TimerInit()

_TestFunc()

Func _TestFunc()
    AdlibRegister("MyAdlib", 2000)
    For $i = 1 To 5
        Sleep(2000)
        ; The following line in this funtion updates start time as expected
        If Not $bCorrupted Then _CorruptTiming() ; Move this line to the function MyAdlib()
    Next
EndFunc

Func MyAdlib()
    ConsoleWrite(Round(TimerDiff($iTimer)/1000) & " seconds" & @LF)
    ; if you place the line here instead, AdlibRegister will not update the start time
    ;If Not $bCorrupted Then _CorruptTiming() ; Allow this line to run
EndFunc

Func _CorruptTiming()
    AdlibUnRegister("MyAdlib")
    Sleep(1000)
    AdlibRegister("MyAdlib", 2000)
    $bCorrupted = True
EndFunc
Edited by czardas

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

I think the tests are pretty conclusive. There's a 1000 ms disparity in my test. If the sleep and delay times are increased, the disparity appears to remain proportional to these increases, though I believe what you say - I don't get enough sleep. :D

Edited by czardas

Share this post


Link to post
Share on other sites

The amount of time you sleep affects the adlib calls.

Feel free to elaborate on that a bit more. Its kinda very general to me.

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0