FreePIE icon indicating copy to clipboard operation
FreePIE copied to clipboard

Joysticks - What's the equivalent of the .update attribute?

Open PWBENNETT opened this issue 7 years ago • 2 comments

I'm sure it's possible, and probably even easy, but before I start hacking on the Python code for it, what I'm actually trying to do is the opposite of what I was trying to do before (if you remember me and what I was trying to do before), which was use MIDI panels to drive X-Plane.

Here's the problem "turned on its head"...

I have a set of flight sim pedals that I want to use as MIDI sliders (in real time, to control FL Studio during live performances). For example, I might want to map a pedal to be a Modulation wheel, or the center note of a bandpass filter -- whatever, I'll write some kind of function that takes (a given joystick, an ID for one of its axes, a MIDI channel, a control type, a control number) as arguments and binds that axis of that joystick to operate that MIDI control.

As I said, I've had great luck converting MIDI devices into flight sim controllers (via FreePIE's vJoy support). What I can't seem to get my head around is that there is no .update attribute for joysticks -- at least there wasn't the last time I looked.

If there's no .update attribute, what should I be hooking into instead?

My last attempt looked something like https://gist.github.com/PWBENNETT/0c178601cf6e614e14b7593ef78ff230

PWBENNETT avatar Oct 18 '17 10:10 PWBENNETT

Joysticks are updated every time the script is executed. Add update() somewhere after the definition of that method, without any indentation (so not in the if starting: block); this way your code executes just after the joysticks have been queried.

It works like this because MIDI sends messages; these messages are queued up in a Queue, and replayed before the script executes. This is to ensure your code has handled all the messages that have been received. Joysticks on the other hand simply fetch the current state, and let the script execute after that. If the frequency of executions is too low, button presses may not be captured for instance, because Joysticks do not send 'change/keypress' messages.

MarijnS95 avatar Oct 18 '17 10:10 MarijnS95

Aha. I think I understand. I'll have a poke & a play. Thanks.

PWBENNETT avatar Oct 18 '17 10:10 PWBENNETT