[Solved] Help: button and repeat a function with mouse click

This case is a bit advanced, and would be very useful if it were possible…

I have a button, and the mouse. To press and release the mouse (a simple click), the button execute a function through the “notifier = function() end”, but this function is only executed once, for example write a specific note (or effect, any parameter) in the pattern editor.Is it possible to repeat this function until the mouse is released?

BUTTON = vb:button {
  id = "BUTTON",
  width = 80,
  height = 22,
  text = "write '7F' volume",
  pressed = function () end, --<---- initiate repeat
  released = function () end, --<---- stop repeat
}

The result would be to write the 7F value repeatedly while holding down the mouse.

I suppose to build the repetition there would be two steps (in pressed):

  1. Do not repeat for a few milliseconds (a wait).
  2. Repeat the write function from after the wait, and ends when the mouse is released.

I have all functions built to insert any parameter in the pattern editor (notes, instruments, volume, panning, delay, and all effects) in any type of track.

Attached is an image capture to get this idea:

7159 gt16-colors_wmp_01.png

For example, hold down the volume button (yellow) with the mouse, write the 7F value with repetition in selected position in pattern editor.This tool allows even jump between patterns, assigning a specific line break value.If the repetition with mouse were possible, it would be a beast, a great ally for the workflow.

Do you have any function to do this?(only as far as repetition is concerned)

Thanks!!!

The objective is not to make repeated clicks all the time:

7160 wmp-mouse-repeat.gif

Not appreciated very well in the animated gif, but I am clicking the mouse like a machine gun. The case is to be able to do the same thing with just one click…

Maybe you could check using a timer, just testing for boolean every 500ms or so…?

Maybe you could check using a timer, just testing for boolean every 500ms or so…?

It would be something like this, the steps just one click:

  1. Clic pressed (button)
  2. Apply function XXX (write “FB” volume_value), just once. Run a “delay timer” of 500ms.
  3. In 501ms repeat function XXX with a “separation timer”, about 100ms. (1000ms/100ms = 11 writings of “FB” volume_value)
  4. Clic released (button), stop repeat function XXX.

With all the steps, I would write 12 “FB” volume_values.I suppose there should be 2 timers, one of initial delay (500ms) and one of separation (100ms).Both could be modified in the code.

Step 3 and 4 would be this:

  1. function XXX
  2. 500ms (initial)___________500ms
  3. function XXX
  4. 100ms (1)
  5. function XXX
  6. 100ms (2)
  7. function XXX
  8. 100ms (3)
  9. function XXX
  10. 100ms (4)
  11. function XXX
  12. 100ms (5)
  13. function XXX
  14. 100ms (6)
  15. function XXX
  16. 100ms (7)
  17. function XXX
  18. 100ms (8)
  19. function XXX
  20. 100ms (9)
  21. function XXX
  22. 100ms (10)______________1000ms
  23. function XXX
  24. ___________________Total 1500ms (12x function XXX)

But I do not really know how to build it, and that pressed and released of button do not be a problem.

Like ffx said, you can do something like this:

On press:

Set a bool flag to true

Start a timer (500ms)

On release:

Set the flag to false

Remove all timers

  1. If the bool flag is still on when the timer (500ms) hits, the button is still pressed. The timer function should then add the second timer (100ms).

Like ffx said, you can do something like this:

On press:

Set a bool flag to true

Start a timer (500ms)

On release:

Set the flag to false

Remove all timers

  1. If the bool flag is still on when the timer (500ms) hits, the button is still pressed. The timer function should then add the second timer (100ms).

I have been experimenting with this code:

function wmp_fn_bt_vol_mouse()
  wmp_fn_bt_vol() --(1 the principal function to insert value)
  local function timer_dly() --(2 delay)
    --wmp_fn_bt_vol()
    renoise.tool():remove_timer( timer_dly )
  end
  renoise.tool():add_timer(timer_dly, 500 )

  local function timer_rep() --(3 repeat)
    wmp_fn_bt_vol()
    --renoise.tool():remove_timer( timer_rep )
  end
  renoise.tool():add_timer(timer_rep, 100 )
  
  repeat until timer_rep()
end

...
pressed = function() wmp_fn_bt_vol_mouse() end,
released = function() renoise.tool():remove_timer( timer_rep ) end

I have tried is to include a delay time in each repetition , but I have problems with repeat and the stop.I really do not know how to approach it. The “wmp_fn_bt_vol()” is the function that I’m trying to repeat (inserts the value in the pattern editor).This function (bad write) enters loop butrepeats the function of insert value.The topic is also to have 2 time values to be able to control them.I have looked for similar practical examples, but I find nothing.

Any examples?I have my related tool module completed. Just need to add this.As soon as I am ready I will share the tool in this thread so that you can try it.I think it’s a great job, and I like you to tell me your opinion about this tool.

I have started a new code. This I think is already close to your comments:

--"wmp_fn_bt_vol()" is the function to repeat

function wmp_fn_bt_vol_mouse( tm )
  if tm == true then
    renoise.tool():add_timer(wmp_fn_bt_vol, 100 )    
  --- ---  
  elseif tm == false then
    renoise.tool():remove_timer( wmp_fn_bt_vol )
    wmp_fn_bt_vol()    
  end 
end
pressed = function() wmp_fn_bt_vol_mouse(true) end,
  released = function() wmp_fn_bt_vol_mouse(false) end

Maybe not very elegant, but it works.It is necessary to add a delay at the beginning, and to lower the value of 100.What do you think?

To release also start the function wmp_fn_bt_vol(), the initial delay is not present. I am testing with a value of 50, for higher speed.

From where you’re at now, maybe it’s simplest to make a “wrapper function” for it, switching from first to second timer after one run. I have not tried the code below, but the principle should be clear.

pressed = function() repeat_wrapper() end,
released = function() repeat_wrapper(true) end
      
      
function repeat_wrapper(release)

  if not release then
    if renoise.tool():has_timer(repeat_wrapper) then
      wmp_fn_bt_vol()
      -- switch to fast timer on second run
      renoise.tool():remove_timer(repeat_wrapper)
      renoise.tool():add_timer(wmp_fn_bt_vol, 100)
    else
      -- first run
      wmp_fn_bt_vol()
      renoise.tool():add_timer(repeat_wrapper, 500)
    end
  else -- release all timers
    if renoise.tool():has_timer(repeat_wrapper) then
      renoise.tool():remove_timer(repeat_wrapper)
    elseif renoise.tool():has_timer(wmp_fn_bt_vol) then
      renoise.tool():remove_timer(wmp_fn_bt_vol)
    end
  end
  
end

PS. A little bit of warning: in case you MIGHT trigger more than one button at a time (for example via midi?) the code might become a bit more complicated. Not 100% sure it’s enough to localize the functions in the correct scope in that case, or if it’s needed to put them in a global table, for example. Anyway, I am guessing you’re only pushing one button at a time here.

From where you’re at now, maybe it’s simplest to make a “wrapper function” for it, switching from first to second timer after one run. I have not tried the code below, but the principle should be clear.

pressed = function() repeat_wrapper() end,
released = function() repeat_wrapper(true) end
      
      
function repeat_wrapper(release)

if not release then
if renoise.tool():has_timer(repeat_wrapper) then
wmp_fn_bt_vol()
-- switch to fast timer on second run
renoise.tool():remove_timer(repeat_wrapper)
renoise.tool():add_timer(wmp_fn_bt_vol, 100)
else
-- first run
wmp_fn_bt_vol()
renoise.tool():add_timer(repeat_wrapper, 500)
end
else -- release all timers
if renoise.tool():has_timer(repeat_wrapper) then
renoise.tool():remove_timer(repeat_wrapper)
elseif renoise.tool():has_timer(wmp_fn_bt_vol) then
renoise.tool():remove_timer(wmp_fn_bt_vol)
end
end
  
end

PS. A little bit of warning: in case you MIGHT trigger more than one button at a time (for example via midi?) the code might become a bit more complicated. Not 100% sure it’s enough to localize the functions in the correct scope in that case, or if it’s needed to put them in a global table, for example. Anyway, I am guessing you’re only pushing one button at a time here.

Thank you for this!It works perfectly! Yes, repeating buttons are only used with the mouse. I have reduced the values to 40 and 400 respectively to fine tune. I am very happy with this tool, the module that includes the virtual piano for write with the mouse.I love!

Too bad that the keys do not light when playing notes in the pattern editor, would be great…

I have already shared the GT16-Colors tool in beta.You can try it here: GT16-Colors v1.2b

Could you try tool module 8 in Advanced Tools Selector (WMP), using the mouse to the beast?What do you think?

Many thanks for the help joule! :slight_smile: