|
|
@ -8,19 +8,40 @@ void init_synth_shed() { |
|
|
|
printf("init_synth_shed() - called\n"); |
|
|
|
} |
|
|
|
|
|
|
|
synth_t* synth_create(const char* brand, const char* model, int osc_count) { |
|
|
|
SYNTH_STATUS synth_create(synth_t **new_synth, const char *brand, const char *model, int osc_count) { |
|
|
|
assert(brand); |
|
|
|
assert(model); |
|
|
|
|
|
|
|
if (brand == NULL || brand[0] == '\0') { |
|
|
|
return SYNTH_STATUS_ARG_ERR; |
|
|
|
} |
|
|
|
|
|
|
|
if (model == NULL || brand[0] == '\0') { |
|
|
|
return SYNTH_STATUS_ARG_ERR; |
|
|
|
} |
|
|
|
|
|
|
|
printf("%s::%s brand:'%s, model: %s'\n", __FILE__, __FUNCTION__, brand, model); |
|
|
|
synth_t* new_synth = (synth_t*) malloc(sizeof(synth_t)); |
|
|
|
assert(new_synth); |
|
|
|
if (new_synth != NULL) { |
|
|
|
new_synth->brand = brand; |
|
|
|
new_synth->model = model; |
|
|
|
new_synth->osc_count = osc_count; |
|
|
|
new_synth->technology = ANALOG; |
|
|
|
new_synth->filter.technology = ANALOG; |
|
|
|
new_synth->filter.type = LPF; |
|
|
|
|
|
|
|
synth_t *_new_synth = (synth_t *) malloc(sizeof(synth_t)); |
|
|
|
assert(_new_synth); |
|
|
|
if (_new_synth == NULL) { |
|
|
|
return SYNTH_STATUS_ERR; |
|
|
|
} |
|
|
|
return new_synth; |
|
|
|
|
|
|
|
_new_synth->brand = brand; |
|
|
|
_new_synth->model = model; |
|
|
|
_new_synth->osc_count = osc_count; |
|
|
|
_new_synth->technology = ANALOG; |
|
|
|
_new_synth->filter[0].technology = ANALOG; |
|
|
|
_new_synth->filter[0].type = LPF; |
|
|
|
_new_synth->filter[1].technology = ANALOG; |
|
|
|
_new_synth->filter[1].type = HPF; |
|
|
|
_new_synth->filter[2].technology = ANALOG; |
|
|
|
_new_synth->filter[2].type = BPF; |
|
|
|
|
|
|
|
*new_synth = _new_synth; |
|
|
|
|
|
|
|
return SYNTH_STATUS_OK; |
|
|
|
} |
|
|
|
|
|
|
|
SYNTH_STATUS synth_set_osc_count(synth_t *synth, int osc_count) { |
|
|
@ -39,6 +60,20 @@ SYNTH_STATUS synth_set_osc_count(synth_t* synth, int osc_count) { |
|
|
|
|
|
|
|
//SYNTH_STATUS synth_set_tech(synth_t* synth, tech_t tech);
|
|
|
|
|
|
|
|
const char *status_to_string(SYNTH_STATUS status) { |
|
|
|
const char *ret = "unknown status"; |
|
|
|
if (status == SYNTH_STATUS_OK) { |
|
|
|
ret = "SYNTH_STATUS_OK"; |
|
|
|
} |
|
|
|
if (status == SYNTH_STATUS_ERR) { |
|
|
|
ret = "SYNTH_STATUS_ERR"; |
|
|
|
} |
|
|
|
if (status == SYNTH_STATUS_ARG_ERR) { |
|
|
|
ret = "SYNTH_STATUS_ARG_ERR"; |
|
|
|
} |
|
|
|
return ret; |
|
|
|
} |
|
|
|
|
|
|
|
const char *tech_to_string(const enum _tech *tech) { |
|
|
|
assert(tech); |
|
|
|
const char *ret = "unknown tech"; |
|
|
@ -52,26 +87,32 @@ const char* tech_to_string(const enum _tech* tech) { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const char* filtertype_to_string(const filtertype_t* const filt) { |
|
|
|
SYNTH_STATUS filtertype_to_string(const filtertype_t *const filt, char **ftstr) { |
|
|
|
assert(filt); |
|
|
|
const char* ret = "unknown filtertype"; |
|
|
|
char *_ftstr = "unknown filtertype"; |
|
|
|
if (filt == NULL) { |
|
|
|
return SYNTH_STATUS_ARG_ERR; |
|
|
|
} |
|
|
|
|
|
|
|
if (*filt == LPF) { |
|
|
|
ret = "LPF"; |
|
|
|
_ftstr = "LPF"; |
|
|
|
} |
|
|
|
if (*filt == HPF) { |
|
|
|
ret = "HPF"; |
|
|
|
_ftstr = "HPF"; |
|
|
|
} |
|
|
|
if (*filt == BPF) { |
|
|
|
ret = "BPF"; |
|
|
|
_ftstr = "BPF"; |
|
|
|
} |
|
|
|
return ret; |
|
|
|
|
|
|
|
*ftstr = _ftstr; |
|
|
|
return SYNTH_STATUS_OK; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const char *play_synth(synth_t *synth) { |
|
|
|
assert(synth); |
|
|
|
char ret[9999]; |
|
|
|
const char* greet = "Playing synth:"; |
|
|
|
const char *greet = "PLAYING SYNTH:"; |
|
|
|
const char *brand = synth->brand; |
|
|
|
const char *model = synth->model; |
|
|
|
|
|
|
@ -79,9 +120,32 @@ const char* play_synth(synth_t* synth) { |
|
|
|
sprintf(osc, "%i", synth->osc_count); |
|
|
|
|
|
|
|
const char *tech = tech_to_string(&synth->technology); |
|
|
|
const char* filt_tech = tech_to_string(&synth->filter.technology); |
|
|
|
const char* filt_type = filtertype_to_string(&synth->filter.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); |
|
|
|
|
|
|
|
const char *filt_tech[3] = {"", "", ""}; |
|
|
|
const char *filtertype_str[3] = {"", "", ""}; |
|
|
|
|
|
|
|
for (int i = 0; i < 3; i++) { |
|
|
|
filt_tech[i] = tech_to_string(&synth->filter[i].technology); |
|
|
|
|
|
|
|
SYNTH_STATUS status = filtertype_to_string(&synth->filter[i].type, &filtertype_str[i]); |
|
|
|
if (status != SYNTH_STATUS_OK) { |
|
|
|
printf("%s", status_to_string(status)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
sprintf(ret, "%s\n" |
|
|
|
"brand: %s\n" |
|
|
|
"model: %s\n" |
|
|
|
"osc: %s\n" |
|
|
|
"tech:%s\n" |
|
|
|
"filt[0]:%s / %s\n" |
|
|
|
"filt[1]:%s / %s\n" |
|
|
|
"filt[2]:%s / %s\n" |
|
|
|
"\n", |
|
|
|
greet, brand, model, osc, tech, |
|
|
|
filt_tech[0], filtertype_str[0], |
|
|
|
filt_tech[1], filtertype_str[1], |
|
|
|
filt_tech[2], filtertype_str[2]); |
|
|
|
return strdup(ret); |
|
|
|
} |
|
|
|