diff --git a/demos/events.c b/demos/events.c index 922357e..fac37c8 100644 --- a/demos/events.c +++ b/demos/events.c @@ -119,7 +119,7 @@ static void control_change(unsigned char controller, unsigned char value, void * printf("control change: %u, %u\n", controller, value); } -static void create_window(void *user_data) { +static void create_window(char const *title, void *user_data) { struct demo *demo = user_data; struct gral_window_interface window_interface = { &close, @@ -139,32 +139,31 @@ static void create_window(void *user_data) { &focus_enter, &focus_leave }; - demo->window = gral_window_create(demo->application, 600, 400, "gral events demo", &window_interface, demo); - demo->timer = gral_timer_create(1000, &timer, demo); - struct gral_midi_interface midi_interface = { - ¬e_on, - ¬e_off, - &control_change - }; - demo->midi = gral_midi_create(demo->application, "gral events demo", &midi_interface, demo); + demo->window = gral_window_create(demo->application, 600, 400, title, &window_interface, demo); } static void start(void *user_data) { printf("start\n"); + struct demo *demo = user_data; + demo->timer = gral_timer_create(1000, &timer, demo); + struct gral_midi_interface midi_interface = {¬e_on, ¬e_off, &control_change}; + demo->midi = gral_midi_create(demo->application, "gral events demo", &midi_interface, demo); } static void open_empty(void *user_data) { printf("open empty\n"); - create_window(user_data); + create_window("gral events demo", user_data); } static void open_file(char const *path, void *user_data) { printf("open file: %s\n", path); - create_window(user_data); + create_window(path, user_data); } static void quit(void *user_data) { printf("quit\n"); + struct demo *demo = user_data; + gral_midi_delete(demo->midi); } int main(int argc, char **argv) { @@ -172,7 +171,6 @@ int main(int argc, char **argv) { struct gral_application_interface interface = {&start, &open_empty, &open_file, &quit}; demo.application = gral_application_create("com.github.eyelash.libgral.demos.events", &interface, &demo); int result = gral_application_run(demo.application, argc, argv); - gral_midi_delete(demo.midi); gral_window_delete(demo.window); gral_application_delete(demo.application); return result;