You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

151 lines
3.7 KiB

#include "synth_shed.h"
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
void init_synth_shed() {
printf("init_synth_shed() - called\n");
}
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) {
return SYNTH_STATUS_ERR;
}
_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) {
assert(synth);
SYNTH_STATUS status = 0;
if (osc_count < 0) {
status = 1;
} else {
synth->osc_count = osc_count;
}
return status;
}
//SYNTH_STATUS synth_set_filter(synth_t* synth, filter_t* filt);
//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";
if (*tech == ANALOG) {
return "ANALOG";
}
if (*tech == DIGITAL) {
return "DIGITAL";
}
return ret;
}
SYNTH_STATUS filtertype_to_string(const filtertype_t *const filt, char **ftstr) {
assert(filt);
char *_ftstr = "unknown filtertype";
if (filt == NULL) {
return SYNTH_STATUS_ARG_ERR;
}
if (*filt == LPF) {
_ftstr = "LPF";
}
if (*filt == HPF) {
_ftstr = "HPF";
}
if (*filt == BPF) {
_ftstr = "BPF";
}
*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 *brand = synth->brand;
const char *model = synth->model;
char osc[4];
sprintf(osc, "%i", synth->osc_count);
const char *tech = tech_to_string(&synth->technology);
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);
}