Open wouter0102 opened 7 years ago
Search mtbs3d forum, there was a guy there that got midi slider working. I guess its about the same for a knob
@AndersMalmgren found nothing there :/
Really? Agreed, I couldn't find a topic describing how to get a knob control the scroll wheel, but there's a lot of information about reading midi controls, and about controlling the scrollwheel. The entire idea of FreePIE is to allow you to hook things up yourself, personalized for your needs :wink:
In other words: search for "midi" on the forums; use all the information to figure out how to get the rotation from your knob (using diagnostics.watch
to see it's value is a great start). Then use some maths (or filters.mapRange
) to scale it to the values you need, and assign it to mouse.wheel
.
@MarijnS95 I am not a coder at all and not a mathmatician but this is kind of what I figured out but basically what it does is switch between max scroll and minimum scrol not the values in between..
if midi[1].data.buffer[0] == 1: mouse.wheel = filters.mapRange(midi[1].data.buffer[1], 0, 127, -Int16.MaxValue, Int16.MaxValue)
Yes that makes sense, you're scaling the small range of [0,127] to a range of [-65536, 65535].
What you should do is use diagnostics.watch(midi[1].data.buffer[1])
to see how much of the turn of your slider changes how much in value. Then do the same for the mouse wheel, and use that for the mapRange. For instance, a single 'click' of your mousewheel is a (-)120 in value.
Also, keep in mind (I forgot to mention it) that mouse.wheel
is relative. Thus, you'll want to keep track of the previous value, and substract it from the new value so you can pass in the correct relative value.
In the end, that gives you something like this:
if starting:
old = 0 # Make sure your slider is in the center, or change this to a more sensible value. It currently depends on your scale, but the code below can be modified so old and new represent MIDI states, and then you map those to mouse.wheel scale later
if midi[1].data.buffer[0] == 1:
new = filters.mapRange(midi[1].data.buffer[1], 0, 127, -4 * 120, 4 * 120) # If you turn your knob all the way down, that'll result in 4 clicks downward,
# This math can also be optimized: (midi[1].data.buffer[1] - 63) * 120 / 16
mouse.wheel = new - old # Calculate the relative value. If the previous value was 120, and the new value is 130, that means a positive difference of 10 that you need to send to the mouse wheel.
old = new
Also, there are multiple MIDI control messages available, and on the mtbs forum multiple messages are handled. Perhaps it's interesting to know what type of knob you have, and which control messages are available.
@wouter0102 I made https://gist.github.com/PWBENNETT/0c178601cf6e614e14b7593ef78ff230 a while ago. Obviously most of the script is me setting the options for my specific MIDI devices, but there's a good chunk of (IMHO) decent theory in there.
Hey there,
How do I use a midi knob to control my scroll wheel?
Kind regards