diff options
Diffstat (limited to 'note_compiler/main.cpp')
-rw-r--r-- | note_compiler/main.cpp | 107 |
1 files changed, 99 insertions, 8 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; } |