26 case(XK_w) : (*midi_key) = 12.0;
28 case(XK_s) : (*midi_key) = 13.0;
30 case(XK_x) : (*midi_key) = 14.0;
32 case(XK_d) : (*midi_key) = 15.0;
34 case(XK_c) : (*midi_key) = 16.0;
36 case(XK_v) : (*midi_key) = 17.0;
38 case(XK_g) : (*midi_key) = 18.0;
40 case(XK_b) : (*midi_key) = 19.0;
42 case(XK_h) : (*midi_key) = 20.0;
44 case(XK_n) : (*midi_key) = 21.0;
46 case(XK_j) : (*midi_key) = 22.0;
48 case(XK_comma) : (*midi_key) = 23.0;
50 case(XK_a) : (*midi_key) = 24.0;
52 case(XK_eacute) : (*midi_key) = 25.0;
54 case(XK_z) : (*midi_key) = 26.0;
56 case(XK_quotedbl) : (*midi_key) = 27.0;
58 case(XK_e) : (*midi_key) = 28.0;
60 case(XK_r) : (*midi_key) = 29.0;
62 case(XK_parenleft) : (*midi_key) = 30.0;
64 case(XK_t) : (*midi_key) = 31.0;
66 case(XK_minus) : (*midi_key) = 32.0;
68 case(XK_y) : (*midi_key) = 33.0;
70 case(XK_egrave) : (*midi_key) = 34.0;
72 case(XK_u) : (*midi_key) = 35.0;
74 case(XK_i) : (*midi_key) = 36.0;
76 case(XK_ccedilla) : (*midi_key) = 37.0;
78 case(XK_o) : (*midi_key) = 38.0;
80 case(XK_agrave) : (*midi_key) = 39.0;
82 case(XK_p) : (*midi_key) = 40.0;
84 case(XK_dead_diaeresis) :
85 case(XK_dead_circumflex) : (*midi_key) = 41.0;
92 case(XK_y) : (*midi_key) = 12.0;
94 case(XK_s) : (*midi_key) = 13.0;
96 case(XK_x) : (*midi_key) = 14.0;
98 case(XK_d) : (*midi_key) = 15.0;
100 case(XK_c) : (*midi_key) = 16.0;
102 case(XK_v) : (*midi_key) = 17.0;
104 case(XK_g) : (*midi_key) = 18.0;
106 case(XK_b) : (*midi_key) = 19.0;
108 case(XK_h) : (*midi_key) = 20.0;
110 case(XK_n) : (*midi_key) = 21.0;
112 case(XK_j) : (*midi_key) = 22.0;
114 case(XK_m) : (*midi_key) = 23.0;
116 case(XK_q) : (*midi_key) = 24.0;
118 case(XK_2) : (*midi_key) = 25.0;
120 case(XK_w) : (*midi_key) = 26.0;
122 case(XK_3) : (*midi_key) = 27.0;
124 case(XK_e) : (*midi_key) = 28.0;
126 case(XK_r) : (*midi_key) = 29.0;
128 case(XK_5) : (*midi_key) = 30.0;
130 case(XK_t) : (*midi_key) = 31.0;
132 case(XK_6) : (*midi_key) = 32.0;
134 case(XK_z) : (*midi_key) = 33.0;
136 case(XK_7) : (*midi_key) = 34.0;
138 case(XK_u) : (*midi_key) = 35.0;
140 case(XK_i) : (*midi_key) = 36.0;
142 case(XK_9) : (*midi_key) = 37.0;
144 case(XK_o) : (*midi_key) = 38.0;
146 case(XK_0) : (*midi_key) = 39.0;
148 case(XK_p) : (*midi_key) = 40.0;
150 case(XK_udiaeresis) : (*midi_key) = 41.0;
152 case(XK_plus) : (*midi_key) = 42.0;
159 if ((*midi_key) == 12) (*midi_key) = 33;
160 else if ((*midi_key) == 33) (*midi_key) = 12;
163 static void set_key_in_matrix(
unsigned long *key_matrix,
int key,
bool set) {
164 unsigned long *use_matrix = &key_matrix[0];
167 use_matrix = &key_matrix[3];
170 use_matrix = &key_matrix[2];
173 use_matrix = &key_matrix[1];
177 (*use_matrix) |= (1 << key);
179 (*use_matrix) &= (~(1 << key));
184 unsigned long *use_matrix = &key_matrix[0];
188 use_matrix = &key_matrix[3];
191 use_matrix = &key_matrix[2];
194 use_matrix = &key_matrix[1];
198 if((*use_matrix) & (1<<key)) {
211 if(key_matrix[j] & (1<<i)) {
226 key_matrix[j] &= (~(1 << i));
233 XWindowAttributes attrs;
234 XGetWindowAttributes(w->
app->
dpy, (Window)w->
widget, &attrs);
235 int width = attrs.width-2;
236 int height = attrs.height-2;
238 const double scale_zero = 20 * (M_PI/180);
243 int grow = (width > height) ? height:width;
248 int knobx = (width - knob_x) * 0.5;
249 int knobx1 = width* 0.5;
251 int knoby = (height - knob_y) * 0.5;
252 int knoby1 = height * 0.5;
255 double angle = scale_zero + knobstate * 2 * (M_PI - scale_zero);
257 double pointer_off =knob_x/3.5;
258 double radius =
min(knob_x-pointer_off, knob_y-pointer_off) / 2;
259 double lengh_x = (knobx+radius+pointer_off/2) - radius * sin(angle);
260 double lengh_y = (knoby+radius+pointer_off/2) + radius * cos(angle);
261 double radius_x = (knobx+radius+pointer_off/2) - radius/ 1.18 * sin(angle);
262 double radius_y = (knoby+radius+pointer_off/2) + radius/ 1.18 * cos(angle);
263 cairo_pattern_t* pat;
264 cairo_new_path (w->
crb);
266 pat = cairo_pattern_create_linear (0, 0, 0, knob_y);
267 cairo_pattern_add_color_stop_rgba (pat, 1, 0.3, 0.3, 0.3, 1.0);
268 cairo_pattern_add_color_stop_rgba (pat, 0.75, 0.2, 0.2, 0.2, 1.0);
269 cairo_pattern_add_color_stop_rgba (pat, 0.5, 0.15, 0.15, 0.15, 1.0);
270 cairo_pattern_add_color_stop_rgba (pat, 0.25, 0.1, 0.1, 0.1, 1.0);
271 cairo_pattern_add_color_stop_rgba (pat, 0, 0.05, 0.05, 0.05, 1.0);
273 cairo_scale (w->
crb, 0.95, 1.05);
274 cairo_arc(w->
crb,knobx1+arc_offset/2, knoby1-arc_offset, knob_x/2.2, 0, 2 * M_PI );
275 cairo_set_source (w->
crb, pat);
276 cairo_fill_preserve (w->
crb);
277 cairo_set_source_rgb (w->
crb, 0.1, 0.1, 0.1);
278 cairo_set_line_width(w->
crb,1);
279 cairo_stroke(w->
crb);
280 cairo_scale (w->
crb, 1.05, 0.95);
281 cairo_new_path (w->
crb);
282 cairo_pattern_destroy (pat);
285 pat = cairo_pattern_create_linear (0, 0, 0, knob_y);
286 cairo_pattern_add_color_stop_rgba (pat, 0, 0.3, 0.3, 0.3, 1.0);
287 cairo_pattern_add_color_stop_rgba (pat, 0.25, 0.2, 0.2, 0.2, 1.0);
288 cairo_pattern_add_color_stop_rgba (pat, 0.5, 0.15, 0.15, 0.15, 1.0);
289 cairo_pattern_add_color_stop_rgba (pat, 0.75, 0.1, 0.1, 0.1, 1.0);
290 cairo_pattern_add_color_stop_rgba (pat, 1, 0.05, 0.05, 0.05, 1.0);
292 cairo_arc(w->
crb,knobx1, knoby1, knob_x/2.6, 0, 2 * M_PI );
293 cairo_set_source (w->
crb, pat);
294 cairo_fill_preserve (w->
crb);
295 cairo_set_source_rgb (w->
crb, 0.1, 0.1, 0.1);
296 cairo_set_line_width(w->
crb,1);
297 cairo_stroke(w->
crb);
298 cairo_new_path (w->
crb);
299 cairo_pattern_destroy (pat);
302 cairo_set_line_cap(w->
crb, CAIRO_LINE_CAP_ROUND);
303 cairo_set_line_join(w->
crb, CAIRO_LINE_JOIN_BEVEL);
304 cairo_move_to(w->
crb, radius_x, radius_y);
305 cairo_line_to(w->
crb,lengh_x,lengh_y);
306 cairo_set_line_width(w->
crb,3);
307 cairo_set_source_rgb (w->
crb,0.63,0.63,0.63);
308 cairo_stroke(w->
crb);
309 cairo_new_path (w->
crb);
311 cairo_text_extents_t extents;
316 cairo_set_source_rgb (w->
crb, 0.6, 0.6, 0.6);
317 cairo_set_font_size (w->
crb, knobx1/3);
318 cairo_text_extents(w->
crb, s, &extents);
319 cairo_move_to (w->
crb, knobx1-extents.width/2, knoby1+extents.height/2);
320 cairo_show_text(w->
crb, s);
321 cairo_new_path (w->
crb);
326 float font_size = ((height/2.2 < (width*0.5)/3) ? height/2.2 : (width*0.5)/3);
327 cairo_set_font_size (w->
crb, font_size);
328 cairo_text_extents(w->
crb,w->
label , &extents);
330 cairo_move_to (w->
crb, knobx1-extents.width/2, height );
332 cairo_new_path (w->
crb);
335 static void draw_keyboard(
void *w_,
void* user_data) {
337 XWindowAttributes attrs;
338 XGetWindowAttributes(w->
app->
dpy, (Window)w->
widget, &attrs);
339 int width_t = attrs.width;
340 int height_t = attrs.height;
341 if (attrs.map_state != IsViewable)
return;
344 cairo_rectangle(w->
crb,0,0,width_t,height_t*0.4);
349 cairo_rectangle(w->
crb,0,height_t*0.38,width_t,height_t*0.02);
350 cairo_fill_preserve (w->
crb);
353 cairo_set_line_width(w->
crb, 1.0);
354 cairo_stroke(w->
crb);
360 for(;i<width_t;i++) {
361 cairo_rectangle(w->
crb,i,height_t*0.4,25,height_t*0.6);
364 cairo_set_line_width(w->
crb, 1.0);
367 cairo_set_line_width(w->
crb, 2.0);
370 cairo_set_line_width(w->
crb, 1.0);
373 cairo_fill_preserve(w->
crb);
375 cairo_stroke(w->
crb);
383 }
else if (set == 4) {
401 for(;i<width_t;i++) {
404 cairo_set_line_width(w->
crb, 1.0);
405 cairo_rectangle(w->
crb,i+15,height_t*0.4,20,height_t*0.39);
408 cairo_set_line_width(w->
crb, 1.0);
411 cairo_set_line_width(w->
crb, 2.0);
414 cairo_set_line_width(w->
crb, 1.0);
417 cairo_fill_preserve(w->
crb);
419 cairo_stroke(w->
crb);
430 }
else if (set == 3) {
443 static void keyboard_motion(
void *w_,
void* xmotion_,
void* user_data) {
447 XMotionEvent *xmotion = (XMotionEvent*)xmotion_;
448 XWindowAttributes attrs;
449 XGetWindowAttributes(w->
app->
dpy, (Window)w->
widget, &attrs);
450 if (attrs.map_state != IsViewable)
return;
451 int width = attrs.width;
452 int height = attrs.height;
454 bool catchit =
false;
456 if(xmotion->y < height*0.4) {
462 if(xmotion->y < height*0.8) {
469 if(xmotion->x > i+15 && xmotion->x < i+35) {
471 if(xmotion->state & Button1Mask) {
491 }
else if (set == 3) {
508 if(xmotion->x > i && xmotion->x < i+25) {
510 if(xmotion->state & Button1Mask) {
529 }
else if (set == 4) {
543 static void get_outkey(
MidiKeyboard *keys, KeySym sym,
float *outkey) {
556 static void key_press(
void *w_,
void *key_,
void *user_data) {
561 XKeyEvent *key = (XKeyEvent*)key_;
564 KeySym sym = XLookupKeysym (key, 0);
565 get_outkey(keys, sym, &outkey);
573 if (sym == XK_space) {
580 static void key_release(
void *w_,
void *key_,
void *user_data) {
585 XKeyEvent *key = (XKeyEvent*)key_;
588 KeySym sym = XLookupKeysym (key, 0);
589 get_outkey(keys, sym, &outkey);
598 static void leave_keyboard(
void *w_,
void* user_data) {
605 static void button_pressed_keyboard(
void *w_,
void* button_,
void* user_data) {
610 XButtonEvent *xbutton = (XButtonEvent*)button_;
611 if(xbutton->button == Button1) {
620 static void button_released_keyboard(
void *w_,
void* button_,
void* user_data) {
625 XButtonEvent *xbutton = (XButtonEvent*)button_;
626 if(xbutton->button == Button1) {
635 static void octave_callback(
void *w_,
void* user_data) {
642 static void layout_callback(
void *w_,
void* user_data) {
649 static void modwheel_callback(
void *w_,
void* user_data) {
658 static void detune_callback(
void *w_,
void* user_data) {
667 static void attack_callback(
void *w_,
void* user_data) {
676 static void sustain_callback(
void *w_,
void* user_data) {
685 static void release_callback(
void *w_,
void* user_data) {
694 static void volume_callback(
void *w_,
void* user_data) {
703 static void velocity_callback(
void *w_,
void* user_data) {
712 static void pitchwheel_callback(
void *w_,
void* user_data) {
721 static void pitchsensity_callback(
void *w_,
void* user_data) {
730 static void wheel_key_release(
void *w_,
void *key_,
void *user_data) {
736 static void wheel_key_press(
void *w_,
void *key_,
void *user_data) {
749 static void keyboard_mem_free(
void *w_,
void* user_data) {
759 static void map_keyboard(
void *w_,
void* user_data) {
771 static void key_dummy(
Widget_t *w,
int *key,
bool on_off) {
778 static void wheel_dummy(
Widget_t *w,
int *value) {
783 int x,
int y,
int width,
int height) {
795 XSelectInput(wid->
app->
dpy, wid->
widget,StructureNotifyMask|ExposureMask|KeyPressMask
796 |EnterWindowMask|LeaveWindowMask|ButtonReleaseMask|KeyReleaseMask
797 |ButtonPressMask|Button1MotionMask|PointerMotionMask);