Update of /cvsroot/pure-data/externals/hcs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24270
Added Files: keyboard_layout.c keyboard_layout-help.pd keyboard_layout.libs Log Message: ported f0.keyboard_layout to Pd, I commented out the 'assist' method because A_CANT is a mytery to me
--- NEW FILE: keyboard_layout.c --- /* Copyright 2006 Fredrik Olofsson * Copyright 2007 Free Software Foundation * ported to Pd by Hans-Christoph Steiner hans@at.or.at from f0.keyboard_layout.c */
#ifdef __APPLE__
#include "m_pd.h" #include <Carbon/Carbon.h>
static t_class *keyboard_layout_class;
typedef struct _keyboard_layout { t_object x_obj; t_outlet* x_data_outlet; t_outlet* x_status_outlet; } t_keyboard_layout;
/* void keyboard_layout_assist(t_keyboard_layout *x, Object *m, long msg, long arg, char *dst) { if(msg==ASSIST_INLET) { sprintf(dst, "bang to get current, symbol to set"); } else if(msg==ASSIST_OUTLET) { switch(arg) { case 0: sprintf(dst, "current keyboard layout (symbol)"); break; case 1: sprintf(dst, "dump outlet (for menu)"); break; } } } */
//---------------------------------------------------------------------------------------------- void keyboard_layout_bang(t_keyboard_layout *x) { //OSStatus err; KeyboardLayoutRef currentLayoutRef; CFStringRef keyboardName; char cKeyboardName[100]; KLGetCurrentKeyboardLayout(¤tLayoutRef); KLGetKeyboardLayoutProperty(currentLayoutRef, kKLName, (const void **)&keyboardName); CFStringGetCString(keyboardName, cKeyboardName, 100, kCFStringEncodingASCII); outlet_anything(x->x_data_outlet, gensym(cKeyboardName), 0, NULL); }
void keyboard_layout_menu(t_keyboard_layout *x) { //OSStatus err; KeyboardLayoutRef currentLayoutRef; CFStringRef keyboardName; char cKeyboardName[100]; CFIndex countOfLayouts; CFIndex i; t_atom name; // TODO this should probably output [menu clear( so other messages work too outlet_anything(x->x_status_outlet, gensym("clear"), 0, NULL); KLGetKeyboardLayoutCount(&countOfLayouts); for(i= 0; i<countOfLayouts; i++) { KLGetKeyboardLayoutAtIndex(i, ¤tLayoutRef); KLGetKeyboardLayoutProperty(currentLayoutRef, kKLName, (const void **)&keyboardName); CFStringGetCString(keyboardName, cKeyboardName, 100, kCFStringEncodingASCII); SETSYMBOL(&name, gensym(cKeyboardName)); // TODO this should probably output [menu append( so other messages work too outlet_anything(x->x_status_outlet, gensym("append"), 1, &name); } }
void keyboard_layout_anything(t_keyboard_layout *x, t_symbol *s, short argc, t_atom *argv) { //OSStatus err; KeyboardLayoutRef currentLayoutRef; CFStringRef keyboardName; char cKeyboardName[100]; keyboardName= CFStringCreateWithCString(NULL, s->s_name, kCFStringEncodingASCII); KLGetKeyboardLayoutWithName(keyboardName, ¤tLayoutRef); KLGetKeyboardLayoutProperty(currentLayoutRef, kKLName, (const void **)&keyboardName); CFStringGetCString(keyboardName, cKeyboardName, 100, kCFStringEncodingASCII); KLSetCurrentKeyboardLayout(currentLayoutRef); //outlet_anything(x->t_out, s, 0, NULL); keyboard_layout_bang(x); }
void *keyboard_layout_new(void) { t_keyboard_layout *x = (t_keyboard_layout *)pd_new(keyboard_layout_class);
x->x_data_outlet = outlet_new(&x->x_obj, &s_float); x->x_status_outlet = outlet_new(&x->x_obj, &s_symbol);
return (x); }
//---------------------------------------------------------------------------------------------- void keyboard_layout_setup(void) { keyboard_layout_class = class_new(gensym("keyboard_layout"), (t_newmethod)keyboard_layout_new, NULL, sizeof(t_keyboard_layout), 0, A_GIMME, 0); class_addbang(keyboard_layout_class, (t_method)keyboard_layout_bang); class_addanything(keyboard_layout_class, (t_method)keyboard_layout_anything);
class_addmethod(keyboard_layout_class, (t_method)keyboard_layout_menu, gensym("menu"), 0); // class_addmethod(keyboard_layout_class, (t_method)keyboard_layout_assist, // gensym("assist"), A_CANT, 0); post("f0.keyboard_layout v1.1-ub; distributed under GNU GPL license"); //target specific }
#else /* GNU/Linux and Windows */
void keyboard_layout_new(void) { post("f0.keyboard_layout v1.1-ub; distributed under GNU GPL license"); post("ERROR: this objectclass is currently only for Mac OS X"); }
void keyboard_layout_setup(void) { keyboard_layout_class = class_new(gensym("text"), (t_method)keyboard_layout_new, NULL, sizeof(t_keyboard_layout), 0, 0); }
#endif /* __APPLE__ */
--- NEW FILE: keyboard_layout-help.pd --- #N canvas 246 251 576 362 10; #X obj 206 158 keyboard_layout; #X obj 279 239 pddp/print; #X obj 92 247 pddp/print; #X msg 205 94 bang; #X msg 233 125 menu; #X connect 0 0 2 0; #X connect 0 1 1 0; #X connect 3 0 0 0; #X connect 4 0 0 0;
--- NEW FILE: keyboard_layout.libs --- -framework Carbon