patch loading

master
vampirefrog 6 years ago
parent 60af68fb58
commit 9b25b01751

@ -245,19 +245,10 @@ int main(int argc, char **argv) {
sr = jack_get_sample_rate(client);
synth_init(&synth);
synth.osc_env.attack = 1;
synth.osc_env.decay = 0;
synth.osc_env.sustain = 100;
synth.osc_env.release = 100;
synth.filter_env.attack = 1;
synth.filter_env.decay = 300;
synth.filter_env.sustain = 0;
synth.filter_env.release = 0;
synth.filter_eg_intensity = .9;
synth.filter_kbd_track = .5;
sine_osc_set_freq(&synth.lfo_osc, 6);
synth.pitch_bend_range = 12; // semitones
synth.monophonic = 1;
if(optind < argc) {
synth_load_patch(&synth, argv[optind]);
}
if (jack_activate(client)) {
fprintf (stderr, "cannot activate client");

@ -191,3 +191,61 @@ void synth_pitch_bend(struct Synth *s, int16_t bend) {
void synth_set_lfo_depth(struct Synth *s, uint8_t mod) {
s->lfo_depth = mod / 127.0;
}
void synth_load_patch(struct Synth *s, const char *filename) {
FILE *f = fopen(filename, "r");
if(!f) {
perror(filename);
return;
}
char buf[256];
while(!feof(f)) {
fgets(buf, sizeof(buf), f);
char *tok = strtok(buf, " \t");
if(tok) {
char *val = strtok(NULL, " \t");
if(val) {
if(!strcmp(tok, "lfo_freq")) {
sine_osc_set_freq(&s->lfo_osc, strtof(val, NULL));
} else if(!strcmp(tok, "osc_env.attack")) {
s->osc_env.attack = strtof(val, NULL);
} else if(!strcmp(tok, "osc_env.decay")) {
s->osc_env.decay = strtof(val, NULL);
} else if(!strcmp(tok, "osc_env.sustain")) {
s->osc_env.sustain = strtof(val, NULL);
} else if(!strcmp(tok, "osc_env.release")) {
s->osc_env.release = strtof(val, NULL);
} else if(!strcmp(tok, "filter_env.attack")) {
printf("filter_env.attack %f\n", strtof(val, NULL));
s->filter_env.attack = strtof(val, NULL);
} else if(!strcmp(tok, "filter_env.decay")) {
printf("filter_env.decay %f\n", strtof(val, NULL));
s->filter_env.decay = strtof(val, NULL);
} else if(!strcmp(tok, "filter_env.sustain")) {
s->filter_env.sustain = strtof(val, NULL);
} else if(!strcmp(tok, "filter_env.release")) {
s->filter_env.release = strtof(val, NULL);
} else if(!strcmp(tok, "filter_eg_intensity")) {
s->filter_eg_intensity = strtof(val, NULL);
} else if(!strcmp(tok, "filter_kbd_track")) {
s->filter_kbd_track = strtof(val, NULL);
} else if(!strcmp(tok, "pitch_bend_range")) {
s->pitch_bend_range = strtof(val, NULL);
} else if(!strcmp(tok, "monophonic")) {
s->monophonic = atoi(val);
} else if(!strcmp(tok, "unison_spread")) {
s->unison_spread = strtof(val, NULL);
} else if(!strcmp(tok, "stereo_spread")) {
s->stereo_spread = strtof(val, NULL);
} else if(!strcmp(tok, "cutoff")) {
s->cutoff = strtof(val, NULL);
} else if(!strcmp(tok, "resonance")) {
for(int i = 0; i < SYNTH_NUM_VOICES; i++) {
filter_set_resonance(&s->voices[i].filter, strtof(val, NULL));
}
}
}
}
}
fclose(f);
}

@ -37,6 +37,7 @@ struct Synth {
};
void synth_init(struct Synth *synth);
void synth_load_patch(struct Synth *synth, const char *filename);
void synth_note_on(struct Synth *synth, uint8_t note, uint8_t velocity);
void synth_note_off(struct Synth *synth, uint8_t note, uint8_t velocity);
void synth_render_sample(struct Synth *synth, float *out);

Loading…
Cancel
Save