From 0cceb2057e382129ae24565fdefff87e91b076ab Mon Sep 17 00:00:00 2001 From: gramanas Date: Sat, 29 Apr 2023 14:34:48 +0300 Subject: self contained adsr --- src/synth_gui.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'src/synth_gui.c') diff --git a/src/synth_gui.c b/src/synth_gui.c index 2405d57..df219ba 100644 --- a/src/synth_gui.c +++ b/src/synth_gui.c @@ -100,22 +100,23 @@ draw_signals(synth_t * synth, int x, int y, int width, int height) for (int i = x; i < WIDTH - x; i++) { DrawCircle(i , y + height / 2 + floor(250 * synth->viz.wave[i - x]), point_radius, MAGENTA); } - if (synth->multi) { - for (int i = x; i < WIDTH - x; i++) { - //DrawCircle(i , y + height / 2 + floor(50 * make_sample(i - x, synth, SAMPLE_RATE / synth->viz.sample_rate_divider, 1)), point_radius, RED); - } - } else { - for (int i = x; i < WIDTH - x; i++) { - //DrawCircle(i , y + height / 2 + floor(50 * make_sample((i - x) % period, synth, SAMPLE_RATE / synth->viz.sample_rate_divider, 1)), point_radius, RED); - } - } for (int i = x; i < WIDTH - x; i++) { - //DrawCircle(i , y + height - 1+ floor((WIDTH / 24) * - adsr_amplitude(synth, synth->adsr.elapsed, synth->n.noteOn, synth->n.noteOff)), point_radius, GREEN); + 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) * - adsr_amplitude(&synth->adsr, synth->midi_note[j].noteOn, synth->midi_note[j].noteOff, synth->midi_note[j].elapsed)), point_radius, GREEN); + } } 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++) { - //DrawCircle(i , y + height - 1 + floor((WIDTH / 24) * - adsr_amplitude(synth, (i - x) * (adsr_duration * SAMPLE_RATE) / WIDTH, synth->n.noteOn, synth->n.noteOff)), point_radius, BLUE); + 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) * - adsr_amplitude(&synth->adsr, synth->midi_note[j].noteOn, synth->midi_note[j].noteOff, (i - x) * (adsr_duration * SAMPLE_RATE) / WIDTH)), point_radius, BLUE); + } } } @@ -181,9 +182,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 .. ] TOGGLE MULTI: ENTER", WIDTH / 2 -300, HEIGHT - 20 - 50, 20, LIGHTGRAY); - snprintf(buf, sizeof buf, "%f", synth->viz.wave[0]); - DrawText(buf, WIDTH / 2 -300, HEIGHT - 40 - 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); EndDrawing(); //---------------------------------------------------------------------------------- -- cgit v1.2.3