diff options
Diffstat (limited to 'note_compiler')
-rw-r--r-- | note_compiler/main.cpp | 107 | ||||
-rw-r--r-- | note_compiler/note.cpp.todo | 72 | ||||
-rw-r--r-- | note_compiler/templates/set_param.1 | 25 | ||||
-rw-r--r-- | note_compiler/templates/set_param.2 | 34 | ||||
-rw-r--r-- | note_compiler/templates/set_param.nofilter | 13 | ||||
-rw-r--r-- | note_compiler/templates/set_param.nofilterenv | 7 |
6 files changed, 178 insertions, 80 deletions
diff --git a/note_compiler/main.cpp b/note_compiler/main.cpp index 7f48c0b..8612bd2 100644 --- a/note_compiler/main.cpp +++ b/note_compiler/main.cpp @@ -657,12 +657,96 @@ void write_get_sample() out << "}\n"; } -void write_foo() +void write_set_param() { - out << "void Note::foo()\n" - "{\n"; + out << "void Note::set_param(const parameter_t &p, fixed_t v)\n" + "{\n" + "\toscillator_t *sel_osc=NULL;\n" + "\tEnvelope *sel_env=NULL;\n" + "\t\n" + "\tswitch (p.osc)\n" + "\t{\n"; - out << "}\n"; + for (int i=0;i<prog.n_osc;i++) + { + out << "\t\tcase "<<i<<": sel_osc=&osc"<<i<<"; "; + + if (prog.env[i].enabled) + out << "sel_env=env"<<i<<"; "; + else + comment << "/* envelope"<<i<<" is disabled */ "; + + out << "break;\n"; + } + + out << "\t\t\n" + "\t\tdefault: output_note(\"NOTE: trying to change the nonexistent oscillator\"+IntToStr(p.osc));\n" + "\t}\n" + "\t\n"; + + include_file("set_param.1"); + + if (prog.use_pfactor) + out << "\t\tcase MODULATION: sel_osc->fm_strength[p.index]=v*pfactor.fm[p.osc][p.index] >>SCALE; break;\n" + "\t\tcase OUTPUT: sel_osc->output=v*pfactor.out[p.osc] >>SCALE; break;\n"; + else + out << "\t\tcase MODULATION: sel_osc->fm_strength[p.index]=v; break;\n" + "\t\tcase OUTPUT: sel_osc->output=v; break;\n"; + + + if ((prog.filter.enabled==true) || (prog.filter.enabled_const==false)) + { + out << "\t\t\n" + "\t\tcase FILTER_ENABLED: output_note(\"NOTE: cannot enable filter in playing notes\"); break;\n" + "\t\t\n"; + + if (prog.filter.env_settings.enabled) + include_file("set_param.2"); + else + include_file("set_param.nofilterenv"); + + if (prog.use_pfactor) + out << "\t\tcase FILTER_ENV_AMOUNT: filter_params.env_amount=float(v*pfactor.filter_env)/ONE/ONE; break;\n" + "\t\tcase FILTER_OFFSET: filter_params.freqfactor_offset=float(v*pfactor.filter_offset)/ONE/ONE; break;\n" + "\t\tcase FILTER_RESONANCE: filter_params.resonance=float(v*pfactor.filter_res)/ONE/ONE; break;\n"; + else + out << "\t\tcase FILTER_ENV_AMOUNT: filter_params.env_amount=float(v)/ONE; break;\n" + "\t\tcase FILTER_OFFSET: filter_params.freqfactor_offset=float(v)/ONE; break;\n" + "\t\tcase FILTER_RESONANCE: filter_params.resonance=float(v)/ONE; break;\n"; + + out << "\t\tcase FILTER_TREMOLO: filter_params.trem_strength=v; break;\n" + "\t\tcase FILTER_TREM_LFO: filter_params.trem_lfo=v; break;\n"; + } + else + include_file("set_param.nofilter"); + + if ((prog.sync_factor!=0) || (prog.sync_factor_const==false)) + out << "\t\t\n" + "\t\tcase SYNC_FACTOR: sync_factor=v; break;\n"; + else + out << "\t\t\n" + "\t\tcase SYNC_FACTOR: output_note(\"NOTE: trying to set sync_factor, but it's disabled\"); break;\n"; + + out << "\t\t\n" + "\t\tdefault: throw string(\"trying to set an unknown parameter\");\n" + "\t}\n" + "}\n"; +} + +void write_create_note() +{ + out << "extern \"C\" NoteSkel* create_note(int n, float v,program_t &prg, jack_nframes_t pf, fixed_t pb, int prg_no)\n" + "{\n" + "\treturn new Note(n,v,prg,pf,pb,prg_no);\n" + "}\n"; +} + +void write_destroy_note() +{ + out << "extern \"C\" void destroy_note(NoteSkel* obj)\n" + "{\n" + "\tdelete obj;\n" + "}\n"; } void generate_source() @@ -703,17 +787,24 @@ void generate_source() write_empty_line(); write_get_sample(); + write_empty_line(); + + write_set_param(); + + write_empty_line(); + write_empty_line(); + write_empty_line(); + + //implementation of create_new_note and destroy_note + write_create_note(); + write_destroy_note(); } int main(int argc, char** argv) { prog=parse("../../filtertest.prog"); - prog.env[1].enabled=false; - - generate_source(); - return 0; } diff --git a/note_compiler/note.cpp.todo b/note_compiler/note.cpp.todo deleted file mode 100644 index a256525..0000000 --- a/note_compiler/note.cpp.todo +++ /dev/null @@ -1,72 +0,0 @@ -void Note::set_param(const parameter_t &p, fixed_t v) //ACHTUNG: -{ - //wenn das verändert wird, muss auch program_t::set_param verändert werden! - switch(p.par) - { - case ATTACK: envelope[p.osc]->set_attack(v*samp_rate >>SCALE); break; - case DECAY: envelope[p.osc]->set_decay(v*samp_rate >>SCALE); break; - case SUSTAIN: envelope[p.osc]->set_sustain(v); break; - case RELEASE: envelope[p.osc]->set_release(v*samp_rate >>SCALE); break; - case HOLD: envelope[p.osc]->set_hold(v!=0); break; - - case KSR: oscillator[p.osc].ksr=float(v)/ONE; break; - case KSL: oscillator[p.osc].ksl=float(v)/ONE; break; - - case FACTOR: oscillator[p.osc].factor=v; break; - case MODULATION: oscillator[p.osc].fm_strength[p.index]=v*pfactor.fm[p.osc][p.index] >>SCALE; break; - case OUTPUT: oscillator[p.osc].output=v*pfactor.out[p.osc] >>SCALE; break; - case TREMOLO: oscillator[p.osc].tremolo_depth=v; break; - case TREM_LFO: oscillator[p.osc].tremolo_lfo=v; break; - case VIBRATO: oscillator[p.osc].vibrato_depth=v; break; - case VIB_LFO: oscillator[p.osc].vibrato_lfo=v; break; - case WAVEFORM: oscillator[p.osc].waveform=v; break; - case SYNC: oscillator[p.osc].sync=(v!=0); break; - - case FILTER_ENABLED: output_note("NOTE: cannot enable filter in playing notes"); break; - case FILTER_ENV_AMOUNT: filter_params.env_amount=float(v*pfactor.filter_env)/ONE/ONE; break; - - case FILTER_ATTACK: - if (filter_params.enabled) - filter_envelope->set_attack(v*samp_rate/filter_update_frames >>SCALE); - else - output_note("NOTE: cannot set filter-attack when filter is disabled"); - break; - - case FILTER_DECAY: - if (filter_params.enabled) - filter_envelope->set_decay(v*samp_rate/filter_update_frames >>SCALE); - else - output_note("NOTE: cannot set filter-decay when filter is disabled"); - break; - - case FILTER_SUSTAIN: - if (filter_params.enabled) - filter_envelope->set_sustain(v); - else - output_note("NOTE: cannot set filter-sustain when filter is disabled"); - break; - - case FILTER_RELEASE: - if (filter_params.enabled) - filter_envelope->set_release(v*samp_rate/filter_update_frames >>SCALE); - else - output_note("NOTE: cannot set filter-release when filter is disabled"); - break; - - case FILTER_HOLD: - if (filter_params.enabled) - filter_envelope->set_hold(v!=0); - else - output_note("NOTE: cannot set filter-hold when filter is disabled"); - break; - - case FILTER_OFFSET: filter_params.freqfactor_offset=float(v*pfactor.filter_offset)/ONE/ONE; break; - case FILTER_RESONANCE: filter_params.resonance=float(v*pfactor.filter_res)/ONE/ONE; break; - case FILTER_TREMOLO: filter_params.trem_strength=v; break; - case FILTER_TREM_LFO: filter_params.trem_lfo=v; break; - - case SYNC_FACTOR: sync_factor=v; break; - default: throw string("trying to set an unknown parameter"); - - } -} diff --git a/note_compiler/templates/set_param.1 b/note_compiler/templates/set_param.1 new file mode 100644 index 0000000..3d20dfe --- /dev/null +++ b/note_compiler/templates/set_param.1 @@ -0,0 +1,25 @@ + if ( ((p.par==ATTACK) || (p.par==DECAY) || (p.par==SUSTAIN) || + (p.par==RELEASE) || (p.par==HOLD)) && sel_env==NULL ) + { + output_note("NOTE: cannot change parameter for envelope"+IntToStr(p.osc)+" because it's disabled"); + return; + } + + switch(p.par) + { + case ATTACK: sel_env->set_attack(v*samp_rate >>SCALE); break; + case DECAY: sel_env->set_decay(v*samp_rate >>SCALE); break; + case SUSTAIN: sel_env->set_sustain(v); break; + case RELEASE: sel_env->set_release(v*samp_rate >>SCALE); break; + case HOLD: sel_env->set_hold(v!=0); break; + + case KSR: sel_osc->ksr=float(v)/ONE; break; + case KSL: sel_osc->ksl=float(v)/ONE; break; + + case FACTOR: sel_osc->factor=v; break; + case TREMOLO: sel_osc->tremolo_depth=v; break; + case TREM_LFO: sel_osc->tremolo_lfo=v; break; + case VIBRATO: sel_osc->vibrato_depth=v; break; + case VIB_LFO: sel_osc->vibrato_lfo=v; break; + case WAVEFORM: sel_osc->waveform=v; break; + case SYNC: sel_osc->sync=(v!=0); break; diff --git a/note_compiler/templates/set_param.2 b/note_compiler/templates/set_param.2 new file mode 100644 index 0000000..aaa21b4 --- /dev/null +++ b/note_compiler/templates/set_param.2 @@ -0,0 +1,34 @@ + case FILTER_ATTACK: + if (filter_params.enabled) + filter_envelope->set_attack(v*samp_rate/filter_update_frames >>SCALE); + else + output_note("NOTE: cannot set filter-attack when filter is disabled"); + break; + + case FILTER_DECAY: + if (filter_params.enabled) + filter_envelope->set_decay(v*samp_rate/filter_update_frames >>SCALE); + else + output_note("NOTE: cannot set filter-decay when filter is disabled"); + break; + + case FILTER_SUSTAIN: + if (filter_params.enabled) + filter_envelope->set_sustain(v); + else + output_note("NOTE: cannot set filter-sustain when filter is disabled"); + break; + + case FILTER_RELEASE: + if (filter_params.enabled) + filter_envelope->set_release(v*samp_rate/filter_update_frames >>SCALE); + else + output_note("NOTE: cannot set filter-release when filter is disabled"); + break; + + case FILTER_HOLD: + if (filter_params.enabled) + filter_envelope->set_hold(v!=0); + else + output_note("NOTE: cannot set filter-hold when filter is disabled"); + break; diff --git a/note_compiler/templates/set_param.nofilter b/note_compiler/templates/set_param.nofilter new file mode 100644 index 0000000..e9ee336 --- /dev/null +++ b/note_compiler/templates/set_param.nofilter @@ -0,0 +1,13 @@ + case FILTER_ENABLED: + case FILTER_ENV_AMOUNT: + case FILTER_ATTACK: + case FILTER_DECAY: + case FILTER_SUSTAIN: + case FILTER_RELEASE: + case FILTER_HOLD: + case FILTER_OFFSET: + case FILTER_RESONANCE: + case FILTER_TREMOLO: + case FILTER_TREM_LFO: + output_note("NOTE: trying to set some filter-param, but filter is disabled"); + break; diff --git a/note_compiler/templates/set_param.nofilterenv b/note_compiler/templates/set_param.nofilterenv new file mode 100644 index 0000000..23ad36d --- /dev/null +++ b/note_compiler/templates/set_param.nofilterenv @@ -0,0 +1,7 @@ + case FILTER_ATTACK: + case FILTER_DECAY: + case FILTER_SUSTAIN: + case FILTER_RELEASE: + case FILTER_HOLD: + output_note("NOTE: trying to change filter envelope, but that envelope is disabled"); + break; |