Reputation: 1
I've noticed that Jython Environment for Music (JEM) has its own Timer implementation, as documented at https://jythonmusic.me/timer-library/ . The documentation shows a function t.setDelay(delay), where delay is in milliseconds.
My issue is, t.setDelay(delay) appears to make no difference to the delay time. The timer continues on using the original delay which was set at the time of creation.
I am wondering if this is a bug (perhaps got broken during another update?), or if there's a trick to it that I'm not seeing.
Code: my code is part of a larger class. Relevant lines are:
in __init__
self.t = Timer(500, self.metronome, (), True)
in self.metronome()
required_delay = int(60000.0/self.adjusted_16count)
self.t.setDelay(required_delay)
The metronome() function continues to recur at the original tempo (in this case, every 500ms) irrespective of the setDelay() function. Weirdly, if I look at the delay value by adding
print self.t.getDelay()
after the above code, it shows the correct value (125 in my case), but it physically continues to operate as if the original value is in force. I have confirmed this experimentally by setting very long and very short initial values with an observable outcome (sound) - the period between sounds stays the same as per the original value, even though getDelay() shows a change.
Thanks in advance for any suggestions.
Upvotes: 0
Views: 112
Reputation: 81
I am not sure the problem is with the Timer class implementation (although it could have been...) The following works just fine (i.e., it changes the Timer's delay time).
from timer import *
delay = 1000
def echo(x):
print x,
t = Timer(delay, echo, ["."])
t.start()
# change this delay as desired, while the program is running, via JEM's
# live-coding functionality (i.e., Run/Run current line)...
t.setDelay(2000)
I think the problem may be elsewhere. Try this and see...
Upvotes: 0