rorywalsh / cabbage

Framework for developing audio plugins with the Csound programming language.
http://cabbageaudio.com
GNU General Public License v3.0
503 stars 35 forks source link

Request for specifying Number Box slider increase interval #129

Closed jomortal closed 1 year ago

jomortal commented 2 years ago

I'm wanting to easily customize number values with a high maximum limit, but would like the slider behavior to still only increment by one when a user interacts with it so they don't have to type in their specific value. The use case is for creating custom scale ratios, and so needs to be precise, but should not be limited to small numbers. Is there a place I can edit the source code perhaps so that I can get this desired behavior. Currently if I have the max set to 1000, if one scrolls over the number box it will increase by an increment of 35, I would like it to increment by 1.

rorywalsh commented 2 years ago

The problem is that number box jumps by calculating the distance moved, in comparison to the height of the widget. It's absolutely unusable for anything where you need really high precision. I've wrangled with this myself over the years. I think in order to do this the way you want you'd need to create an entirely new class, rather than inherit from JUCE::Slider as I have done. On the other hand, you can always roll your own in Cabbage:

<Cabbage>
form caption("Custom Numberbox") size(400, 300), guiMode("queue") pluginId("def1")
label bounds(42, 36, 69, 26) channel("myNumberBox"), text("0"), colour("black")
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d
</CsOptions>
<CsInstruments>
; Initialize the global variables. 
ksmps = 32
nchnls = 2
0dbfs = 1

instr 1
    kValue init 0
    kY init 0
    kPrevY init 0
    kMouseY chnget "MOUSE_Y"
    SCurrentWidget, kTrig cabbageGet "CURRENT_WIDGET"
    kMouseDown chnget "MOUSE_DOWN_LEFT"
    if kMouseDown == 1 && strcmpk(SCurrentWidget, "myNumberBox")==0 && (kPrevY != kMouseY) then
        if kPrevY <= kMouseY then
            kValue -= 1
            cabbageSet 1, "myNumberBox", sprintfk("text(\"%d\")", kValue)
        else
            kValue += 1
            cabbageSet 1, "myNumberBox", sprintfk("text(\"%d\")", kValue)
        endif
        kPrevY = kMouseY
    endif
endin

</CsInstruments>
<CsScore>
f0 z
i1 0 [60*60*24*7] 
</CsScore>
</CsoundSynthesizer>

It needs some finishing touches, but you could easily wrap this up in a UDO and use as many of them as you would like.

jomortal commented 2 years ago

Thanks for a quick response. This is great! Where can I find documentation for user interaction codes such as "MOUSE_DOWN_LEFT" ? I would also like to capture mouse wheel events as well.

rorywalsh commented 2 years ago

They are listed under Reserved channels. Although there is a middle mouse down, which equates to a mouse wheel click, I don't actually have a mouse wheel channel, but I could add one if that would be of any help.

rorywalsh commented 2 years ago

I just pushed 2 new reserved channels for you:

MOUSEWHEEL_DELTA_Y Returns the amount the wheel has moved on the Y axis. MOUSEWHEEL_DELTA_X Returns the amount the wheel has moved on the X axis.

You can grab the latest beta builds from here

jomortal commented 2 years ago

You get my developer of the year vote. This is great!