My goal is to pulse the reload parameter on a moviefilein TOP using a timer CHOPs callback DAT. For my specific application, I found that the expression op(‘moviefilein1’).par.reloadpulse.pulse()
will successfully pulse the parameter I want. However, in the callback DAT under the timer CHOP, I can’t figure out how to send this pulse out only when a specific segment starts
I am looking at the def onSegmentEnter section of the callback DAT
I’m still learning python and TD and could use some help figuring out how to properly use the callback DAT to pulse the parameter in question. I think I have all the right pieces but I just don’t know the right syntax for this scenario. I can only upload a screenshot so hopefully this will give enough clues.
In this case the arguments that are passed to the onSegmentEnter python function have definitions that you can see at the top of the callback:
# timerOp - the connected Timer CHOP
# cycle - the cycle index
# segment - the segment index
# fraction - the time in fractional form
#
# interrupt - True if the user initiated a premature
# interrupt, False if a result of a normal timeout.
#
# onInitialize(): if return value > 0, it will be
# called again after the returned number of frames.
What we can do is use segment to test if we should run our reload pulse - the code above could be read as, if the segment number is exactly 2, then reload the operator called moviefilein1. You’ll sometimes see if statements described as control flow, or logic statements when learning python.
One of my favorite ways to see what’s happening in a callback DAT is to use print() or debug() statements. Those both will print to your text port, and can be helpful when trying to figure out what’s happening in the callback.
For example, try this to see some interesting results:
def onSegmentEnter(timerOp, segment, interrupt):
print("The current segment is ", segment)
print("The timerOp is ", timerOp)
return
I had an intuition that a relational operator would be necessary but I guess that I didn’t realize how versatile callbacks can be in regards to python. Thank you so much for clarifying, this makes the most sense. Next time I will follow that intuition further. Hopefully this will find someone in the future in a similar position
I really appreciate the thoroughness and the attention to this specific case. The examples gave me everything I needed to follow through on the experiment as well as some things to consider for next time I encounter a similar scenario. It constantly surprises me how python works in such a dynamic environment like Touch but I appreciate it’s complexities for that nonetheless.