}
}
-static void
+static void
draw_note(PianoKeyboard *pk, cairo_t* cr, int note)
{
int is_white = pk->notes[note].white;
int h = pk->notes[note].h;
if (pk->notes[note].pressed || pk->notes[note].sustained) {
- is_white = !is_white;
+ if (is_white) {
+ cairo_set_source_rgb (cr, 0.60f, 0.60f, 0.60f);
+ } else {
+ cairo_set_source_rgb (cr, 0.50f, 0.50f, 0.50f);
+ }
+ } else {
+ if (is_white) {
+ cairo_set_source_rgb (cr, 1.0f, 1.0f, 1.0f);
+ } else {
+ cairo_set_source_rgb (cr, 0.0f, 0.0f, 0.0f);
+ }
}
cairo_set_line_width (cr, 1.0);
- if (is_white) {
- cairo_set_source_rgb (cr, 1.0f, 1.0f, 1.0f);
- } else {
- cairo_set_source_rgb (cr, 0.0f, 0.0f, 0.0f);
- }
-
cairo_rectangle (cr, x, 0, w, h);
cairo_fill (cr);
}
}
-static int
+static int
press_key(PianoKeyboard *pk, int key)
{
assert(key >= 0);
return 1;
}
-static int
+static int
release_key(PianoKeyboard *pk, int key)
{
assert(key >= 0);
rest (PianoKeyboard* pk)
{
g_signal_emit_by_name(GTK_WIDGET(pk), "rest");
-}
+}
-static void
+static void
stop_unsustained_notes(PianoKeyboard *pk)
{
int i;
}
}
-static void
+static void
stop_sustained_notes(PianoKeyboard *pk)
{
int i;
g_hash_table_remove_all(pk->key_bindings);
}
-static void
+static void
bind_keys_qwerty(PianoKeyboard *pk)
{
clear_notes(pk);
bind_key(pk, "p", 40);
}
-static void
+static void
bind_keys_qwertz(PianoKeyboard *pk)
{
bind_keys_qwerty(pk);
bind_key(pk, "p", 40);
}
-static gint
-keyboard_event_handler(GtkWidget *mk, GdkEventKey *event, gpointer notused)
+static gint
+keyboard_event_handler(GtkWidget *mk, GdkEventKey *event, gpointer ignored)
{
int note;
char *key;
if (event->type == GDK_KEY_RELEASE) {
rest (pk);
}
-
+
return TRUE;
}
return TRUE;
}
-static int
+static int
get_note_for_xy(PianoKeyboard *pk, int x, int y)
{
int height = GTK_WIDGET(pk)->allocation.height;
return -1;
}
-static gboolean
-mouse_button_event_handler(PianoKeyboard *pk, GdkEventButton *event, gpointer notused)
+static gboolean
+mouse_button_event_handler(PianoKeyboard *pk, GdkEventButton *event, gpointer ignored)
{
int x = event->x;
int y = event->y;
return TRUE;
}
-static gboolean
-mouse_motion_event_handler(PianoKeyboard *pk, GdkEventMotion *event, gpointer notused)
+static gboolean
+mouse_motion_event_handler(PianoKeyboard *pk, GdkEventMotion *event, gpointer ignored)
{
int note;
note = get_note_for_xy(pk, event->x, event->y);
if (note != pk->note_being_pressed_using_mouse && note >= 0) {
-
+
if (pk->note_being_pressed_using_mouse >= 0)
release_key(pk, pk->note_being_pressed_using_mouse);
press_key(pk, note);
int i;
PianoKeyboard *pk = PIANO_KEYBOARD(widget);
cairo_t* cr = gdk_cairo_create (GDK_DRAWABLE (GTK_WIDGET(pk)->window));
-
+
gdk_cairo_region (cr, event->region);
cairo_clip (cr);
return TRUE;
}
-static void
+static void
piano_keyboard_size_request(GtkWidget* widget, GtkRequisition *requisition)
{
requisition->width = PIANO_KEYBOARD_DEFAULT_WIDTH;
G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
- widget_klass = (GtkWidgetClass*) klass;
+ widget_klass = (GtkWidgetClass*) klass;
widget_klass->expose_event = piano_keyboard_expose;
widget_klass->size_request = piano_keyboard_size_request;
}
}
-void
+void
piano_keyboard_sustain_release(PianoKeyboard *pk)
{
if (pk->maybe_stop_sustained_notes)
return FALSE;
}
-