Joystick Plugin: adding throttle support to control volume
Mike Swieton <[email protected]>
| Newsgroups | gmane.comp.multimedia.xmms.devel |
|---|---|
| Message-ID | <[email protected]> |
Earlier this morning it occured to me that I should be able to use the throttle on my joystick to control the volume. I wrote a quick hack to make it work, which I've attached. This does not patch the GUI at all, and all constants are hardcoded. Sorry, but I do not have the time to learn GTK to do it right, but maybe someone else here does. Attached is a small C source file which has my changes. Insert the code into the XMMS source file General/joystick/joy.c between the "}" and the "break;" near line 258, to add support for the first joystick (The plugin supports two joysticks). If you want a second joystick supported, you may paste it into the line 291 (this line looks just like the first. You'll have to do a bit of work to make this run. The directions are at the top of the attached snippet. This code is public domain. Have fun, guys! Mike Swieton -- The perversity of the Universe tends towards a maximum. - O'Tool's Corollary of Finagle's Law
throttle.c
(text/plain, 2.1 KB)
/* MKS - Begin throttle volume support */ /* THIS CODE IS PLACED IN THE PUBLIC DOMAIN. The original author is Michael Swieton, who may be contacted via email at [email protected] */ /* DIRECTIONS: *************************/ /* First: uncomment the printf statement at the bottom. This will help you find * out what axis number your throttle uses, and also its range. When you have * these numbers, I advise you to comment out that line again. Performance may * suffer if you don't. * Second: Set the range values below where noted. Note * that the maximum CAN be less that the minimum: it is the value at which you * want the throttle to represent full volume. */ /***************************************/ else if (js.number == 3) { /* Range of the joystick's throttle */ gint max=-13000; gint min= 13000; /* The current value of the throttle */ gint val=js.value; /* The calculated volume */ gint volume; gboolean swapped = FALSE; /* The maximums and minimums on my joystick seem * rather arbitrary. These two if's simplify things * by making minimum zero and maximum whatever and * ensures that the reading is in the same relative * position in the middle. We'll swap it back later * if they are backwards, so the throttle changes * things in the right direction. */ if (max < min) { int tmp=max; max = min; min = tmp; swapped = TRUE; } if (min < 0) { max += -1*min; val += -1*min; min = 0; } /* Clip the throttle value */ if (val < min) val = min; else if (val > max) val = max; /* Calculate and clip the final volume */ volume = (int)((double)val/max * 100.0); if (volume < 0) volume = 0; else if (volume > 100) volume = 100; /* If our max and min are reversed, re-reverse it */ if (swapped) volume = 100 - volume; /* Do it, mofo */ xmms_remote_set_main_volume (joy_gp.xmms_session, (gint)volume); } /* The below line can be used to help determine what * axis number your throttle is and what its range is. * It is recommended that this code be commented out * before regular use, however */ /* printf ("Axis %d: Value: %d\n", js.number, js.value); */ /* MKS - End throttle volume support */