summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Jung <flo@thinkpad.(none)>2011-01-06 23:31:51 +0100
committerFlorian Jung <flo@thinkpad.(none)>2011-01-06 23:31:51 +0100
commit892c323f7851c76bf678369987c5c7a361626ea2 (patch)
tree4393d75c4e9755defa41519488f335dcff9b2c59
parente78131ccbbcb81da94e5992f788c6ea291a2050d (diff)
Added a rudimentary CLI to the note compiler + bugfix
-rw-r--r--note_compiler/main.cpp12
-rw-r--r--note_compiler/plugin_factory/infile.cpp118
-rw-r--r--note_compiler/templates/head.11
-rw-r--r--synth/jack.cpp44
4 files changed, 95 insertions, 80 deletions
diff --git a/note_compiler/main.cpp b/note_compiler/main.cpp
index 3015551..38302ef 100644
--- a/note_compiler/main.cpp
+++ b/note_compiler/main.cpp
@@ -802,9 +802,17 @@ void generate_source()
int main(int argc, char** argv)
{
- prog=parse("../../filtertest.prog");
+ try
+ {
+ cerr << "parsing '"<<argv[1]<<"'..." << endl;
+ prog=parse(argv[1]);
- generate_source();
+ generate_source();
+ }
+ catch(string err)
+ {
+ cerr << "FATAL: "<<err<<endl;
+ }
return 0;
}
diff --git a/note_compiler/plugin_factory/infile.cpp b/note_compiler/plugin_factory/infile.cpp
index aca9ff1..f8e34a0 100644
--- a/note_compiler/plugin_factory/infile.cpp
+++ b/note_compiler/plugin_factory/infile.cpp
@@ -2,7 +2,6 @@
#include <cmath>
#include <string>
-#include <iostream>
#include "defines.h"
#include "programs.h"
@@ -59,12 +58,15 @@ class Note : public NoteSkel
//sync is disabled
- LowPassFilter filter;
- filter_params_t filter_params;
- int filter_update_counter;
- Envelope *filter_envelope;
+ //filter is disabled
- //pfactors/velocity influence are disabled
+ pfactor_value_t pfactor;
+ struct
+ {
+ oscillator_t osc0;
+ oscillator_t osc1;
+ //filter is disabled
+ } orig;
// member variables end here
};
@@ -95,20 +97,17 @@ Note::Note(int n, float v, program_t &prg, jack_nframes_t pf, fixed_t pb, int pr
env1=new Envelope (prg.env_settings[1]);
osc0=prg.osc_settings[0];
+ orig.osc0=prg.osc_settings[0];
osc1=prg.osc_settings[1];
+ orig.osc1=prg.osc_settings[1];
//initalize oscillator.phase to multiples of their wave resolution
osc0.phase=ONE * PHASE_INIT;
- osc1.phase=init_custom_osc_phase(osc1.custom_wave->wave_len, osc1.custom_wave->samp_rate);
+ osc1.phase=ONE * PHASE_INIT;
do_ksl();
- filter_params=prg.filter_settings;
- filter_envelope=new Envelope(filter_params.env_settings);
- filter_update_counter=filter_update_frames;
-
-
portamento_frames=0;
set_portamento_frames(pf);
@@ -125,13 +124,18 @@ Note::~Note()
{
delete [] osc0.fm_strength;
delete env0;
+ delete pfactor.fm[0];
delete [] osc1.fm_strength;
delete env1;
+ delete pfactor.fm[1];
delete [] oscval;
delete [] old_oscval;
+
+ delete [] pfactor.out;
+ delete [] pfactor.fm;
}
void Note::destroy()
{
@@ -140,9 +144,22 @@ void Note::destroy()
void Note::recalc_factors()
{
+ for (int i=0;i<2;i++)
+ {
+ pfactor.out[i]=calc_pfactor(curr_prg->pfactor.out[i], vel);
+
+ for (int j=0;j<2;j++)
+ pfactor.fm[i][j]=calc_pfactor(curr_prg->pfactor.fm[i][j], vel);
+ }
}
void Note::apply_pfactor()
{
+ osc0.output=orig.osc0.output*pfactor.out[0] >>SCALE;
+ for (int i=0;i<2;i++)
+ osc0.fm_strength[i]=orig.osc0.fm_strength[i]*pfactor.fm[0][i] >>SCALE;
+ osc1.output=orig.osc1.output*pfactor.out[1] >>SCALE;
+ for (int i=0;i<2;i++)
+ osc1.fm_strength[i]=orig.osc1.fm_strength[i]*pfactor.fm[1][i] >>SCALE;
}
bool Note::still_active()
@@ -157,8 +174,6 @@ void Note::release()
{
env0->release_key();
env1->release_key();
-
- filter_envelope->release_key();
}
void Note::release_quickly(jack_nframes_t maxt)
{
@@ -175,8 +190,6 @@ void Note::reattack()
{
env0->reattack();
env1->reattack();
-
- filter_envelope->reattack();
}
void Note::do_ksr()
@@ -219,29 +232,18 @@ fixed_t Note::get_sample()
//sync is disabled
- osc0.phase+= (actual_freq*osc0.factor/samp_rate)>>SCALE;
- oscval[0] = wave[0][ ( ( osc0.phase + ( + (old_oscval[1] * osc0.fm_strength[1]) >>SCALE ) ) * WAVE_RES >>SCALE ) % WAVE_RES ] * env0->get_level() >>SCALE;
- //oscillator0 has no tremolo
+ osc0.phase+= ( (osc0.vibrato_depth==0) ? ((actual_freq*osc0.factor/samp_rate)>>SCALE) : (( (curr_lfo[osc0.vibrato_lfo][osc0.vibrato_depth]*actual_freq >>SCALE)*osc0.factor/samp_rate)>>SCALE) );
+ oscval[0] = wave[1][ ( ( osc0.phase + ( + (old_oscval[0] * 104857) + (old_oscval[1] * osc0.fm_strength[1]) >>SCALE ) ) * WAVE_RES >>SCALE ) % WAVE_RES ] * env0->get_level() >>SCALE;
+ if (osc0.tremolo_depth)
+ oscval[0] = oscval[0] * curr_lfo[0][osc0.tremolo_depth] >>SCALE;
- osc1.phase+= (actual_freq*osc1.factor/samp_rate)>>SCALE;
- oscval[1] = osc1.custom_wave->wave[ ( osc1.phase * osc1.custom_wave->samp_rate >>(2*SCALE) ) % osc1.custom_wave->wave_len ] * env1->get_level() >>SCALE;
+ osc1.phase+= ( (curr_lfo[osc1.vibrato_lfo][osc1.vibrato_depth]*actual_freq >>SCALE)*osc1.factor/samp_rate)>>SCALE;
+ oscval[1] = wave[0][ ( osc1.phase * WAVE_RES >>SCALE ) % WAVE_RES ] * env1->get_level() >>SCALE;
//oscillator1 has no tremolo
fixed_t out = ( + osc0.output*oscval[0] >>SCALE );
- filter_update_counter++;
- if (filter_update_counter>=filter_update_frames)
- {
- filter_update_counter=0;
-
- float cutoff= float(actual_freq)/ONE *
- float(curr_lfo[filter_params.trem_lfo][filter_params.trem_strength])/ONE *
- ( filter_params.freqfactor_offset + filter_envelope->get_level() * filter_params.env_amount / float(ONE) );
- filter.set_params( cutoff, filter_params.resonance );
- }
-
- filter.process_sample(&out);
return out;
}
@@ -285,51 +287,22 @@ void Note::set_param(const parameter_t &p, fixed_t v)
case WAVEFORM: sel_osc->waveform=v; break;
case SYNC: sel_osc->sync=(v!=0); break;
- case MODULATION: sel_osc->fm_strength[p.index]=v; break;
- case OUTPUT: sel_osc->output=v; break;
-
- case FILTER_ENABLED: output_note("NOTE: cannot enable filter in playing notes"); break;
-
+ case MODULATION: sel_osc->fm_strength[p.index]=v*pfactor.fm[p.osc][p.index] >>SCALE; break;
+ case OUTPUT: sel_osc->output=v*pfactor.out[p.osc] >>SCALE; break;
+ case FILTER_ENABLED:
+ case FILTER_ENV_AMOUNT:
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");
+ 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;
- case FILTER_ENV_AMOUNT: filter_params.env_amount=float(v)/ONE; break;
- case FILTER_OFFSET: filter_params.freqfactor_offset=float(v)/ONE; break;
- case FILTER_RESONANCE: filter_params.resonance=float(v)/ONE; break;
- case FILTER_TREMOLO: filter_params.trem_strength=v; break;
- case FILTER_TREM_LFO: filter_params.trem_lfo=v; break;
case SYNC_FACTOR: output_note("NOTE: trying to set sync_factor, but it's disabled"); break;
@@ -341,7 +314,6 @@ void Note::set_param(const parameter_t &p, fixed_t v)
extern "C" NoteSkel* create_note(int n, float v,program_t &prg, jack_nframes_t pf, fixed_t pb, int prg_no)
{
- cout << "test" << endl;
if (wave==NULL)
throw string("FATAL: trying to create a new note from a shared object without initalizing\n"
" the object first! this should /never/ happen, please contact the developer");
@@ -351,7 +323,6 @@ extern "C" NoteSkel* create_note(int n, float v,program_t &prg, jack_nframes_t p
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)
{
- cout << "inited." << endl;
samp_rate=sr;
filter_update_frames=fupfr;
wave=w;
@@ -360,3 +331,4 @@ extern "C" void init_vars(int sr, int fupfr, fixed_t **w, fixed_t **clfo, output
output_note=out_n;
}
+
diff --git a/note_compiler/templates/head.1 b/note_compiler/templates/head.1
index af3c227..6759f56 100644
--- a/note_compiler/templates/head.1
+++ b/note_compiler/templates/head.1
@@ -9,7 +9,6 @@
#include "fixed.h"
#include "filter.h"
#include "note_skel.h"
-#include "util.h"
using namespace std;
diff --git a/synth/jack.cpp b/synth/jack.cpp
index 8d599de..3949722 100644
--- a/synth/jack.cpp
+++ b/synth/jack.cpp
@@ -317,7 +317,7 @@ int process_callback(jack_nframes_t nframes, void *notused)
}
else if (tmp2==0)
{
- if (lastframe>tmp+44100*2)
+ if (lastframe>tmp+44100*1)
{
tmp2=1;
cout << "BÄÄM" << endl;
@@ -326,17 +326,53 @@ int process_callback(jack_nframes_t nframes, void *notused)
}
else if (tmp2==1)
{
- if (lastframe>tmp+44100*4)
+ if (lastframe>tmp+44100*2)
{
tmp2=2;
- //channel[0]->event(0x90,87,5);
+ channel[0]->event(0x90,87,5);
channel[0]->set_controller(58, 0);
cout << "BÄÄM2" << endl;
}
}
+ else if (tmp2==2)
+ {
+ if (lastframe>tmp+44100*3)
+ {
+ tmp2=3;
+ channel[0]->event(0x90,90,127);
+ cout << "BÄÄM2" << endl;
+ }
+ }
+ else if (tmp2==3)
+ {
+ if (lastframe>tmp+44100*4)
+ {
+ tmp2=4;
+ channel[0]->event(0x90,60,96);
+ cout << "BÄÄM2" << endl;
+ }
+ }
+ else if (tmp2==4)
+ {
+ if (lastframe>tmp+44100*5)
+ {
+ tmp2=5;
+ channel[0]->event(0x90,63,32);
+ cout << "BÄÄM2" << endl;
+ }
+ }
+ else if (tmp2==5)
+ {
+ if (lastframe>tmp+44100*6)
+ {
+ tmp2=6;
+ channel[0]->event(0x90,66,60);
+ cout << "BÄÄM2" << endl;
+ }
+ }
else
{
- if (lastframe>tmp+44100*10)
+ if (lastframe>tmp+44100*8)
{
cout << "finished" << endl;
exit(0);