mruby-zest / mruby-zest-build

Root repo for mruby-zest containing links to all submodules
GNU Lesser General Public License v2.1
19 stars 24 forks source link

Rocker buttons #102

Closed polluxsynth closed 1 year ago

polluxsynth commented 1 year ago

It's over a year ago since I opened issue https://github.com/zynaddsubfx/zyn-fusion-issues/issues/352, but I finally got around to implementing a variant of the Button class, as suggested by @zynmuse, where a new rocker attribute has been added to the class, which when enabled will display the button as two adjacent buttons of half the width, where one is depressed and the other not. The labels for the two button halves will be extracted from the two portions of the label string separated by a '/'.

Technically, the button isn't really a rocker button, as that would imply that one half would be sloping, but it seemed a better name than 'two button radio button' or similar. I feel it ties in with the existing graphic style quite nicely.

Two commits utilize the new rocker property, one for the trigger threshold in the portamento section, and one for the amplifier envelopes.

Linlog button with lin depressed

Linlog button with log depressed

fundamental commented 1 year ago

The if(value == true) and if(value == false) comparisons are redundant, but otherwise the code looks reasonable.

polluxsynth commented 1 year ago

Actually, those specific expressions were already in the code, so I just copied the paradigm when testing the 'rocker' variable, thinking it was some sort of convention or even necessary in certain contexts in Ruby. Personally I really dislike redundant tests against boolean constants.

Looking over several files, it appears it's only used in Button.qml and TriggerButton.qml in qml/ and a bunch of Button*.qml fles in example/ . However, in some cases, in Button.qml for example, it looks like the tests against boolean values are used to distinguish between the value actually being a boolean value, or a float, for instance in Button.qml:draw_button(). I haven't looked further into why a button would have a float value though. In draw_button() it looks like a float value != 0 is used to set the brightness of the button when rendering.

I can resubmit the PR cleaning up the usage for the rocker variable in Button.qml . I'll have a look at the other uses as well.

polluxsynth commented 1 year ago

I went through Button.qml and it turns out the tests for 'value' against 'true' are legit, because when the Button is a TriggerButton, the value is used to control the animation (brightness of background), and in that case its important to test against the correct type.

However, I changed all the comparisons against true/false of the 'rocker' variable to simple boolean expressions.

fundamental commented 1 year ago

Now that you mention it, I do recall hacking around the value for animating buttons. Everything seems to be in order. Thanks for the enhancement :+1: Merged

polluxsynth commented 1 year ago

Thanks!