From 7828597e5f159010c168f9fe366828825fc75205 Mon Sep 17 00:00:00 2001 From: grm Date: Thu, 27 Nov 2025 15:53:51 +0200 Subject: chore: remove x value, tidy some code --- src/archive/gtk.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/gtk.c | 78 --------------------------------------------------- src/gui_functions.c | 23 +++++++++++++++ src/synth_engine.h | 4 +-- src/synth_engine_v2.c | 33 ++++++++-------------- src/synth_gui.c | 22 +++++++-------- 6 files changed, 124 insertions(+), 114 deletions(-) create mode 100644 src/archive/gtk.c delete mode 100644 src/gtk.c create mode 100644 src/gui_functions.c (limited to 'src') diff --git a/src/archive/gtk.c b/src/archive/gtk.c new file mode 100644 index 0000000..2b91b94 --- /dev/null +++ b/src/archive/gtk.c @@ -0,0 +1,78 @@ +/* + * This program uses the PortAudio Portable Audio Library. + * For more information see: http://www.portaudio.com/ + * Copyright (c) 1999-2000 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/* audio */ +#include +#include + +#include + +/* graphics */ +#include + +/* synth */ +#include "synth_engine.h" +#include "midi.h" + +#define NUM_SECONDS (1) + +#define WAVE_SIZE (44100) + +static void +activate (GtkApplication* app, + gpointer user_data) +{ + GtkWidget *window; + + window = gtk_application_window_new (app); + gtk_window_set_title (GTK_WINDOW (window), "Synth"); + gtk_window_set_default_size (GTK_WINDOW (window), WIDTH, HEIGHT); + gtk_window_present (GTK_WINDOW (window)); +} + + +int +main(int argc, char * argv[]) { + synth_t synth; + midi_t midi; + + init_synth(&synth); + init_midi(&midi, &synth); + + GtkApplication *app; + int status; + + app = gtk_application_new ("org.gtk.example", G_APPLICATION_DEFAULT_FLAGS); + g_signal_connect (app, "activate", G_CALLBACK (activate), NULL); + status = g_application_run (G_APPLICATION (app), argc, argv); + g_object_unref (app); + + // rayrun(&synth); + + terminate_midi(&midi); + free_synth(&synth); + + return status; +} diff --git a/src/gtk.c b/src/gtk.c deleted file mode 100644 index 2b91b94..0000000 --- a/src/gtk.c +++ /dev/null @@ -1,78 +0,0 @@ -/* - * This program uses the PortAudio Portable Audio Library. - * For more information see: http://www.portaudio.com/ - * Copyright (c) 1999-2000 Ross Bencina and Phil Burk - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files - * (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, - * publish, distribute, sublicense, and/or sell copies of the Software, - * and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF - * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -/* audio */ -#include -#include - -#include - -/* graphics */ -#include - -/* synth */ -#include "synth_engine.h" -#include "midi.h" - -#define NUM_SECONDS (1) - -#define WAVE_SIZE (44100) - -static void -activate (GtkApplication* app, - gpointer user_data) -{ - GtkWidget *window; - - window = gtk_application_window_new (app); - gtk_window_set_title (GTK_WINDOW (window), "Synth"); - gtk_window_set_default_size (GTK_WINDOW (window), WIDTH, HEIGHT); - gtk_window_present (GTK_WINDOW (window)); -} - - -int -main(int argc, char * argv[]) { - synth_t synth; - midi_t midi; - - init_synth(&synth); - init_midi(&midi, &synth); - - GtkApplication *app; - int status; - - app = gtk_application_new ("org.gtk.example", G_APPLICATION_DEFAULT_FLAGS); - g_signal_connect (app, "activate", G_CALLBACK (activate), NULL); - status = g_application_run (G_APPLICATION (app), argc, argv); - g_object_unref (app); - - // rayrun(&synth); - - terminate_midi(&midi); - free_synth(&synth); - - return status; -} diff --git a/src/gui_functions.c b/src/gui_functions.c new file mode 100644 index 0000000..b024368 --- /dev/null +++ b/src/gui_functions.c @@ -0,0 +1,23 @@ +/* + * Header library for gui functions + */ +#ifndef SYNTH_GUI_H_ +#define SYNTH_GUI_H_ + +#include "control.h" +#include + +void frequencyToColor(float frequency, int *red, int *green, int *blue); +float generic_vbar(float val, float def, float min, float max, int x, int y, int width, int height); +float generic_hbar(float val, float def, float min, float max, int x, int y, int width, int height); + +void draw_cc_circle(cc_t * cc, int x, int y, int width, int height); +void draw_cc_hbar(cc_t * cc, int x, int y, int width, int height); +void draw_cc_vbar(cc_t * cc, int x, int y, int width, int height); + +int gui_string_spinner(Rectangle rect, char * text, int * index); + +#endif // SYNTH_GUI_H_ +#ifdef SYNTH_GUI_IMPLEMENTATION + +#endif // SYNTH_GUI_IMPLEMENTATION diff --git a/src/synth_engine.h b/src/synth_engine.h index dafff90..a29c389 100644 --- a/src/synth_engine.h +++ b/src/synth_engine.h @@ -103,8 +103,6 @@ typedef struct { int autogain; - float x; - midi_note_t midi_note[MIDI_NOTES]; midi_note_t * midi_active[MIDI_NOTES]; int midi_active_n; @@ -133,7 +131,7 @@ typedef struct { int modifiers[16]; int modi; - float (*gen[7]) (float freq, midi_note_t * midi_note, float x, unsigned int sample_rate); + float (*gen[7]) (float freq, midi_note_t * midi_note); int geni; BWLowPass* fff; diff --git a/src/synth_engine_v2.c b/src/synth_engine_v2.c index 95ed61b..e15df85 100644 --- a/src/synth_engine_v2.c +++ b/src/synth_engine_v2.c @@ -1,7 +1,6 @@ #include "synth_engine.h" #include "synth_math.h" #include "lowpass.h" -#include "filter.h" #include "control.h" #include "sound.h" #include "midi.h" @@ -12,63 +11,56 @@ #include float -gen0(float f, midi_note_t * midi_note, float x, unsigned int sample_rate) +gen0(float f, midi_note_t * midi_note) { - (void)x; (void)sample_rate; float sample = osc_sin(midi_note->wvt_index); midi_note->wvt_index = osc_sin_next(f, midi_note->wvt_index); return sample; } float -gen1(float f, midi_note_t * midi_note, float x, unsigned int sample_rate) +gen1(float f, midi_note_t * midi_note) { - (void)x; (void)sample_rate; float sample = osc_saw(midi_note->wvt_index); midi_note->wvt_index = osc_saw_next(f, midi_note->wvt_index); return sample; } float -gen2(float f, midi_note_t * midi_note, float x, unsigned int sample_rate) +gen2(float f, midi_note_t * midi_note) { - (void)x; (void)sample_rate; float sample = osc_weird(midi_note->wvt_index); midi_note->wvt_index = osc_weird_next(f, midi_note->wvt_index); return sample; } float -gen3(float f, midi_note_t * midi_note, float x, unsigned int sample_rate) +gen3(float f, midi_note_t * midi_note) { - (void)x; (void)sample_rate; float sample = osc_tri(midi_note->wvt_index); midi_note->wvt_index = osc_tri_next(f, midi_note->wvt_index); return sample; } float -gen4(float f, midi_note_t * midi_note, float x, unsigned int sample_rate) +gen4(float f, midi_note_t * midi_note) { - (void)x; (void)sample_rate; float sample = osc_sound(midi_note->wvt_index); midi_note->wvt_index = osc_sound_next(f, midi_note->wvt_index); return sample; } float -gen5(float f, midi_note_t * midi_note, float x, unsigned int sample_rate) +gen5(float f, midi_note_t * midi_note) { - (void)x; (void)sample_rate; float sample = osc_digisaw(midi_note->wvt_index); midi_note->wvt_index = osc_digisaw_next(f, midi_note->wvt_index); return sample; } float -gen6(float f, midi_note_t * midi_note, float x, unsigned int sample_rate) +gen6(float f, midi_note_t * midi_note) { - (void)x; (void)sample_rate; float sample = osc_sqr(midi_note->wvt_index); midi_note->wvt_index = osc_sqr_next(f, midi_note->wvt_index); return sample; @@ -196,7 +188,7 @@ get_max_sample(synth_t *synth, int test_size) note_dup.adsr = note->adsr; note_dup.active = note->active; for (int i = 0; i < test_size; i++) { - osc_wave[i] += synth->gen[synth->geni](note_dup.freq * 3, ¬e_dup, synth->x, SAMPLE_RATE); + osc_wave[i] += synth->gen[synth->geni](note_dup.freq * 3, ¬e_dup); } } @@ -220,9 +212,9 @@ float Q_rsqrt(float number) } float -make_single_sample(synth_t *synth, float freq, midi_note_t * note, unsigned int sample_rate) +make_single_sample(synth_t *synth, float freq, midi_note_t * note) { - return synth->gen[synth->geni](freq, note, synth->x, sample_rate); + return synth->gen[synth->geni](freq, note); } /** @@ -275,8 +267,7 @@ make_sample(synth_t * synth, unsigned int sample_rate, int frame) sample += rms * note->velocity * adsr * make_single_sample(synth, targ_freq, - note, - sample_rate); + note); } /* filter */ @@ -540,8 +531,6 @@ init_synth(void) // synth->modi = 0; synth->autogain = 1; - synth->x = 1; - synth->adsr.a = 0.00001f; synth->adsr.peak = 1.0f; synth->adsr.d = 0.3; diff --git a/src/synth_gui.c b/src/synth_gui.c index 77e1876..db37bf7 100644 --- a/src/synth_gui.c +++ b/src/synth_gui.c @@ -369,7 +369,7 @@ draw_osc(synth_t * synth, int x, int y, int width, int height) midi_note_t note_dup = {0}; for (int i = 0; i < width; i++) { float freq = SAMPLE_RATE/(float)width; - osc_wave[i] += synth->gen[synth->geni](freq, ¬e_dup, synth->x, SAMPLE_RATE); + osc_wave[i] += synth->gen[synth->geni](freq, ¬e_dup); } for (int i = 0; i < width; i++) { @@ -645,9 +645,10 @@ draw_signals(synth_t * synth, int x, int y, int width, int height) DrawRectangleLines(x, y, width, height, WHITE); if (synth->viz.wave_enabled || synth->viz.spectrum_enabled) { - synth->viz.rate_divider = - GuiSlider((Rectangle){x + (width / 2.0) / 2, y - 12, width / 2.0, 12}, - "", NULL, synth->viz.rate_divider, 1, 150); + synth->viz.rate_divider = generic_hbar(synth->viz.rate_divider, 15, 1, 150, x + (width / 2.0) / 2, y - 12, width / 2.0, 12); + /* synth->viz.rate_divider = */ + /* GuiSlider((Rectangle){x + (width / 2.0) / 2, y - 12, width / 2.0, 12}, */ + /* "", NULL, synth->viz.rate_divider, 1, 150); */ synth->viz.y_divider = generic_vbar(synth->viz.y_divider, 1.0, 0.5, 3.0, x - 10, y, 10, height); /* /\* GuiSlider((Rectangle){x - 10, y, 10, height}, "", NULL, *\/ */ /* /\* synth->viz.y_divider, 0.5, 3); *\/ */ @@ -1254,11 +1255,12 @@ draw_main(synth_t *synth) draw_osc(synth, WIDTH / 2 + 180, 140, 80, 80); } - if ( GuiButton((Rectangle){ WIDTH / 2.0 - 108, 150 - 6 - 6 + 42, 216, 6 }, "")) { - synth->x = 1; - } - snprintf(buf, sizeof buf, "%.1f", synth->x); - synth->x = GuiSlider((Rectangle){ WIDTH / 2.0 - 108, 150 + 42, 216, 24 }, "x", buf, synth->x , 0.0f, 2.0f); + // x variable + /* if ( GuiButton((Rectangle){ WIDTH / 2.0 - 108, 150 - 6 - 6 + 42, 216, 6 }, "")) { */ + /* synth->x = 1; */ + /* } */ + /* snprintf(buf, sizeof buf, "%.1f", synth->x); */ + /* synth->x = GuiSlider((Rectangle){ WIDTH / 2.0 - 108, 150 + 42, 216, 24 }, "x", buf, synth->x , 0.0f, 2.0f); */ synth->filter = GuiToggle((Rectangle){ WIDTH - 100 - 50 - 100 - 50 , 50 , 46, 24 }, "LP", synth->filter); synth->biquad = GuiToggle((Rectangle){ WIDTH - 100 - 50 - 100 - 50 + 46 + 8 , 50 , 46, 24 }, "bq", synth->biquad); @@ -1341,8 +1343,6 @@ rayrun(synth_t *synth){ ws_send_message(b); sprintf(b, "autogain:%d", synth->autogain); ws_send_message(b); - sprintf(b, "x:%f", synth->x); - ws_send_message(b); sprintf(b, "midi_active_n:%d", synth->midi_active_n); ws_send_message(b); sprintf(b, "octave:%d", synth->octave); -- cgit v1.2.3