Jump to content


Photo

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

mouse click repeat function hold down mouse

  • Please log in to reply
8 replies to this topic

#1 Raul (ulneiz)

Raul (ulneiz)

    Guruh Member

  • Normal Members
  • PipPipPipPipPipPipPipPipPipPipPipPip
  • 929 posts
  • Gender:Male
  • Location:Spain

Posted 25 December 2016 - 22:28

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:

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!!!


Edited by Raul (ulneiz), 27 December 2016 - 22:50.

:excl: Development of my tool: GT16-Colors

 

:excl: My API wishlist R3.1 (updated 24 July 2017):

Spoiler

 

:excl: My Renoise 3.1 wishlist (updated 18 July 2017):

Spoiler

#2 Raul (ulneiz)

Raul (ulneiz)

    Guruh Member

  • Normal Members
  • PipPipPipPipPipPipPipPipPipPipPipPip
  • 929 posts
  • Gender:Male
  • Location:Spain

Posted 25 December 2016 - 23:14

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

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...


:excl: Development of my tool: GT16-Colors

 

:excl: My API wishlist R3.1 (updated 24 July 2017):

Spoiler

 

:excl: My Renoise 3.1 wishlist (updated 18 July 2017):

Spoiler

#3 ffx

ffx

    Guruh Motha Fakka is Levitating and Knows Everything About Renoise Member

  • Normal Members
  • PipPipPipPipPipPipPipPipPipPipPipPipPip
  • 2869 posts
  • Gender:Not Telling
  • Interests:Renoise sidechaining, macOS fanboying

Posted 25 December 2016 - 23:16

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


  • joule likes this

MacOS 10.12.6 Retina, Renoise 3.1 64 bit   -   Tuned Shortcuts | Multi-Jump From/To Send | Quick Template | Insert Native DSP Menu (incl. deprecated)


#4 Raul (ulneiz)

Raul (ulneiz)

    Guruh Member

  • Normal Members
  • PipPipPipPipPipPipPipPipPipPipPipPip
  • 929 posts
  • Gender:Male
  • Location:Spain

Posted 25 December 2016 - 23:46

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.


Edited by Raul (ulneiz), 25 December 2016 - 23:47.

:excl: Development of my tool: GT16-Colors

 

:excl: My API wishlist R3.1 (updated 24 July 2017):

Spoiler

 

:excl: My Renoise 3.1 wishlist (updated 18 July 2017):

Spoiler

#5 joule

joule

    Guruh Motha Fakka is Levitating and Knows Everything About Renoise Member

  • Normal Members
  • PipPipPipPipPipPipPipPipPipPipPipPipPip
  • 1443 posts
  • Gender:Not Telling
  • Location:Sweden
  • Interests:music, philosophy, engineering

Posted 26 December 2016 - 18:59

Like ffx said, you can do something like this:

 

1.

On press:

Set a bool flag to true

Start a timer (500ms)

 

On release:

Set the flag to false

Remove all timers

 

2. 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).



#6 Raul (ulneiz)

Raul (ulneiz)

    Guruh Member

  • Normal Members
  • PipPipPipPipPipPipPipPipPipPipPipPip
  • 929 posts
  • Gender:Male
  • Location:Spain

Posted 26 December 2016 - 19:54

Like ffx said, you can do something like this:

 

1.

On press:

Set a bool flag to true

Start a timer (500ms)

 

On release:

Set the flag to false

Remove all timers

 

2. 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 but repeats 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.


:excl: Development of my tool: GT16-Colors

 

:excl: My API wishlist R3.1 (updated 24 July 2017):

Spoiler

 

:excl: My Renoise 3.1 wishlist (updated 18 July 2017):

Spoiler

#7 Raul (ulneiz)

Raul (ulneiz)

    Guruh Member

  • Normal Members
  • PipPipPipPipPipPipPipPipPipPipPipPip
  • 929 posts
  • Gender:Male
  • Location:Spain

Posted 26 December 2016 - 23:17

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.


Edited by Raul (ulneiz), 26 December 2016 - 23:32.

:excl: Development of my tool: GT16-Colors

 

:excl: My API wishlist R3.1 (updated 24 July 2017):

Spoiler

 

:excl: My Renoise 3.1 wishlist (updated 18 July 2017):

Spoiler

#8 joule

joule

    Guruh Motha Fakka is Levitating and Knows Everything About Renoise Member

  • Normal Members
  • PipPipPipPipPipPipPipPipPipPipPipPipPip
  • 1443 posts
  • Gender:Not Telling
  • Location:Sweden
  • Interests:music, philosophy, engineering

Posted 27 December 2016 - 10:44

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.


Edited by joule, 27 December 2016 - 10:53.

  • Raul (ulneiz) likes this

#9 Raul (ulneiz)

Raul (ulneiz)

    Guruh Member

  • Normal Members
  • PipPipPipPipPipPipPipPipPipPipPipPip
  • 929 posts
  • Gender:Male
  • Location:Spain

Posted 27 December 2016 - 22:50

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!  ^_^


Edited by Raul (ulneiz), 27 December 2016 - 22:52.

:excl: Development of my tool: GT16-Colors

 

:excl: My API wishlist R3.1 (updated 24 July 2017):

Spoiler

 

:excl: My Renoise 3.1 wishlist (updated 18 July 2017):

Spoiler