Skip to content

Commit

Permalink
improve the events demo
Browse files Browse the repository at this point in the history
  • Loading branch information
eyelash committed Sep 18, 2024
1 parent 3d9e0b4 commit 482ec20
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions demos/events.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -139,40 +139,38 @@ 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 = {
&note_on,
&note_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 = {&note_on, &note_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) {
struct demo demo;
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;
Expand Down

0 comments on commit 482ec20

Please sign in to comment.