Browse Source

lib_synth_shed - add brand/model, for having a create_synth() with multiple char * args (for YML gen testing)

master
heck 5 years ago
parent
commit
ffaed67f12
  1. 1
      examples/ext/synth_shed/synth_shed/Makefile
  2. 11
      examples/lib/lib_synth_shed/main.c
  3. 35
      examples/lib/lib_synth_shed/synth_shed.c
  4. 16
      examples/lib/lib_synth_shed/synth_shed.h

1
examples/ext/synth_shed/synth_shed/Makefile

@ -40,7 +40,6 @@ $(TARGET_MODULE_STATIC) : $(OBJS) $(LIBS_STATIC)
$(CXX) $(LDFLAGS_STATIC) -o $@ $^ $(CXX) $(LDFLAGS_STATIC) -o $@ $^
clean: clean:
$(MAKE) -C gen clean
rm -f $(TARGET) rm -f $(TARGET)
rm -f $(OBJS) rm -f $(OBJS)

11
examples/lib/lib_synth_shed/main.c

@ -2,15 +2,24 @@
#include <stdio.h> #include <stdio.h>
//void synth_init(synth_t *sfac) {
// sfac = synth_create("UltraBoog");
//}
int main() { int main() {
init_synth_shed(); init_synth_shed();
// synth_t* newsynth = NULL;
// synth_init(newsynth);
synth_t* my_synth = synth_create("UltraBoog"); synth_t* my_synth = synth_create("Korg", "MS20", 2);
printf("brand %s\n", my_synth->brand);
printf("model %s\n", my_synth->model);
printf("%s", play_synth(my_synth)); printf("%s", play_synth(my_synth));
synth_set_osc_count(my_synth, 33); synth_set_osc_count(my_synth, 33);
printf("%s", play_synth(my_synth)); printf("%s", play_synth(my_synth));
return 0; return 0;
} }

35
examples/lib/lib_synth_shed/synth_shed.c

@ -8,17 +8,19 @@ void init_synth_shed() {
printf("init_synth_shed() - called\n"); printf("init_synth_shed() - called\n");
} }
synth_t* synth_create(const char* name) { synth_t* synth_create(const char* brand, const char* model, int osc_count) {
synth_t* new = (synth_t*) malloc(sizeof(synth_t)); printf("%s::%s brand:'%s, model: %s'\n",__FILE__, __FUNCTION__, brand, model);
assert(new); synth_t* new_synth = (synth_t*) malloc(sizeof(synth_t));
if (new != NULL) { assert(new_synth);
new->model_name = "TESTNAME"; if (new_synth != NULL) {
new->osc_count = 1; new_synth->brand = brand;
new->technolgy = ANALOG; new_synth->model = model;
new->filter.technology = ANALOG; new_synth->osc_count = osc_count;
new->filter.type = LPF; new_synth->technolgy = ANALOG;
new_synth->filter.technology = ANALOG;
new_synth->filter.type = LPF;
} }
return new; return new_synth;
} }
SYNTH_STATUS synth_set_osc_count(synth_t* synth, int osc_count) { SYNTH_STATUS synth_set_osc_count(synth_t* synth, int osc_count) {
@ -33,11 +35,9 @@ SYNTH_STATUS synth_set_osc_count(synth_t* synth, int osc_count) {
} }
//SYNTH_STATUS synth_set_filter(synth_t* synth, //SYNTH_STATUS synth_set_filter(synth_t* synth, filter_t* filt);
// filter_t* filt);
// //SYNTH_STATUS synth_set_tech(synth_t* synth, tech_t tech);
//SYNTH_STATUS synth_set_tech(synth_t* synth,
// tech_t tech);
const char* tech_to_string(const enum _tech* tech) { const char* tech_to_string(const enum _tech* tech) {
assert(tech); assert(tech);
@ -72,7 +72,8 @@ const char* play_synth(synth_t* synth) {
assert(synth); assert(synth);
char ret[9999]; char ret[9999];
const char* greet = "Playing synth:"; const char* greet = "Playing synth:";
const char* model = synth->model_name; const char* brand = synth->brand;
const char* model = synth->model;
char osc[4]; char osc[4];
sprintf(osc, "%i", synth->osc_count); sprintf(osc, "%i", synth->osc_count);
@ -81,6 +82,6 @@ const char* play_synth(synth_t* synth) {
const char* filt_tech = tech_to_string(&synth->filter.technology); const char* filt_tech = tech_to_string(&synth->filter.technology);
const char* filt_type = filtertype_to_string(&synth->filter.type); const char* filt_type = filtertype_to_string(&synth->filter.type);
sprintf(ret, "%s\nnamed: %s\nosc: %s\ntech:%s\nfilt:%s / %s\n\n", greet, model, osc, tech, filt_tech, filt_type); sprintf(ret, "%s\nbrand: %s\nmodel: %s\nosc: %s\ntech:%s\nfilt:%s / %s\n\n", greet, brand,model, osc, tech, filt_tech, filt_type);
return strdup(ret); return strdup(ret);
} }

16
examples/lib/lib_synth_shed/synth_shed.h

@ -31,7 +31,8 @@ typedef struct _filter {
} filter_t; } filter_t;
struct _synth { struct _synth {
const char* model_name; const char* brand;
const char* model;
int osc_count; int osc_count;
tech_t technolgy; tech_t technolgy;
filter_t filter; filter_t filter;
@ -41,15 +42,16 @@ struct _synth {
// Functions // Functions
void init_synth_shed(); void init_synth_shed();
synth_t* synth_create(const char* name); synth_t* synth_create(const char* brand, const char* model, int osc_count);
// This function covers the problem of a pointer to pointer arg
SYNTH_STATUS synth_create_pp(synth_t** new_synth);
SYNTH_STATUS synth_set_osc_count(synth_t* synth, int osc_count); SYNTH_STATUS synth_set_osc_count(synth_t* synth, int osc_count);
//SYNTH_STATUS synth_set_filter(synth_t* synth, //SYNTH_STATUS synth_set_filter(synth_t* synth, filter_t* filt);
// filter_t* filt);
// //SYNTH_STATUS synth_set_tech(synth_t* synth, tech_t tech);
//SYNTH_STATUS synth_set_tech(synth_t* synth,
// tech_t tech);
const char* tech_to_string(const enum _tech* tech); const char* tech_to_string(const enum _tech* tech);

Loading…
Cancel
Save