Callback when last line in pattern is reached

Hi.

How would I go about notifying a function when the last line of the current pattern has been reached?

Thanks

1 Like

You mean during playback? Or when you edit?

During playback

This would be handy for some tools I’ve been hacking on.

1 Like

As workaround you can use a timer or maybe even the “idle”-callback and simply check renoise.song().transport.playback_pos with the pattern length. But its not stable enough for higher lpb values.

Edit: You could be inspired by checking the source of this tool: New Tool (3.2.2) Playback Loop Selection v1.3.004 (August 2020)

Thanks, that is helpful. I was able to blast through my issue.

function current_line_is_last_in_pattern()
  return renoise.song().transport.playback_pos.line == renoise.song().selected_pattern.number_of_lines
end

function main()
  if current_line_is_last_in_pattern() then
    print("last line!")
  end
end

renoise.tool():add_timer(main, 200)

Trick here is to add it to a timer. Remember and account for the fact that Renoise timers are not perfect.

1 Like

@James_Britt ^

I’d have to go look at my code because I think I tried something like this but I was getting double triggers or missed triggers.

Basically I want to have code loop over a patter range N times, and when it enters the last pattern at loop N to set a new loop range.

But it would at times get the loop count wrong , I think because the line checking would sometimes miss.

I was hoping for something existed in the API that did not require manual timers.

1 Like

I too was hoping for something in the API. Hope we get that eventually… so many cool ideas can become stable or just become.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.