diff options
Diffstat (limited to 'src/synth_gui.c')
-rw-r--r-- | src/synth_gui.c | 308 |
1 files changed, 191 insertions, 117 deletions
diff --git a/src/synth_gui.c b/src/synth_gui.c index cb899db..43cfda1 100644 --- a/src/synth_gui.c +++ b/src/synth_gui.c @@ -23,6 +23,9 @@ draw_text(synth_t * synth, int x, int y) DrawText(buf, x, y + offset * count++, text_size, GRAY); snprintf(buf, sizeof buf, "extra pitch %.4f", synth->cc_pitch.value); DrawText(buf, x, y + offset * count++, text_size, GRAY); + count++; + snprintf(buf, sizeof buf, "%s", synth->soundcard.name); + DrawText(buf, x, y + offset * count++, text_size, GRAY); DrawRectangleLines(x - 6, y - 3, 120, 3 + (count * offset) + 3, GRAY); } @@ -684,6 +687,184 @@ draw_bars(synth_t * synth, int x, int y, int width, int height, int offset) #include "sound.h" #include "midi.h" +void get_nth_entry(const char *str, int n, char *result) { + char temp[strlen(str) + 1]; // Create a modifiable copy + strcpy(temp, str); + + char *token = strtok(temp, ";"); + int count = 0; + + while (token) { + if (count == n) { + strcpy(result, token); // Replace result content + return; + } + token = strtok(NULL, ";"); + count++; + } + + // If nth entry isn't found, clear result + result[0] = '\0'; +} + +char *soundcards = NULL; +void +draw_audiomidisetup(synth_t *synth, const char *midi_devices) +{ + static int edit_midi = 0; + static int edit_sound = 0; + + static int pick = 0; + + if (synth->gui.audiomidi_initialized == 0) { + soundcards = get_soundcards(); + pick = 0; + synth->gui.audiomidi_initialized = 1; + 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")) { + synth->gui.screen = SCREEN_MAIN; + } + if (GuiButton((Rectangle){WIDTH - 100 - 50, + 50 + 24 + 6 + 24 + 6 + 24 + 6 + 24 + 6, 100, 24}, + "apply")) { + if (pick != 0) { + get_nth_entry(soundcards, pick, synth->soundcard.name); + printf("CHANGING TO %s\n", synth->soundcard.name); + change_soundcard(synth); + } + synth->gui.screen = SCREEN_MAIN; + } + + + // audio dev + if (GuiDropdownBox((Rectangle){WIDTH - 300 - 50, + 12 + 24 + 6, 300, + 24}, + soundcards, &pick, edit_sound)) { + edit_sound = !edit_sound; + } + + /* if (old_soundcard_id != synth->soundcard_id) { */ + /* old_soundcard_id = synth->soundcard_id; */ + /* get_nth_entry(soundcards, pick, synth->soundcard_name); */ + /* } */ + // midi dev + if (GuiDropdownBox((Rectangle){WIDTH - 300 - 50, + 12, 200, + 24}, + midi_devices, &synth->midi_device_id, edit_midi)) { + edit_midi = !edit_midi; + } + + /* if (old_midi_device_id != synth->midi_device_id) { */ + /* old_midi_device_id = synth->midi_device_id; */ + /* change_midi_device(synth); */ + /* } */ + + + + EndDrawing(); +} + +void +draw_main(synth_t *synth) +{ + if (synth->gui.audiomidi_initialized != 0) { + if (soundcards) free(soundcards); + synth->gui.audiomidi_initialized = 0; + } + BeginDrawing(); + ClearBackground(BLACK); + + int fb = 0; + int foffset = 9; + draw_cc_circle(&synth->cc_adsr_a, 30 + (30 + foffset) * fb++, 180, 30, 30); + draw_cc_circle(&synth->cc_adsr_peak, 30 + (30 + foffset) * fb++, 180, 30, 30); + draw_cc_circle(&synth->cc_adsr_d, 30 + (30 + foffset) * fb++, 180, 30, 30); + draw_cc_circle(&synth->cc_adsr_s, 30 + (30 + foffset) * fb++, 180, 30, 30); + draw_cc_circle(&synth->cc_adsr_r, 30 + (30 + foffset) * fb++, 180, 30, 30); + + draw_cc_circle(&synth->cc_pitch, 30, 220, 30, 30); + + fb = 0; + draw_cc_circle(&synth->cc_f_adsr_a, 30 + (30 + foffset) * fb++, 260, 30, 30); + draw_cc_circle(&synth->cc_f_adsr_peak, 30 + (30 + foffset) * fb++, 260, 30, 30); + draw_cc_circle(&synth->cc_f_adsr_d, 30 + (30 + foffset) * fb++, 260, 30, 30); + draw_cc_circle(&synth->cc_f_adsr_s, 30 + (30 + foffset) * fb++, 260, 30, 30); + draw_cc_circle(&synth->cc_f_adsr_r, 30 + (30 + foffset) * fb++, 260, 30, 30); + + draw_cc_hbar(&synth->cc_cutoff, 30, 300, 256, 24); + draw_cc_vbar(&synth->cc_resonance, 330, 20, 24, 256); + //draw_cc_vbar(&synth->cc_adsr_s, 30, 250, 30, 30); + + + // GUI + char buf[64]; + snprintf(buf, sizeof buf, "%d", synth->wvt_pos); + synth->wvt_pos = GuiSlider((Rectangle){WIDTH / 2.0 - 108, 150 + 42 + 42, 216, 24 }, "", buf, synth->wvt_pos , 0, 127); + set_sound_start(synth->wvt_pos*2048); + set_sound_len(synth->wvt_pos*2048 + 2048); + + draw_bars(synth, 20, 20, 200, 16, 3); + draw_text(synth, WIDTH / 2 - 108, 20); + + if ( GuiButton((Rectangle){ WIDTH / 2.0 - 108, 150 - 6 - 6 + 42, 216, 6 }, "")) { + synth->x = 1; + } + snprintf(buf, sizeof buf, "%.1f", synth->x); + synth->x = GuiSlider((Rectangle){ WIDTH / 2.0 - 108, 150 + 42, 216, 24 }, "x", buf, synth->x , 0.0f, 2.0f); + + synth->filter = GuiToggle((Rectangle){ WIDTH - 100 - 50 - 100 - 50 , 50 , 46, 24 }, "LP", synth->filter); + synth->biquad = GuiToggle((Rectangle){ WIDTH - 100 - 50 - 100 - 50 + 46 + 8 , 50 , 46, 24 }, "bq", synth->biquad); + if (synth->biquad) { + if (GuiToggle((Rectangle){WIDTH - 100 - 50 - 100 - 50 , 50 + 24 + 6 + 24 + 6, 24, 24}, "l", synth->biquad_type == 'l')) { + synth->biquad_type = 'l'; + } + if (GuiToggle((Rectangle){WIDTH - 100 - 50 - 100 - 50 + 24 + 8, 50 + 24 + 6 + 24 + 6, 24, 24}, "b", synth->biquad_type == 'b')) { + synth->biquad_type = 'b'; + } + if (GuiToggle((Rectangle){WIDTH - 100 - 50 - 100 - 50 + 24 + 8 + 24 + 8 , 50 + 24 + 6 + 24 + 6, 24, 24}, "h", synth->biquad_type == 'h')) { + synth->biquad_type = 'h'; + } + } + + GuiSpinner((Rectangle){ WIDTH - 100 - 50 , 50, 100, 24 }, "oct: ", &(synth->octave), 0, 7, 0); + snprintf(buf, sizeof buf, "generator %d --> ", synth->geni); + GuiSpinner((Rectangle){ WIDTH - 100 - 50 , 50 + 24 + 6, 100, 24 }, buf, &(synth->geni), 0, 6, 0); + + synth->clamp = GuiToggle((Rectangle){ WIDTH - 100 - 50, 50 + 24 + 6 + 24 + 6, 100, 24 }, "clamp", synth->clamp); + synth->delay = GuiToggle((Rectangle){ WIDTH - 100 - 50, 50 + 24 + 6 + 24 + 6 + 24 + 6, 100, 24 }, "delay", synth->delay); + + 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 + 24 + 6, 100, 24 }, "LOAD!")) { + load_synth(synth, "asdas"); + } + + + // signals + draw_signals(synth, 20, 390, WIDTH - 2*20, 200); + //draw_signals(synth, 300, 390, WIDTH - 2*300, 200); + + //DrawText("THE SYNTH!!!!!!!!!!!!!!!!!!1", WIDTH / 2 - 100, 50, 20, LIGHTGRAY); + /* 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 rayrun(synth_t *synth){ PaTime current_time = 0; @@ -691,11 +872,10 @@ rayrun(synth_t *synth){ osc_sound(0); + /* //char *midi_devices = "test1;test2;test3"; */ char *midi_devices = get_midi_devices(); - //char *midi_devices = "test1;test2;test3"; - char *soundcards = get_soundcards(); - int old_soundcard_id = synth->soundcard_id; - int old_midi_device_id = synth->midi_device_id; + /* int old_soundcard_id = synth->soundcard_id; */ + /* int old_midi_device_id = synth->midi_device_id; */ InitWindow(WIDTH, HEIGHT, "Raylib synth"); SetTargetFPS(60); // Set our game to run at 60 frames-per-second @@ -705,126 +885,20 @@ rayrun(synth_t *synth){ // Draw //---------------------------------------------------------------------------------- - BeginDrawing(); - ClearBackground(BLACK); - - int fb = 0; - int foffset = 9; - draw_cc_circle(&synth->cc_adsr_a, 30 + (30 + foffset) * fb++, 180, 30, 30); - draw_cc_circle(&synth->cc_adsr_peak, 30 + (30 + foffset) * fb++, 180, 30, 30); - draw_cc_circle(&synth->cc_adsr_d, 30 + (30 + foffset) * fb++, 180, 30, 30); - draw_cc_circle(&synth->cc_adsr_s, 30 + (30 + foffset) * fb++, 180, 30, 30); - draw_cc_circle(&synth->cc_adsr_r, 30 + (30 + foffset) * fb++, 180, 30, 30); - - draw_cc_circle(&synth->cc_pitch, 30, 220, 30, 30); - - fb = 0; - draw_cc_circle(&synth->cc_f_adsr_a, 30 + (30 + foffset) * fb++, 260, 30, 30); - draw_cc_circle(&synth->cc_f_adsr_peak, 30 + (30 + foffset) * fb++, 260, 30, 30); - draw_cc_circle(&synth->cc_f_adsr_d, 30 + (30 + foffset) * fb++, 260, 30, 30); - draw_cc_circle(&synth->cc_f_adsr_s, 30 + (30 + foffset) * fb++, 260, 30, 30); - draw_cc_circle(&synth->cc_f_adsr_r, 30 + (30 + foffset) * fb++, 260, 30, 30); - - draw_cc_hbar(&synth->cc_cutoff, 30, 300, 256, 24); - draw_cc_vbar(&synth->cc_resonance, 330, 20, 24, 256); - //draw_cc_vbar(&synth->cc_adsr_s, 30, 250, 30, 30); - - - // GUI - char buf[64]; - snprintf(buf, sizeof buf, "%d", synth->wvt_pos); - synth->wvt_pos = GuiSlider((Rectangle){WIDTH / 2.0 - 108, 150 + 42 + 42, 216, 24 }, "", buf, synth->wvt_pos , 0, 127); - set_sound_start(synth->wvt_pos*2048); - set_sound_len(synth->wvt_pos*2048 + 2048); - - draw_bars(synth, 20, 20, 200, 16, 3); - draw_text(synth, WIDTH / 2 - 108, 20); - - if ( GuiButton((Rectangle){ WIDTH / 2.0 - 108, 150 - 6 - 6 + 42, 216, 6 }, "")) { - synth->x = 1; - } - snprintf(buf, sizeof buf, "%.1f", synth->x); - synth->x = GuiSlider((Rectangle){ WIDTH / 2.0 - 108, 150 + 42, 216, 24 }, "x", buf, synth->x , 0.0f, 2.0f); - - synth->filter = GuiToggle((Rectangle){ WIDTH - 100 - 50 - 100 - 50 , 50 , 46, 24 }, "LP", synth->filter); - synth->biquad = GuiToggle((Rectangle){ WIDTH - 100 - 50 - 100 - 50 + 46 + 8 , 50 , 46, 24 }, "bq", synth->biquad); - if (synth->biquad) { - if (GuiToggle((Rectangle){WIDTH - 100 - 50 - 100 - 50 , 50 + 24 + 6 + 24 + 6, 24, 24}, "l", synth->biquad_type == 'l')) { - synth->biquad_type = 'l'; - } - if (GuiToggle((Rectangle){WIDTH - 100 - 50 - 100 - 50 + 24 + 8, 50 + 24 + 6 + 24 + 6, 24, 24}, "b", synth->biquad_type == 'b')) { - synth->biquad_type = 'b'; - } - if (GuiToggle((Rectangle){WIDTH - 100 - 50 - 100 - 50 + 24 + 8 + 24 + 8 , 50 + 24 + 6 + 24 + 6, 24, 24}, "h", synth->biquad_type == 'h')) { - synth->biquad_type = 'h'; - } - } - - GuiSpinner((Rectangle){ WIDTH - 100 - 50 , 50, 100, 24 }, "oct: ", &(synth->octave), 0, 7, 0); - snprintf(buf, sizeof buf, "generator %d --> ", synth->geni); - GuiSpinner((Rectangle){ WIDTH - 100 - 50 , 50 + 24 + 6, 100, 24 }, buf, &(synth->geni), 0, 6, 0); - - synth->clamp = GuiToggle((Rectangle){ WIDTH - 100 - 50, 50 + 24 + 6 + 24 + 6, 100, 24 }, "clamp", synth->clamp); - synth->delay = GuiToggle((Rectangle){ WIDTH - 100 - 50, 50 + 24 + 6 + 24 + 6 + 24 + 6, 100, 24 }, "delay", synth->delay); - - 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 + 24 + 6, 100, 24 }, "LOAD!")) { - load_synth(synth, "asdas"); - } - - static int edit_midi = 0; - static int edit_sound = 0; - - // signals - draw_signals(synth, 20, 390, WIDTH - 2*20, 200); - //draw_signals(synth, 300, 390, WIDTH - 2*300, 200); - - //DrawText("THE SYNTH!!!!!!!!!!!!!!!!!!1", WIDTH / 2 - 100, 50, 20, LIGHTGRAY); - /* 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); */ - - // midi dev - if (GuiDropdownBox( - (Rectangle){WIDTH - 200 - 50, - 50 + 24 + 6 + 24 + 6 + 24 + 6 + 24 + 6 , 200, - 24}, - midi_devices, &synth->midi_device_id, edit_midi)) { - edit_midi = !edit_midi; - } - - if (old_midi_device_id != synth->midi_device_id) { - old_midi_device_id = synth->midi_device_id; - change_midi_device(synth); - } - - // audio dev - if (GuiDropdownBox( - (Rectangle){WIDTH - 300 - 50, - 12, 300, - 24}, - soundcards, &synth->soundcard_id, edit_sound)) { - edit_sound = !edit_sound; - } - - if (old_soundcard_id != synth->soundcard_id) { - old_soundcard_id = synth->soundcard_id; - change_soundcard(synth); - } - - EndDrawing(); + if (synth->gui.screen == SCREEN_MAIN) + draw_main(synth); + else if (synth->gui.screen == SCREEN_AUDIOMIDISETUP) + draw_audiomidisetup(synth, midi_devices); //---------------------------------------------------------------------------------- + current_time = Pa_GetStreamTime(synth->stream); //printf("%f :: %ld\n", current_time - prev_time, phase); prev_time = current_time; (void)prev_time; } - free(soundcards); - free(midi_devices); + /* free(soundcards); */ + /* free(midi_devices); */ CloseWindow(); } |