summaryrefslogtreecommitdiffstats
path: root/src/synth_gui.c
diff options
context:
space:
mode:
authorgramanas <anastasis.gramm2@gmail.com>2023-06-27 22:37:53 +0300
committergramanas <anastasis.gramm2@gmail.com>2023-06-27 22:37:53 +0300
commit60c82a72fedd719f69c1f1de896aca00784a2881 (patch)
tree3679e0886fc12aa8eeeab60260347ee7a0c5ae0e /src/synth_gui.c
parente77d4d42cacd21bf80e4f47cba2fe85f5a5b0991 (diff)
downloadsynth-project-60c82a72fedd719f69c1f1de896aca00784a2881.tar.gz
synth-project-60c82a72fedd719f69c1f1de896aca00784a2881.tar.bz2
synth-project-60c82a72fedd719f69c1f1de896aca00784a2881.zip
Changes
Diffstat (limited to 'src/synth_gui.c')
-rw-r--r--src/synth_gui.c82
1 files changed, 73 insertions, 9 deletions
diff --git a/src/synth_gui.c b/src/synth_gui.c
index 4f9f5a3..510075b 100644
--- a/src/synth_gui.c
+++ b/src/synth_gui.c
@@ -36,7 +36,7 @@ keyboard(void *synthData, PaStream *stream)
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 = 16.35160 * 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);
@@ -58,6 +58,63 @@ keyboard(void *synthData, PaStream *stream)
}
}
}
+
+ int mods[] = {KEY_Z, KEY_X, KEY_C, KEY_V, KEY_B, KEY_N, KEY_M, 0};
+ synth->modi = 0;
+ for (int i = 0; mods[i]; i++) {
+ if (IsKeyDown(mods[i])) {
+ synth->modifiers[synth->modi++] = mods[i];
+ }
+ }
+
+ if (IsKeyDown(265)) { // up
+ for (int i = 0; i < synth->modi; i++) {
+ if (synth->modifiers[i] == KEY_Z) {
+ cc_step(&synth->cc_cutoff, 1);
+ }
+ if (synth->modifiers[i] == KEY_X) {
+ cc_step(&synth->cc_resonance, 1);
+ }
+ if (synth->modifiers[i] == KEY_C) {
+ cc_step(&synth->cc_pitch, 1);
+ }
+ if (synth->modifiers[i] == KEY_V) {
+ cc_step(&synth->cc_lfo_freq, 1);
+ }
+ }
+ }
+ if (IsKeyDown(264)) { // down
+ for (int i = 0; i < synth->modi; i++) {
+ if (synth->modifiers[i] == KEY_Z) {
+ cc_step(&synth->cc_cutoff, -1);
+ }
+ if (synth->modifiers[i] == KEY_X) {
+ cc_step(&synth->cc_resonance, -1);
+ }
+ if (synth->modifiers[i] == KEY_C) {
+ cc_step(&synth->cc_pitch, -1);
+ }
+ if (synth->modifiers[i] == KEY_V) {
+ cc_step(&synth->cc_lfo_freq, -1);
+ }
+ }
+ }
+ if (IsKeyDown(KEY_ENTER)) { // down
+ for (int i = 0; i < synth->modi; i++) {
+ if (synth->modifiers[i] == KEY_Z) {
+ cc_reset(&synth->cc_cutoff);
+ }
+ if (synth->modifiers[i] == KEY_X) {
+ cc_reset(&synth->cc_resonance);
+ }
+ if (synth->modifiers[i] == KEY_C) {
+ cc_reset(&synth->cc_pitch);
+ }
+ if (synth->modifiers[i] == KEY_V) {
+ cc_reset(&synth->cc_lfo_freq);
+ }
+ }
+ }
}
void
@@ -78,12 +135,12 @@ draw_adsr_sliders(synth_t * synth, int x, int y, int width, int height, int offs
synth->adsr.r = GuiSlider((Rectangle){ x, y + count++ * (height + offset), width, height }, "R: ", buf, synth->adsr.r , -0.001f, 3.0f);
snprintf(buf, sizeof buf, "%.3f", synth->cutoff);
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->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);
+ synth->lfo.amp = GuiSliderBar((Rectangle){ x, y + count++ * (height + offset), width, height }, "lfo amp: ", buf, synth->lfo.amp , 0.0f, 0.93f);
}
void
@@ -149,11 +206,18 @@ rayrun(void *synthData)
draw_adsr_sliders(synth, 30, 20, 256, 20, 4);
- if ( GuiButton((Rectangle){ WIDTH / 2 - 108, 150 - 42 - 6 - 6, 216, 6 }, "")) {
- synth->freq_offset = 0;
- }
- snprintf(buf, sizeof buf, "%.1f", synth->freq_offset);
- 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 - 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, "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;