Mouse Down Events and Toggle Buttons

Home Forums General Using Ctrlr Mouse Down Events and Toggle Buttons

This topic contains 38 replies, has 3 voices, and was last updated by goodweather goodweather 2 months ago.

Viewing 20 posts - 1 through 20 (of 39 total)
  • Author
    Posts
  • #99356

    FOLKDISCO
    Participant
    • Topics: 2
    • Replies: 18
    • Total: 20

    I have a panel with 100 radio group toggle buttons.
    I found that triggering on mouse up is not accurate on a small touch screen, so I selected “Trigger button on mouse down events”.
    This works great, but obviously the button re-toggles off again when I let go!
    It isn’t ideal to send midi twice, but the main issue for me is the button colour.
    Is there any way to turn off “Trigger button on mouse up events”, because I can’t see how to do this.
    Or a way around this?
    Lua?
    Help!

    #99487
    goodweather
    goodweather
    Participant
    • Topics: 39
    • Replies: 374
    • Total: 413
    • ★★

    I can help you but tbh I don’t understand your issue…
    Can you explain what you want to do or make and send a test panel with just one or 2 buttons so we can look at your issue?

    #99535

    FOLKDISCO
    Participant
    • Topics: 2
    • Replies: 18
    • Total: 20

    Many thanks, goodweather!
    Sorry, this has 8 buttons, not one or two.
    My original panel has 100 buttons and 60 rotaries.

    THE UPLOADED PANEL
    All buttons are identical, except for the note-on key output, and that the blue radio buttons have “Trigger button on mouse down events” ticked, and the green buttons have this unticked, to show the difference.
    Blue buttons are radio group 3, green buttons are radio group 4.
    I use my panel to control the Playtime session view in reaper.
    https://www.helgoboss.org/projects/playtime/
    It is very simple in operation, just sending static midi on notes, no 2-way communication or Lua.

    The blue buttons work consistently on my small 8″ touch screen, sending out at least one note-on.
    I have found you need to be careful how you touch the green buttons, or they do not send midi.

    Obviously, it isn’t ideal that the blue buttons trigger twice, on mouse down and mouse up, but especially that they do not hold their red colour.
    However, the green buttons are not consistent on a small touch screen.
    Often you press them, your finger moves a little, and no midi is sent.
    In performance situations, you need to tap a button and know it will perform.

    My ideal would be for the buttons to respond only to mouse down events, to have some way to disable mouse up events.
    Also, it would be nice if the buttons did not toggle off when you press them again, so that they stay red no matter how many times you press them.
    I don’t know if you can use Lua to program only a mouse-down event for the buttons?
    Or if there are any internal ways to disable mouse-up?
    Obviously, on a toggle button, when you cannot disable mouse up events, it toggles off again every single time you let go!
    Cheers, in advance for looking at this.

    • This reply was modified 2 months, 2 weeks ago by  FOLKDISCO.
    • This reply was modified 2 months, 2 weeks ago by  FOLKDISCO.
    Attachments:
    You must be logged in to view attached files.
    #99589
    goodweather
    goodweather
    Participant
    • Topics: 39
    • Replies: 374
    • Total: 413
    • ★★

    OK. I will look at this during the w-e and come back to you.
    No pbm about 8 buttons io 2 😉

    As a general feedback, I’m using OnMouseDown tracking in all my panels (to display some help text or the current modulator value in a screen for example) and I know also how to handle mouse events but I do this all by Lua methods.
    So pretty sure we’ll find a solution to your issue.

    #99626
    goodweather
    goodweather
    Participant
    • Topics: 39
    • Replies: 374
    • Total: 413
    • ★★

    OK. Had some time during lunch and couldn’t resist 😉
    I had a look at Playtime and saw it can be triggered by Note or CC.
    I also saw that you have different options to manage the behaviour of the triggers.

    I join a new version of your panel including resources.
    I re-created the buttons but with uiImageButton instead.
    Green ones are acting as toggles and are in a radio group
    Blue ones are acting momentary and are NOT in a radio group

    I didn’t attach anything further yet.

    As first next step, I’d like you to use CC as communication method for each button (in Edit mode, under the MIDI section) and that you set the buttons in the panel and your Playtime software to different CC’s.
    Once this is done, start Ctrlr Midi Monitor and activate the Output monitor
    Use your touch screen and check what is happening in the Midi monitor.
    Do you have still double messages? Are all messages correct? …
    If this is OK then we stop here

    Otherwise, based on your feedback, we can control everything by using Lua and this will secure we get only what we want and nothing else.

    So, waiting for your feedback.
    You can make a small video of the action by using a free nice software called Flashback Express I just discovered and that I used to report a bug in a soft I’m using. Export in .mp4.

    Attachments:
    You must be logged in to view attached files.
    #99629
    goodweather
    goodweather
    Participant
    • Topics: 39
    • Replies: 374
    • Total: 413
    • ★★

    Sorry… Attached the same panel twice… (due to editing the post)

    #99663

    FOLKDISCO
    Participant
    • Topics: 2
    • Replies: 18
    • Total: 20

    Thank you so much!
    For some reason, your new buttons are replicating my buttons behaviour, but not sending out any midi.
    Is this correct?
    I know the monitor really well, but have never done any Lua.
    Don’t think I have disabled Lua, Lua disable is not ticked in preferences.
    Please note my current button behaviour is not what I am trying to achieve.
    The different colour buttons just show what happens with “Trigger button on mouse down events” ticked (blue) and unticked (green).
    My panel buttons and rotaries are made and placed automatically as text with a PHP script which I copy/paste into a .panel file, so all I need is one working button, and I can replicate this and fill the different note/CC colour values.
    I just use blue/green/red buttons to make it easier to visualise the different tracks.
    1-3=blue, 4-6=green, 7-9=blue, 10+red (scenes).
    All the buttons just output a simple static trigger, note or CC is fine.

    IDEAL BEHAVIOUR OF BUTTONS
    ON MOUSE/TOUCH DOWN
    1) Midi note on OR midi CC sent.
    2) Button changes colour to red. Ideally, subsequent presses on a red button would leave it red.
    3) Other buttons in the same radio group are reset to their original colour (blue or green).

    ON MOUSE/TOUCH UP
    Nothing!

    *IDEALLY*, pressing a scene button would turn all the other clip and scene buttons back to their original colours, but lets not worry about that for now!
    If a double note on or CC is sent, that isn’t ideal, but I easily could live with it.
    Many, many thanks again for looking at this. 🙂

    #99693
    goodweather
    goodweather
    Participant
    • Topics: 39
    • Replies: 374
    • Total: 413
    • ★★

    As I stated above, I didn’t do any Midi configuration on my buttons.
    Please do this. Add CC messages on them (whatever they are).
    Assign something to a Midi Output channel then test my buttons with your touch screen (this is what I cannot test). Check the Midi monitor window in Ctrlr to verify it displays what you expect.

    Are my buttons also reacting on mouse up? Meaning sending 2 times the CC message?

    I think that we will need a simple Lua script anyway because you don’t want a toggle when the user presses an already red button. With the current behaviour, it will toggle it to green and this is not what we want.

    Scene button: just need to put all your scene buttons in the same radio group. After doing the assignment to the radio group, you need to save, close and re-open your panel to see it working.

    Don’t understand why you build it by script. Will the panel change all the time?
    Otherwise, I just did this in a few minutes by copy/paste…

    #99769

    FOLKDISCO
    Participant
    • Topics: 2
    • Replies: 18
    • Total: 20

    You can test for touchscreen, as this responds exactly like a mouse click.
    Touch a button=mouse down, let go=mouse up.
    I am testing on my laptop, not my tablet.

    But I am really confused now.
    All the options down to Component generic:”Called when a double click occurs on this component” are the same.
    Looking down from here, your buttons and my buttons have completely different options!
    My buttons have the tick boxes Component:”Button is toggle button” and Component:”Trigger button on mouse down events”.
    Your buttons do not!
    Is this because yours is a uiImageButton and mine is a uiButton?

    However, I can see “Called when a mouse is down on this component” on both sets of buttons.
    I have no idea what to do with this!
    All I want to do is output static midi.
    I know all about what midi hex numbers to send, no problem, but I’m completely baffled what to put in these boxes to send that midi!
    Have created a copy of one of your buttons, have turned off midi, and am currently trying to write a myMethod.
    It very much isn’t working out for me!

    #99771

    FOLKDISCO
    Participant
    • Topics: 2
    • Replies: 18
    • Total: 20

    I forgot to say… I set some midi output for your buttons, but on both normal and momentary buttons it outputs midi on mouse up, not mouse down.
    Just one message, but nothing on mouse down.

    #99800
    goodweather
    goodweather
    Participant
    • Topics: 39
    • Replies: 374
    • Total: 413
    • ★★

    Yep, uiButton and uiImageButton are different. The second one has probably been created afterwards.
    I’m always using uiImageButton to have more control.

    Called when a mouse is down on this component: this is where we will attach our Lua method for each button.
    I’ll build that for you and you will be able to proceed further.

    Did you look at my already old Step by Step guide?
    http://ctrlr.org/forums/topic/ctrlr-step-by-step-guide/

    Before going further, I’d like to have from you:
    – how do you see that the Midi msg is sent on Mouse up io Mouse Down?
    – what is the difference? How does it matter?
    – please give me the names you would like for the buttons. I can call them Button1 to Button99
    – please give me the typical messages you would like to send to Playtime. Provide me with all the different message types and the complete ones. You can take them from the Midi monitor.

    Not easy to exchange by messages… If needed I’ll contact you by PM and we can set a conf call.

    #99875

    FOLKDISCO
    Participant
    • Topics: 2
    • Replies: 18
    • Total: 20

    Goodweather, I sent you a PM with my number and other stuff.
    I really wanted to spend more time with your “Ctrlr – Step by step guide” today, but time ran out.
    Have already tried to get Lua information from this as a docx, but I think the most relevant bits weren’t complete.
    Anyway, here’s some answers to your questions, and a panel upload.

    – how do you see that the Midi msg is sent on Mouse up io Mouse Down?
    From the midi monitor.
    You can clearly see buttons responding to mouse down/up events.
    When you use uiButton, you get a tickbox Component:”Trigger button on mouse down events”
    To show you the difference I set blue buttons with this ticked and green buttons unticked.
    Unfortunately, there is no tickbox Component:”Trigger button on mouse up events”, or I could easily turn it off without any Lua.

    – what is the difference? How does it matter?
    I just found that on a small touchscreen, mouse up didn’t respond consistently.
    There are lots of buttons jammed in there 10×10 in 10 radio groups, and 60 rotaries on an 8″ screen, and my finger must just slide a bit or something.
    I just found that when buttons respond to mouse/finger down it triggers every time.
    With mouse up, I lose a lot of button presses.
    I’m probably going to be doing other stuff like playing guitar and singing, so it needs to be consistent.

    – please give me the names you would like for the buttons. I can call them Button1 to Button99
    Whatever button names are fine.
    Unless there’s some reason I don’t know about to care, I don’t care!
    I was trying to be metodical and consistent with note and CC output, but unless you’re referencing components from Lua, I’m not sure it makes any practical difference?

    – please give me the typical messages you would like to send to Playtime.
    There are 60 rotaries sending CC, controlling all kinds of fun stuff. Volumes, filter cuttoff, velocity scale, random note kill.
    I’m already using all those CCs, so it just made more sense to use something else like note on for the buttons controlling Playtime. But again, I’m not too bothered about this.

    – Provide me with all the different message types and the complete ones.
    – You can take them from the Midi monitor.
    You can clearly see the double sends here.
    If you tap fast, the two notes have the same time stamp.
    If you hold on a while, it’s longer.
    Like I said, if I just have one working button, I will probably use my PHP script to repeat that across the panel, with the correct values inserted.
    I open the panel file in a text editor, add that to my PHP script, The PHP script outputs text with 100 buttons and 60 rotaries in the correct positions etc, I insert that into the panel file, and….
    BINGO!
    [00:15:00:000164]: [Note on] Ch:[15] No:[ 0] Val:[ 64]
    [00:15:00:000727]: [Note on] Ch:[15] No:[ 0] Val:[ 64]
    [00:15:02:000455]: [Note on] Ch:[15] No:[ 17] Val:[ 64]
    [00:15:02:000821]: [Note on] Ch:[15] No:[ 17] Val:[ 64]
    [00:15:08:000689]: [Note on] Ch:[15] No:[ 48] Val:[ 64]
    [00:15:08:000689]: [Note on] Ch:[15] No:[ 48] Val:[ 64]
    [00:15:09:000634]: [Note on] Ch:[15] No:[ 48] Val:[ 64]
    [00:15:09:000634]: [Note on] Ch:[15] No:[ 48] Val:[ 64]
    [00:15:29:000568]: [Controller] Ch:[15] No:[ 0] Val:[ 63]
    [00:15:29:000580]: [Controller] Ch:[15] No:[ 0] Val:[ 62]
    [00:15:29:000592]: [Controller] Ch:[15] No:[ 0] Val:[ 60]
    [00:15:29:000603]: [Controller] Ch:[15] No:[ 0] Val:[ 59]
    [00:15:36:000068]: [Controller] Ch:[15] No:[ 16] Val:[ 65]
    [00:15:36:000103]: [Controller] Ch:[15] No:[ 16] Val:[ 66]
    [00:15:36:000118]: [Controller] Ch:[15] No:[ 16] Val:[ 67]

    Anyway I realised that I hadn’t uploaded the original panel, so here it is, and a pic of it.
    Currently, the panel works in portrait mode, but is used landscape, because less screen is wasted that way!
    Go figure!
    I don’t really care what it looks like, I just want a ridiculous number of lovely buttons and rotaries on one screen!

    Attachments:
    You must be logged in to view attached files.
    #100161
    goodweather
    goodweather
    Participant
    • Topics: 39
    • Replies: 374
    • Total: 413
    • ★★

    OK my friend, I have good news for you.
    I looked now a bit further thanks to the details you gave me and my conclusion is that the issue of double sending is due to your buttons.

    I realized that I had never the issue and that I’m also sending sometimes CC messages from my panel.
    So, I enabled Midi and tested my buttons with CC and NoteOn messages and they fire only once.
    Your buttons are firing twice.

    Therefore, I suggest you modify the Midi message of the buttons I created in this small test panel and that you test that with your device.
    In Midi monitor, you will see that your buttons are sending 2 messages while my buttons are sending only once.
    Maybe this is due to some difference between uiButton and uiImageButton.

    #100205

    FOLKDISCO
    Participant
    • Topics: 2
    • Replies: 18
    • Total: 20

    My original green buttons are sending midi once, and I can set the blue buttons to send midi once easily.
    I can make your buttons and my buttons send midi once easily.
    The problem is that they are sending midi once on mouse up, and I want them to send midi on mouse down.
    Also, I have chosen to send midi twice, as this is better than sending midi only on mouse up, for the reasons explained above.
    If you have some Lua code that will work only on Component generic:”Called when a mouse is down on this component” and does not do anything on mouse up, then that is problem one fixed.
    If this also works the radio group on mouse down, resetting button colour on other group members, that would be extra brilliant.
    My big problem number two is that a radio group toggle uiButton which works great on mouse down, then resets its colour to off when you let go (mouse up).
    I have found that you can slide sideways out of the button and then let go, it works fine on my buttons, sends midi once and leaves the colour set.
    But obviously having to press and slide finger/mouse sideways isn’t ideal.
    If there is some, any Lua that sends midi on mouse down and not up, on one button, that would be great, and I can copy/paste this to other buttons.
    My problem is I am just not making any Lua work and send out any midi.
    If there is a way to make CTRLR work on mouse down and not up without Lua, then I don’t need any Lua, but there doesn’t seem to be a way to do this.
    My big problem currently is getting Lua in Component generic:”Called when a mouse is down on this component” to send any midi.
    My scripts don’t compile.
    I don’t know what I am doing!
    If I can see one example of a simple Lua script sending midi CC or Note on, then that would be a big help.
    I have seen examples of coding, but not whole scripts to paste in the Component generic:”Called when a mouse is down on this component” box.
    If the correct Lua scripting is in this box, and the MIDI:”Midi message type” is set to “None” then will that send midi on mouse down, and not send it on mouse up?
    Cheers again!

    • This reply was modified 2 months, 2 weeks ago by  FOLKDISCO.
    • This reply was modified 2 months, 2 weeks ago by  FOLKDISCO.
    • This reply was modified 2 months, 2 weeks ago by  FOLKDISCO.
    • This reply was modified 2 months, 2 weeks ago by  FOLKDISCO.
    #100353
    goodweather
    goodweather
    Participant
    • Topics: 39
    • Replies: 374
    • Total: 413
    • ★★

    Hi,
    here is a panel you can try and adapt further.
    – to modify, go to panel mode then open Lua editor
    – you have 2 methods
    – the OnClick method is fired at mouse down ONLY when you click on the button label, not on the button itself
    I used it here just to show some text. Basically, you can remove it from “Called when mouse is down”
    – the OnChange method is the one fired when the value change. It sends the Midi message that you can tailor as you want. You can adapt this method further (I used a CC and a combo to set the Midi channel)

    Please note that I found a bug in CtrlrMidiMessage which is not working properly for NoteOn messages.

    Further than that I cannot help you if it doesn’t work (your mouse up / mouse down stuff).

    Attachments:
    You must be logged in to view attached files.
    #100355
    goodweather
    goodweather
    Participant
    • Topics: 39
    • Replies: 374
    • Total: 413
    • ★★

    Just thinking about something else: if this doesn’t work, we could remove the image of the buttons and only keep the labels.
    Then you would use the OnClick method only and that one is fired on mouse down only 😉

    #100398

    FOLKDISCO
    Participant
    • Topics: 2
    • Replies: 18
    • Total: 20

    Hmmm….! So something happens on mouse down, but still no midi.
    I was trying to shove midi send data into the Button_OnClick function to see if anything happens.
    It doesn’t!
    But at least I have some Lua which does something!
    Also, the title doesn’t go red every time I try to compile it!

    --
    -- Called when a mouse is down on this component
    --
    
    Button_OnClick = function(--[[ CtrlrComponent --]] comp, --[[ MouseEvent --]] event)
    	
    	-- Get current button
    
    	sName= L(comp:getOwner():getName())
    
    	message = CtrlrMidiMessage({0xf0, 0x42, 0x30, 0x00, 0x01, 0x0d, 0x41, 0x03, 0x00, 0x23, 0x00, 0x00, 0x0f, 0x7f, 0x7f, 0x7f, 0x7d, 0xf7})
    	panel:sendMidiMessageNow(message)
    	utils.infoWindow("Info", "This is "..sName)
    
    end 

    There was stuff I was doing in flash a couple of decades ago, changing the way a component works, by its name.
    So if we can read a button name as a variable, then the button name can be “Button-9e-01” and it can read its own name then send out midi “9e 00 40”.
    Still haven’t managed to get Lua to actually send midi tho!
    It does make it difficult programming when there is no manual.

    #100421
    Possemo
    Possemo
    Participant
    • Topics: 13
    • Replies: 541
    • Total: 554
    • ★★★

    Hi folkdisco

    here is a different approach for you to test. I replicated your blue buttons behaviour but only on mouse down and the colour will stay the same when you click it several times. It will use the midi-channel from the general MIDI output settings of the panel.

    It uses the “modulator custom index” to get the note number. I think this would be the easiest way.

    Attachments:
    You must be logged in to view attached files.
    #100432
    goodweather
    goodweather
    Participant
    • Topics: 39
    • Replies: 374
    • Total: 413
    • ★★

    I would suggest that you solve your midi issue first.
    Create a new modulator (uiImageButton or uiSlider or…) and put CC i the Midi section.
    You can leave controller number to 1
    In the Midi menu, select a device and a channel as output. If you have a controller it is fine as well.
    The key is to have any equipment that appears in the list. We don’t care it will receive something.
    Once this is done, you open the Midi monitor and activate the output monitor.
    Turning the slider should make the output appears in the monitor.

    If this is working then you can take next step with your actual device.
    Watch for channel number
    Always start your device first then Ctrlr and the panel.

    Then about your button name extraction, yep this is piece of cake…
    sName= L(comp:getOwner():getName())
    s = string.sub(sName,8,9)
    To be safe, convert this to decimal and put that value in the midi message
    tonumber(s,16)
    like tonumber(“3F”,16) gives 63

    Also look at possemo’s proposal!
    There are always several ways to achieve the same target and one learns everyday.
    This is the fun in coding 😉

    #100435

    FOLKDISCO
    Participant
    • Topics: 2
    • Replies: 18
    • Total: 20

    Got the midi send and button name extraction working really late last night. Buttons called b15-1, b15-2…
    Sending note on, channel 15.
    I’m thinking b16-1, b16-2, to send to channel 16, via function buttonDown16.
    When I have so many buttons, and I want to keep them on 0-15 track1, 16-31 track2, etc, then I run out of buttons and CCs on one channel!
    Want to keep it so if it expands or contracts in future, the note-ons and CCs follow a consistent plan.
    So the same song can be run with a huge panel or a simplified panel, and all the top buttons and CCs will be the same.
    Not 100% sure how I’ll use it yet!
    How many buttons and CCs I’ll need!

    The Lua substring stuff was easy, because there is plenty of documentation for Lua.
    Just not full documentation CTRLR Lua.
    The problem I was having, above anything else is that when no output is set, midi LOOKS like it is working because midi from components appears in the monitor.
    However Lua does not output midi or appear in the monitor until you set an output!
    Took a while to work out why everything was suddenly working.

    buttonDown15 = function(--[[ CtrlrComponent --]] comp, --[[ MouseEvent --]] event)
    	-- t=table containing midi message as numbers. 
    	t={0x9e, tonumber(string.sub(L(comp:getOwner():getName()), 5)), 0x47}
    	msg = CtrlrMidiMessage(t)
    	panel:sendMidiMessageNow(msg)
    end

    So going forward, I am thinking that if a button is set ON in Lua, then that will trigger the rest of the radio group off and reset the other radio group button colours without me having to do it manually?
    Let’s see!
    Also turning the current button ON via Lua, would that change its colour?
    Not sure if it is good to use the toggle functionality in CTRLR or if that will cause unwanted button off behaviour, etc.
    That’s probably better than manually resetting all the other colours via Lua, so I’ll try that first.
    Again, many thanks for your help, it has has been really useful.
    I now need to put 4 young boys to bed, and have a look at Possemo’s stuff.
    I won’t do anything more whatsoever until I have had a good look at your posts today.
    Big cheers, both of you.

    • This reply was modified 2 months, 2 weeks ago by  FOLKDISCO.
Viewing 20 posts - 1 through 20 (of 39 total)

You must be logged in to reply to this topic.

There is currently 0 users and 39 guests online
No users are currently active
Forum Statistics
Threads: 2,213, Posts: 15,610, Members: 55,379
Most users ever online was 12 on January 22, 2019 3:47 pm
Do NOT follow this link or you will be banned from the site!