summaryrefslogtreecommitdiffstats
path: root/src/synth_gui.c
diff options
context:
space:
mode:
authorgramanas <anastasis.gramm2@gmail.com>2023-04-29 14:34:36 +0300
committergramanas <anastasis.gramm2@gmail.com>2023-04-29 14:34:36 +0300
commit402f6791150d503fc29ed75a7b8be9abfdd3867f (patch)
tree1061ae5cd2f9e1728b59a1ae6fbe0dfe8582c849 /src/synth_gui.c
parente919ad41b01595d2cd8fb0771bd3542817ec1058 (diff)
downloadsynth-project-402f6791150d503fc29ed75a7b8be9abfdd3867f.tar.gz
synth-project-402f6791150d503fc29ed75a7b8be9abfdd3867f.tar.bz2
synth-project-402f6791150d503fc29ed75a7b8be9abfdd3867f.zip
midi cc
Diffstat (limited to 'src/synth_gui.c')
-rw-r--r--src/synth_gui.c30
1 files changed, 23 insertions, 7 deletions
diff --git a/src/synth_gui.c b/src/synth_gui.c
index fc4e5fa..2405d57 100644
--- a/src/synth_gui.c
+++ b/src/synth_gui.c
@@ -34,15 +34,26 @@ 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] %fHz\n", int_to_note(i % 12), (synth->octave + (i / 12)) % 8, note);
+ synth->midi_note[i].freq = 16.35 * pow(2, (synth->octave + i / 12.0)); //notes[i % 12][(synth->octave + (i / 12)) % 8];
+ //synth->midi_note[i].freq = notes[i % 12][(synth->octave + (i / 12)) % 8];
+ synth->midi_note[i].channel = -1;
+ synth->midi_note[i].noteOn = Pa_GetStreamTime(synth->stream);
+ synth->midi_note[i].noteOff = 0;
+ synth->midi_note[i].velocity = 1.0;
+ synth->midi_note[i].elapsed = 0;
+ synth->midi_note[i].active = 1;
}
}
}
for (int i = 0; keys[i]; i++) {
if (IsKeyReleased(keys[i])) {
+ synth->midi_note[i].noteOff = Pa_GetStreamTime(synth->stream);
note = notes[i % 12][(synth->octave + (i / 12)) % 8];
if (synth->n.key == keys[i]) {
synth->n.noteOff = Pa_GetStreamTime(stream);
+ synth->midi_note[i].noteOff = Pa_GetStreamTime(synth->stream);
//printf("Note Off: %s[%d]\n", int_to_note(i % 12), (synth->octave + (i / 12)) % 8);
}
}
@@ -69,6 +80,10 @@ draw_adsr_sliders(synth_t * synth, int x, int y, int width, int height, int offs
synth->cutoff = GuiSliderBar((Rectangle){ x, y + count++ * (height + offset), width, height }, "fC: ", buf, synth->cutoff , 0.0f, 11000.0f);
snprintf(buf, sizeof buf, "%.3f", synth->resonance);
synth->resonance = GuiSliderBar((Rectangle){ x, y + count++ * (height + offset), width, height }, "fR: ", buf, synth->resonance , 0.001f, 5.0f);
+ snprintf(buf, sizeof buf, "%.3f", synth->lfo.freq);
+ 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 amprrrrrr: ", buf, synth->lfo.amp , 0.0f, 0.93f);
}
void
@@ -81,25 +96,26 @@ 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);
int period = (1 / (synth->n.freq + 1)) * SAMPLE_RATE / synth->viz.sample_rate_divider;
+
for (int i = x; i < WIDTH - x; i++) {
- DrawCircle(i , y + height / 2 + floor(50 * synth->viz.wave[x * (SAMPLE_RATE / 2)]), point_radius, MAGENTA);
+ 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);
+ //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);
+ //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)), point_radius, GREEN);
+ //DrawCircle(i , y + height - 1+ floor((WIDTH / 24) * - adsr_amplitude(synth, synth->adsr.elapsed, synth->n.noteOn, synth->n.noteOff)), 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)), point_radius, BLUE);
+ //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);
}
}
@@ -124,7 +140,7 @@ rayrun(void *synthData)
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
- ClearBackground(RAYWHITE);
+ ClearBackground(BLACK);
// GUI
char buf[64];
@@ -166,7 +182,7 @@ rayrun(void *synthData)
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, "time?: %lld adsr: %lld note: %lld", synth->adsr.elapsed / SAMPLE_RATE, synth->adsr.elapsed, synth->n.elapsed);
+ snprintf(buf, sizeof buf, "%f", synth->viz.wave[0]);
DrawText(buf, WIDTH / 2 -300, HEIGHT - 40 - 50, 20, LIGHTGRAY);
EndDrawing();