diff options
Diffstat (limited to 'src/synth_gui.c')
-rw-r--r-- | src/synth_gui.c | 79 |
1 files changed, 28 insertions, 51 deletions
diff --git a/src/synth_gui.c b/src/synth_gui.c index 8aef751..35c940a 100644 --- a/src/synth_gui.c +++ b/src/synth_gui.c @@ -157,7 +157,7 @@ draw_bars(synth_t * synth, int x, int y, int width, int height, int offset) int count = 0; snprintf(buf, sizeof buf, "%.3f", synth->adsr.a); - synth->adsr.a = GuiSlider((Rectangle){ x, y + count++ * (height + offset), width, height }, "A: ", buf, synth->adsr.a , 0.0f, 2.0f); + synth->adsr.a = GuiSlider((Rectangle){ x, y + count++ * (height + offset), width, height }, "A: ", buf, synth->adsr.a , 0.00001f, 2.0f); snprintf(buf, sizeof buf, "%.3f", synth->adsr.peak); synth->adsr.peak = GuiSlider((Rectangle){ x, y + count++ * (height + offset), width, height }, "P: ", buf, synth->adsr.peak , 0.0f, 1.0f); snprintf(buf, sizeof buf, "%.3f", synth->adsr.d); @@ -192,18 +192,14 @@ draw_signals(synth_t * synth, int x, int y, int width, int height) //GuiSpinner((Rectangle){ x+ 100, y - 24 - 6, 100, 24 }, "rate divider: ", &(synth->viz.sample_rate_divider), 1, 10, 0); for (int i = x; i < WIDTH - x; i++) { - DrawCircle(i , y + height / 2 + floor(250 * synth->viz.wave[i - x]), point_radius, RAYWHITE); + if (synth->viz.wave[i - x] > 1 || synth->viz.wave[i - x] < -1) + DrawCircle(i , y + height / 2 + floor(50 * synth->viz.wave[i - x]), point_radius, RED); + else if (synth->viz.wave[i - x] >= 0.99 || synth->viz.wave[i - x] <= -0.99) + DrawCircle(i , y + height / 2 + floor(50 * synth->viz.wave[i - x]), point_radius, MAGENTA); + else + DrawCircle(i , y + height / 2 + floor(50 * synth->viz.wave[i - x]), point_radius, RAYWHITE); } -/* float adsr_duration = synth->adsr.a + synth->adsr.d + (synth->adsr.a + synth->adsr.d + synth->adsr.r) / 3.0 + synth->adsr.r; */ -/* for (int i = x; i < WIDTH - x; i++) { */ -/* for (int j = 0; j < MIDI_NOTES; j++) { */ -/* if (!synth->midi_note[j].active) */ -/* continue; */ - -/* DrawCircle(i , y + height - 1 + 4.5*floor((WIDTH / 24) * - fix_adsr(&synth->adsr, synth->midi_note[j].noteOn, synth->midi_note[j].noteOff, (i - x) * (adsr_duration * SAMPLE_RATE) / WIDTH, synth->midi_note[j].noteOffSample)), point_radius, BLUE); */ -/* } */ -/* } */ int c = 0; for (int i = 0; i < MIDI_NOTES; i++) { if (!synth->midi_note[i].active) continue; @@ -212,35 +208,25 @@ draw_signals(synth_t * synth, int x, int y, int width, int height) int x_prev = x; for (int i = 0; i < MIDI_NOTES; i++) { - if (!synth->midi_note[i].active) - continue; - - int rec_y = y + height - 1 + - 4.5 * floor( (WIDTH / 24) * - - fix_adsr(&synth->adsr, - synth->midi_note[i].noteOn, - synth->midi_note[i].noteOff, - synth->midi_note[i].elapsed, - synth->midi_note[i].noteOffSample)); - - int rec_width = (WIDTH - x - x) / c; - int rec_height = HEIGHT - rec_y; - - //DrawLine(x_prev, v, x_prev + (WIDTH - x) / c, v , WHITE); - DrawRectangleGradientV(x_prev, rec_y, rec_width, rec_height, ColorAlpha(GREEN, .2) ,ColorAlpha(RED, .2)); - DrawRectangleLines(x_prev, rec_y, rec_width, rec_height, GRAY); - x_prev += rec_width; - } - + if (!synth->midi_note[i].active) + continue; + + int rec_y = y + height - 1 + + 4.5 * floor( (WIDTH / 24) * + - fix_adsr(&synth->adsr, + synth->midi_note[i].noteOn, + synth->midi_note[i].noteOff, + synth->midi_note[i].elapsed, + synth->midi_note[i].noteOffSample)); + + int rec_width = (WIDTH - x - x) / c; + int rec_height = HEIGHT - rec_y; - /* for (int i = x; i < WIDTH - x; i++) { */ - /* for (int j = 0; j < MIDI_NOTES; j++) { */ - /* if (!synth->midi_note[j].active) */ - /* continue; */ - - /* DrawCircle(i , y + height - 1 + 4.5*floor((WIDTH / 24) * - fix_adsr(&synth->adsr, synth->midi_note[j].noteOn, synth->midi_note[j].noteOff, synth->midi_note[j].elapsed, synth->midi_note[j].noteOffSample)), point_radius, GREEN); */ - /* } */ - /* } */ + //DrawLine(x_prev, v, x_prev + (WIDTH - x) / c, v , WHITE); + DrawRectangleGradientV(x_prev, rec_y, rec_width, rec_height, ColorAlpha(GREEN, .2) ,ColorAlpha(RED, .2)); + DrawRectangleLines(x_prev, rec_y, rec_width, rec_height, GRAY); + x_prev += rec_width; + } } @@ -274,22 +260,13 @@ rayrun(void *synthData){ 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, "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 + 42, 216, 6 }, "")) { synth->x = 1; } 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 , 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); @@ -302,9 +279,9 @@ rayrun(void *synthData){ draw_signals(synth, 20, 390, WIDTH - 2*20, 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); + /* 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(); //---------------------------------------------------------------------------------- |