summaryrefslogtreecommitdiff
path: root/note_compiler
diff options
context:
space:
mode:
Diffstat (limited to 'note_compiler')
-rw-r--r--note_compiler/main.cpp51
-rw-r--r--note_compiler/parser.cpp52
-rw-r--r--note_compiler/programs.h40
-rw-r--r--note_compiler/templates/head.11
-rw-r--r--note_compiler/templates/interface.13
-rw-r--r--note_compiler/templates/set_param.116
-rw-r--r--note_compiler/util.cpp12
7 files changed, 154 insertions, 21 deletions
diff --git a/note_compiler/main.cpp b/note_compiler/main.cpp
index 4d3fcae..ee69471 100644
--- a/note_compiler/main.cpp
+++ b/note_compiler/main.cpp
@@ -36,6 +36,15 @@ void include_file(string file)
}
}
+void write_freqenv_decs()
+{
+ out << "\t\tdouble freqfactor_factor["<<prog.n_osc<<"];\n";
+ for (int i=0;i<prog.n_osc;i++)
+ if ((prog.osc[i].freq_env_amount!=0) || (prog.osc[i].freq_env_amount==false))
+ out << "\t\tEnvelope* freq_env"<<i<<";\n";
+ else
+ comment << "\t\t//freq-envelope #"<<i<<" is unused\n";
+}
void write_env_decs()
{
for (int i=0;i<prog.n_osc;i++)
@@ -122,14 +131,25 @@ void write_ctor()
"\tpfactor.fm=new fixed_t* ["<<prog.n_osc<<"];\n"
"\tfor (int i=0;i<"<<prog.n_osc<<";i++)\n"
"\t\tpfactor.fm[i]=new fixed_t ["<<prog.n_osc<<"];\n"
+ "\t\n"
+ "\t\tpfactor.freq_env_amount=new fixed_t ["<<prog.n_osc<<"];\n"
"\t\n";
for (i=0;i<prog.n_osc;i++)
if (prog.env[i].enabled)
- out << "\tenv"<<i<<"=new Envelope (prg.env_settings["<<i<<"]);\n";
+ out << "\tenv"<<i<<"=new Envelope (prg.env_settings["<<i<<"], envelope_update_frames);\n";
else
comment << "\t//envelope"<<i<<" is disabled\n";
+ for (i=0;i<prog.n_osc;i++)
+ {
+ out << "\tfreqfactor_factor["<<i<<"]=1.0;\n";
+ if ((prog.osc[i].freq_env_amount!=0) || (prog.osc[i].freq_env_amount==false))
+ out << "\tfreq_env"<<i<<"=new Envelope (prg.osc_settings["<<i<<"].freq_env, envelope_update_frames);\n";
+ else
+ comment << "\t//freq-env #"<<i<<" is disabled\n";
+ }
+
out << "\t\n";
for (i=0;i<prog.n_osc;i++)
@@ -204,6 +224,11 @@ void write_dtor()
else
comment << "\t//envelope"<<i<<" is disabled\n";
+ if ((prog.osc[i].freq_env_amount!=0) || (prog.osc[i].freq_env_amount==false))
+ out << "\tdelete freq_env"<<i<<",\n";
+ else
+ comment << "\t//freq-env #"<<i<<" is disabled\n";
+
out << "\tdelete pfactor.fm["<<i<<"];\n";
out << "\t\n";
@@ -215,6 +240,7 @@ void write_dtor()
"\t\n"
"\tdelete [] pfactor.out;\n"
"\tdelete [] pfactor.fm;\n"
+ "\tdelete [] pfactor.freq_env_amount;\n"
"}\n";
}
@@ -238,6 +264,8 @@ void write_recalc_factors()
"\t\t\n"
"\t\tfor (int j=0;j<"<<prog.n_osc<<";j++)\n"
"\t\t\tpfactor.fm[i][j]=calc_pfactor(curr_prg->pfactor.fm[i][j], vel);\n"
+ "\t\t\n"
+ "\t\tpfactor.freq_env_amount[i]=calc_pfactor(curr_prg->pfactor.freq_env_amount[i], vel);\n"
"\t}\n";
out << "}\n";
@@ -258,7 +286,8 @@ void write_apply_pfactor()
{
out << "\tosc"<<i<<".output=orig.osc"<<i<<".output*pfactor.out["<<i<<"] >>SCALE;\n"
"\tfor (int i=0;i<"<<prog.n_osc<<";i++)\n"
- "\t\tosc"<<i<<".fm_strength[i]=orig.osc"<<i<<".fm_strength[i]*pfactor.fm["<<i<<"][i] >>SCALE;\n";
+ "\t\tosc"<<i<<".fm_strength[i]=orig.osc"<<i<<".fm_strength[i]*pfactor.fm["<<i<<"][i] >>SCALE;\n"
+ "\tosc"<<i<<".freq_env_amount=orig.osc"<<i<<".freq_env_amount*pfactor.freq_env_amount["<<i<<"] /ONE;\n";
}
out << "}\n";
@@ -303,6 +332,11 @@ void write_release()
out << "\tenv"<<i<<"->release_key();\n";
else
comment << "\t//envelope"<<i<<" is disabled\n";
+
+ if ((prog.osc[i].freq_env_amount!=0) || (prog.osc[i].freq_env_amount==false))
+ out << "\tfreq_env"<<i<<"->release_key();\n";
+ else
+ comment << "\t//freq-env #"<<i<<" is disabled\n";
}
@@ -346,6 +380,11 @@ void write_reattack()
out << "\tenv"<<i<<"->reattack();\n";
else
comment << "\t//envelope"<<i<<" is disabled\n";
+
+ if ((prog.osc[i].freq_env_amount!=0) || (prog.osc[i].freq_env_amount==false))
+ out << "\tfreq_env"<<i<<"->reattack();\n";
+ else
+ comment << "\t//freq-env #"<<i<<" is disabled\n";
}
@@ -646,6 +685,7 @@ void write_set_param()
"\toscillator_t* sel_osc=NULL;\n"
"\toscillator_t* sel_orig_osc=NULL;\n"
"\tEnvelope* sel_env=NULL;\n"
+ "\tEnvelope* sel_factor_env=NULL;\n"
"\t\n"
"\tswitch (p.osc)\n"
"\t{\n";
@@ -659,6 +699,11 @@ void write_set_param()
else
comment << "/* envelope"<<i<<" is disabled */ ";
+ if ((prog.osc[i].freq_env_amount!=0) || (prog.osc[i].freq_env_amount==false))
+ out << "sel_factor_env=freq_env"<<i<<"; ";
+ else
+ comment << "/* freq-env #"<<i<<" is disabled */ ";
+
out << "break;\n";
}
@@ -720,6 +765,8 @@ void generate_source()
write_empty_line();
write_osc_decs();
write_empty_line();
+ write_freqenv_decs();
+ write_empty_line();
write_sync_decs();
write_empty_line();
write_filter_decs();
diff --git a/note_compiler/parser.cpp b/note_compiler/parser.cpp
index 7fb3fa0..e9af004 100644
--- a/note_compiler/parser.cpp
+++ b/note_compiler/parser.cpp
@@ -41,6 +41,20 @@ void init_oscs(int n_osc, oscillator_t *osc)
osc[i].sync_const=true;
osc[i].ksr_const=true;
osc[i].ksl_const=true;
+
+ osc[i].freq_env_amount=0;
+ osc[i].freq_env_amount_const=true;
+ osc[i].freq_env.attack=0;
+ osc[i].freq_env.attack_const=true;
+ osc[i].freq_env.decay=0;
+ osc[i].freq_env.decay_const=true;
+ osc[i].freq_env.sustain=ONE;
+ osc[i].freq_env.sustain_const=true;
+ osc[i].freq_env.release=-1;
+ osc[i].freq_env.release_const=true;
+ osc[i].freq_env.hold=true;
+ osc[i].freq_env.hold_const=true;
+
}
}
@@ -326,6 +340,26 @@ program_t parse(string fn)
case SYNC_FACTOR:
sync_factor=val*ONE;
break;
+
+ case FREQ_ATTACK:
+ osc[ind].freq_env.attack=val;
+ break;
+ case FREQ_DECAY:
+ osc[ind].freq_env.decay=val;
+ break;
+ case FREQ_SUSTAIN:
+ osc[ind].freq_env.sustain=val;
+ break;
+ case FREQ_RELEASE:
+ osc[ind].freq_env.release=val;
+ break;
+ case FREQ_HOLD:
+ osc[ind].freq_env.hold=(val!=0);
+ break;
+ case FREQ_ENV_AMOUNT:
+ osc[ind].freq_env_amount=val;
+ break;
+
default:
throw string("unknown variable ('"+array+"')");
}
@@ -350,6 +384,7 @@ program_t parse(string fn)
case FILTER_ENV_AMOUNT:
case FILTER_RESONANCE:
case FILTER_OFFSET:
+ case FREQ_ENV_AMOUNT:
// everything ok, do nothing
break;
@@ -424,6 +459,19 @@ program_t parse(string fn)
filter.trem_lfo_const=false; break;
case SYNC_FACTOR:
sync_factor_const=false; break;
+ case FREQ_ATTACK:
+ osc[ind].freq_env.attack_const=false; break;
+ case FREQ_DECAY:
+ osc[ind].freq_env.decay_const=false; break;
+ case FREQ_SUSTAIN:
+ osc[ind].freq_env.sustain_const=false; break;
+ case FREQ_RELEASE:
+ osc[ind].freq_env.release_const=false; break;
+ case FREQ_HOLD:
+ osc[ind].freq_env.hold_const=false; break;
+ case FREQ_ENV_AMOUNT:
+ osc[ind].freq_env_amount_const=false; break;
+
default:
throw string("unknown variable ('"+array+"')");
}
@@ -444,11 +492,11 @@ program_t parse(string fn)
for (int i=0;i<n_osc;i++)
if ((env[i].attack==0) && (env[i].sustain==1.0)
- && (env[i].release>100)) //TODO FINDMICH besseres kriterium?
+ && (env[i].release<0))
env[i].enabled=false;
if ( ((filter.env_settings.attack==0) && (filter.env_settings.sustain==1.0)
- && (filter.env_settings.release>100)) //TODO FINDMICH siehe oben
+ && (filter.env_settings.release<0))
|| ((filter.env_amount==0) && (filter.env_amount_const==true)) )
filter.env_settings.enabled=false;
diff --git a/note_compiler/programs.h b/note_compiler/programs.h
index d7acd61..b311696 100644
--- a/note_compiler/programs.h
+++ b/note_compiler/programs.h
@@ -35,11 +35,31 @@ enum parameter_enum
FILTER_TREM_LFO,
SYNC_FACTOR,
+ FREQ_ATTACK,
+ FREQ_DECAY,
+ FREQ_SUSTAIN,
+ FREQ_RELEASE,
+ FREQ_HOLD,
+ FREQ_ENV_AMOUNT,
PARAMETER_N_ENTRIES,
UNKNOWN=-1
};
+struct env_settings_t
+{
+ bool enabled;
+ float attack;
+ bool attack_const;
+ float decay;
+ bool decay_const;
+ float sustain;
+ bool sustain_const;
+ float release;
+ bool release_const;
+ bool hold;
+ bool hold_const;
+};
struct oscillator_t
{
@@ -51,6 +71,11 @@ struct oscillator_t
bool waveform_const;
fixed_t factor;
bool factor_const;
+
+ float freq_env_amount;
+ bool freq_env_amount_const;
+ env_settings_t freq_env;
+
fixed_t tremolo_depth;
bool tremolo_depth_const;
@@ -74,21 +99,6 @@ struct oscillator_t
bool sync_const;
};
-struct env_settings_t
-{
- bool enabled;
- float attack;
- bool attack_const;
- float decay;
- bool decay_const;
- float sustain;
- bool sustain_const;
- float release;
- bool release_const;
- bool hold;
- bool hold_const;
-};
-
struct filter_params_t
{
bool enabled;
diff --git a/note_compiler/templates/head.1 b/note_compiler/templates/head.1
index b50d694..73beec6 100644
--- a/note_compiler/templates/head.1
+++ b/note_compiler/templates/head.1
@@ -13,6 +13,7 @@
using namespace std;
int filter_update_frames=0;
+int envelope_update_frames=0;
int samp_rate=0;
fixed_t** wave=NULL;
fixed_t** curr_lfo=NULL;
diff --git a/note_compiler/templates/interface.1 b/note_compiler/templates/interface.1
index 2ccee41..7a7c58e 100644
--- a/note_compiler/templates/interface.1
+++ b/note_compiler/templates/interface.1
@@ -7,10 +7,11 @@ extern "C" NoteSkel* create_note(int n, float v,program_t &prg, jack_nframes_t p
return new Note(n,v,prg,pf,pb,prg_no,vol_fac);
}
-extern "C" void init_vars(int sr, int fupfr, fixed_t **w, fixed_t **clfo, output_note_func_t* out_n, IntToStr_func_t* its)
+extern "C" void init_vars(int sr, int fupfr, int envupfr, fixed_t **w, fixed_t **clfo, output_note_func_t* out_n, IntToStr_func_t* its)
{
samp_rate=sr;
filter_update_frames=fupfr;
+ envelope_update_frames=envupfr;
wave=w;
curr_lfo=clfo;
IntToStr=its;
diff --git a/note_compiler/templates/set_param.1 b/note_compiler/templates/set_param.1
index 21fc983..e99f481 100644
--- a/note_compiler/templates/set_param.1
+++ b/note_compiler/templates/set_param.1
@@ -5,6 +5,13 @@
return;
}
+ if ( ((p.par==FREQ_ATTACK) || (p.par==FREQ_DECAY) || (p.par==FREQ_SUSTAIN) ||
+ (p.par==FREQ_RELEASE) || (p.par==FREQ_HOLD)) && sel_factor_env==NULL )
+ {
+ output_note("NOTE: cannot change parameter for freq-envelope"+IntToStr(p.osc)+" because it's disabled");
+ return;
+ }
+
switch(p.par)
{
case ATTACK: sel_env->set_attack(v*samp_rate >>SCALE); break;
@@ -13,10 +20,17 @@
case RELEASE: sel_env->set_release(v*samp_rate >>SCALE); break;
case HOLD: sel_env->set_hold(v!=0); break;
+ case FREQ_ATTACK: sel_factor_env->set_attack(v*samp_rate >>SCALE); break;
+ case FREQ_DECAY: sel_factor_env->set_decay(v*samp_rate >>SCALE); break;
+ case FREQ_SUSTAIN: sel_factor_env->set_sustain(v); break;
+ case FREQ_RELEASE: sel_factor_env->set_release(v*samp_rate >>SCALE); break;
+ case FREQ_HOLD: sel_factor_env->set_hold((v!=0)); break;
+ case FREQ_ENV_AMOUNT: sel_orig_osc->freq_env_amount=double(v)/ONE; apply_pfactor(); 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 FACTOR: sel_orig_osc->factor=v; sel_osc->factor=v*freqfactor_factor[p.osc]; 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;
diff --git a/note_compiler/util.cpp b/note_compiler/util.cpp
index f73b8bb..b3ea1af 100644
--- a/note_compiler/util.cpp
+++ b/note_compiler/util.cpp
@@ -173,6 +173,18 @@ parameter_enum param_to_enum(string param)
return FILTER_TREM_LFO;
else if (param=="sync_factor")
return SYNC_FACTOR;
+ else if (param=="freq.env_amount")
+ return FREQ_ENV_AMOUNT;
+ else if (param=="freq.attack")
+ return FREQ_ATTACK;
+ else if (param=="freq.decay")
+ return FREQ_DECAY;
+ else if (param=="freq.sustain")
+ return FREQ_SUSTAIN;
+ else if (param=="freq.release")
+ return FREQ_RELEASE;
+ else if (param=="freq.hold")
+ return FREQ_HOLD;
else
return UNKNOWN;
}