From e8382521c1a35ad59efea5e8cebb915a67c0008e Mon Sep 17 00:00:00 2001 From: Florian Jung Date: Wed, 5 Jan 2011 18:25:04 +0100 Subject: Finished note-compiler, seems to work. TODO: CLI The note-compiler now also generates code for set_param, and a function has been added which returns a pointer to a newly created object (important for loading from a shared object). There's also a destroyer function. TODO: - write a CLI for the note-compiler - let the note-compiler issue the build-commands on his own - make the synth load instruments from shared objects --- note_compiler/main.cpp | 107 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 99 insertions(+), 8 deletions(-) (limited to 'note_compiler/main.cpp') 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;ifm_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; } -- cgit v1.2.3