diff options
Diffstat (limited to 'src/synth_gui.c')
-rw-r--r-- | src/synth_gui.c | 108 |
1 files changed, 82 insertions, 26 deletions
diff --git a/src/synth_gui.c b/src/synth_gui.c index e1f3101..169d057 100644 --- a/src/synth_gui.c +++ b/src/synth_gui.c @@ -707,10 +707,70 @@ void get_nth_entry(const char *str, int n, char *result) { result[0] = '\0'; } +void draw_load_patch(synth_t *synth) { + static bool save_name_edit = false; + static char save_text[1024] = ""; // TODO default to current patch name + + GuiPanel((Rectangle){ WIDTH / 2.0 - 200, HEIGHT / 2.0 - 140, 400, 280 }, "Save patch"); + if (GuiButton( + (Rectangle){WIDTH / 2.0 - 50 - 50 - 3, HEIGHT / 2.0 - 12, 100, 24}, + "load")) { + if (strlen(save_text) > 0) { + if (load_synth(synth, save_text)) { + fprintf(stderr, "Can't load %s\n", save_text); + return; + } + synth->gui.popup = POPUP_NONE; + } + } + if (GuiButton((Rectangle){WIDTH / 2.0 + 3, HEIGHT / 2.0 - 12, 100, 24}, + "cancel")) { + synth->gui.popup = POPUP_NONE; + } + + + if (GuiTextBox( + (Rectangle){WIDTH / 2.0 - 125, HEIGHT / 2.0 - 18 - 24 - 6, 250, 36}, + save_text, 20, save_name_edit)) { + save_name_edit = true; + } +} + +void draw_save_patch(synth_t *synth) +{ + static bool save_name_edit = false; + static char save_text[1024] = ""; // TODO default to current patch name + + GuiPanel((Rectangle){ WIDTH / 2.0 - 200, HEIGHT / 2.0 - 140, 400, 280 }, "Save patch"); + if (GuiButton( + (Rectangle){WIDTH / 2.0 - 50 - 50 - 3, HEIGHT / 2.0 - 12, 100, 24}, + "save")) { + if (strlen(save_text) > 0) { + if (save_synth(synth, save_text)) { + fprintf(stderr, "Can't save at %s\n", save_text); + return; + } + synth->gui.popup = POPUP_NONE; + } + } + if (GuiButton((Rectangle){WIDTH / 2.0 + 3, HEIGHT / 2.0 - 12, 100, 24}, + "cancel")) { + synth->gui.popup = POPUP_NONE; + } + + + if (GuiTextBox( + (Rectangle){WIDTH / 2.0 - 125, HEIGHT / 2.0 - 18 - 24 - 6, 250, 36}, + save_text, 20, save_name_edit)) { + save_name_edit = true; + } +} + + char *soundcards = NULL; char *midi_devices = NULL; void -draw_audiomidisetup(synth_t *synth, const char *midi_devices) +draw_audiomidisetup(synth_t *synth) { static int edit_midi = 0; static int edit_sound = 0; @@ -727,9 +787,6 @@ draw_audiomidisetup(synth_t *synth, const char *midi_devices) printf("================ AUDIOMIDISETUP GUI INITIALIZED!\n"); } - BeginDrawing(); - ClearBackground(BLACK); - if (GuiButton((Rectangle){WIDTH - 100 - 50 - 6 - 100, 50 + 24 + 6 + 24 + 6 + 24 + 6 + 24 + 6, 100, 24}, "cancel")) { @@ -767,14 +824,6 @@ draw_audiomidisetup(synth_t *synth, const char *midi_devices) soundcards, &soundcard_pick, edit_sound)) { edit_sound = !edit_sound; } - - /* if (old_midi_device_id != synth->midi_device_id) { */ - /* old_midi_device_id = synth->midi_device_id; */ - /* } */ - - - - EndDrawing(); } void @@ -785,8 +834,6 @@ draw_main(synth_t *synth) if (midi_devices) free(midi_devices); synth->gui.audiomidi_initialized = 0; } - BeginDrawing(); - ClearBackground(BLACK); int fb = 0; int foffset = 9; @@ -850,12 +897,15 @@ draw_main(synth_t *synth) if ( GuiButton((Rectangle){ WIDTH - 100 - 50, 50 + 24 + 6 + 24 + 6 + 24 + 6 + 24 + 6, 100, 24 }, "audiomidi")) { synth->gui.screen = SCREEN_AUDIOMIDISETUP; } - if ( GuiButton((Rectangle){ WIDTH - 100 - 50, 50 + 24 + 6 + 24 + 6 + 24 + 6 + 24 + 6 + 24 + 6, 100, 24 }, "SAVE!")) { - save_synth(synth, "asdas"); + if (GuiButton((Rectangle){WIDTH - 100 - 50, + 50 + 24 + 6 + 24 + 6 + 24 + 6 + 24 + 6 + 24 + 6, + 100, 24}, + "SAVE!")) { + synth->gui.popup = POPUP_SAVE_PATCH; } if ( GuiButton((Rectangle){ WIDTH - 100 - 50, 50 + 24 + 6 + 24 + 6 + 24 + 6 + 24 + 6 + 24 + 6 + 24 + 6, 100, 24 }, "LOAD!")) { - load_synth(synth, "asdas"); + synth->gui.popup = POPUP_LOAD_PATCH; } @@ -867,7 +917,6 @@ draw_main(synth_t *synth) /* DrawText("KEYBOARD: Q .. ]", WIDTH / 2 -300, HEIGHT - 300 - 50, 20, LIGHTGRAY); */ /* snprintf(buf, sizeof buf, "stream time: %f", Pa_GetStreamTime(synth->stream)); */ /* DrawText(buf, WIDTH / 2 -300, HEIGHT - 300, 11, LIGHTGRAY); */ - EndDrawing(); } void @@ -878,17 +927,14 @@ rayrun(synth_t *synth){ osc_sound(0); - /* //char *midi_devices = "test1;test2;test3"; */ - char *midi_devices = get_midi_devices(); - /* int old_soundcard_id = synth->soundcard_id; */ - /* int old_midi_device_id = synth->midi_device_id; */ - SetTraceLogLevel(LOG_ERROR); InitWindow(WIDTH, HEIGHT, "Raylib synth"); SetTargetFPS(60); // Set our game to run at 60 frames-per-second while (!WindowShouldClose()) { - keyboard(synth); - mouse(synth); + if (synth->gui.popup == POPUP_NONE) { + keyboard(synth); + mouse(synth); + } if (true || mod++ % 10 == 0) { char b[256]; @@ -927,10 +973,20 @@ rayrun(synth_t *synth){ } // Draw //---------------------------------------------------------------------------------- + BeginDrawing(); + ClearBackground(BLACK); + if (synth->gui.screen == SCREEN_MAIN) draw_main(synth); else if (synth->gui.screen == SCREEN_AUDIOMIDISETUP) - draw_audiomidisetup(synth, midi_devices); + draw_audiomidisetup(synth); + + if (synth->gui.popup == POPUP_SAVE_PATCH) + draw_save_patch(synth); + else if (synth->gui.popup == POPUP_LOAD_PATCH) + draw_load_patch(synth); + + EndDrawing(); //---------------------------------------------------------------------------------- current_time = Pa_GetStreamTime(synth->stream); |