summaryrefslogtreecommitdiffstats
path: root/src/synth_gui.c
diff options
context:
space:
mode:
authorgrm <grm@eyesin.space>2025-02-22 03:40:43 +0200
committergrm <grm@eyesin.space>2025-02-22 03:40:43 +0200
commit35208c579c9e7d0078d786e61f4a323919e2dcdf (patch)
tree022f464e6350c18f76443a6e96eccd02698df7d1 /src/synth_gui.c
parent500b9a07b93d6cd3e771edc5698e06d163da60f1 (diff)
downloadsynth-project-35208c579c9e7d0078d786e61f4a323919e2dcdf.tar.gz
synth-project-35208c579c9e7d0078d786e61f4a323919e2dcdf.tar.bz2
synth-project-35208c579c9e7d0078d786e61f4a323919e2dcdf.zip
Small fixesHEADmaster
Diffstat (limited to 'src/synth_gui.c')
-rw-r--r--src/synth_gui.c47
1 files changed, 24 insertions, 23 deletions
diff --git a/src/synth_gui.c b/src/synth_gui.c
index 6f8e06b..cb899db 100644
--- a/src/synth_gui.c
+++ b/src/synth_gui.c
@@ -1,4 +1,5 @@
#include "synth_gui.h"
+#include "osc.h"
#include <portaudio.h>
#define RAYGUI_IMPLEMENTATION
#include "raygui.h"
@@ -113,7 +114,7 @@ keyboard(synth_t * synth)
//note = notes[i % 12][(synth->octave + (i / 12)) % 8];
}
}
-
+
int patates[] = {KEY_Z, KEY_X, KEY_C, KEY_V, KEY_B, KEY_N, KEY_M, 0};
synth->modi = 0;
for (int i = 0; patates[i]; i++) {
@@ -121,7 +122,7 @@ keyboard(synth_t * synth)
synth->modifiers[synth->modi++] = patates[i];
}
}
-
+
if (IsKeyDown(265)) { // up
for (int i = 0; i < synth->modi; i++) {
if (synth->modifiers[i] == KEY_Z) {
@@ -246,7 +247,7 @@ draw_adsr(synth_t *synth, int x, int y, int width, int height)
int x_prev = x;
for (int i = 0; i < synth->midi_active_n; i++) {
int rec_y = y + height - 1 +
- 4.5 * floor( (width / 24) *
+ 4.5 * floor( (width / 24.0) *
- fix_adsr(&synth->adsr,
synth->midi_active[i]->noteOn,
synth->midi_active[i]->noteOff,
@@ -280,7 +281,7 @@ draw_wave(synth_t *synth, int x, int y, int width, int height)
col = MAGENTA;
else
col = WHITE;
- DrawPixel(i + x , y + height / 2 + floor(50 * synth->viz.wave_viz_buffer[ii + j]), col);
+ DrawPixel(i + x , y + height / 2 + (int)floor(50.0 * synth->viz.wave_viz_buffer[ii + j]), col);
}
}
/* for (int j = 0; j < 100; j++) { */
@@ -297,13 +298,13 @@ draw_fft(synth_t *synth, int x, int y, int width, int height)
size_t fft_output_len = viz_size / 2 + 1;
fftwf_complex* output = (fftwf_complex*)fftwf_malloc(sizeof(fftwf_complex) * fft_output_len);
-
+
fftwf_plan forward_plan = fftwf_plan_dft_r2c_1d(fft_output_len, synth->viz.fft_input_buffer, output, FFTW_ESTIMATE);
fftwf_execute(forward_plan);
fftwf_destroy_plan(forward_plan);
-
+
// "Squash" into the Logarithmic Scale
float step = 1.06;
float lowf = 1.0f;
@@ -343,7 +344,7 @@ draw_fft(synth_t *synth, int x, int y, int width, int height)
Color color = ColorFromHSV(hue*360, saturation, value);
Vector2 startPos = {
x + i*cell_width + cell_width/2,
- y + height - height*2/3*t,
+ y + height - height*2/3.0*t,
};
Vector2 endPos = {
x + i*cell_width + cell_width/2,
@@ -394,9 +395,9 @@ draw_osc(synth_t * synth, int x, int y, int width, int height)
if (synth->midi_active_n) {
for (int i = 0; i < width; i++) {
- DrawPixel(i + x , y + height / 2 + floor(height/2 * osc_wave[i] / max), RED);
+ DrawPixel(i + x , y + height / 2.0 + floor(height/2.0 * osc_wave[i] / max), RED);
}
- }
+ }
}
@@ -454,7 +455,7 @@ draw_adsr_graph(synth_t * synth, int x, int y, int width, int height)
for (int i = 0; i < width; i++) {
DrawPixel(i + x , y + height - adsr_graph[i], RED);
}
-
+
for (int i = 0; i < synth->midi_active_n; i++) {
midi_note_t * note = synth->midi_active[i];
int elapsed_samples = note->elapsed;
@@ -486,7 +487,7 @@ draw_signals(synth_t * synth, int x, int y, int width, int height)
synth->viz.rate_divider = GuiSlider((Rectangle){ x + (width / 2.0) / 2, y - 12, width / 2.0, 12 }, "", NULL, synth->viz.rate_divider , 1, 150);
int viz_size = width * synth->viz.rate_divider;
-
+
float samples[RING_SIZE];
int rc = PaUtil_ReadRingBuffer( &synth->viz.wave_buffer, &samples, RING_SIZE);
@@ -531,8 +532,8 @@ draw_signals(synth_t * synth, int x, int y, int width, int height)
}
}
-char * flag = NULL;
-char * flag_circle = NULL;
+char * flag = NULL;
+char * flag_circle = NULL;
void
draw_cc_circle(cc_t * cc, int x, int y, int width, int height) {
@@ -553,15 +554,15 @@ draw_cc_circle(cc_t * cc, int x, int y, int width, int height) {
}
if (dx.y < 0) cc_step(cc, 1*x);
if (dx.y > 0) cc_step(cc, -1*x);
- }
+ }
if (IsMouseButtonReleased(0) && flag_circle == cc->name) {
flag_circle = 0;
}
int min = 110;
int max = 110 + (360+70 - 110) * (cc->target) / (cc->max - cc->min);
- DrawRing((Vector2){x + width/2, y + height/2}, width / 2 - 6, width / 2, min, max, 0, Fade(MAROON, 0.7f));
- DrawCircle(x + width/2, y + height/2, width / 2 - 5, BLACK); // Draw circle sector outline
+ DrawRing((Vector2){x + width/2.0, y + height/2.0}, width / 2.0 - 6, width / 2.0, min, max, 0, Fade(MAROON, 0.7f));
+ DrawCircle(x + width/2, y + height/2, width / 2.0 - 5, BLACK); // Draw circle sector outline
char buf[32];
snprintf(buf, sizeof buf, "%0.2f", cc->target);
@@ -603,7 +604,7 @@ draw_cc_hbar(cc_t * cc, int x, int y, int width, int height) {
char tmp[128] = "";
sprintf(tmp, "%f", cc->value);
ws_send_message(tmp);
- }
+ }
if (IsMouseButtonReleased(0) && flag == cc->name) {
flag = 0;
}
@@ -645,7 +646,7 @@ draw_cc_vbar(cc_t * cc, int x, int y, int width, int height) {
//cc->target = cc->min + cc->max - (cc->min + (cc->max - cc->min) * ((((p.y - y) * (float)1/height) - 0) / (1 - 0)));
cc_set(cc, (cc->min + cc->max - (cc->min + (cc->max - cc->min) * ((((p.y - y) * (float)1/height) - 0) / (1 - 0)))));
}
- }
+ }
if (IsMouseButtonReleased(0) && flag == cc->name) {
flag = 0;
}
@@ -667,7 +668,7 @@ void
draw_bars(synth_t * synth, int x, int y, int width, int height, int offset)
{
int count = 0;
-
+
draw_cc_hbar(&synth->cc_adsr_a , x, y + count++ * (height + offset), width, height);
synth->f_adsr_enabled = GuiCheckBox((Rectangle){ x + width + offset, y + (count - 1) * (height + offset), height, 16 }, "", synth->f_adsr_enabled);
draw_cc_hbar(&synth->cc_adsr_peak , x, y + count++ * (height + offset), width, height);
@@ -696,7 +697,7 @@ rayrun(synth_t *synth){
int old_soundcard_id = synth->soundcard_id;
int old_midi_device_id = synth->midi_device_id;
- InitWindow(WIDTH, HEIGHT, "Raylib synth");
+ InitWindow(WIDTH, HEIGHT, "Raylib synth");
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
while (!WindowShouldClose()) {
keyboard(synth);
@@ -735,7 +736,7 @@ rayrun(synth_t *synth){
synth->wvt_pos = GuiSlider((Rectangle){WIDTH / 2.0 - 108, 150 + 42 + 42, 216, 24 }, "", buf, synth->wvt_pos , 0, 127);
set_sound_start(synth->wvt_pos*2048);
set_sound_len(synth->wvt_pos*2048 + 2048);
-
+
draw_bars(synth, 20, 20, 200, 16, 3);
draw_text(synth, WIDTH / 2 - 108, 20);
@@ -765,7 +766,7 @@ rayrun(synth_t *synth){
synth->clamp = GuiToggle((Rectangle){ WIDTH - 100 - 50, 50 + 24 + 6 + 24 + 6, 100, 24 }, "clamp", synth->clamp);
synth->delay = GuiToggle((Rectangle){ WIDTH - 100 - 50, 50 + 24 + 6 + 24 + 6 + 24 + 6, 100, 24 }, "delay", synth->delay);
-
+
if ( GuiButton((Rectangle){ WIDTH - 100 - 50, 50 + 24 + 6 + 24 + 6 + 24 + 6 + 24 + 6 + 24 + 6, 100, 24 }, "SAVE!")) {
save_synth(synth, "asdas");
}
@@ -773,7 +774,7 @@ rayrun(synth_t *synth){
if ( GuiButton((Rectangle){ WIDTH - 100 - 50, 50 + 24 + 6 + 24 + 6 + 24 + 6 + 24 + 6 + 24 + 6 + 24 + 6, 100, 24 }, "LOAD!")) {
load_synth(synth, "asdas");
}
-
+
static int edit_midi = 0;
static int edit_sound = 0;