From 6c4d9818b49b3ed53ec61e10ca10a2c875968fd7 Mon Sep 17 00:00:00 2001 From: heck Date: Sat, 12 Dec 2020 22:50:02 +0100 Subject: [PATCH] Add gen example "synth_shed" --- gen/data/input/synth_shed/Makefile | 25 +++++++++ gen/data/input/synth_shed/main.c | 14 +++++ gen/data/input/synth_shed/synth_shed.c | 76 ++++++++++++++++++++++++++ gen/data/input/synth_shed/synth_shed.h | 58 ++++++++++++++++++++ 4 files changed, 173 insertions(+) create mode 100644 gen/data/input/synth_shed/Makefile create mode 100644 gen/data/input/synth_shed/main.c create mode 100644 gen/data/input/synth_shed/synth_shed.c create mode 100644 gen/data/input/synth_shed/synth_shed.h diff --git a/gen/data/input/synth_shed/Makefile b/gen/data/input/synth_shed/Makefile new file mode 100644 index 0000000..e956f99 --- /dev/null +++ b/gen/data/input/synth_shed/Makefile @@ -0,0 +1,25 @@ +TARGET=synth_shed + +SRCS+=$(wildcard *.c) +CFLAGS+=-std=c99 -g +INCLUDES+= +LIB_DIRS+= +LIBS+= +LDFLAGS+= + + +CXXFLAGS+=$(INCLUDES) +LDFLAGS+=$(LIB_DIRS+) +LDFLAGS+=$(LIBS) +OBJS+=$(SRCS:.c=.o) + +.PHONY: all, clean + +all: $(TARGET) + +$(TARGET) : $(OBJS) + $(CC) $(LDFLAGS) -o $@ $^ + +clean: + rm -f $(TARGET) + rm -f $(OBJS) diff --git a/gen/data/input/synth_shed/main.c b/gen/data/input/synth_shed/main.c new file mode 100644 index 0000000..444e4a0 --- /dev/null +++ b/gen/data/input/synth_shed/main.c @@ -0,0 +1,14 @@ +#include "synth_shed.h" +#include + + + +int main() { + init_synth_shed(); + + synth_t* my_synth = synth_create("UltraBoog"); + + printf("%s", play_synth(my_synth)); + + return 0; +} diff --git a/gen/data/input/synth_shed/synth_shed.c b/gen/data/input/synth_shed/synth_shed.c new file mode 100644 index 0000000..a69c170 --- /dev/null +++ b/gen/data/input/synth_shed/synth_shed.c @@ -0,0 +1,76 @@ +#include "synth_shed.h" +#include +#include +#include +#include + +void init_synth_shed() { + printf("init_synth_shed() - called\n"); +} + +synth_t* synth_create(const char* name) { + synth_t* new = (synth_t*) malloc(sizeof(synth_t)); + if (new != NULL) { + new->model_name = name; + new->osc_count = 1; + new->technolgy = ANALOG; + new->filter.technology = ANALOG; + new->filter->type = LPF; + } + return new; +} + +//SYNTH_STATUS synth_set_osc_count(synth_t* synth, +// int osc_count); +// +//SYNTH_STATUS synth_set_filter(synth_t* synth, +// filter_t* filt); +// +//SYNTH_STATUS synth_set_tech(synth_t* synth, +// tech_t tech); + +const char* tech_to_string(const tech_t* const tech) { + assert(tech); + const char* ret = "unknown tech"; + if (*tech == ANALOG) { + return "ANALOG"; + } + if (*tech == DIGITAL) { + return "DIGITAL"; + } + return ret; +} + + +const char* filtertype_to_string(const filtertype_t* const filt) { + assert(filt); + const char* ret = "unknown filtertype"; + if (*filt == LPF) { + ret = "LPF"; + } + if (*filt == HPF) { + ret = "HPF"; + } + if (*filt == BPF) { + ret = "BPF"; + } + return ret; +} + + +const char* play_synth(synth_t* synth) { + assert(synth); + char ret[9999]; + const char* greet = "Playing synth:"; + const char* model = synth->model_name; + + char osc[4]; + sprintf(osc, "%i", synth->osc_count); + + const char* tech = tech_to_string(&synth->technolgy); + const char* filt_tech = tech_to_string(&synth->filter.technology); + const char* filt_type = filtertype_to_string(synth->filter->type); + + sprintf(ret, "%s\nnamed: %s\nosc: %s\ntech:%s\nfilt:%s / %s\n", greet, model, osc, tech, filt_tech, filt_type); + return strdup(ret); +} diff --git a/gen/data/input/synth_shed/synth_shed.h b/gen/data/input/synth_shed/synth_shed.h new file mode 100644 index 0000000..0f2c8f4 --- /dev/null +++ b/gen/data/input/synth_shed/synth_shed.h @@ -0,0 +1,58 @@ +#ifndef SYNTH_SHED_H +#define SYNTH_SHED_H + +// Types +// != 0 means ERR +typedef int SYNTH_STATUS; +typedef enum _filtertype filtertype_t; +typedef struct _synth synth_t; + +// Enums +enum _filtertype { + HPF, + LPF, + BPF +}; + +typedef enum _tech { + ANALOG, + DIGITAL +} tech_t; + +// Structs +typedef struct _filter { + tech_t technology; + filtertype_t *type; +} filter_t; + + +struct _synth { + const char* model_name; + int osc_count; + tech_t technolgy; + filter_t filter; +}; + + +// Functions +void init_synth_shed(); + +synth_t* synth_create(const char* name); + +//SYNTH_STATUS synth_set_osc_count(synth_t* synth, +// int osc_count); +// +//SYNTH_STATUS synth_set_filter(synth_t* synth, +// filter_t* filt); +// +//SYNTH_STATUS synth_set_tech(synth_t* synth, +// tech_t tech); + +const char* tech_to_string(const tech_t* tech); + +const char* filtertype_to_string(const filtertype_t *filt); + + +const char* play_synth(synth_t *synth); + +#endif //SYNTH_SHED_H