From 1e374b426b4182c7b73b35219aadaca267b9623c Mon Sep 17 00:00:00 2001 From: gramanas Date: Wed, 19 Apr 2023 04:00:08 +0300 Subject: fake poly --- src/synth_gui.c | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) (limited to 'src/synth_gui.c') diff --git a/src/synth_gui.c b/src/synth_gui.c index f5e02cf..d09a9b6 100644 --- a/src/synth_gui.c +++ b/src/synth_gui.c @@ -14,8 +14,16 @@ set_note(void *synthData, float note, PaTime time, int key) synth->n.noteOn = time; synth->n.noteOff = 0; synth->n.elapsed = 0; - synth->adsr.elapsed = 0; + if (synth->poly) { + if (!synth->notes_active) synth->adsr.elapsed = 0; + } else { + synth->adsr.elapsed = 0; + } + synth->active = 1; + + synth->freq[synth->notes_active] = note; + synth->freq_count[synth->notes_active++] = 0; } @@ -33,15 +41,40 @@ keyboard(void *synthData, PaStream *stream) note = notes[i % 12][(synth->octave + (i / 12)) % 8]; if (note) { set_note(synth, note, Pa_GetStreamTime(stream), keys[i]); - printf("Note On : %s[%d]\n", int_to_note(i % 12), (synth->octave + (i / 12)) % 8); + //printf("Note On : %s[%d] %fHz\n", int_to_note(i % 12), (synth->octave + (i / 12)) % 8, note); + } + printf("["); + for (int j = 0; j < synth->notes_active; j++) { + printf("%f ", synth->freq[j]); } + printf("]\n"); } } for (int i = 0; keys[i]; i++) { if (IsKeyReleased(keys[i])) { + note = notes[i % 12][(synth->octave + (i / 12)) % 8]; + int j; + for (j = 0; j < synth->notes_active; j++) { + // printf("Comparing freq(j): %f to note: %f\n", synth->freq[j], note); + if (synth->freq[j] == note) { + synth->freq[j] = 0; + synth->notes_active--; + //printf("Note down %f\n", note); + break; + } + } + for (int k = j; k < synth->notes_active + 1; k++) { + //printf("moving %f <-- %f\n", synth->freq[k], synth->freq[k + 1]); + synth->freq[k] = synth->freq[k + 1]; + } + printf("["); + for (int j = 0; j < synth->notes_active; j++) { + printf("%f ", synth->freq[j]); + } + printf("]\n"); if (synth->n.key == keys[i]) { synth->n.noteOff = Pa_GetStreamTime(stream); - printf("Note Off: %s[%d]\n", int_to_note(i % 12), (synth->octave + (i / 12)) % 8); + //printf("Note Off: %s[%d]\n", int_to_note(i % 12), (synth->octave + (i / 12)) % 8); } } } @@ -147,6 +180,7 @@ rayrun(void *synthData, PaStream *stream) 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); GuiSpinner((Rectangle){ WIDTH - 100 - 50 , 50, 100, 24 }, "oct: ", &(synth->octave), 0, 7, 0); snprintf(buf, sizeof buf, "generator %d --> ", synth->geni); -- cgit v1.2.3