Update of /cvsroot/pure-data/externals/deprecated In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17141/deprecated
Added Files: Makefile linuxevent.c linuxhid.h linuxmouse.c pan_gogins~.c range.c Log Message: cleaned up buildsrc and unfiltered sections and turned them into libdirs; made 'pan' libdir and cleaned up source dir for easy makefile install rules; created 'deprecated' libdir and moved cruft there
--- NEW FILE: range.c --- /* ------------------------- range ------------------------------------------ */ /* */ /* Ranges input to lie within an output range. */ /* Written by Olaf Matthes olaf.matthes@gmx.de */ /* Get source at http://www.akustische-kunst.org/puredata/maxlib/ */ /* */ /* This program is free software; you can redistribute it and/or */ /* modify it under the terms of the GNU General Public License */ /* as published by the Free Software Foundation; either version 2 */ /* of the License, or (at your option) any later version. */ /* */ /* This program is distributed in the hope that it will be useful, */ /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ /* GNU General Public License for more details. */ /* */ /* You should have received a copy of the GNU General Public License */ /* along with this program; if not, write to the Free Software */ /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* */ /* Based on PureData by Miller Puckette and others. */ /* */ /* ---------------------------------------------------------------------------- */
#include "m_pd.h" #include <stdio.h> #include <math.h>
static char *version = "range v0.2, written by Olaf Matthes olaf.matthes@gmx.de";
typedef struct range { t_object x_ob; t_float x_f; /* current input value */ t_float x_il; /* low border of input range */ t_float x_ih; /* high border of input range */ t_float x_ol; /* low border of output range */ t_float x_oh; /* high border of output range */ t_float x_logcoeff; /* log-coefficient */ t_outlet *x_outlet1; /* result */ } t_range;
static void range_float(t_range *x, t_floatarg f) { t_float ir = x->x_ih - x->x_il; t_float or = x->x_oh - x->x_ol; double oq; double result; double k; if(ir == 0) { post("range: input range must not be 0"); return; } /* we accept an output range of 0 in case someone really wants this */ if(!x->x_logcoeff) /* linear */ { k = (or / ir); result = ((f - x->x_il) * k) + x->x_ol; } else /* logarythmical range */ { oq = x->x_oh / x->x_ol; // k = (log((double)oq)/log(x->x_logcoeff))/((double)ir); k = log((double)oq)/((double)ir);
if(x->x_ol) { // result = (double)x->x_ol*exp(k*(double)(f - x->x_il)*log(x->x_logcoeff)); result = (double)x->x_ol*exp(k*(double)(f - x->x_il)); } else { /* in case the low output is 0 we have to cheat... */ /* okay, here's the chating: we calculate for a lower out limit of 1 and remove this shift after the calculation */ result = ((double)(x->x_ol+1)*exp(k*(double)(f - x->x_il)))-1.0; } }
x->x_f = f; /* save current input value */
outlet_float(x->x_outlet1, result); }
static void range_bang(t_range *x) { range_float(x, x->x_f); /* recalculate result */ }
static t_class *range_class;
static void *range_new(t_floatarg fil, t_floatarg fih, t_floatarg fol, t_floatarg foh, t_floatarg flc) { t_range *x = (t_range *)pd_new(range_class);
floatinlet_new(&x->x_ob, &x->x_il); floatinlet_new(&x->x_ob, &x->x_ih); floatinlet_new(&x->x_ob, &x->x_ol); floatinlet_new(&x->x_ob, &x->x_oh); floatinlet_new(&x->x_ob, &x->x_logcoeff);
x->x_outlet1 = outlet_new(&x->x_ob, gensym("float"));
/* default values taken from Max's range */ x->x_il = fil; x->x_ih = fih; if(!x->x_ih)x->x_ih = 127.0; x->x_ol = fol; x->x_oh = foh; if(!x->x_oh)x->x_oh = 1.0; x->x_logcoeff = flc; x->x_f = 0;
post(version);
return (void *)x; }
void range_setup(void) { range_class = class_new(gensym("range"), (t_newmethod)range_new, 0, sizeof(t_range), 0, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0); class_addfloat(range_class, range_float); class_addbang(range_class, range_bang); class_sethelpsymbol(range_class, gensym("range.pd")); }
--- NEW FILE: linuxhid.h ---
#ifdef __gnu_linux__ #include <linux/input.h> #endif #ifndef NT #include <sys/ioctl.h> #endif
#include <sys/stat.h> #include <string.h> #include <sys/time.h> #include <sys/types.h> #include <sys/fcntl.h> #include <unistd.h>
#define DEBUG(x) //#define DEBUG(x) x
#define DEFAULT_DELAY 5
/*------------------------------------------------------------------------------ * from evtest.c from the ff-utils package */
#define BITS_PER_LONG (sizeof(long) * 8) #define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1) #define OFF(x) ((x)%BITS_PER_LONG) #define BIT(x) (1UL<<OFF(x)) #define LONG(x) ((x)/BITS_PER_LONG) #define test_bit(bit, array) ((array[LONG(bit)] >> OFF(bit)) & 1)
#ifdef __gnu_linux__ char *events[EV_MAX + 1] = { "Reset", "Key", "Relative", "Absolute", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "LED", "Sound", NULL, "Repeat", "ForceFeedback", NULL, "ForceFeedbackStatus"}; char *keys[KEY_MAX + 1] = { "Reserved", "Esc", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "Minus", "Equal", "Backspace", "Tab", "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "LeftBrace", "RightBrace", "Enter", "LeftControl", "A", "S", "D", "F", "G", "H", "J", "K", "L", "Semicolon", "Apostrophe", "Grave", "LeftShift", "BackSlash", "Z", "X", "C", "V", "B", "N", "M", "Comma", "Dot", "Slash", "RightShift", "KPAsterisk", "LeftAlt", "Space", "CapsLock", "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "NumLock", "ScrollLock", "KP7", "KP8", "KP9", "KPMinus", "KP4", "KP5", "KP6", "KPPlus", "KP1", "KP2", "KP3", "KP0", "KPDot", "103rd", "F13", "102nd", "F11", "F12", "F14", "F15", "F16", "F17", "F18", "F19", "F20", "KPEnter", "RightCtrl", "KPSlash", "SysRq", "RightAlt", "LineFeed", "Home", "Up", "PageUp", "Left", "Right", "End", "Down", "PageDown", "Insert", "Delete", "Macro", "Mute", "VolumeDown", "VolumeUp", "Power", "KPEqual", "KPPlusMinus", "Pause", "F21", "F22", "F23", "F24", "KPComma", "LeftMeta", "RightMeta", "Compose", "Stop", "Again", "Props", "Undo", "Front", "Copy", "Open", "Paste", "Find", "Cut", "Help", "Menu", "Calc", "Setup", "Sleep", "WakeUp", "File", "SendFile", "DeleteFile", "X-fer", "Prog1", "Prog2", "WWW", "MSDOS", "Coffee", "Direction", "CycleWindows", "Mail", "Bookmarks", "Computer", "Back", "Forward", "CloseCD", "EjectCD", "EjectCloseCD", "NextSong", "PlayPause", "PreviousSong", "StopCD", "Record", "Rewind", "Phone", "ISOKey", "Config", "HomePage", "Refresh", "Exit", "Move", "Edit", "ScrollUp", "ScrollDown", "KPLeftParenthesis", "KPRightParenthesis", "International1", "International2", "International3", "International4", "International5", "International6", "International7", "International8", "International9", "Language1", "Language2", "Language3", "Language4", "Language5", "Language6", "Language7", "Language8", "Language9", NULL, "PlayCD", "PauseCD", "Prog3", "Prog4", "Suspend", "Close", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "Btn0", "Btn1", "Btn2", "Btn3", "Btn4", "Btn5", "Btn6", "Btn7", "Btn8", "Btn9", NULL, NULL, NULL, NULL, NULL, NULL, "LeftBtn", "RightBtn", "MiddleBtn", "SideBtn", "ExtraBtn", "ForwardBtn", "BackBtn", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "Trigger", "ThumbBtn", "ThumbBtn2", "TopBtn", "TopBtn2", "PinkieBtn", "BaseBtn", "BaseBtn2", "BaseBtn3", "BaseBtn4", "BaseBtn5", "BaseBtn6", NULL, NULL, NULL, "BtnDead", "BtnA", "BtnB", "BtnC", "BtnX", "BtnY", "BtnZ", "BtnTL", "BtnTR", "BtnTL2", "BtnTR2", "BtnSelect", "BtnStart", "BtnMode", "BtnThumbL", "BtnThumbR", NULL, "ToolPen", "ToolRubber", "ToolBrush", "ToolPencil", "ToolAirbrush", "ToolFinger", "ToolMouse", "ToolLens", NULL, NULL, "Touch", "Stylus", "Stylus2" };
char *absval[5] = { "Value", "Min ", "Max ", "Fuzz ", "Flat " }; char *relatives[REL_MAX + 1] = { "X", "Y", "Z", NULL, NULL, NULL, "HWheel", "Dial", "Wheel" }; char *absolutes[ABS_MAX + 1] = { "X", "Y", "Z", "Rx", "Ry", "Rz", "Throttle", "Rudder", "Wheel", "Gas", "Brake", NULL, NULL, NULL, NULL, NULL, "Hat0X", "Hat0Y", "Hat1X", "Hat1Y", "Hat2X", "Hat2Y", "Hat3X", "Hat 3Y", "Pressure", "Distance", "XTilt", "YTilt"}; char *leds[LED_MAX + 1] = { "NumLock", "CapsLock", "ScrollLock", "Compose", "Kana", "Sleep", "Suspend", "Mute" }; char *repeats[REP_MAX + 1] = { "Delay", "Period" }; char *sounds[SND_MAX + 1] = { "Bell", "Click" };
char **names[EV_MAX + 1] = { events, keys, relatives, absolutes, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, leds, sounds, NULL, repeats, NULL, NULL, NULL };
#endif
/*------------------------------------------------------------------------------ */
--- NEW FILE: linuxevent.c --- #include <m_pd.h>
#include "linuxhid.h"
#define LINUXEVENT_DEVICE "/dev/input/event0"
static char *version = "$Revision: 1.1 $";
/*------------------------------------------------------------------------------ * CLASS DEF */ static t_class *linuxevent_class;
typedef struct _linuxevent { t_object x_obj; t_int x_fd; t_symbol *x_devname; t_clock *x_clock; int x_read_ok; int x_started; int x_delay; #ifdef __gnu_linux__ struct input_event x_input_event; #endif t_outlet *x_input_event_time_outlet; t_outlet *x_input_event_type_outlet; t_outlet *x_input_event_code_outlet; t_outlet *x_input_event_value_outlet; }t_linuxevent;
/*------------------------------------------------------------------------------ * IMPLEMENTATION */
void linuxevent_stop(t_linuxevent* x) { DEBUG(post("linuxevent_stop"););
if (x->x_fd >= 0 && x->x_started) { clock_unset(x->x_clock); post("linuxevent: polling stopped"); x->x_started = 0; } }
static int linuxevent_close(t_linuxevent *x) { DEBUG(post("linuxevent_close"););
/* just to be safe, stop it first */ linuxevent_stop(x);
if (x->x_fd <0) return 0; close (x->x_fd); post ("[linuxevent] closed %s",x->x_devname->s_name); return 1; }
static int linuxevent_open(t_linuxevent *x, t_symbol *s) { int eventType, eventCode, buttons, rel_axes, abs_axes, ff; #ifdef __gnu_linux__ unsigned long bitmask[EV_MAX][NBITS(KEY_MAX)]; #endif char devicename[256] = "Unknown"; DEBUG(post("linuxevent_open");)
linuxevent_close(x);
/* set obj device name to parameter * otherwise set to default */ if (s != &s_) x->x_devname = s;
#ifdef __gnu_linux__ /* open device */ if (x->x_devname) { /* open the device read-only, non-exclusive */ x->x_fd = open (x->x_devname->s_name, O_RDONLY | O_NONBLOCK); /* test if device open */ if (x->x_fd < 0 ) { post("[linuxevent] open %s failed",x->x_devname->s_name); x->x_fd = -1; return 0; } } else return 1;
/* read input_events from the LINUXEVENT_DEVICE stream * It seems that is just there to flush the event input buffer? */ while (read (x->x_fd, &(x->x_input_event), sizeof(struct input_event)) > -1);
/* get name of device */ ioctl(x->x_fd, EVIOCGNAME(sizeof(devicename)), devicename); post ("Configuring %s on %s",devicename,x->x_devname->s_name);
/* get bitmask representing supported events (axes, buttons, etc.) */ memset(bitmask, 0, sizeof(bitmask)); ioctl(x->x_fd, EVIOCGBIT(0, EV_MAX), bitmask[0]); post("\nSupported events:");
rel_axes = 0; abs_axes = 0; buttons = 0; ff = 0;
/* cycle through all possible event types */ for (eventType = 0; eventType < EV_MAX; eventType++) { if (test_bit(eventType, bitmask[0])) { post(" %s (type %d) ", events[eventType] ? events[eventType] : "?", eventType); // post("Event type %d",eventType);
/* get bitmask representing supported button types */ ioctl(x->x_fd, EVIOCGBIT(eventType, KEY_MAX), bitmask[eventType]);
/* cycle through all possible event codes (axes, keys, etc.) * testing to see which are supported */ for (eventCode = 0; eventCode < KEY_MAX; eventCode++) if (test_bit(eventCode, bitmask[eventType])) { post(" Event code %d (%s)", eventCode, names[eventType] ? (names[eventType][eventCode] ? names[eventType][eventCode] : "?") : "?");
switch(eventType) { // the API changed at some point... #ifdef EV_RST case EV_RST: #else case EV_SYN: #endif break; case EV_KEY: buttons++; break; case EV_REL: rel_axes++; break; case EV_ABS: abs_axes++; break; case EV_MSC: break; case EV_LED: break; case EV_SND: break; case EV_REP: break; case EV_FF: ff++; break; } } } }
post ("\nUsing %d relative axes, %d absolute axes, and %d buttons.", rel_axes, abs_axes, buttons); if (ff > 0) post ("Detected %d force feedback types",ff); post ("\nWARNING * WARNING * WARNING * WARNING * WARNING * WARNING * WARNING"); post ("This object is under development! The interface could change at anytime!"); post ("As I write cross-platform versions, the interface might have to change."); post ("WARNING * WARNING * WARNING * WARNING * WARNING * WARNING * WARNING\n"); #endif
return 1; }
static int linuxevent_read(t_linuxevent *x,int fd) { if (x->x_fd < 0) return 0;
#ifdef __gnu_linux__ while (read (x->x_fd, &(x->x_input_event), sizeof(struct input_event)) > -1) { outlet_float (x->x_input_event_value_outlet, (int)x->x_input_event.value); outlet_float (x->x_input_event_code_outlet, x->x_input_event.code); outlet_float (x->x_input_event_type_outlet, x->x_input_event.type); /* input_event.time is a timeval struct from <sys/time.h> */ /* outlet_float (x->x_input_event_time_outlet, x->x_input_event.time); */ } #endif
if (x->x_started) { clock_delay(x->x_clock, x->x_delay); }
return 1; }
/* Actions */ static void linuxevent_float(t_linuxevent* x) { DEBUG(post("linuxevent_float");)
}
void linuxevent_delay(t_linuxevent* x, t_float f) { DEBUG(post("linuxevent_DELAY %f",f);) /* if the user sets the delay less than zero, reset to default */ if ( f > 0 ) { x->x_delay = (int)f; } else { x->x_delay = DEFAULT_DELAY; } }
void linuxevent_start(t_linuxevent* x) { DEBUG(post("linuxevent_start"););
if (x->x_fd >= 0 && !x->x_started) { clock_delay(x->x_clock, DEFAULT_DELAY); post("linuxevent: polling started"); x->x_started = 1; } else { post("You need to set a input device (i.e /dev/input/event0)"); } }
/* setup functions */ static void linuxevent_free(t_linuxevent* x) { DEBUG(post("linuxevent_free");)
if (x->x_fd < 0) return;
linuxevent_stop(x); clock_free(x->x_clock); close (x->x_fd); }
static void *linuxevent_new(t_symbol *s) { int i; t_linuxevent *x = (t_linuxevent *)pd_new(linuxevent_class);
DEBUG(post("linuxevent_new");)
post("[linuxevent] %s, written by Hans-Christoph Steiner hans@eds.org",version); #ifndef __linux__ post(" !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !!"); post(" This is a dummy, since this object only works with a Linux kernel!"); post(" !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !!"); #endif
/* init vars */ x->x_fd = -1; x->x_read_ok = 1; x->x_started = 0; x->x_delay = DEFAULT_DELAY; x->x_devname = gensym(LINUXEVENT_DEVICE);
x->x_clock = clock_new(x, (t_method)linuxevent_read);
/* create outlets for each axis */ x->x_input_event_time_outlet = outlet_new(&x->x_obj, &s_float); x->x_input_event_type_outlet = outlet_new(&x->x_obj, &s_float); x->x_input_event_code_outlet = outlet_new(&x->x_obj, &s_float); x->x_input_event_value_outlet = outlet_new(&x->x_obj, &s_float);
/* set to the value from the object argument, if that exists */ if (s != &s_) x->x_devname = s;
/* Open the device and save settings */
if (!linuxevent_open(x,s)) return x;
return (x); }
void linuxevent_setup(void) { DEBUG(post("linuxevent_setup");) linuxevent_class = class_new(gensym("linuxevent"), (t_newmethod)linuxevent_new, (t_method)linuxevent_free, sizeof(t_linuxevent),0,A_DEFSYM,0);
/* add inlet datatype methods */ class_addfloat(linuxevent_class,(t_method) linuxevent_float); class_addbang(linuxevent_class,(t_method) linuxevent_read);
/* add inlet message methods */ class_addmethod(linuxevent_class,(t_method) linuxevent_delay,gensym("delay"),A_DEFFLOAT,0); class_addmethod(linuxevent_class,(t_method) linuxevent_open,gensym("open"),A_DEFSYM,0); class_addmethod(linuxevent_class,(t_method) linuxevent_close,gensym("close"),0); class_addmethod(linuxevent_class,(t_method) linuxevent_start,gensym("start"),0); class_addmethod(linuxevent_class,(t_method) linuxevent_start,gensym("poll"),0); class_addmethod(linuxevent_class,(t_method) linuxevent_stop,gensym("stop"),0); class_addmethod(linuxevent_class,(t_method) linuxevent_stop,gensym("nopoll"),0); }
--- NEW FILE: Makefile --- TARGET := $(shell pwd | sed 's|.*/(.*)$$|\1|') EXTERNALS_ROOT := $(shell pwd | sed 's|^(/.*externals).*|\1|')
default: make -C $(EXTERNALS_ROOT) $(TARGET)
install: make -C $(EXTERNALS_ROOT) $(TARGET)_install
clean: make -C $(EXTERNALS_ROOT) $(TARGET)_clean
test_locations: make -C $(EXTERNALS_ROOT) test_locations
etags: etags *.[ch] ~/cvs/pure-data/pd/src/*.[ch] /usr/include/*.h /usr/include/sys/*.h
--- NEW FILE: linuxmouse.c --- #include <m_pd.h>
#ifdef PD_MAJOR_VERSION #include "s_stuff.h" #else #include "m_imp.h" #endif
#include "linuxhid.h"
#define LINUXMOUSE_DEVICE "/dev/input/event0" #define LINUXMOUSE_AXES 3
static char *version = "$Revision: 1.1 $";
/*------------------------------------------------------------------------------ * CLASS DEF */ static t_class *linuxmouse_class;
typedef struct _linuxmouse { t_object x_obj; t_int x_fd; t_symbol *x_devname; int x_read_ok; int x_started; #ifdef __gnu_linux__ struct input_event x_input_event; #endif t_outlet *x_axis_out[LINUXMOUSE_AXES]; t_outlet *x_button_num_out; t_outlet *x_button_val_out; unsigned char x_buttons; unsigned char x_axes; } t_linuxmouse;
/*------------------------------------------------------------------------------ * IMPLEMENTATION */
/* Actions */ void linuxmouse_stop(t_linuxmouse* x) { DEBUG(post("linuxmouse_stop"););
#ifdef __gnu_linux__ if (x->x_fd >= 0 && x->x_started) { sys_rmpollfn(x->x_fd); post("[linuxmouse] stopped"); x->x_started = 0; } #endif }
static int linuxmouse_close(t_linuxmouse *x) { DEBUG(post("linuxmouse_close"););
/* just to be safe, stop it first */ linuxmouse_stop(x); if (x->x_fd < 0) { return 0; } else { close (x->x_fd); post ("[linuxmouse] closed %s",x->x_devname->s_name); return 1; } }
static int linuxmouse_open(t_linuxmouse *x, t_symbol *s) { int eventType, eventCode; char devicename[256] = "Unknown"; #ifdef __gnu_linux__ unsigned long bitmask[EV_MAX][NBITS(KEY_MAX)]; #endif DEBUG(post("linuxmouse_open");); linuxmouse_close(x); /* set obj device name to parameter otherwise set to default */ if ( s != &s_ ) x->x_devname = s; #ifdef __gnu_linux__ /* open device */ if (x->x_devname) { /* open the device read-only, non-exclusive */ x->x_fd = open (x->x_devname->s_name, O_RDONLY | O_NONBLOCK); /* test if device open */ if (x->x_fd < 0 ) { post("[linuxmouse] open %s failed",x->x_devname->s_name); x->x_fd = -1; return 0; } } else { post("[linuxmouse] no device set: %s",x->x_devname->s_name); return 1; } /* read input_events from the LINUXMOUSE_DEVICE stream * It seems that is just there to flush the event input buffer? */ while (read (x->x_fd, &(x->x_input_event), sizeof(struct input_event)) > -1); /* get name of device */ ioctl(x->x_fd, EVIOCGNAME(sizeof(devicename)), devicename); post ("Configuring %s on %s.",devicename,x->x_devname->s_name); post("\nSupported events:");
/* get bitmask representing supported events (axes, buttons, etc.) */ memset(bitmask, 0, sizeof(bitmask)); ioctl(x->x_fd, EVIOCGBIT(0, EV_MAX), bitmask[0]); x->x_axes = 0; x->x_buttons = 0; /* cycle through all possible event types */ for (eventType = 0; eventType < EV_MAX; eventType++) { if (test_bit(eventType, bitmask[0])) { post(" %s (type %d) ", events[eventType] ? events[eventType] : "?", eventType); // post("Event type %d",eventType); /* get bitmask representing supported button types */ ioctl(x->x_fd, EVIOCGBIT(eventType, KEY_MAX), bitmask[eventType]); /* cycle through all possible event codes (axes, keys, etc.) * testing to see which are supported */ for (eventCode = 0; eventCode < KEY_MAX; eventCode++) { if (test_bit(eventCode, bitmask[eventType])) { post(" Event code %d (%s)", eventCode, names[eventType] ? (names[eventType][eventCode] ? names[eventType][eventCode] : "?") : "?"); if ( eventType == EV_KEY ) x->x_buttons++; else if ( eventType == EV_REL ) x->x_axes++; } } } } post ("\nUsing %d axes and %d buttons.", x->x_axes, x->x_buttons); post ("\nWARNING * WARNING * WARNING * WARNING * WARNING * WARNING * WARNING"); post ("This object is under development! The interface could change at anytime!"); post ("As I write cross-platform versions, the interface might have to change."); post ("WARNING * WARNING * WARNING * WARNING * WARNING * WARNING * WARNING\n"); #endif return 1; }
static int linuxmouse_read(t_linuxmouse *x,int fd) { int axis_num = 0; t_float button_num = 0; if (x->x_fd < 0) return 0; #ifdef __gnu_linux__ while (read (x->x_fd, &(x->x_input_event), sizeof(struct input_event)) > -1) { if ( x->x_input_event.type == EV_REL ) { /* Relative Axes Event Type */ switch ( x->x_input_event.code ) { case REL_X: axis_num = 0; break; case REL_Y: axis_num = 1; break; case REL_WHEEL: axis_num = 2; break; } outlet_float (x->x_axis_out[axis_num], (int)x->x_input_event.value); } else if ( x->x_input_event.type == EV_KEY ) { /* key/button event type */ switch ( x->x_input_event.code ) { case BTN_LEFT: button_num = 0; break; case BTN_RIGHT: button_num = 1; break; case BTN_MIDDLE: button_num = 2; break; case BTN_SIDE: button_num = 3; break; case BTN_EXTRA: button_num = 4; break; case BTN_FORWARD: button_num = 5; break; case BTN_BACK: button_num = 6; break; } outlet_float (x->x_button_val_out, x->x_input_event.value); outlet_float (x->x_button_num_out, button_num); } } #endif
return 1; }
void linuxmouse_start(t_linuxmouse* x) { DEBUG(post("linuxmouse_start"););
/* if the device isn't open already, open it */ /* (I'll test this later -HCS) */ /* if (x->x_fd < 0) linuxmouse_open(x,&s_); */ #ifdef __gnu_linux__ if (x->x_fd >= 0 && !x->x_started) { sys_addpollfn(x->x_fd, (t_fdpollfn)linuxmouse_read, x); post("[linuxmouse] started"); x->x_started = 1; } else { post("You need to set a input device (i.e /dev/input/event0)"); } #endif }
/* setup functions */ static void linuxmouse_free(t_linuxmouse* x) { DEBUG(post("linuxmouse_free"););
if (x->x_fd < 0) return; linuxmouse_stop(x); close (x->x_fd); }
static void *linuxmouse_new(t_symbol *s) { int i; t_linuxmouse *x = (t_linuxmouse *)pd_new(linuxmouse_class); DEBUG(post("linuxmouse_new");); post("[linuxmouse] %s, written by Hans-Christoph Steiner hans@eds.org",version); #ifndef __gnu_linux__ post(" !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !!"); post(" This is a dummy, since this object only works with a Linux kernel!"); post(" !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !!"); #endif /* init vars */ x->x_fd = -1; x->x_read_ok = 1; x->x_started = 0; x->x_devname = gensym("/dev/input/event0");
/* create outlets for each axis */ for (i = 0; i < LINUXMOUSE_AXES; i++) x->x_axis_out[i] = outlet_new(&x->x_obj, &s_float); /* create outlets for buttons */ x->x_button_num_out = outlet_new(&x->x_obj, &s_float); x->x_button_val_out = outlet_new(&x->x_obj, &s_float);
if (!linuxmouse_open(x,s)) return x; return (x); }
void linuxmouse_setup(void) { DEBUG(post("linuxmouse_setup");); linuxmouse_class = class_new(gensym("linuxmouse"), (t_newmethod)linuxmouse_new, (t_method)linuxmouse_free, sizeof(t_linuxmouse), 0, A_DEFSYM, 0); /* add inlet message methods */ class_addmethod(linuxmouse_class,(t_method) linuxmouse_open,gensym("open"),A_DEFSYM,0); class_addmethod(linuxmouse_class,(t_method) linuxmouse_close,gensym("close"),0); class_addmethod(linuxmouse_class,(t_method) linuxmouse_start,gensym("start"),0); class_addmethod(linuxmouse_class,(t_method) linuxmouse_stop,gensym("stop"),0); class_addmethod(linuxmouse_class,(t_method) linuxmouse_start,gensym("poll"),0); class_addmethod(linuxmouse_class,(t_method) linuxmouse_stop,gensym("nopoll"),0); }
--- NEW FILE: pan_gogins~.c --- /*************************************************************************** * File: pan_gogins~.c (a quick hack of pan~.c) * Auth: Marco Scoffier [marco@metm.org] modified code by * Iain Mott [iain.mott@bigpond.com] * Maintainer (of pan~.c) : Iain Mott [iain.mott@bigpond.com] * Date: March 2003 * * Description: Pd signal external. Stereo panning implementing an * algorithm concieved by Michael Gogins and described at * http://www.csounds.com/ezine/autumn1999/beginners/ * Angle input specified in degrees. -45 left, 0 centre, 45 right. * See supporting Pd patch: pan_gogins~.pd * * Copyright (C) 2001 by Iain Mott [iain.mott@bigpond.com] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License, which should be included with this * program, for more details. * ****************************************************************************/
#include "m_pd.h" #include <math.h>
static t_class *pan_gogins_class; #define RADCONST 0.017453293 #define ROOT2DIV2 0.707106781 // PHASECONST = pi - pi/2 // as per http://www.csounds.com/ezine/autumn1999/beginners/ #define PHASECONST 1.570796327
typedef struct _pan_gogins { t_object x_obj; float x_f; float pan; float left; float right; } t_pan_gogins;
static void *pan_gogins_new(t_symbol *s, int argc, t_atom *argv) { t_pan_gogins *x = (t_pan_gogins *)pd_new(pan_gogins_class); outlet_new(&x->x_obj, gensym("signal")); outlet_new(&x->x_obj, gensym("signal")); inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("panf"));
x->x_f = 0; x->left = ROOT2DIV2; x->right = ROOT2DIV2; return (x); }
static t_int *pan_gogins_perform(t_int *w) { float *in1 = (t_float *)(w[1]); float *out1 = (t_float *)(w[2]); float *out2 = (t_float *)(w[3]); int n = (int)(w[4]); t_pan_gogins *x = (t_pan_gogins *)(w[5]); float value; while (n--) { value = *in1++; *out1++ = value * x->left; *out2++ = value * x->right; } return (w+6); }
static void pan_gogins_dsp(t_pan_gogins *x, t_signal **sp) { int n = sp[0]->s_n; float *in1 = sp[0]->s_vec; float *out1 = sp[1]->s_vec; float *out2 = sp[2]->s_vec;
dsp_add(pan_gogins_perform, 5, in1, out1, out2, n, x); }
void pan_gogins_f(t_pan_gogins *x, t_floatarg f) { double angle; f = f < -45 ? -45 : f; f = f > 45 ? 45 : f; angle = f * RADCONST * PHASECONST; // convert degrees to radians x->right = ROOT2DIV2 * (cos(angle) + sin(angle)); x->left = ROOT2DIV2 * (cos(angle) - sin(angle)); /* post("left = %f : right = %f", x->left, x->right); */ }
void pan_gogins_tilde_setup(void) { pan_gogins_class = class_new(gensym("pan_gogins~"), (t_newmethod)pan_gogins_new, 0, sizeof(t_pan_gogins), 0, A_GIMME, 0); class_addmethod(pan_gogins_class, nullfn, gensym("signal"), 0);
class_addmethod(pan_gogins_class, (t_method)pan_gogins_dsp, gensym("dsp"), 0); class_addmethod(pan_gogins_class, (t_method)pan_gogins_f, gensym("panf"), A_FLOAT, 0); }