summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorgrm <grm@eyesin.space>2025-11-23 22:54:56 +0200
committergrm <grm@eyesin.space>2025-11-23 22:54:56 +0200
commita4acc4cd3a4ef237fb7238894336bbc4af659e07 (patch)
tree68d05d5cc4c1900e6c19ee9bf3b6b06a1ce5fafd /src
parent8f00dd3df55677beff2924d2c6eec205744ebdf6 (diff)
downloadsynth-project-a4acc4cd3a4ef237fb7238894336bbc4af659e07.tar.gz
synth-project-a4acc4cd3a4ef237fb7238894336bbc4af659e07.tar.bz2
synth-project-a4acc4cd3a4ef237fb7238894336bbc4af659e07.zip
add lsan supression
Diffstat (limited to 'src')
-rw-r--r--src/generator.c114
-rw-r--r--src/generator.h10
-rw-r--r--src/sequencer.c6
-rw-r--r--src/synth.c12
-rw-r--r--src/synth_gui.c52
5 files changed, 150 insertions, 44 deletions
diff --git a/src/generator.c b/src/generator.c
index ab2206f..de75bc8 100644
--- a/src/generator.c
+++ b/src/generator.c
@@ -3,21 +3,30 @@
#include "generator.h"
+float play_tree(sound_node *root, midi_note_t *note)
+{
+ (void) root;
+ (void) note;
+ return 0;
+}
float
generate(generator * g, synth_t * s, int i, sound_node * root)
{
+ (void) g;
float sample = 0;
- sampe = play_tree(root, s->midi_note[i]);
-
+ sample = play_tree(root, &s->midi_note[i]);
+
return sample;
}
int
sound_tree_add_node(sound_node * root, const char * cmp)
{
-
+ (void) root;
+ (void) cmp;
+ return 0;
}
int
@@ -25,52 +34,111 @@ load_preset(sound_node * tree, const char * path)
{
config_t cfg;
config_setting_t *setting, *x;
- const char *str;
config_init(&cfg);
- if (! config_read_file(&cfg, "../preset.synth")) {
+ if (! config_read_file(&cfg, path)) {
fprintf(stderr, "%s:%d - %s\n", config_error_file(&cfg),
config_error_line(&cfg), config_error_text(&cfg));
config_destroy(&cfg);
return(EXIT_FAILURE);
- }
- setting = config_lookup(&cfg, "patch");
- if (setting != NULL) {
- int count = config_setting_length(setting);
-
- for(int i = 0; i < count; ++i) {
- x = config_setting_get_elem(setting, i);
- printf("%s = %f\n", config_setting_name(x), config_setting_get_float(x));
- // TODO
- sound_tree_add_node(tree, name);
- }
}
- setting = config_tree_setting(&cfg);
+ setting = config_root_setting(&cfg);
if (setting != NULL) {
int count = config_setting_length(setting);
for(int i = 0; i < count; ++i) {
- chat * name = config_setting_name(x);
x = config_setting_get_elem(setting, i);
+ char * name = config_setting_name(x);
printf("%s -- %d\n", config_setting_name(x), config_setting_type(x));
if (name[0] == 'o') { // osc
// TODO
- configure_osc(tree, id);
+ printf("Creating osc: %s\n", config_setting_name(x));
+ int count2 = config_setting_length(x);
+ config_setting_t *s;
+
+ for (int j = 0; j < count2; ++j) {
+ s = config_setting_get_elem(x, j);
+ printf("%s -> ", config_setting_name(s));
+ switch (config_setting_type(s)) {
+ case CONFIG_TYPE_INT:
+ printf("%d\n", config_setting_get_int(s));
+ break;
+ case CONFIG_TYPE_FLOAT:
+ printf("%f\n", config_setting_get_float(s));
+ break;
+ case CONFIG_TYPE_STRING:
+ printf("%s\n", config_setting_get_string(s));
+ break;
+ }
+ }
+
+ //configure_osc(tree, id);
} else if (name[0] == 'a') { // adsr
// TODO
- configure_adsr(tree, id);
+ printf("Creating adsr: %s\n", config_setting_name(x));
+ int count2 = config_setting_length(x);
+ config_setting_t *s;
+
+ for (int j = 0; j < count2; ++j) {
+ s = config_setting_get_elem(x, j);
+ printf("%s -> ", config_setting_name(s));
+ switch (config_setting_type(s)) {
+ case CONFIG_TYPE_INT:
+ printf("%d\n", config_setting_get_int(s));
+ break;
+ case CONFIG_TYPE_FLOAT:
+ printf("%f\n", config_setting_get_float(s));
+ break;
+ case CONFIG_TYPE_STRING:
+ printf("%s\n", config_setting_get_string(s));
+ break;
+ }
+ }
+ //configure_adsr(tree, id);
} else if (name[0] == 'l') { // lfo
// TODO
- configure_lfo(tree, id);
+ printf("Creating lfo: %s\n", config_setting_name(x));
+ int count2 = config_setting_length(x);
+ config_setting_t *s;
+
+ for (int j = 0; j < count2; ++j) {
+ s = config_setting_get_elem(x, j);
+ printf("%s -> ", config_setting_name(s));
+ switch (config_setting_type(s)) {
+ case CONFIG_TYPE_INT:
+ printf("%d\n", config_setting_get_int(s));
+ break;
+ case CONFIG_TYPE_FLOAT:
+ printf("%f\n", config_setting_get_float(s));
+ break;
+ case CONFIG_TYPE_STRING:
+ printf("%s\n", config_setting_get_string(s));
+ break;
+ }
+ }
+ //configure_lfo(tree, id);
} else {
- printf("%s: wrong!", name);
+ printf("%s: wrong!\n", name);
}
}
}
-
+
+ setting = config_lookup(&cfg, "patch");
+ if (setting != NULL) {
+ int count = config_setting_length(setting);
+
+ for(int i = 0; i < count; ++i) {
+ x = config_setting_get_elem(setting, i);
+ printf("adding sound node: %s = %f\n", config_setting_name(x), config_setting_type(x) == CONFIG_TYPE_INT ? (float)config_setting_get_int(x) : config_setting_get_float(x));
+ // TODO
+ sound_tree_add_node(tree, config_setting_name(x));
+ }
+ }
+
config_destroy(&cfg);
+ return 0;
}
diff --git a/src/generator.h b/src/generator.h
index df90578..72d10ca 100644
--- a/src/generator.h
+++ b/src/generator.h
@@ -15,7 +15,7 @@ enum osc_enum {
SQR
};
-enum adsr_type {
+enum adsr_enum {
LINEAR,
CUBIC
};
@@ -43,7 +43,7 @@ typedef struct sound_node {
int n;
} sound_node;
-struct generator {
+typedef struct generator {
// list of indexes for oscilators, lfos and adsrs
float osc[MAX_CMP];
float lfo[MAX_CMP];
@@ -58,12 +58,14 @@ struct generator {
//o0-saw:l0-sin:l1-sin:a0-linear
//a0-o0/frequency:l0-o0/frequency:l1-l0/frequency:o0-1
-};
+} generator;
int sound_tree_add_node(sound_node * root, const char * cmp);
// needs to "play" the wiring defined in the struct
// using sounds from `s` and the midi note `i`
-float generate(generator * g, synth_t * s, int i);
+float generate(generator * g, synth_t * s, int i, sound_node * root);
+
+int load_preset(sound_node * tree, const char * path);
#endif /* GENERATOR_H */
diff --git a/src/sequencer.c b/src/sequencer.c
index 5687640..12c0741 100644
--- a/src/sequencer.c
+++ b/src/sequencer.c
@@ -14,12 +14,6 @@
#define MIDI_CHANNEL 0
#define SLEEP_INTERVAL_MS 2.0 // main loop sleep
-
-
-//-------------------------------------------------
-// Helper for time math
-//-------------------------------------------------
-
typedef struct step_t {
PmTimestamp note_on;
PmTimestamp note_off;
diff --git a/src/synth.c b/src/synth.c
index 1b5187b..f5038b6 100644
--- a/src/synth.c
+++ b/src/synth.c
@@ -26,17 +26,27 @@
#include "synth_engine.h"
#include "synth_gui.h"
#include "web.h"
+//#include "generator.h"
+
+// Add this function to your code
+const char *__lsan_default_options() {
+ return "suppressions=lsan.supp:print_suppressions=0";
+}
int
main(void) {
synth_t * synth = init_synth();
+ /* sound_node sn = {0}; */
+ /* load_preset(&sn, "preset.synth"); */
+
init_web(synth);
-
+
rayrun(synth);
free_web();
free_synth(synth);
+
return 0;
}
diff --git a/src/synth_gui.c b/src/synth_gui.c
index f7a541f..77e1876 100644
--- a/src/synth_gui.c
+++ b/src/synth_gui.c
@@ -34,7 +34,7 @@ draw_text(synth_t * synth, int x, int y)
void
mouse(synth_t *synth)
{
- float m = GetMouseWheelMove();
+ float m = GetMouseWheelMove();
int x = 0;
if (m < 0) x = -1;
else if (m > 0) x = 1;
@@ -237,14 +237,6 @@ void frequencyToColor(float frequency, int *red, int *green, int *blue) {
#include "fftw3.h"
-float
-amp(float re, float im) {
- float a = fabsf(re);
- float b = fabsf(im);
- if (a < b) return b;
- return a;
-}
-
void
draw_adsr(synth_t *synth, int x, int y, int width, int height)
{
@@ -609,6 +601,44 @@ generic_vbar(float val, float def, float min, float max, int x, int y, int widt
return val;
}
+float
+generic_hbar(float val, float def, float min, float max,
+ int x, int y, int width, int height)
+{
+ Vector2 p = GetMousePosition();
+ uint checksum = rect_checksum(x, y, width, height);
+
+ if (CheckCollisionPointRec(p, (Rectangle){x, y, width, height})) {
+ if (IsMouseButtonPressed(0)) {
+ rect_id_pressed = checksum;
+ }
+ if (IsMouseButtonPressed(1)) {
+ val = def;
+ }
+ }
+
+ if (IsMouseButtonDown(0) && rect_id_pressed == checksum) {
+ if (p.x < x) {
+ val = min;
+ } else if (p.x >= x + width) {
+ val = max;
+ } else {
+ val = min + (max - min) * ((p.x - x) / (float)width);
+ }
+ }
+
+ if (IsMouseButtonReleased(0) && rect_id_pressed == checksum) {
+ rect_id_pressed = 0;
+ }
+
+ int fill_width = map(val, min, max, 0, width - 2);
+
+ DrawRectangleLines(x, y, width, height, WHITE);
+ DrawRectangle(x + 1, y + 1, fill_width, height - 2, Fade(MAROON, 0.7f));
+
+ return val;
+}
+
void
draw_signals(synth_t * synth, int x, int y, int width, int height)
{
@@ -1210,7 +1240,9 @@ draw_main(synth_t *synth)
// GUI
char buf[64];
snprintf(buf, sizeof buf, "%d", synth->wvt_pos);
- synth->wvt_pos = GuiSlider((Rectangle){WIDTH / 2.0 - 108, 150 + 42 + 42, 216, 24 }, "", buf, synth->wvt_pos , 0, 127);
+ float wvt_pos_x = WIDTH / 2.0 - 108, wvt_pos_y = 150 + 42 + 42, wvt_pos_width = 216, wvt_pos_height = 24, wvt_pos_font_size = 10;
+ synth->wvt_pos = generic_hbar(synth->wvt_pos, 1.0, 0, 127, wvt_pos_x, wvt_pos_y, wvt_pos_width, wvt_pos_height);
+ DrawText(buf, wvt_pos_x + wvt_pos_width + 5, wvt_pos_y + wvt_pos_height / 2 - wvt_pos_font_size / 2, wvt_pos_font_size, GRAY);
set_sound_start(synth->wvt_pos*2048);
set_sound_len(synth->wvt_pos*2048 + 2048);