Go Back   Cockos Incorporated Forums > REAPER Forums > REAPER Q&A, Tips, Tricks and Howto

Reply
 
Thread Tools Display Modes
Old 08-21-2009, 05:56 PM   #1
zenmonkey
Human being with feelings
 
zenmonkey's Avatar
 
Join Date: Jun 2007
Location: Texas
Posts: 109
Default Using a simple USB gamepad as an expression controller (with script!)

Hello everyone!

I use a fairly unique keyboard as my primary playing surface because I love its ability to help me see patterns in music. Unfortunately the KB doesn't have pitch bend, modwheel, aftertouch, or any CC controllers.

For a while now I've been using a cheap 25 key keyboard along with the Axis just for the PB/MW and 16 rotary encoders. This wasn't ideal because the Xboard is much larger than the Axis and hindered my musical portability.

Two days ago I was at Fry's electronics and saw this little controller for $15. I remembered seeing Reaper 3 had joystick support so I figured I'd give it a go...

Two days layer I have a very usable, small, inexpensive controller I place next to my Axis and I get all the expression I need.



>>> DOWNLOAD GAMEPAD SCRIPT HERE <<<



To Install:
1. Download the file, unzip it and place gamepad_expression.txt into (REAPER ROOT)\joystick_midi
2. Load Reaper with your joystick connected and go to Options -> Preferences... (Ctrl+P)
3. Select in the left hand frame Audio->MIDI Devices then click on the button [ Add Joystick MIDI... ] on the right hand side of the box in the middle.
4. In the popup dialog box titled "Joystick->MIDI" select your joystick in the Device: pulldown, then select "gamepad_expression.txt" in the "Processing Script:" pulldown. You can optionally select what midi channel you want messages sent on via the "Script mode:" pulldown.

At this point you should be ready to go! If you move the analog sticks you should see numbers changing on the "axis=" line in the Joystick->MIDI box. If you don't there might be a problem with Windows seeing your joystick.

How the script configures the joystick:

Since I'm a lefty (sorry!) I configured this script to place the joystick on the right side of my keyboard in the following way:


Please note the directions I use in the instructions below are in relation to this diagram! UP in the directions is normally "left" when holding the joystick if you were playing a game with it.

The script has 10 joystick presets and starts at preset 1 by default. The different presets only change how the analog joysticks work, the buttons and D-PAD (POV) are always the same. The presets configure the gamepad in the following way:

Preset 1:
Joy 0 up = pitchbend up
Joy 0 dn = pitchbend down
Joy 1 up = modwheel 0-127
Joy 1 dn = aftertouch (channel pressure) 0-127

Presets 2-10:
Joy 0 is now an XY controller with two CCs mapped to the XY axis. When centered the CCs transmit 63 for both. This is great for synths like Zebra and Alchemy that have XY expression controllers.
Joy 1 up is the same as Joy 0's X-axis.
Joy 1 down is the same as Joy 0's Y-axis.
The CCs for presets 2-10 go from 102 to 119 with even CCs being the Y-axis and odd CCs being the X-axis.

This is useful as some people map 0,0 to be the default sound and others map 63,63 as the default.

The buttons
Buttons 1-4 can be used to quickly change to any of the 10 joystick presets. Subsequent button presses are added up until the same button is pressed twice. That value is then used to switch to that preset. The second button preset is not summed with the value.

It sounds a bit weird but is really simple once you start using it.

examples:
switch to preset 1: 1, 1
switch to preset 2: 2, 2
switch to preset 3: 2, 1, 1 or 3, 3
switch to preset 4: 4, 4 or 3, 1, 1
switch to preset 10: 3, 2, 3, 2, 2 (one of many)

Button 5 switches the D-PAD (POV) from joystick preset mode to midi preset mode (more on this when I talk about the D-pad). This is a momentary button, you have to hold down button 5 to keep the pad in midi mode. As soon as it's released the pad goes back into joystick preset mode.

Button 6 (bottom shoulder button, closest to top) is akin to a panic reset. It puts the joystick back in preset 1, sends all notes off, and resets pitchbend, modwheel, and channel pressure. It also resets your midi bank select to 0, 0, 0. So use this button with care!

The bottom shoulder buttons (7,8) and the joystick depression buttons (11, 12) are unmapped. I may think of something for 7,8 in the future but I find 11 and 12 are just too hard to use w/o causing the joystick to wiggle.

Buttons 9 and 10 (in the select and start spots in PS2/PS3 controller configs) are the freeze/unfreeze buttons for each joystick.

Button 9 works as you expect. Move Joystick 0, press button 9, and the pitchbend/midi CC doesn't change if you keep moving it. Press button 9 again and you can move the joystick again.

Button 10 works a bit differently. It only freezes the active direction. This is really useful if you want to freeze the modwheel position (up) and then adjust channel pressure (down). Centering the joystick and pressing button 10 will unfreeze it.

The D-Pad (aka POV)
When button 5 is not depressed (see above) the D-Pad operates as follows:
UP = unfreezes and resets Joy 0's parameters
DN = unfreezes and resets Joy 1's parameters
LEFT = selects the previous joystick preset (wraps around at 0 back to 10)
RIGHT = selects the next joystick preset (wraps around at 10 back to 0).

When Button 5 is held down the pad changes to sending MIDI bank select messages:
UP = the previous BANK (note this wraps at 0 to very large bank configs (MSB 127, LSB 127, PC 127). If you're not at the beginning of a bank, it takes you back to the beginning of the current bank. If you are at the beginning of a bank then it will take you to the previous bank.

Example. You're on preset 260. You press 5+UP. You're now at preset 256. You press 5+UP. You're now at Preset 128. You press 5+UP. You're now at Preset 0.

DN = the next BANK (will wrap around to 0). This always goes to the next bank in the series.

Example. You're on preset 260. You press 5+DN. You're now at preset 384 (256+128). You press 5+DN. You're now at preset 512.

LEFT = the previous midi preset (wraps at 0)
RIGHT = the next midi preset (wraps at 2+ million -- 21 bits)

Joystick thresholds
These joysticks are cheap, dirt cheap. This means they're not super-fine precision instruments. On my specific gamepad Joy 0 has a bigger dead spot for center than Joy 1 does. I'd imagine every joystick has slightly different dead spots.

The script initializes during init what are considered the dead spots for the positive and negative directions of the joystick. These can't be detected and have to be entered by the user.

In the Joystick->MIDI menu there is status about the joystick under the "Running:" title.

Look for the line like "axis=-0.008000 0.008000 0.000000 0.000000"
These are the current axis readings for your 4 joystick axes. If you see numbers like above that are non-zero when you're not touching the joystick you need to modify the following lines in the script:
Code:
       // Axis thresholds are based on the particular joystick when it is centered
        // but the read value isn't true zero.  Any joystick value falling within this
        // range will be treated as true zero.
        //   offset + 0 == the negative direction threshold
        //   offset + 1 == the positive direction threshold

        mem[axis_thresh + (AXIS_IDX_0 * 2)]     = -0.032;
        mem[axis_thresh + (AXIS_IDX_0 * 2) + 1] =  0.001;

        mem[axis_thresh + (AXIS_IDX_1 * 2)]     = -0.047;
        mem[axis_thresh + (AXIS_IDX_1 * 2) + 1] =  0.001;

        mem[axis_thresh + (AXIS_IDX_2 * 2)]     = -0.024;
        mem[axis_thresh + (AXIS_IDX_2 * 2) + 1] =  0.001;

        mem[axis_thresh + (AXIS_IDX_3 * 2)]     = -0.001;
        mem[axis_thresh + (AXIS_IDX_3 * 2) + 1] =  0.001;
These lines are important to get true zero readings for values, especially pitchbend.

I wanted to add these as options to the menu but I couldn't see how to get a different submode dialog box. For now you'll have to edit it by hand. Considering you get this for free I think that's a fair trade-off.

Final thoughts
If something gets out of whack, just remember to press button 6 to reset everything.

If that doesn't work, the Joystick->MIDI menu for your gamepad has a [Reload Script] button on it. That will reset the script as well.

If anyone has any suggestions let me know. I couldn't get Reaper to see the up/down axis on joystick 1 for some reason (I submitted a bug) so for now that axis is unusable.

I hope someone out there finds this useful. I sure as heck do, it's made playing my softsynths a ton more fun!

A biiiiiig thanks to the Reaper devs for adding joystick support + scripting!!


UPDATE:

I've added a second script to use the Saitek P3200. It required a few tweaks because the axes are enumerated differently. I also updated the P3200's reset button to require hitting LB then RB. I found I got less accidental resets this way.

Last edited by zenmonkey; 09-19-2009 at 06:11 PM. Reason: Updated new Download URL
zenmonkey is offline   Reply With Quote
Old 08-21-2009, 06:08 PM   #2
BenK-msx
Human being with feelings
 
BenK-msx's Avatar
 
Join Date: Jun 2008
Location: Whales, UK
Posts: 6,009
Default

ooh nice one zenmonkey,
when joystick support came up i tried it but had much trouble getting the analog sticks to work in a usable way, and the scripting was beyond my non-programmer status, so was waiting for a good script or an update or something - so I will try this out for sure - looks like you covered most aspects - v. thorough!

am lefty too so thats all good..

the more cc controllers i have the better i'd say - got foot controllers going and some little hand ones are welcome - also for live applications.


cheers for the efforts

Last edited by BenK-msx; 08-21-2009 at 06:17 PM.
BenK-msx is offline   Reply With Quote
Old 08-24-2009, 05:36 AM   #3
politcat
Human being with feelings
 
politcat's Avatar
 
Join Date: Jul 2006
Location: stuck in transition
Posts: 1,870
Default

Quote:
Originally Posted by zenmonkey View Post
Two days ago I was at Fry's electronics and saw this little controller for $15. I remembered seeing Reaper 3 had joystick support so I figured I'd give it a go...
i'm assuming the sticks don't spring back to the center on that little controller, correct?
politcat is offline   Reply With Quote
Old 08-24-2009, 07:27 AM   #4
Reverbio
Human being with feelings
 
Reverbio's Avatar
 
Join Date: Mar 2008
Posts: 168
Default

that's cool
Reverbio is offline   Reply With Quote
Old 08-24-2009, 07:47 AM   #5
zenmonkey
Human being with feelings
 
zenmonkey's Avatar
 
Join Date: Jun 2007
Location: Texas
Posts: 109
Default

Quote:
Originally Posted by politcat View Post
i'm assuming the sticks don't spring back to the center on that little controller, correct?
They do. That's why I made buttons 9 and 10 freeze/unfreeze. It allows you to move the joystick, hit the button and the value you were holding remain unchanged.

It's very difficult to find compact joysticks that aren't self-centering. The only ones I know of are the doepfer ones and they're very expensive (about $70 for just the joystick, another 12 for the rod, and that doesn't include the circuit to send midi).

At first I thought the self-centering would be limiting too but now that I've used it with freeze/unfreeze I actually like it. Especially having modwheel and channel pressure on the same joystick adds a lot of variability under my right thumb.
zenmonkey is offline   Reply With Quote
Old 08-24-2009, 08:18 AM   #6
politcat
Human being with feelings
 
politcat's Avatar
 
Join Date: Jul 2006
Location: stuck in transition
Posts: 1,870
Default

ah ha. I see

nice job and thx!
politcat is offline   Reply With Quote
Old 08-30-2009, 07:40 AM   #7
zenmonkey
Human being with feelings
 
zenmonkey's Avatar
 
Join Date: Jun 2007
Location: Texas
Posts: 109
Default

Quote:
Originally Posted by politcat View Post
ah ha. I see

nice job and thx!
Glad you like it, I hope you and others find it useful.
zenmonkey is offline   Reply With Quote
Old 09-03-2009, 08:35 AM   #8
zenmonkey
Human being with feelings
 
zenmonkey's Avatar
 
Join Date: Jun 2007
Location: Texas
Posts: 109
Default

I purchased a much better quality controller, a Saitek P3200 Rumble for the ridiculously low price of $6.20 from Amazon.com.

This controller is different in how it maps its axes.

Reaper sees 5 axes now:

0,1 are Joy 0
2 is linked to the two analog triggers on the side (left is mid -> max, right is mid -> zero), seen as Z
3,4 are Joy 1, seen as R and U

I'll update the script in the zip to fix the layout with this controller.

This controller's joysticks are *much* more reliable than the Logitech and need no threshold adjustments. Highly recommended.
zenmonkey is offline   Reply With Quote
Old 12-19-2009, 05:08 AM   #9
cygnus
Human being with feelings
 
cygnus's Avatar
 
Join Date: Dec 2009
Posts: 12
Default

Quote:
Originally Posted by zenmonkey View Post
They do. That's why I made buttons 9 and 10 freeze/unfreeze. It allows you to move the joystick, hit the button and the value you were holding remain unchanged.

It's very difficult to find compact joysticks that aren't self-centering. The only ones I know of are the doepfer ones and they're very expensive (about $70 for just the joystick, another 12 for the rod, and that doesn't include the circuit to send midi).

At first I thought the self-centering would be limiting too but now that I've used it with freeze/unfreeze I actually like it. Especially having modwheel and channel pressure on the same joystick adds a lot of variability under my right thumb.
Just a thought - couldn't you just pull your controllers apart, and remove the offending springs?
cygnus is offline   Reply With Quote
Old 12-19-2009, 10:29 AM   #10
zenmonkey
Human being with feelings
 
zenmonkey's Avatar
 
Join Date: Jun 2007
Location: Texas
Posts: 109
Default

Quote:
Originally Posted by cygnus View Post
Just a thought - couldn't you just pull your controllers apart, and remove the offending springs?
Belive me, I tried and I'm fairly decent with a soldering iron. The problem is with how these small joysticks are constructed. They have a large metal flashing on the exterior of the joystick that's been wave-soldered down. I ruined 2 gamepads trying to carefully de-solder this flashing and removing the bent metal strip that acts as the spring.

The first one didn't work when I re-soldered it and the second one the joystick wouldn't stay still, it just flopped to one corner. I came to the conclusion these cheap sticks were never meant to be springless.

I'd really love a joystick option like that though, both spring and springless have their uses.
zenmonkey is offline   Reply With Quote
Old 12-19-2009, 12:40 PM   #11
socrates112
Human being with feelings
 
socrates112's Avatar
 
Join Date: Dec 2009
Posts: 170
Default

what is an expression controller?
socrates112 is offline   Reply With Quote
Old 12-20-2009, 01:50 AM   #12
cygnus
Human being with feelings
 
cygnus's Avatar
 
Join Date: Dec 2009
Posts: 12
Default

Quote:
Originally Posted by zenmonkey View Post
Belive me, I tried and I'm fairly decent with a soldering iron. The problem is with how these small joysticks are constructed. They have a large metal flashing on the exterior of the joystick that's been wave-soldered down. I ruined 2 gamepads trying to carefully de-solder this flashing and removing the bent metal strip that acts as the spring.

The first one didn't work when I re-soldered it and the second one the joystick wouldn't stay still, it just flopped to one corner. I came to the conclusion these cheap sticks were never meant to be springless.

I'd really love a joystick option like that though, both spring and springless have their uses.
I see - hadn't got that far myself, but I don't got a plethora of spare gear 'round the place, and I ain't so flash with a soldering iron. I've only pulled apart much older, simpler, and more forgiving gear, and that was a long time ago...
cygnus is offline   Reply With Quote
Old 09-27-2009, 02:54 PM   #13
corazon
Human being with feelings
 
Join Date: Jan 2008
Posts: 125
Default

This will be a great October project for me. Thanks for sharing
your knowlege and skill! Reaper community is always innovating and cool.
corazon is offline   Reply With Quote
Old 09-27-2009, 03:20 PM   #14
zenmonkey
Human being with feelings
 
zenmonkey's Avatar
 
Join Date: Jun 2007
Location: Texas
Posts: 109
Default

Quote:
Originally Posted by corazon View Post
This will be a great October project for me. Thanks for sharing
your knowlege and skill! Reaper community is always innovating and cool.
Thanks for posting, I hope you like it! Feedback is always appreciated too.
zenmonkey is offline   Reply With Quote
Old 10-14-2009, 12:19 PM   #15
raintalk
Human being with feelings
 
Join Date: Oct 2007
Posts: 4
Default I just ran across this thread = Amazing!

Zenmonkey you are Amazing
I was looking at the Axis-49 and now it looks like you've got a complete solution for me.

I'm going to squeeze out some funds and try to get this going for me. It will be a while before I have the cash, but at least now I know I'm heading in the right direction.

I'm left handed and this will work beautifully.

Thank You!
raintalk is offline   Reply With Quote
Old 10-14-2009, 12:52 PM   #16
zenmonkey
Human being with feelings
 
zenmonkey's Avatar
 
Join Date: Jun 2007
Location: Texas
Posts: 109
Default

Quote:
Originally Posted by raintalk View Post
Zenmonkey you are Amazing
I was looking at the Axis-49 and now it looks like you've got a complete solution for me.

I'm going to squeeze out some funds and try to get this going for me. It will be a while before I have the cash, but at least now I know I'm heading in the right direction.

I'm left handed and this will work beautifully.

Thank You!
Thank you for the kind words my friend.

If you have any suggestions I'd like to hear them. I love the combination of the Axis-49 and the P3200. Now if I could just find the time to practice more so my playing wasn't so poor...
zenmonkey is offline   Reply With Quote
Old 12-19-2009, 05:03 AM   #17
cygnus
Human being with feelings
 
cygnus's Avatar
 
Join Date: Dec 2009
Posts: 12
Default

hey, zenmonkey! Your custom script has much more incomprehensible jargon in it than the generic one, and I'm even more confused having looked through it(plus it makes my generic controllers do wierd stuff). Any chance you could point me in the right direction as to how I might go about separating my two gamepads to individual midi channels? My needs regarding gamepad control are relatively unsophisticated, and the basic functionality enabled by the generic script does the job for me, but for being able to assign a separate midi channel for each controller(each one with its own instrument). I don't need to be able to change channels on the fly, just have each one assigned to its own channel. This one's got me stumped, and any help/info' would be greatly appreciated. Cygnus....
cygnus is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 08:20 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.