Style fixes; no functional changes.
git-svn-id: svn://svn.code.sf.net/p/jack-keyboard/code/trunk@8 1fa2bf75-7d80-4145-9e94-f9b4e25a1cb2
This commit is contained in:
parent
baff42ccae
commit
0f3cb64475
@ -52,15 +52,20 @@ static guint piano_keyboard_signals[LAST_SIGNAL] = { 0 };
|
|||||||
static void
|
static void
|
||||||
draw_keyboard_cue(PianoKeyboard *pk)
|
draw_keyboard_cue(PianoKeyboard *pk)
|
||||||
{
|
{
|
||||||
int w = pk->notes[0].w;
|
int w, h, first_note_in_lower_row, last_note_in_lower_row,
|
||||||
int h = pk->notes[0].h;
|
first_note_in_higher_row, last_note_in_higher_row;
|
||||||
|
|
||||||
GdkGC *gc = GTK_WIDGET(pk)->style->fg_gc[0];
|
GdkGC *gc;
|
||||||
|
|
||||||
int first_note_in_lower_row = (pk->octave + 5) * 12;
|
w = pk->notes[0].w;
|
||||||
int last_note_in_lower_row = (pk->octave + 6) * 12 - 1;
|
h = pk->notes[0].h;
|
||||||
int first_note_in_higher_row = (pk->octave + 6) * 12;
|
|
||||||
int last_note_in_higher_row = (pk->octave + 7) * 12 + 4;
|
gc = GTK_WIDGET(pk)->style->fg_gc[0];
|
||||||
|
|
||||||
|
first_note_in_lower_row = (pk->octave + 5) * 12;
|
||||||
|
last_note_in_lower_row = (pk->octave + 6) * 12 - 1;
|
||||||
|
first_note_in_higher_row = (pk->octave + 6) * 12;
|
||||||
|
last_note_in_higher_row = (pk->octave + 7) * 12 + 4;
|
||||||
|
|
||||||
gdk_draw_line(GTK_WIDGET(pk)->window, gc, pk->notes[first_note_in_lower_row].x + 3,
|
gdk_draw_line(GTK_WIDGET(pk)->window, gc, pk->notes[first_note_in_lower_row].x + 3,
|
||||||
h - 6, pk->notes[last_note_in_lower_row].x + w - 3, h - 6);
|
h - 6, pk->notes[last_note_in_lower_row].x + w - 3, h - 6);
|
||||||
@ -72,17 +77,19 @@ draw_keyboard_cue(PianoKeyboard *pk)
|
|||||||
static void
|
static void
|
||||||
draw_note(PianoKeyboard *pk, int note)
|
draw_note(PianoKeyboard *pk, int note)
|
||||||
{
|
{
|
||||||
|
int is_white, x, w, h;
|
||||||
|
|
||||||
GdkColor black = {0, 0, 0, 0};
|
GdkColor black = {0, 0, 0, 0};
|
||||||
GdkColor white = {0, 65535, 65535, 65535};
|
GdkColor white = {0, 65535, 65535, 65535};
|
||||||
|
|
||||||
GdkGC *gc = GTK_WIDGET(pk)->style->fg_gc[0];
|
GdkGC *gc = GTK_WIDGET(pk)->style->fg_gc[0];
|
||||||
GtkWidget *widget;
|
GtkWidget *widget;
|
||||||
|
|
||||||
int is_white = pk->notes[note].white;
|
is_white = pk->notes[note].white;
|
||||||
|
|
||||||
int x = pk->notes[note].x;
|
x = pk->notes[note].x;
|
||||||
int w = pk->notes[note].w;
|
w = pk->notes[note].w;
|
||||||
int h = pk->notes[note].h;
|
h = pk->notes[note].h;
|
||||||
|
|
||||||
if (pk->notes[note].pressed || pk->notes[note].sustained)
|
if (pk->notes[note].pressed || pk->notes[note].sustained)
|
||||||
is_white = !is_white;
|
is_white = !is_white;
|
||||||
@ -113,8 +120,9 @@ draw_note(PianoKeyboard *pk, int note)
|
|||||||
* that didn't work.
|
* that didn't work.
|
||||||
*/
|
*/
|
||||||
widget = GTK_WIDGET(pk);
|
widget = GTK_WIDGET(pk);
|
||||||
gtk_paint_shadow(widget->style, widget->window, GTK_STATE_NORMAL, GTK_SHADOW_IN, NULL, widget, NULL, pk->widget_margin, 0,
|
gtk_paint_shadow(widget->style, widget->window, GTK_STATE_NORMAL, GTK_SHADOW_IN, NULL,
|
||||||
widget->allocation.width - pk->widget_margin * 2 + 1, widget->allocation.height);
|
widget, NULL, pk->widget_margin, 0, widget->allocation.width - pk->widget_margin * 2 + 1,
|
||||||
|
widget->allocation.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -127,7 +135,7 @@ press_key(PianoKeyboard *pk, int key)
|
|||||||
|
|
||||||
/* This is for keyboard autorepeat protection. */
|
/* This is for keyboard autorepeat protection. */
|
||||||
if (pk->notes[key].pressed)
|
if (pk->notes[key].pressed)
|
||||||
return 0;
|
return (0);
|
||||||
|
|
||||||
if (pk->sustain_new_notes)
|
if (pk->sustain_new_notes)
|
||||||
pk->notes[key].sustained = 1;
|
pk->notes[key].sustained = 1;
|
||||||
@ -139,7 +147,7 @@ press_key(PianoKeyboard *pk, int key)
|
|||||||
g_signal_emit_by_name(GTK_WIDGET(pk), "note-on", key);
|
g_signal_emit_by_name(GTK_WIDGET(pk), "note-on", key);
|
||||||
draw_note(pk, key);
|
draw_note(pk, key);
|
||||||
|
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -151,7 +159,7 @@ release_key(PianoKeyboard *pk, int key)
|
|||||||
pk->maybe_stop_sustained_notes = 0;
|
pk->maybe_stop_sustained_notes = 0;
|
||||||
|
|
||||||
if (!pk->notes[key].pressed)
|
if (!pk->notes[key].pressed)
|
||||||
return 0;
|
return (0);
|
||||||
|
|
||||||
if (pk->sustain_new_notes)
|
if (pk->sustain_new_notes)
|
||||||
pk->notes[key].sustained = 1;
|
pk->notes[key].sustained = 1;
|
||||||
@ -159,12 +167,12 @@ release_key(PianoKeyboard *pk, int key)
|
|||||||
pk->notes[key].pressed = 0;
|
pk->notes[key].pressed = 0;
|
||||||
|
|
||||||
if (pk->notes[key].sustained)
|
if (pk->notes[key].sustained)
|
||||||
return 0;
|
return (0);
|
||||||
|
|
||||||
g_signal_emit_by_name(GTK_WIDGET(pk), "note-off", key);
|
g_signal_emit_by_name(GTK_WIDGET(pk), "note-off", key);
|
||||||
draw_note(pk, key);
|
draw_note(pk, key);
|
||||||
|
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -207,9 +215,9 @@ key_binding(PianoKeyboard *pk, const char *key)
|
|||||||
found = g_hash_table_lookup_extended(pk->key_bindings, key, ¬used, ¬e);
|
found = g_hash_table_lookup_extended(pk->key_bindings, key, ¬used, ¬e);
|
||||||
|
|
||||||
if (!found)
|
if (!found)
|
||||||
return -1;
|
return (-1);
|
||||||
|
|
||||||
return (int)note;
|
return ((int)note);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -341,14 +349,14 @@ keyboard_event_handler(GtkWidget *mk, GdkEventKey *event, gpointer notused)
|
|||||||
|
|
||||||
if (key == NULL) {
|
if (key == NULL) {
|
||||||
g_message("gtk_keyval_name() returned NULL; please report this.");
|
g_message("gtk_keyval_name() returned NULL; please report this.");
|
||||||
return FALSE;
|
return (FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
note = key_binding(pk, key);
|
note = key_binding(pk, key);
|
||||||
|
|
||||||
if (note < 0) {
|
if (note < 0) {
|
||||||
/* Key was not bound. Maybe it's one of the keys handled in jack-keyboard.c. */
|
/* Key was not bound. Maybe it's one of the keys handled in jack-keyboard.c. */
|
||||||
return FALSE;
|
return (FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
note += pk->octave * 12;
|
note += pk->octave * 12;
|
||||||
@ -363,14 +371,15 @@ keyboard_event_handler(GtkWidget *mk, GdkEventKey *event, gpointer notused)
|
|||||||
release_key(pk, note);
|
release_key(pk, note);
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
get_note_for_xy(PianoKeyboard *pk, int x, int y)
|
get_note_for_xy(PianoKeyboard *pk, int x, int y)
|
||||||
{
|
{
|
||||||
int height = GTK_WIDGET(pk)->allocation.height;
|
int height, note;
|
||||||
int note;
|
|
||||||
|
height = GTK_WIDGET(pk)->allocation.height;
|
||||||
|
|
||||||
if (y <= height / 2) {
|
if (y <= height / 2) {
|
||||||
for (note = 0; note < NNOTES - 1; note++) {
|
for (note = 0; note < NNOTES - 1; note++) {
|
||||||
@ -378,7 +387,7 @@ get_note_for_xy(PianoKeyboard *pk, int x, int y)
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (x >= pk->notes[note].x && x <= pk->notes[note].x + pk->notes[note].w)
|
if (x >= pk->notes[note].x && x <= pk->notes[note].x + pk->notes[note].w)
|
||||||
return note;
|
return (note);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -387,28 +396,30 @@ get_note_for_xy(PianoKeyboard *pk, int x, int y)
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (x >= pk->notes[note].x && x <= pk->notes[note].x + pk->notes[note].w)
|
if (x >= pk->notes[note].x && x <= pk->notes[note].x + pk->notes[note].w)
|
||||||
return note;
|
return (note);
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
mouse_button_event_handler(PianoKeyboard *pk, GdkEventButton *event, gpointer notused)
|
mouse_button_event_handler(PianoKeyboard *pk, GdkEventButton *event, gpointer notused)
|
||||||
{
|
{
|
||||||
int x = event->x;
|
int x, y, note;
|
||||||
int y = event->y;
|
|
||||||
|
|
||||||
int note = get_note_for_xy(pk, x, y);
|
x = event->x;
|
||||||
|
y = event->y;
|
||||||
|
|
||||||
|
note = get_note_for_xy(pk, x, y);
|
||||||
|
|
||||||
if (event->button != 1)
|
if (event->button != 1)
|
||||||
return TRUE;
|
return (TRUE);
|
||||||
|
|
||||||
if (event->type == GDK_BUTTON_PRESS) {
|
if (event->type == GDK_BUTTON_PRESS) {
|
||||||
/* This is possible when you make the window a little wider and then click
|
/* This is possible when you make the window a little wider and then click
|
||||||
on the grey area. */
|
on the grey area. */
|
||||||
if (note < 0) {
|
if (note < 0) {
|
||||||
return TRUE;
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pk->note_being_pressed_using_mouse >= 0)
|
if (pk->note_being_pressed_using_mouse >= 0)
|
||||||
@ -430,7 +441,7 @@ mouse_button_event_handler(PianoKeyboard *pk, GdkEventButton *event, gpointer no
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
@ -439,7 +450,7 @@ mouse_motion_event_handler(PianoKeyboard *pk, GdkEventMotion *event, gpointer no
|
|||||||
int note;
|
int note;
|
||||||
|
|
||||||
if ((event->state & GDK_BUTTON1_MASK) == 0)
|
if ((event->state & GDK_BUTTON1_MASK) == 0)
|
||||||
return TRUE;
|
return (TRUE);
|
||||||
|
|
||||||
note = get_note_for_xy(pk, event->x, event->y);
|
note = get_note_for_xy(pk, event->x, event->y);
|
||||||
|
|
||||||
@ -451,7 +462,7 @@ mouse_motion_event_handler(PianoKeyboard *pk, GdkEventMotion *event, gpointer no
|
|||||||
pk->note_being_pressed_using_mouse = note;
|
pk->note_being_pressed_using_mouse = note;
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
@ -463,7 +474,7 @@ piano_keyboard_expose(GtkWidget *widget, GdkEventExpose *event)
|
|||||||
for (i = 0; i < NNOTES; i++)
|
for (i = 0; i < NNOTES; i++)
|
||||||
draw_note(pk, i);
|
draw_note(pk, i);
|
||||||
|
|
||||||
return TRUE;
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -476,18 +487,13 @@ piano_keyboard_size_request(GtkWidget *widget, GtkRequisition *requisition)
|
|||||||
static void
|
static void
|
||||||
recompute_dimensions(PianoKeyboard *pk)
|
recompute_dimensions(PianoKeyboard *pk)
|
||||||
{
|
{
|
||||||
int number_of_white_keys = (NNOTES - 1) * (7.0 / 12.0);
|
int number_of_white_keys, key_width, black_key_width, useful_width, note,
|
||||||
|
white_key = 0, note_in_octave, width, height;
|
||||||
|
|
||||||
int key_width;
|
number_of_white_keys = (NNOTES - 1) * (7.0 / 12.0);
|
||||||
int black_key_width;
|
|
||||||
int useful_width;
|
|
||||||
|
|
||||||
int note;
|
width = GTK_WIDGET(pk)->allocation.width;
|
||||||
int white_key = 0;
|
height = GTK_WIDGET(pk)->allocation.height;
|
||||||
int note_in_octave;
|
|
||||||
|
|
||||||
int width = GTK_WIDGET(pk)->allocation.width;
|
|
||||||
int height = GTK_WIDGET(pk)->allocation.height;
|
|
||||||
|
|
||||||
key_width = width / number_of_white_keys;
|
key_width = width / number_of_white_keys;
|
||||||
black_key_width = key_width * 0.8;
|
black_key_width = key_width * 0.8;
|
||||||
@ -530,9 +536,8 @@ piano_keyboard_size_allocate(GtkWidget *widget, GtkAllocation *allocation)
|
|||||||
|
|
||||||
recompute_dimensions(PIANO_KEYBOARD(widget));
|
recompute_dimensions(PIANO_KEYBOARD(widget));
|
||||||
|
|
||||||
if (GTK_WIDGET_REALIZED(widget)) {
|
if (GTK_WIDGET_REALIZED(widget))
|
||||||
gdk_window_move_resize (widget->window, allocation->x, allocation->y, allocation->width, allocation->height);
|
gdk_window_move_resize (widget->window, allocation->x, allocation->y, allocation->width, allocation->height);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -549,7 +554,7 @@ piano_keyboard_class_init(PianoKeyboardClass *klass)
|
|||||||
G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
|
G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
|
||||||
0, NULL, NULL, g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT);
|
0, NULL, NULL, g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT);
|
||||||
|
|
||||||
widget_klass = (GtkWidgetClass*) klass;
|
widget_klass = (GtkWidgetClass*)klass;
|
||||||
|
|
||||||
widget_klass->expose_event = piano_keyboard_expose;
|
widget_klass->expose_event = piano_keyboard_expose;
|
||||||
widget_klass->size_request = piano_keyboard_size_request;
|
widget_klass->size_request = piano_keyboard_size_request;
|
||||||
@ -589,15 +594,17 @@ piano_keyboard_get_type(void)
|
|||||||
mk_type = g_type_register_static(GTK_TYPE_DRAWING_AREA, "PianoKeyboard", &mk_info, 0);
|
mk_type = g_type_register_static(GTK_TYPE_DRAWING_AREA, "PianoKeyboard", &mk_info, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return mk_type;
|
return (mk_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
GtkWidget *
|
GtkWidget *
|
||||||
piano_keyboard_new(void)
|
piano_keyboard_new(void)
|
||||||
{
|
{
|
||||||
GtkWidget *widget = gtk_type_new(piano_keyboard_get_type());
|
GtkWidget *widget;
|
||||||
|
PianoKeyboard *pk;
|
||||||
|
|
||||||
PianoKeyboard *pk = PIANO_KEYBOARD(widget);
|
widget = gtk_type_new(piano_keyboard_get_type());
|
||||||
|
pk = PIANO_KEYBOARD(widget);
|
||||||
|
|
||||||
pk->maybe_stop_sustained_notes = 0;
|
pk->maybe_stop_sustained_notes = 0;
|
||||||
pk->sustain_new_notes = 0;
|
pk->sustain_new_notes = 0;
|
||||||
@ -608,7 +615,7 @@ piano_keyboard_new(void)
|
|||||||
pk->key_bindings = g_hash_table_new(g_str_hash, g_str_equal);
|
pk->key_bindings = g_hash_table_new(g_str_hash, g_str_equal);
|
||||||
bind_keys_qwerty(pk);
|
bind_keys_qwerty(pk);
|
||||||
|
|
||||||
return widget;
|
return (widget);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -678,9 +685,9 @@ piano_keyboard_set_keyboard_layout(PianoKeyboard *pk, const char *layout)
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
/* Unknown layout name. */
|
/* Unknown layout name. */
|
||||||
return TRUE;
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
return FALSE;
|
return (FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user