libxputty  0.1
A damn tiny abstraction Layer to create X11 window/widgets with cairo surfaces
xmidi_keyboard.h File Reference
#include "xwidgets.h"
Include dependency graph for xmidi_keyboard.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  MidiKeyboard
 

Macros

#define XMIDI_KEYBOARD_H_
 

Typedefs

typedef void(* midikeyfunc) (Widget_t *w, int *key, bool on_off)
 
typedef void(* midiwheelfunc) (Widget_t *w, int *value)
 

Functions

void keysym_azerty_to_midi_key (long inkey, float *midi_key)
 
void keysym_qwertz_to_midi_key (long inkey, float *midi_key)
 
void keysym_qwerty_to_midi_key (unsigned int inkey, float *midi_key)
 
bool is_key_in_matrix (unsigned long *key_matrix, int key)
 
bool have_key_in_matrix (unsigned long *key_matrix)
 
void clear_key_matrix (unsigned long *key_matrix)
 
Widget_topen_midi_keyboard (Widget_t *w)
 

Macro Definition Documentation

◆ XMIDI_KEYBOARD_H_

#define XMIDI_KEYBOARD_H_

Definition at line 24 of file xmidi_keyboard.h.

Typedef Documentation

◆ midikeyfunc

typedef void(* midikeyfunc) (Widget_t *w, int *key, bool on_off)

Definition at line 32 of file xmidi_keyboard.h.

◆ midiwheelfunc

typedef void(* midiwheelfunc) (Widget_t *w, int *value)

Definition at line 33 of file xmidi_keyboard.h.

Function Documentation

◆ clear_key_matrix()

void clear_key_matrix ( unsigned long *  key_matrix)

Definition at line 221 of file xmidi_keyboard.c.

221  {
222  int i = 0;
223  int j = 0;
224  for(;j<4;j++) {
225  for(;i<32;i++) {
226  key_matrix[j] &= (~(1 << i));
227  }
228  i = 0;
229  }
230 }

◆ have_key_in_matrix()

bool have_key_in_matrix ( unsigned long *  key_matrix)

Definition at line 204 of file xmidi_keyboard.c.

204  {
205 
206  bool ret = false;
207  int i = 0;
208  int j = 0;
209  for(;j<4;j++) {
210  for(;i<32;i++) {
211  if(key_matrix[j] & (1<<i)) {
212  ret = true;
213  break;
214  }
215  }
216  i = 0;
217  }
218  return ret;
219 }

◆ is_key_in_matrix()

bool is_key_in_matrix ( unsigned long *  key_matrix,
int  key 
)

Definition at line 183 of file xmidi_keyboard.c.

183  {
184  unsigned long *use_matrix = &key_matrix[0];
185 
186 
187  if(key>94) {
188  use_matrix = &key_matrix[3];
189  key -=94;
190  } else if(key>62) {
191  use_matrix = &key_matrix[2];
192  key -=62;
193  } else if(key>31) {
194  use_matrix = &key_matrix[1];
195  key -= 31;
196  }
197  bool ret = false;
198  if((*use_matrix) & (1<<key)) {
199  ret = true;
200  }
201  return ret;
202 }

◆ keysym_azerty_to_midi_key()

void keysym_azerty_to_midi_key ( long  inkey,
float *  midi_key 
)

Definition at line 24 of file xmidi_keyboard.c.

24  {
25  switch(inkey) {
26  case(XK_w) : (*midi_key) = 12.0; /* w = C0 */
27  break;
28  case(XK_s) : (*midi_key) = 13.0; /* s */
29  break;
30  case(XK_x) : (*midi_key) = 14.0; /* x */
31  break;
32  case(XK_d) : (*midi_key) = 15.0; /* d */
33  break;
34  case(XK_c) : (*midi_key) = 16.0; /* c */
35  break;
36  case(XK_v) : (*midi_key) = 17.0; /* v */
37  break;
38  case(XK_g) : (*midi_key) = 18.0; /* g */
39  break;
40  case(XK_b) : (*midi_key) = 19.0; /* b */
41  break;
42  case(XK_h) : (*midi_key) = 20.0; /* h */
43  break;
44  case(XK_n) : (*midi_key) = 21.0; /* n */
45  break;
46  case(XK_j) : (*midi_key) = 22.0; /* j */
47  break;
48  case(XK_comma) : (*midi_key) = 23.0; /* , */
49  break;
50  case(XK_a) : (*midi_key) = 24.0; /* a */
51  break;
52  case(XK_eacute) : (*midi_key) = 25.0; /* eacute */
53  break;
54  case(XK_z) : (*midi_key) = 26.0; /* z */
55  break;
56  case(XK_quotedbl) : (*midi_key) = 27.0; /* quotedbl */
57  break;
58  case(XK_e) : (*midi_key) = 28.0; /* e */
59  break;
60  case(XK_r) : (*midi_key) = 29.0; /* r */
61  break;
62  case(XK_parenleft) : (*midi_key) = 30.0; /* parenleft */
63  break;
64  case(XK_t) : (*midi_key) = 31.0; /* t */
65  break;
66  case(XK_minus) : (*midi_key) = 32.0; /* minus */
67  break;
68  case(XK_y) : (*midi_key) = 33.0; /* y */
69  break;
70  case(XK_egrave) : (*midi_key) = 34.0; /* egrave */
71  break;
72  case(XK_u) : (*midi_key) = 35.0; /* u */
73  break;
74  case(XK_i) : (*midi_key) = 36.0; /* i */
75  break;
76  case(XK_ccedilla) : (*midi_key) = 37.0; /* ccedilla */
77  break;
78  case(XK_o) : (*midi_key) = 38.0; /* o */
79  break;
80  case(XK_agrave) : (*midi_key) = 39.0; /* agrave */
81  break;
82  case(XK_p) : (*midi_key) = 40.0; /* p */
83  break;
84  case(XK_dead_diaeresis) :
85  case(XK_dead_circumflex) : (*midi_key) = 41.0; /* dead circumflex */
86  break;
87  }
88 }

◆ keysym_qwerty_to_midi_key()

void keysym_qwerty_to_midi_key ( unsigned int  inkey,
float *  midi_key 
)

Definition at line 157 of file xmidi_keyboard.c.

157  {
158  keysym_qwertz_to_midi_key(inkey,midi_key);
159  if ((*midi_key) == 12) (*midi_key) = 33;
160  else if ((*midi_key) == 33) (*midi_key) = 12;
161 }

References keysym_qwertz_to_midi_key().

◆ keysym_qwertz_to_midi_key()

void keysym_qwertz_to_midi_key ( long  inkey,
float *  midi_key 
)

Definition at line 90 of file xmidi_keyboard.c.

90  {
91  switch(inkey) {
92  case(XK_y) : (*midi_key) = 12.0; /* y = C0 */
93  break;
94  case(XK_s) : (*midi_key) = 13.0; /* s */
95  break;
96  case(XK_x) : (*midi_key) = 14.0; /* x */
97  break;
98  case(XK_d) : (*midi_key) = 15.0; /* d */
99  break;
100  case(XK_c) : (*midi_key) = 16.0; /* c */
101  break;
102  case(XK_v) : (*midi_key) = 17.0; /* v */
103  break;
104  case(XK_g) : (*midi_key) = 18.0; /* g */
105  break;
106  case(XK_b) : (*midi_key) = 19.0; /* b */
107  break;
108  case(XK_h) : (*midi_key) = 20.0; /* h */
109  break;
110  case(XK_n) : (*midi_key) = 21.0; /* n */
111  break;
112  case(XK_j) : (*midi_key) = 22.0; /* j */
113  break;
114  case(XK_m) : (*midi_key) = 23.0; /* m */
115  break;
116  case(XK_q) : (*midi_key) = 24.0; /* q */
117  break;
118  case(XK_2) : (*midi_key) = 25.0; /* 2 */
119  break;
120  case(XK_w) : (*midi_key) = 26.0; /* w */
121  break;
122  case(XK_3) : (*midi_key) = 27.0; /* 3 */
123  break;
124  case(XK_e) : (*midi_key) = 28.0; /* e */
125  break;
126  case(XK_r) : (*midi_key) = 29.0; /* r */
127  break;
128  case(XK_5) : (*midi_key) = 30.0; /* 5 */
129  break;
130  case(XK_t) : (*midi_key) = 31.0; /* t */
131  break;
132  case(XK_6) : (*midi_key) = 32.0; /* 6 */
133  break;
134  case(XK_z) : (*midi_key) = 33.0; /* z */
135  break;
136  case(XK_7) : (*midi_key) = 34.0; /* 7 */
137  break;
138  case(XK_u) : (*midi_key) = 35.0; /* u */
139  break;
140  case(XK_i) : (*midi_key) = 36.0; /* i */
141  break;
142  case(XK_9) : (*midi_key) = 37.0; /* 9 */
143  break;
144  case(XK_o) : (*midi_key) = 38.0; /* o */
145  break;
146  case(XK_0) : (*midi_key) = 39.0; /* 0 */
147  break;
148  case(XK_p) : (*midi_key) = 40.0; /* p */
149  break;
150  case(XK_udiaeresis) : (*midi_key) = 41.0; /* ΓΌ */
151  break;
152  case(XK_plus) : (*midi_key) = 42.0; /* + */
153  break;
154  }
155 }

◆ open_midi_keyboard()

Widget_t* open_midi_keyboard ( Widget_t w)

Definition at line 793 of file xmidi_keyboard.c.

793  {
794  Widget_t *wid = create_window(w->app, DefaultRootWindow(w->app->dpy), 0, 0, 700, 200);
795  XSelectInput(wid->app->dpy, wid->widget,StructureNotifyMask|ExposureMask|KeyPressMask
796  |EnterWindowMask|LeaveWindowMask|ButtonReleaseMask|KeyReleaseMask
797  |ButtonPressMask|Button1MotionMask|PointerMotionMask);
798  MidiKeyboard *keys = (MidiKeyboard*)malloc(sizeof(MidiKeyboard));
799  wid->parent_struct = keys;
800  wid->parent = w;
801  wid->flags |= HAS_MEM | NO_AUTOREPEAT;
802  keys->prelight_key = -1;
803  keys->active_key = -1;
804  keys->send_key = -1;
805  keys->octave = 12*2;
806  keys->layout = 0;
807  keys->icon = NULL;
808  int j = 0;
809  for(;j<4;j++) {
810  keys->key_matrix[j] = 0;
811  }
812 
813  wid->func.expose_callback = draw_keyboard;
814  wid->func.motion_callback = keyboard_motion;
815  wid->func.leave_callback = leave_keyboard;
816  wid->func.button_press_callback = button_pressed_keyboard;
817  wid->func.button_release_callback = button_released_keyboard;
818  wid->func.key_press_callback = key_press;
819  wid->func.key_release_callback = key_release;
820  wid->func.mem_free_callback = keyboard_mem_free;
821  wid->func.map_notify_callback = map_keyboard;
822  widget_set_icon_from_png(wid,keys->icon,LDVAR(midikeyboard_png));
823  widget_set_title(wid, "Midi Keyboard");
824  keys->mk_send_note = key_dummy;
825  keys->mk_send_pitch = wheel_dummy;
826  keys->mk_send_pitchsensity = wheel_dummy;
827  keys->mk_send_mod = wheel_dummy;
828  keys->mk_send_detune = wheel_dummy;
829  keys->mk_send_attack = wheel_dummy;
830  keys->mk_send_sustain = wheel_dummy;
831  keys->mk_send_release = wheel_dummy;
832  keys->mk_send_volume = wheel_dummy;
833  keys->mk_send_velocity = wheel_dummy;
834  keys->mk_send_all_sound_off = wheel_dummy;
835 
836  Widget_t *p = add_keyboard_knob(wid, "PitchBend", 5, 0, 60, 75);
837  p->func.value_changed_callback = pitchwheel_callback;
838  keys->pitchwheel = (int)adj_get_value(p->adj);
839 
840  Widget_t *s = add_keyboard_knob(wid, "P.Sensity", 65, 0, 60, 75);
841  s->func.value_changed_callback = pitchsensity_callback;
842  keys->pitchsensity = (int)adj_get_value(s->adj);
843 
844  Widget_t *m = add_keyboard_knob(wid, "ModWheel", 125, 0, 60, 75);
845  m->func.value_changed_callback = modwheel_callback;
846  keys->modwheel = (int)adj_get_value(m->adj);
847 
848  Widget_t *de = add_keyboard_knob(wid, "Detune", 185, 0, 60, 75);
849  de->func.value_changed_callback = detune_callback;
850  keys->detune = (int)adj_get_value(de->adj);
851 
852  Widget_t *at = add_keyboard_knob(wid, "Attack", 245, 0, 60, 75);
853  at->func.value_changed_callback = attack_callback;
854  keys->attack = (int)adj_get_value(at->adj);
855 
856  Widget_t *su = add_keyboard_knob(wid, "Sustain", 305, 0, 60, 75);
857  su->func.value_changed_callback = sustain_callback;
858  keys->sustain = (int)adj_get_value(su->adj);
859 
860  Widget_t *re = add_keyboard_knob(wid, "Release", 365, 0, 60, 75);
861  re->func.value_changed_callback = release_callback;
862  keys->release = (int)adj_get_value(re->adj);
863 
864  Widget_t *v = add_keyboard_knob(wid, "Volume", 425, 0, 60, 75);
865  v->func.value_changed_callback = volume_callback;
866  keys->volume = (int)adj_get_value(v->adj);
867 
868  Widget_t *ve = add_keyboard_knob(wid, "Velocity", 485, 0, 60, 75);
869  set_adjustment(ve->adj,127.0, 127.0, 0.0, 127.0, 1.0, CL_CONTINUOS);
870  ve->func.value_changed_callback = velocity_callback;
871  keys->velocity = (int)adj_get_value(ve->adj);
872 
873  Widget_t *b = add_hslider(wid, "Keyboard mapping", 540, 40, 160, 35);
874  b->flags |= NO_AUTOREPEAT;
875  set_adjustment(b->adj,2.0, 2.0, 0.0, 4.0, 1.0, CL_CONTINUOS);
876  adj_set_scale(b->adj, 0.05);
877  b->func.value_changed_callback = octave_callback;
878 
879  Widget_t *layout = add_combobox(wid, "", 550, 2, 130, 30);
880  layout->flags |= NO_AUTOREPEAT;
881  layout->scale.gravity = ASPECT;
882  combobox_add_entry(layout,"qwertz");
883  combobox_add_entry(layout,"qwerty");
884  combobox_add_entry(layout,"azerty");
885  combobox_set_active_entry(layout, 0);
886  set_adjustment(layout->adj,0.0, 0.0, 0.0, 2.0, 1.0, CL_ENUM);
887  layout->func.value_changed_callback = layout_callback;
888 
889  return wid;
890 }

References MidiKeyboard::active_key, Widget_t::app, create_window(), Xputty::dpy, Func_t::expose_callback, Widget_t::flags, Widget_t::func, HAS_MEM, MidiKeyboard::icon, MidiKeyboard::key_matrix, MidiKeyboard::layout, NO_AUTOREPEAT, MidiKeyboard::octave, Widget_t::parent, Widget_t::parent_struct, MidiKeyboard::prelight_key, MidiKeyboard::send_key, and Widget_t::widget.

Func_t::leave_callback
xevfunc leave_callback
Definition: xwidget.h:83
MidiKeyboard::mk_send_volume
midiwheelfunc mk_send_volume
Definition: xmidi_keyboard.h:62
MidiKeyboard::mk_send_detune
midiwheelfunc mk_send_detune
Definition: xmidi_keyboard.h:58
MidiKeyboard::icon
Pixmap * icon
Definition: xmidi_keyboard.h:36
Resize_t::gravity
Gravity gravity
Definition: xwidget.h:192
MidiKeyboard::velocity
int velocity
Definition: xmidi_keyboard.h:46
widget_set_title
void widget_set_title(Widget_t *w, const char *title)
widget_set_title - set window title for a Widget_t
Definition: xwidget.c:387
MidiKeyboard::modwheel
int modwheel
Definition: xmidi_keyboard.h:40
MidiKeyboard::mk_send_velocity
midiwheelfunc mk_send_velocity
Definition: xmidi_keyboard.h:63
Widget_t::parent_struct
void * parent_struct
Definition: xwidget.h:306
combobox_add_entry
Widget_t * combobox_add_entry(Widget_t *wid, const char *label)
combobox_add_entry - add a entry to the combobox
Definition: xcombobox.c:56
CL_ENUM
@ CL_ENUM
Definition: xadjustment.h:55
add_hslider
Widget_t * add_hslider(Widget_t *parent, const char *label, int x, int y, int width, int height)
add_hslider - add a horizontal slider to a Widget_t connect to func.value_changed_callback to impleme...
Definition: xslider.c:41
MidiKeyboard::attack
int attack
Definition: xmidi_keyboard.h:42
MidiKeyboard::detune
int detune
Definition: xmidi_keyboard.h:41
Func_t::key_release_callback
evfunc key_release_callback
Definition: xwidget.h:97
NO_AUTOREPEAT
@ NO_AUTOREPEAT
Definition: xwidget.h:253
Func_t::expose_callback
xevfunc expose_callback
Definition: xwidget.h:80
adj_get_value
float adj_get_value(Adjustment_t *adj)
adj_get_value - get the current value of the Adjustment_t
Definition: xadjustment.c:154
MidiKeyboard::mk_send_all_sound_off
midiwheelfunc mk_send_all_sound_off
Definition: xmidi_keyboard.h:64
keysym_qwertz_to_midi_key
void keysym_qwertz_to_midi_key(long inkey, float *midi_key)
Definition: xmidi_keyboard.c:90
MidiKeyboard::send_key
int send_key
Definition: xmidi_keyboard.h:51
adj_set_scale
void adj_set_scale(Adjustment_t *adj, float value)
adj_set_scale - internal use to scale the pointer movement (0.1 -1.0)
Definition: xadjustment.c:179
MidiKeyboard::mk_send_release
midiwheelfunc mk_send_release
Definition: xmidi_keyboard.h:61
MidiKeyboard::octave
int octave
Definition: xmidi_keyboard.h:38
Func_t::motion_callback
evfunc motion_callback
Definition: xwidget.h:95
Widget_t::flags
long long flags
Definition: xwidget.h:324
Widget_t::adj
Adjustment_t * adj
Definition: xwidget.h:334
MidiKeyboard::pitchsensity
int pitchsensity
Definition: xmidi_keyboard.h:48
Widget_t::scale
Resize_t scale
Definition: xwidget.h:356
Func_t::key_press_callback
evfunc key_press_callback
Definition: xwidget.h:96
MidiKeyboard::mk_send_mod
midiwheelfunc mk_send_mod
Definition: xmidi_keyboard.h:57
MidiKeyboard::key_matrix
unsigned long key_matrix[4]
Definition: xmidi_keyboard.h:52
MidiKeyboard
Definition: xmidi_keyboard.h:35
HAS_MEM
@ HAS_MEM
Definition: xwidget.h:251
Widget_t::app
Xputty * app
Definition: xwidget.h:300
MidiKeyboard::mk_send_attack
midiwheelfunc mk_send_attack
Definition: xmidi_keyboard.h:59
Func_t::button_press_callback
evfunc button_press_callback
Definition: xwidget.h:93
Xputty::dpy
Display * dpy
Definition: xputty.h:181
add_keyboard_knob
Widget_t * add_keyboard_knob(Widget_t *parent, const char *label, int x, int y, int width, int height)
Definition: xmidi_keyboard.c:782
MidiKeyboard::sustain
int sustain
Definition: xmidi_keyboard.h:43
MidiKeyboard::release
int release
Definition: xmidi_keyboard.h:44
combobox_set_active_entry
void combobox_set_active_entry(Widget_t *w, int active)
combobox_set_active_entry - set the active combobox entry
Definition: xcombobox.c:25
Func_t::map_notify_callback
xevfunc map_notify_callback
Definition: xwidget.h:89
MidiKeyboard::mk_send_pitchsensity
midiwheelfunc mk_send_pitchsensity
Definition: xmidi_keyboard.h:56
Widget_t::widget
Window widget
Definition: xwidget.h:302
Widget_t
Widget_t - struct to hold the basic Widget_t info.
Definition: xwidget.h:298
ASPECT
@ ASPECT
Definition: xwidget.h:167
LDVAR
#define LDVAR(NAME)
Definition: xpngloader.h:71
Func_t::mem_free_callback
xevfunc mem_free_callback
Definition: xwidget.h:87
MidiKeyboard::mk_send_note
midikeyfunc mk_send_note
Definition: xmidi_keyboard.h:54
Func_t::button_release_callback
evfunc button_release_callback
Definition: xwidget.h:94
create_window
Widget_t * create_window(Xputty *app, Window win, int x, int y, int width, int height)
*create_window - create a Window You need to create as least minimun one Window to get started....
Definition: xwidget.c:145
MidiKeyboard::volume
int volume
Definition: xmidi_keyboard.h:45
set_adjustment
void set_adjustment(Adjustment_t *adj, float std_value, float value, float min_value, float max_value, float step, CL_type type)
*set_adjustment - set a new range to a existing Adjustment_t it will be created if it not exsits yet
Definition: xadjustment.c:80
MidiKeyboard::mk_send_sustain
midiwheelfunc mk_send_sustain
Definition: xmidi_keyboard.h:60
MidiKeyboard::prelight_key
int prelight_key
Definition: xmidi_keyboard.h:49
MidiKeyboard::pitchwheel
int pitchwheel
Definition: xmidi_keyboard.h:47
Widget_t::func
Func_t func
Definition: xwidget.h:310
MidiKeyboard::mk_send_pitch
midiwheelfunc mk_send_pitch
Definition: xmidi_keyboard.h:55
widget_set_icon_from_png
void widget_set_icon_from_png(Widget_t *w, Pixmap *icon_, const unsigned char *name)
widget_set_icon_from_png - set icon image from png binary to Widget_t those icon will be used in the ...
Definition: xpngloader.c:124
MidiKeyboard::layout
int layout
Definition: xmidi_keyboard.h:39
add_combobox
Widget_t * add_combobox(Widget_t *parent, const char *label, int x, int y, int width, int height)
add_combobox - add a combobox
Definition: xcombobox.c:32
MidiKeyboard::active_key
int active_key
Definition: xmidi_keyboard.h:50
Widget_t::parent
void * parent
Definition: xwidget.h:304
Func_t::value_changed_callback
xevfunc value_changed_callback
Definition: xwidget.h:85
CL_CONTINUOS
@ CL_CONTINUOS
Definition: xadjustment.h:49