diff options
author | gramanas <anastasis.gramm2@gmail.com> | 2023-08-31 01:06:56 +0300 |
---|---|---|
committer | gramanas <anastasis.gramm2@gmail.com> | 2023-08-31 01:07:16 +0300 |
commit | 0ea48752390228224e7f25575b096efc0aacd70b (patch) | |
tree | 62756ecadab1459dc02fa19e42c3cbe81deb63e2 /src/synth_gui.c | |
parent | 42479d2ed8fcbad5fb3ffb52553dad05a329590f (diff) | |
download | synth-project-0ea48752390228224e7f25575b096efc0aacd70b.tar.gz synth-project-0ea48752390228224e7f25575b096efc0aacd70b.tar.bz2 synth-project-0ea48752390228224e7f25575b096efc0aacd70b.zip |
Lets work on generators
Diffstat (limited to 'src/synth_gui.c')
-rw-r--r-- | src/synth_gui.c | 94 |
1 files changed, 64 insertions, 30 deletions
diff --git a/src/synth_gui.c b/src/synth_gui.c index ca1acc9..46ec71f 100644 --- a/src/synth_gui.c +++ b/src/synth_gui.c @@ -4,6 +4,53 @@ //#include "raylib.h" void +draw_text(synth_t * synth, Font f, int x, int y) +{ + char buf[64]; + int count = 0; + float text_size = 10; + int offset = 12; + + snprintf(buf, sizeof buf, "lfo freq %.4f", synth->cc_lfo_freq.value); + DrawText(buf, x, y + offset * count++, text_size, GRAY); + snprintf(buf, sizeof buf, "lfo amp %.4f", synth->cc_lfo_amp.value); + DrawText(buf, x, y + offset * count++, text_size, GRAY); + snprintf(buf, sizeof buf, "filter reso %.4f", synth->cc_resonance.value); + DrawText(buf, x, y + offset * count++, text_size, GRAY); + snprintf(buf, sizeof buf, "filter cutoff %.1f", synth->cc_cutoff.value); + 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); + + DrawRectangleLines(x - 6, y - 3, 120, 3 + (count * offset) + 3, GRAY); +} + +void +mouse(void *synthData, PaStream *stream) +{ + synth_t * synth = (synth_t *)synthData; + float m = GetMouseWheelMove(); + int x = 0; + if (m < 0) x = -1; + else if (m > 0) x = 1; + int y = GetMouseY(); + + if (x) { + if (y > 20 && y <= 32) { + cc_step(&synth->cc_lfo_freq, x); + } else if (y > 32 && y <= 44) { + cc_step(&synth->cc_lfo_amp, x); + } else if (y > 44 && y <= 56) { + cc_step(&synth->cc_resonance, x); + } else if (y > 56 && y <= 68) { + cc_step(&synth->cc_cutoff, x); + } else if (y > 68 && y <= 80) { + cc_step(&synth->cc_pitch, x); + } + } +} + +void keyboard(void *synthData, PaStream *stream) { synth_t * synth = (synth_t *)synthData; @@ -104,7 +151,7 @@ keyboard(void *synthData, PaStream *stream) } void -draw_adsr_sliders(synth_t * synth, int x, int y, int width, int height, int offset) +draw_bars(synth_t * synth, int x, int y, int width, int height, int offset) { char buf[64]; int count = 0; @@ -127,6 +174,8 @@ draw_adsr_sliders(synth_t * synth, int x, int y, int width, int height, int offs synth->lfo.freq = GuiSliderBar((Rectangle){ x, y + count++ * (height + offset), width, height }, "lfo freq: ", buf, synth->lfo.freq , 0.001f, 10.0f); snprintf(buf, sizeof buf, "%.3f", synth->lfo.amp); synth->lfo.amp = GuiSliderBar((Rectangle){ x, y + count++ * (height + offset), width, height }, "lfo amp: ", buf, synth->lfo.amp , 0.0f, 0.93f); + snprintf(buf, sizeof buf, "%.3f", synth->gain); + synth->gain = GuiSlider((Rectangle){ x, y + count++ * (height + offset), width, height }, "gain: ", buf, synth->gain , 0.0f, 2.0f); } void @@ -161,18 +210,20 @@ draw_signals(synth_t * synth, int x, int y, int width, int height) } } +#include "raystyle.h" void -rayrun(void *synthData) -{ +rayrun(void *synthData){ synth_t * synth = (synth_t *)synthData; PaTime current_time = 0; PaTime prev_time = 0; - InitWindow(WIDTH, HEIGHT, "Raylib synth"); + InitWindow(WIDTH, HEIGHT, "Raylib synth"); + Font f = LoadFont("/usr/share/fonts/TTF/DejaVuSans.ttf"); SetTargetFPS(60); // Set our game to run at 60 frames-per-second while (!WindowShouldClose()) { keyboard(synth, synth->stream); + mouse(synth, synth->stream); int prec = 100000; if (IsKeyPressed(KEY_ENTER)) { @@ -187,31 +238,15 @@ rayrun(void *synthData) // GUI char buf[64]; - draw_adsr_sliders(synth, 30, 20, 256, 20, 4); - + draw_bars(synth, 33, 20, 256, 20, 4); + draw_text(synth, f, WIDTH / 2 - 108, 20); /* if ( GuiButton((Rectangle){ WIDTH / 2 - 108, 150 - 42 - 6 - 6, 216, 6 }, "")) { */ /* synth->freq_offset = 0; */ /* } */ - snprintf(buf, sizeof buf, "extra pitch %.4f", synth->cc_pitch.value); - DrawText(buf, WIDTH / 2 - 108, 150 - 82, 20, LIGHTGRAY); - snprintf(buf, sizeof buf, "filter cutoff %.1f", synth->cc_cutoff.value); - DrawText(buf, WIDTH / 2 - 108, 150 - 42, 20, LIGHTGRAY); - snprintf(buf, sizeof buf, "filter reso %.4f", synth->cc_resonance.value); - DrawText(buf, WIDTH / 2 - 108, 150 - 62, 20, LIGHTGRAY); - snprintf(buf, sizeof buf, "lfo amp %.4f", synth->cc_lfo_amp.value); - DrawText(buf, WIDTH / 2 - 108, 150 - 22, 20, LIGHTGRAY); - snprintf(buf, sizeof buf, "lfo freq %.4f", synth->cc_lfo_freq.value); - DrawText(buf, WIDTH / 2 - 108, 150 - 102, 20, LIGHTGRAY); /* snprintf(buf, sizeof buf, "freq offset %.1f", synth->freq_offset); */ /* DrawText(buf, WIDTH / 2 - 108, 150 - 42, 20, LIGHTGRAY); */ - /* synth->freq_offset = GuiSlider((Rectangle){ WIDTH / 2 - 108, 150 - 42, 216, 24 }, "fine", buf, synth->freq_offset , -20.0f, 20.0f); */ - - if ( GuiButton((Rectangle){ WIDTH / 2 - 108, 150 - 6 - 6, 216, 6 }, "")) { - synth->gain = 1; - } - snprintf(buf, sizeof buf, "%.1f", synth->gain); - synth->gain = GuiSlider((Rectangle){ WIDTH / 2 - 108, 150, 216, 24 }, "gain", buf, synth->gain , 0.0f, 2.0f); + /* synth->freq_offset = GuiSlider((Rectangle){ WIDTH / 2 - 108, 150 - 42, 216, 24 }, "fine", buf, synth->freq_offset , -20.0f, 20.0f); */ if ( GuiButton((Rectangle){ WIDTH / 2 - 108, 150 - 6 - 6 + 42, 216, 6 }, "")) { synth->x = 1; @@ -219,9 +254,9 @@ rayrun(void *synthData) snprintf(buf, sizeof buf, "%.1f", synth->x); synth->x = GuiSlider((Rectangle){ WIDTH / 2 - 108, 150 + 42, 216, 24 }, "x", buf, synth->x , 0.0f, 2.0f); - synth->multi = GuiToggle((Rectangle){ WIDTH - 100 - 50 - 100 - 50 , 50, 100, 24 }, "!MULTI!", synth->multi); - synth->filter = GuiToggle((Rectangle){ WIDTH - 100 - 50 - 100 - 50 , 50 + 24 + 6, 100, 24 }, "FILTER", synth->filter); - synth->poly = GuiToggle((Rectangle){ WIDTH - 100 - 50 - 100 - 50 , 50 + 24 + 6 + 24 + 6, 100, 24 }, "POLY", synth->poly); + //synth->multi = GuiToggle((Rectangle){ WIDTH - 100 - 50 - 100 - 50 , 50, 100, 24 }, "!MULTI!", synth->multi); + synth->filter = GuiToggle((Rectangle){ WIDTH - 100 - 50 - 100 - 50 , 50 , 100, 24 }, "FILTER", synth->filter); + //synth->poly = GuiToggle((Rectangle){ WIDTH - 100 - 50 - 100 - 50 , 50 + 24 + 6 + 24 + 6, 100, 24 }, "POLY", synth->poly); GuiSpinner((Rectangle){ WIDTH - 100 - 50 , 50, 100, 24 }, "oct: ", &(synth->octave), 0, 7, 0); snprintf(buf, sizeof buf, "generator %d --> ", synth->geni); @@ -229,14 +264,13 @@ rayrun(void *synthData) synth->clamp = GuiToggle((Rectangle){ WIDTH - 100 - 50, 50 + 24 + 6 + 24 + 6, 100, 24 }, "clamp", synth->clamp); - // signals draw_signals(synth, 20, 390, WIDTH - 2*20, 200); //DrawText("THE SYNTH!!!!!!!!!!!!!!!!!!1", WIDTH / 2 - 100, 50, 20, LIGHTGRAY); - DrawText("KEYBOARD: Q .. ] TOGGLE MULTI: ENTER", WIDTH / 2 -300, HEIGHT - 300 - 50, 20, LIGHTGRAY); - snprintf(buf, sizeof buf, "%f stream time: %f", synth->viz.wave[0], Pa_GetStreamTime(synth->stream)); - DrawText(buf, WIDTH / 2 -300, HEIGHT - 300, 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(); //---------------------------------------------------------------------------------- |