1 /* scherzo - Music notation training
3 * Copyright © 2010 Carl Worth
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see http://www.gnu.org/licenses/ .
20 #include <gdk/gdkkeysyms.h>
22 #include <asoundlib.h>
27 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
29 #define unused(foo) foo __attribute__((unused))
31 #define MIDI_BUF_SIZE 4096
33 typedef struct challenge
44 typedef struct note_group
52 typedef struct scherzo
59 score_staff_t *treble;
63 /* The word "keyboard" here is referring to a "computer
64 * keyboard". Any "piano keyboard" key knows its own octave and
65 * accidental already. */
67 score_pitch_accidental_t keyboard_accidental;
70 snd_midi_event_t *snd_midi_event;
73 challenge_t challenge;
75 note_group_t notes_pressed;
76 note_group_t notes_pedaled;
81 /* Forward declarations. */
83 scherzo_press_note (scherzo_t *scherzo, score_pitch_t pitch, int octave);
86 scherzo_release_note (scherzo_t *scherzo, score_pitch_t pitch, int octave);
89 scherzo_press_pedal (scherzo_t *scherzo);
92 scherzo_release_pedal (scherzo_t *scherzo);
95 _judge_note (scherzo_t *scherzo, score_note_t *note);
98 _score_challenge (scherzo_t *scherzo);
101 on_delete_event_quit (unused (GtkWidget *widget),
102 unused (GdkEvent *event),
103 unused (gpointer user_data))
107 /* Returning FALSE allows the default handler for delete-event
108 * to proceed to cleanup the widget. */
113 on_expose_event_draw (GtkWidget *widget,
114 unused (GdkEventExpose *expose),
117 scherzo_t *scherzo = user_data;
118 score_t *score = scherzo->score;
120 GtkAllocation allocation;
121 static const int pad = 10;
124 gtk_widget_get_allocation (widget, &allocation);
125 widget_width = allocation.width;
127 cr = gdk_cairo_create (widget->window);
129 /* White background */
130 cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
133 /* Add some padding on the sides and top */
134 cairo_translate (cr, pad, scherzo->staff_height);
135 score_set_staff_height (score, scherzo->staff_height);
136 score_set_width (score, widget_width - 2 * pad);
138 score_draw (score, cr);
144 on_key_press_event (GtkWidget *widget,
148 scherzo_t *scherzo = user_data;
150 score_pitch_name_t pitch_name;
153 if (scherzo->challenge.note)
154 octave = scherzo->challenge.note->octave;
156 octave = scherzo->keyboard_octave;
158 switch (key->keyval) {
162 case GDK_KEY_KP_Equal:
163 scherzo->staff_height += 4;
164 gtk_widget_queue_draw (widget);
168 case GDK_KEY_KP_Subtract:
169 scherzo->staff_height -= 4;
170 gtk_widget_queue_draw (widget);
180 pitch_name = SCORE_PITCH_NAME_C;
184 pitch_name = SCORE_PITCH_NAME_D;
188 pitch_name = SCORE_PITCH_NAME_E;
192 pitch_name = SCORE_PITCH_NAME_F;
196 pitch_name = SCORE_PITCH_NAME_G;
200 pitch_name = SCORE_PITCH_NAME_A;
204 pitch_name = SCORE_PITCH_NAME_B;
215 scherzo->keyboard_octave = key->keyval - GDK_KEY_0;
218 scherzo_press_pedal (scherzo);
221 if (scherzo->keyboard_accidental < SCORE_PITCH_ACCIDENTAL_DOUBLE_SHARP)
222 scherzo->keyboard_accidental++;
225 if (scherzo->keyboard_accidental > SCORE_PITCH_ACCIDENTAL_DOUBLE_FLAT)
226 scherzo->keyboard_accidental--;
230 pitch = SCORE_PITCH (pitch_name, scherzo->keyboard_accidental);
232 if ((key->keyval >= GDK_KEY_A && key->keyval <= GDK_KEY_G) ||
233 (key->keyval >= GDK_KEY_a && key->keyval <= GDK_KEY_g))
237 note = scherzo_press_note (scherzo, pitch, octave);
238 _judge_note (scherzo, note);
239 gtk_widget_queue_draw (scherzo->window);
245 /* Allow an unhandled event to propagate to other handlers. */
250 on_key_release_event (unused (GtkWidget *widget),
254 scherzo_t *scherzo = user_data;
256 score_pitch_name_t pitch_name;
259 if (scherzo->challenge.note)
260 octave = scherzo->challenge.note->octave;
262 octave = scherzo->keyboard_octave;
264 switch (key->keyval) {
267 pitch_name = SCORE_PITCH_NAME_C;
271 pitch_name = SCORE_PITCH_NAME_D;
275 pitch_name = SCORE_PITCH_NAME_E;
279 pitch_name = SCORE_PITCH_NAME_F;
283 pitch_name = SCORE_PITCH_NAME_G;
287 pitch_name = SCORE_PITCH_NAME_A;
291 pitch_name = SCORE_PITCH_NAME_B;
294 scherzo_release_pedal (scherzo);
298 pitch = SCORE_PITCH (pitch_name, scherzo->keyboard_accidental);
300 if ((key->keyval >= GDK_KEY_A && key->keyval <= GDK_KEY_G) ||
301 (key->keyval >= GDK_KEY_a && key->keyval <= GDK_KEY_g))
303 scherzo_release_note (scherzo, pitch, octave);
304 _score_challenge (scherzo);
305 gtk_widget_queue_draw (scherzo->window);
311 /* Allow an unhandled event to propagate to other handlers. */
316 _score_pitch_and_octave_to_midi (score_pitch_t pitch,
319 unsigned char midi_note = 12 * (octave + 1);
321 switch (SCORE_PITCH_NAME (pitch)) {
322 case SCORE_PITCH_NAME_C:
324 case SCORE_PITCH_NAME_D:
327 case SCORE_PITCH_NAME_E:
330 case SCORE_PITCH_NAME_F:
333 case SCORE_PITCH_NAME_G:
336 case SCORE_PITCH_NAME_A:
339 case SCORE_PITCH_NAME_B:
344 switch (SCORE_PITCH_ACCIDENTAL (pitch)) {
345 case SCORE_PITCH_ACCIDENTAL_DOUBLE_FLAT:
348 case SCORE_PITCH_ACCIDENTAL_FLAT:
351 case SCORE_PITCH_ACCIDENTAL_NATURAL:
353 case SCORE_PITCH_ACCIDENTAL_SHARP:
356 case SCORE_PITCH_ACCIDENTAL_DOUBLE_SHARP:
365 _midi_to_score_pitch_and_octave (unsigned char midi_note,
366 score_pitch_t *pitch,
369 *octave = midi_note / 12 - 1;
371 switch (midi_note % 12)
374 *pitch = SCORE_PITCH_C;
377 *pitch = SCORE_PITCH_Cs;
380 *pitch = SCORE_PITCH_D;
383 *pitch = SCORE_PITCH_Ds;
386 *pitch = SCORE_PITCH_E;
389 *pitch = SCORE_PITCH_F;
392 *pitch = SCORE_PITCH_Fs;
395 *pitch = SCORE_PITCH_G;
398 *pitch = SCORE_PITCH_Gs;
401 *pitch = SCORE_PITCH_A;
404 *pitch = SCORE_PITCH_As;
407 *pitch = SCORE_PITCH_B;
412 /* Determine a chord name (if any) from the current notes pressed */
414 typedef struct analyzed_note {
415 /* Original note being analzyed. */
418 /* Absolute pitch (expressed as midi number). */
421 /* Pitch relative to bass note. */
426 _compare_analyzed_note_by_midi_pitch (const void *va, const void *vb)
428 const analyzed_note_t *a = va, *b = vb;
430 return a->midi_pitch - b->midi_pitch;
434 _compare_analyzed_note_by_relative_pitch (const void *va, const void *vb)
436 const analyzed_note_t *a = va, *b = vb;
438 return a->relative_pitch - b->relative_pitch;
442 _chord_signature_matches (analyzed_note_t *notes,
444 int *signature_pitches,
445 int num_signature_pitches)
449 if (num_notes != num_signature_pitches)
452 for (i = 0; i < num_notes; i++)
453 if (notes[i].relative_pitch != signature_pitches[i])
460 scherzo_analyze_chord (scherzo_t *scherzo)
462 void *local = talloc_new (NULL);
463 analyzed_note_t *notes;
464 note_group_t *note_group;
465 unsigned i, j, num_notes;
467 const char *chord_name = NULL;
469 if (scherzo->pedal_pressed)
470 note_group = &scherzo->notes_pedaled;
472 note_group = &scherzo->notes_pressed;
474 num_notes = note_group->num_notes;
476 struct { int pitches[1]; const char *name; } octaves[] = {
480 struct { int pitches[2]; const char *name; } intervals[] = {
481 { {0, 1}, "Minor 2nd"},
482 { {0, 2}, "Major 2nd"},
483 { {0, 3}, "Minor 3rd"},
484 { {0, 4}, "Major 3rd"},
485 { {0, 5}, "Perfect 4th"},
486 { {0, 6}, "Diminished 5th/Augmented 4th"},
487 { {0, 7}, "Perfect 5th"},
488 { {0, 8}, "Minor 6th"},
489 { {0, 9}, "Major 6th"},
490 { {0, 10}, "Minor 7th"},
491 { {0, 11}, "Major 7th"}
494 struct { int pitches[3]; const char *name; } triads[] = {
495 { {0, 4, 8}, "Augmented triad" },
496 { {0, 4, 7}, "Major triad" },
497 { {0, 3, 7}, "Minor triad" },
498 { {0, 3, 6}, "Diminished triad" }
501 struct { int pitches[4]; const char *name; } sevenths[] = {
502 { {0, 4, 8, 11}, "Augmented/major 7" },
503 { {0, 4, 8, 10}, "Augmented 7" },
504 { {0, 4, 7, 11}, "Major 7" },
505 { {0, 4, 7, 10}, "Dominant 7" },
506 { {0, 3, 7, 11}, "Minor/major 7" },
507 { {0, 3, 7, 10}, "Minor 7" },
508 { {0, 3, 6, 11}, "Diminished/major 7" },
509 { {0, 3, 6, 10}, "Half-diminished 7" },
510 { {0, 3, 6, 9}, "Diminished 7" }
513 if (scherzo->chord) {
514 score_remove_chord (scherzo->chord);
515 scherzo->chord = NULL;
521 notes = talloc_array (local, analyzed_note_t, num_notes);
525 for (i = 0; i < num_notes; i++) {
526 score_note_t *note = note_group->notes[i];
527 notes[i].note = note;
528 notes[i].midi_pitch = _score_pitch_and_octave_to_midi (note->pitch,
530 /* Relative pitch will be filled in after sorting. */
531 notes[i].relative_pitch = 0;
534 /* First, sort by midi pitch to find the bass note. */
535 qsort (notes, num_notes, sizeof (analyzed_note_t),
536 _compare_analyzed_note_by_midi_pitch);
538 bass_pitch = notes[0].midi_pitch;
540 /* With the bass note identified, we can find all relative pitches. */
541 for (i = 0; i < num_notes; i++) {
542 notes[i].relative_pitch = notes[i].midi_pitch - bass_pitch;
543 while (notes[i].relative_pitch >= 12)
544 notes[i].relative_pitch -= 12;
547 /* Now, sort again by relative pitch. */
548 qsort (notes, num_notes, sizeof (analyzed_note_t),
549 _compare_analyzed_note_by_relative_pitch);
551 /* Finally, eliminate all duplicate notes. */
552 for (i = 0; i < num_notes - 1; i++) {
553 if (notes[i+1].relative_pitch == notes[i].relative_pitch) {
555 while (j < num_notes &&
556 notes[j].relative_pitch == notes[i].relative_pitch)
560 /* The loop incremented j one past the last
561 * duplicate. Decrement so that it points to the
562 * last duplicate (and is guaranteed to not exceed
563 * the array bounds).*/
566 if (j < num_notes - 1) {
567 memmove (¬es[i+1], ¬es[j+1],
568 (num_notes - j) * sizeof (analyzed_note_t));
571 num_notes -= (j - i);
577 for (i = 0; i < ARRAY_SIZE (octaves); i++) {
578 if (_chord_signature_matches (notes, num_notes, octaves[i].pitches, 1))
579 chord_name = octaves[i].name;
583 for (i = 0; i < ARRAY_SIZE (intervals); i++) {
584 if (_chord_signature_matches (notes, num_notes, intervals[i].pitches, 2))
585 chord_name = intervals[i].name;
589 for (i = 0; i < ARRAY_SIZE (triads); i++) {
590 if (_chord_signature_matches (notes, num_notes, triads[i].pitches, 3))
591 chord_name = triads[i].name;
595 for (i = 0; i < ARRAY_SIZE(sevenths); i++) {
596 if (_chord_signature_matches (notes, num_notes, sevenths[i].pitches, 4))
597 chord_name = sevenths[i].name;
603 scherzo->chord = score_add_chord (scherzo->treble, chord_name);
605 scherzo->chord = score_add_chord (scherzo->treble, "Unknown or not a chord");
612 note_group_init (void *ctx, note_group_t *group)
617 group->num_notes = 0;
621 note_group_add_note (note_group_t *group, score_note_t *note)
625 /* Do nothing if note is already in group. */
626 for (i = 0; i < group->num_notes; i++) {
627 if (group->notes[i]->pitch == note->pitch &&
628 group->notes[i]->octave == note->octave)
636 if (group->num_notes > group->size) {
638 group->notes = talloc_realloc (group->ctx, group->notes,
639 score_note_t*, group->size);
641 if (group->notes == NULL) {
642 fprintf (stderr, "Out of memory.\n");
647 group->notes[group->num_notes - 1] = note;
651 note_group_remove_note_at (note_group_t *group, int i)
653 if (i >= group->num_notes) {
654 fprintf (stderr, "Internal error: No note to remove at index %d\n", i);
658 if (i < group->num_notes - 1) {
659 memmove (group->notes + i, group->notes + i + 1,
660 (group->num_notes - 1 - i) * sizeof (score_note_t*));
665 static score_note_t *
666 scherzo_press_note (scherzo_t *scherzo, score_pitch_t pitch, int octave)
668 score_staff_t *staff;
672 if (scherzo->challenge.note) {
673 staff = scherzo->challenge.staff;
674 } else if (octave >= 4) {
675 staff = scherzo->treble;
677 staff = scherzo->bass;
680 /* Do nothing if this note is already pressed. */
681 for (i = 0; i < scherzo->notes_pressed.num_notes; i++) {
682 if (scherzo->notes_pressed.notes[i]->pitch == pitch &&
683 scherzo->notes_pressed.notes[i]->octave == octave)
685 return scherzo->notes_pressed.notes[i];
689 note = score_add_note (staff, pitch, octave, SCORE_DURATION_WHOLE);
691 note_group_add_note (&scherzo->notes_pressed, note);
693 if (scherzo->pedal_pressed)
694 note_group_add_note (&scherzo->notes_pedaled, note);
696 scherzo_analyze_chord (scherzo);
702 scherzo_release_note (scherzo_t *scherzo, score_pitch_t pitch, int octave)
708 for (i = scherzo->notes_pressed.num_notes - 1; i >=0; i--) {
709 note = scherzo->notes_pressed.notes[i];
710 if (note->pitch == pitch && note->octave == octave) {
712 if (! scherzo->pedal_pressed)
713 score_remove_note (note);
714 note_group_remove_note_at (&scherzo->notes_pressed, i);
719 fprintf (stderr, "Internal error: Failed to find note to release.\n");
722 scherzo_analyze_chord (scherzo);
725 static score_note_t *
726 scherzo_press_note_midi (scherzo_t *scherzo, unsigned char midi_note)
731 _midi_to_score_pitch_and_octave (midi_note, &pitch, &octave);
733 return scherzo_press_note (scherzo, pitch, octave);
737 scherzo_release_note_midi (scherzo_t *scherzo, unsigned char midi_note)
742 _midi_to_score_pitch_and_octave (midi_note, &pitch, &octave);
744 scherzo_release_note (scherzo, pitch, octave);
748 scherzo_press_pedal (scherzo_t *scherzo)
752 scherzo->pedal_pressed = 1;
754 /* Copy all pressed notes to pedaled notes */
755 for (i = 0; i < scherzo->notes_pressed.num_notes; i++)
756 note_group_add_note (&scherzo->notes_pedaled, scherzo->notes_pressed.notes[i]);
760 scherzo_release_pedal (scherzo_t *scherzo)
762 score_note_t *note, *new_note;
765 /* Make new notes in score for all pressed notes. */
766 for (i = 0; i < scherzo->notes_pressed.num_notes; i++) {
767 note = scherzo->notes_pressed.notes[i];
768 new_note = score_add_note (note->staff, note->pitch, note->octave, note->duration);
769 scherzo->notes_pressed.notes[i] = new_note;
772 /* Then remove all previously pedaled notes from the score. */
773 for (i = scherzo->notes_pedaled.num_notes - 1; i >=0; i--) {
774 note = scherzo->notes_pedaled.notes[i];
775 score_remove_note (note);
776 note_group_remove_note_at (&scherzo->notes_pedaled, i);
779 scherzo->pedal_pressed = 0;
781 scherzo_analyze_chord (scherzo);
783 gtk_widget_queue_draw (scherzo->window);
787 _select_challenge (scherzo_t *scherzo)
789 category_t *category_unused;
790 bool_t introduced_unused;
792 challenge_t *challenge = &scherzo->challenge;
797 if (challenge->note) {
798 score_remove_note (challenge->note);
799 challenge->note = NULL;
802 mnemon_select_item (&scherzo->mnemon,
804 &challenge->item_index,
808 item = challenge->bin->items[challenge->item_index];
811 if (strncmp (s, "treble:", 7) == 0) {
813 challenge->staff = scherzo->treble;
814 } else if (strncmp (s, "bass:", 5) == 0) {
816 challenge->staff = scherzo->bass;
819 "Malformed staff name: %s (expected 'treble:' or 'bass:')\n",
826 pitch = SCORE_PITCH_C;
829 pitch = SCORE_PITCH_D;
832 pitch = SCORE_PITCH_E;
835 pitch = SCORE_PITCH_F;
838 pitch = SCORE_PITCH_G;
841 pitch = SCORE_PITCH_A;
844 pitch = SCORE_PITCH_B;
847 fprintf (stderr, "Malformed pitch name: %s (expected 'A' - 'G')\n", s);
852 if (*s < '0' || *s > '9') {
853 fprintf (stderr, "Malformed octave number: %s (expected '0' - '9')\n", s);
859 challenge->note = score_add_note (challenge->staff, pitch, octave,
860 SCORE_DURATION_WHOLE);
861 challenge->satisfied = 0;
862 challenge->mistaken = 0;
865 /* Determine whether the user hit the correct note. */
867 _judge_note (scherzo_t *scherzo, score_note_t *note)
869 challenge_t *challenge = &scherzo->challenge;
871 if (! scherzo->challenge.note) {
872 score_set_note_color_rgb (note, 0.0, 0.0, 0.0); /* black */
876 if (note->pitch == challenge->note->pitch &&
877 note->octave == challenge->note->octave)
879 challenge->satisfied = 1;
880 score_set_note_color_rgb (note, 18/256., 130/256., 28/256.); /* green */
884 challenge->mistaken = 1;
885 score_set_note_color_rgb (note, 184/256., 4/256., 22/256.); /* red */
889 /* If the user got the right note (eventually), then score it in
890 * mnemon and show the next note. */
892 _score_challenge (scherzo_t *scherzo)
894 challenge_t *challenge = &scherzo->challenge;
896 if (! challenge->note)
899 if (! challenge->satisfied)
902 mnemon_score_item (&scherzo->mnemon, challenge->bin, challenge->item_index,
903 ! challenge->mistaken);
905 _select_challenge (scherzo);
909 on_midi_input (unused (GIOChannel *channel),
910 unused (GIOCondition condition),
913 unsigned char buf[MIDI_BUF_SIZE], *next;
914 scherzo_t *scherzo = user_data;
916 snd_seq_event_t event;
918 int need_redraw = FALSE;
920 remaining = read (scherzo->midi_fd, buf, MIDI_BUF_SIZE);
926 consumed = snd_midi_event_encode (scherzo->snd_midi_event,
927 next, remaining, &event);
929 remaining -= consumed;
932 switch (event.type) {
933 case SND_SEQ_EVENT_NONE:
934 /* Incomplete event. Nothing to do. */
936 case SND_SEQ_EVENT_NOTEON:
937 note = scherzo_press_note_midi (scherzo, event.data.note.note);
938 _judge_note (scherzo, note);
941 case SND_SEQ_EVENT_NOTEOFF:
942 scherzo_release_note_midi (scherzo, event.data.note.note);
943 _score_challenge (scherzo);
946 case SND_SEQ_EVENT_CLOCK:
947 /* Ignore for now as my piano sends a constant stream of these. */
949 case SND_SEQ_EVENT_SENSING:
950 /* Ignore for now as my piano sends a constant stream of these. */
952 case SND_SEQ_EVENT_CONTROLLER:
953 /* XXX: My piano gives me 64 for the sustain pedal, is
955 if (event.data.control.param == 64) {
956 if (event.data.control.value == 0)
957 scherzo_release_pedal (scherzo);
959 scherzo_press_pedal (scherzo);
961 fprintf (stderr, "Fixme: Unhandled MIDI Control event (param=%d, value=%d)\n",
962 event.data.control.param, event.data.control.value);
966 fprintf (stderr, "Fixme: Do not yet know how to handle MIDI event %d\n",
973 gtk_widget_queue_draw (scherzo->window);
975 /* Return TRUE to continue to get called in the future. */
980 main (int argc, char *argv[])
982 GtkWidget *drawing_area;
988 gtk_init (&argc, &argv);
990 scherzo.ctx = talloc_new (NULL);
992 scherzo.score = score_create (scherzo.ctx);
993 scherzo.staff_height = 100;
994 score_set_staff_height (scherzo.score, scherzo.staff_height);
996 score_add_brace (scherzo.score, 2);
997 scherzo.treble = score_add_staff (scherzo.score, SCORE_CLEF_G);
998 scherzo.bass = score_add_staff (scherzo.score, SCORE_CLEF_F);
1000 scherzo.chord = NULL;
1002 /* Default to octave 4 and natural for computer keyboard keypresses. */
1003 scherzo.keyboard_octave = 4;
1004 scherzo.keyboard_accidental = SCORE_PITCH_ACCIDENTAL_NATURAL;
1006 note_group_init (scherzo.ctx, &scherzo.notes_pressed);
1007 note_group_init (scherzo.ctx, &scherzo.notes_pedaled);
1009 scherzo.pedal_pressed = 0;
1011 mnemon_init (&scherzo.mnemon);
1012 /* XXX: Should create a default file if one cannot be loaded. */
1013 mnemon_load_category (&scherzo.mnemon, "scherzo-notes");
1015 scherzo.challenge.note = NULL;
1017 _select_challenge (&scherzo);
1020 err = snd_midi_event_new (MIDI_BUF_SIZE, &scherzo.snd_midi_event);
1022 fprintf (stderr, "Out of memory.\n");
1026 #define MIDI_DEVICE "/dev/midi1"
1027 scherzo.midi_fd = open (MIDI_DEVICE, O_RDONLY);
1028 if (scherzo.midi_fd < 0) {
1029 printf ("failed to open " MIDI_DEVICE ". Midi input will not be available.\n");
1031 GIOChannel *channel;
1033 channel = g_io_channel_unix_new (scherzo.midi_fd);
1034 g_io_channel_set_encoding (channel, NULL, NULL);
1035 g_io_add_watch (channel, G_IO_IN, on_midi_input, &scherzo);
1038 scherzo.window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
1040 gtk_window_set_default_size (GTK_WINDOW (scherzo.window), 1000, 600);
1042 g_signal_connect (scherzo.window, "delete-event",
1043 G_CALLBACK (on_delete_event_quit), NULL);
1045 drawing_area = gtk_drawing_area_new ();
1047 gtk_container_add (GTK_CONTAINER (scherzo.window), drawing_area);
1049 g_signal_connect (drawing_area, "expose-event",
1050 G_CALLBACK (on_expose_event_draw),
1053 g_signal_connect (scherzo.window, "key-press-event",
1054 G_CALLBACK (on_key_press_event),
1057 g_signal_connect (scherzo.window, "key-release-event",
1058 G_CALLBACK (on_key_release_event),
1061 gtk_widget_show_all (scherzo.window);
1065 mnemon_save (&scherzo.mnemon);
1067 snd_midi_event_free (scherzo.snd_midi_event);
1069 talloc_free (scherzo.ctx);