aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2025-04-27 11:07:55 -0400
committerSam Anthony <sam@samanthony.xyz>2025-04-27 11:07:55 -0400
commitdec2f0fe3ea9e3e95d6fc6abc421f1a81149c10c (patch)
treea5af814c7b4249ccee710a8e455ac3195d2ad068
parentf45e9a8d37a384ccea33158a4d3062d633720c93 (diff)
downloadvolute-dec2f0fe3ea9e3e95d6fc6abc421f1a81149c10c.zip
init compressor-select widget
-rw-r--r--main.c4
-rw-r--r--ui.c4
-rw-r--r--widget.c54
-rw-r--r--widget.h21
4 files changed, 81 insertions, 2 deletions
diff --git a/main.c b/main.c
index a18f08f..74c4f84 100644
--- a/main.c
+++ b/main.c
@@ -1,12 +1,14 @@
/* Headers. */
+#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include "microui.h"
#include "renderer.h"
-#include "widget.h"
#include "unit.h"
+#include "compressor.h"
+#include "widget.h"
#include "engine.h"
#include "ui.h"
diff --git a/ui.c b/ui.c
index a28a169..cb65da7 100644
--- a/ui.c
+++ b/ui.c
@@ -1,9 +1,11 @@
#include <assert.h>
+#include <limits.h>
#include <string.h>
#include "microui.h"
-#include "widget.h"
#include "unit.h"
+#include "compressor.h"
+#include "widget.h"
#include "engine.h"
#include "ui.h"
diff --git a/widget.c b/widget.c
index 670d91d..4fcb137 100644
--- a/widget.c
+++ b/widget.c
@@ -1,7 +1,11 @@
+#include <limits.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include "microui.h"
+#include "unit.h"
+#include "compressor.h"
#include "widget.h"
#include "util.h"
@@ -106,6 +110,56 @@ w_select(mu_Context *ctx, w_Select *select) {
return res;
}
+/* Returns non-zero on error. */
+int
+w_init_select_compressor(w_Select_Compressor *select, int n, const Compressor *comps) {
+ int i;
+ size_t namesize;
+
+ select->comps = comps;
+ select->n = n;
+
+ select->filtered = malloc(n * sizeof(*select->filtered));
+ if (select->filtered == NULL) {
+ return 1;
+ }
+ /* TODO: parallelize. */
+ for (i = 0; i < n; i++) {
+ select->filtered[i] = i;
+ }
+ select->nfiltered = n;
+
+ namesize = sizeof((*comps).brand) + sizeof((*comps).series) + sizeof((*comps).model) + 3;
+ select->names = malloc(n * namesize);
+ if (select->names == NULL) {
+ free(select->filtered);
+ return 1;
+ }
+ /* TODO: parallelize. */
+ for (i = 0; i < n; i++) {
+ snprintf(select->names[i], namesize, "%s %s %s",
+ comps[i].brand, comps[i].series, comps[i].model);
+ }
+
+ select->idx = 0;
+ select -> oldidx = 0;
+
+ select->active = 0;
+
+ return 0;
+}
+
+void
+w_free_select_compressor(w_Select_Compressor *select) {
+ free(select->filtered);
+ free(select->names);
+}
+
+int
+w_select_compressor(mu_Context *ctx, w_Select_Compressor *select) {
+ /* TODO */
+}
+
void
w_init_number(w_Number num) {
num[0] = '\0';
diff --git a/widget.h b/widget.h
index 1237e29..34e6edf 100644
--- a/widget.h
+++ b/widget.h
@@ -1,6 +1,7 @@
enum {
FIELD_SIZE = 64,
NUMBER_SIZE = 128,
+ NAME_SIZE = 256,
};
@@ -28,6 +29,26 @@ void w_init_select(w_Select *select, int nopts, const char *const opts[]);
int w_select(mu_Context *ctx, w_Select *select);
+typedef struct {
+ const Compressor *comps;
+ int n; /* len(comps) */
+
+ int *filtered; /* indices of compressors accepted by the filter. */
+ int nfiltered; /* len(filtered) */
+
+ char **names; /* buffer to hold names of compressors. */
+
+ int idx; /* index of selected in filtered. */
+ int oldidx; /* index of previously selected. */
+
+ int active;
+} w_Select_Compressor;
+
+int w_init_select_compressor(w_Select_Compressor *select, int n, const Compressor *const comps);
+void w_free_select_compressor(w_Select_Compressor *select);
+int w_select_compressor(mu_Context *ctx, w_Select_Compressor *select);
+
+
typedef char w_Number[NUMBER_SIZE];
void w_init_number(w_Number num);