mouseDown for TextButtons

Hello everyone!

First and foremost, I am definitely a beginner when it comes to Juce and to C++ in general, however I do have a good deal of experience in other programming languages. That being said, please excuse me if this is a dumb question.

I’m working on a simple midi vst for myself and I’m trying to add a mousedown/mouseup trigger to the textbuttons built in to gui magic, but am currently only able to make onClick work. The main issue with that for me is that the event isn’t fired until the mouse is released. I was hoping someone could point me in the right direction as far as adding mousedown and mouseup triggers, as I haven’t really been able to find anything in the documentation. Even something like isMouseDown() to call and check if the button is pressed would be an enormous help.

Thank you for your time!

Edit: So it looks like I am unable to assign a midi controller button to a text button in my DAW. That pretty much defeats the purpose of what I was trying to achieve. So what I now need to do is find a way to make a toggle button to be momentary.

Hello @sherbethead2010,

Thank you for joining and welcome!

The juce::TextButton is indeed not well suited for your use case. The reason is that it also detects e.g. dragging, in which case no onClick shall be executed. I know it could be worked around in the juce codebase by checking if the button implements dragging behaviour at all. But that is simply how the juce TextButton works.

As a solution I would create a bespoke button and wrap it into PluginGuiMagic. The method how to add your own button can be seen in the examples/ExtendingExample.

An even nicer solution would be to create a class started by copying the juce::MidiKeyboardComponent as MidiDrumPadComponent. Would be great to have that in PGM, but I have no idea when I would find time to write that. But I note it down on the wishlist.

Now thinking about it, it would even be possible to create such MidiDrumPadComponent for MPE, but that’s even more unrealistic now :wink:

If you want to take a stab at the MidiDrumPadComponent I’d be happy to lend a hand.

Hope that helps, good luck!

Just wanted to let you know that I added a drumpad component on the develop branch. That will allow to trigger midi messages on mouse down.

Does that help?
Let me know if you have any questions

This is great! Definitely a big help. Thanks a ton!