Cabbage Logo
Back to Cabbage Site

Velocity curve widget?

Nice find. So you want to make a pull request? I can add your changes in the next few days but a PR would be quicker. And I’m also happy to have PRs coming in. It sets up a quicker workflow for resolving things. And thanks again for taking the time to look into this. I very much appreciate it .

Ok, it’s my first time making a pull request, so I hope I have done everything right. :blush:

I noticed that something was wrong in the velocity values returned by my $VELCURVE macro. For example, in the keyboard widget, when you press a note key with the mouse in the middle of it, you don’t get a 0.5 value, even when you draw a perfectly linear curve 0-1 in the gentable widget. But the problem was not in the macro… The problem was in this csound flag:


It converts the velocity values [0, 127] it receives from midi note-on events to [0, 0dbfs] amp values (0dbfs is the global csound variable). Usually 0dbfs=1, but the conversion from [0, 127] --> [0, 1] is not linear, because amp values are in decibel… So, for example, a velocity value of 64 doesn’t translate in 0.5, but in 0.2. This is a problem because the $VELCURVE macro expects linear velocity values, not decibel, so the curve you draw in the graph doesn’t correspond to the requested velocity.

I solved the problem by using the following flag instead of the above one:


that simply returns the original MIDI velocity values without alterations. Being that they are defined in [0, 127], you have to make other little mods to the code:

#define VELCURVE(vel) #
        $vel    tab_i   floor((giVelCurveRes - 1) * $vel), giFT_velCurve
instr 1
        iFreq	    =	        p4
        iAmp	    =           p5 / 127 ; <-- convert the MIDI velocity to [0, 1] values.

Now the curve will reflect exactly your desired velocity response behavior.

1 Like

In the gentable widget, you could drag the first and last handle too and this led to an inconsistent and wrong behavior like the following:

I fixed the code so that you cannot x-drag the first and the last handle inside the graph on the x-axis, but only on the y-axis. And there is another problem with the fontcolour in the titlebar too: if you have a transparent fontcolour, when the window looses focus the hidden title reappears… I fixed this too. I will do a PR soon.

EDIT: sent PR. :wink:

Nice one. Thanks for spending some time on the gentable widget. I’ve always felt it was jut a little below production ready. Your changes are a big help.