zynaddsubfx

ZynAddSubFX open source synthesizer
Log | Files | Refs | Submodules | LICENSE

commit 6dac8b077731e44360e8966cd312587d4d67f480
parent bdaf3b03a971e108a213e846b4507d977fa592b2
Author: falkTX <[email protected]>
Date:   Mon,  4 Jan 2016 20:27:22 +0000

Merge branch 'master' of ssh://git.code.sf.net/p/zynaddsubfx/code into dpf-plugin

Diffstat:
Msrc/Output/DSSIaudiooutput.cpp | 4++--
Msrc/Params/FilterParams.cpp | 14+++++++-------
Msrc/Params/FilterParams.h | 12++++++------
Msrc/Params/PADnoteParameters.cpp | 10+++++-----
Msrc/Synth/Envelope.cpp | 5+++--
Msrc/Synth/OscilGen.cpp | 5+++++
Msrc/Tests/AdNoteTest.h | 8++++----
Msrc/Tests/PadNoteTest.h | 6+++---
Msrc/Tests/SubNoteTest.h | 2+-
Msrc/Tests/guitar-adnote.xmz | 6++++++
Msrc/UI/EnvelopeFreeEdit.cpp | 94++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------
Msrc/UI/EnvelopeFreeEdit.h | 4+++-
Msrc/UI/EnvelopeUI.fl | 11++++++-----
Msrc/UI/PADnoteUI.fl | 6+++---
14 files changed, 118 insertions(+), 69 deletions(-)

diff --git a/src/Output/DSSIaudiooutput.cpp b/src/Output/DSSIaudiooutput.cpp @@ -612,7 +612,7 @@ DSSIaudiooutput *DSSIaudiooutput::getInstance(LADSPA_Handle instance) * @param sampleRate [in] the sample rate to be used by the synth. * @return */ -DSSIaudiooutput::DSSIaudiooutput(unsigned long sampleRate) : dssi_control({dssi_control_description[0], +DSSIaudiooutput::DSSIaudiooutput(unsigned long sampleRate) : dssi_control{dssi_control_description[0], dssi_control_description[1], dssi_control_description[2], dssi_control_description[3], @@ -623,7 +623,7 @@ DSSIaudiooutput::DSSIaudiooutput(unsigned long sampleRate) : dssi_control({dssi_ dssi_control_description[8], dssi_control_description[9], dssi_control_description[10], - dssi_control_description[11]}) + dssi_control_description[11]} { SYNTH_T synth; synth.samplerate = sampleRate; diff --git a/src/Params/FilterParams.cpp b/src/Params/FilterParams.cpp @@ -38,14 +38,14 @@ constexpr int sizeof_pvowels = sizeof(FilterParams::Pvowels); #define rObject FilterParams::Pvowels_t::formants_t -#undef rChangeCb -#define rChangeCb if (obj->time) { obj->last_update_timestamp = obj->time->time(); } +//#undef rChangeCb +//#define rChangeCb if (obj->time) { obj->last_update_timestamp = obj->time->time(); } static const rtosc::Ports subsubports = { rParamZyn(freq, "Formant frequency"), rParamZyn(amp, "Strength of formant"), rParamZyn(q, "Quality Factor"), }; -#undef rChangeCb +//#undef rChangeCb #undef rObject static const rtosc::Ports subports = { @@ -59,13 +59,13 @@ static const rtosc::Ports subports = { FilterParams::Pvowels_t *obj = (FilterParams::Pvowels_t *) d.obj; d.obj = (void*) &obj->formants[idx]; subsubports.dispatch(msg, d); - if (obj->time) { obj->last_update_timestamp = obj->time->time(); } +// if (obj->time) { obj->last_pdate_timestamp = obj->time->time(); } }}, }; #define rObject FilterParams #undef rChangeCb -#define rChangeCb obj->changed = true; if ( obj->time) { \ +#define rChangeCb obj->changed = true; if ( obj->time) { \ obj->last_update_timestamp = obj->time->time(); } const rtosc::Ports FilterParams::ports = { rSelf(FilterParams), @@ -189,13 +189,13 @@ void FilterParams::defaults(int n) { int j = n; - Pvowels[j].time = time; +// Pvowels[j].time = time; for(int i = 0; i < FF_MAX_FORMANTS; ++i) { Pvowels[j].formants[i].freq = (int)(RND * 127.0f); //some random freqs Pvowels[j].formants[i].q = 64; Pvowels[j].formants[i].amp = 127; - Pvowels[j].formants[i].time = time; +// Pvowels[j].formants[i].time = time; } } diff --git a/src/Params/FilterParams.h b/src/Params/FilterParams.h @@ -68,17 +68,17 @@ class FilterParams:public PresetsArray unsigned char Pcenterfreq, Poctavesfreq; //the center frequency of the res. func., and the number of octaves struct Pvowels_t { - Pvowels_t() : last_update_timestamp(0) {} +// Pvowels_t() : last_update_timestamp(0) {} struct formants_t { - formants_t() : last_update_timestamp(0) {} +// formants_t() : last_update_timestamp(0) {} unsigned char freq, amp, q; //frequency,amplitude,Q - const AbsTime *time; - int64_t last_update_timestamp; +// const AbsTime *time; +// int64_t last_update_timestamp; } formants[FF_MAX_FORMANTS]; - const AbsTime *time; - int64_t last_update_timestamp; +// const AbsTime *time; +// int64_t last_update_timestamp; } Pvowels[FF_MAX_VOWELS]; diff --git a/src/Params/PADnoteParameters.cpp b/src/Params/PADnoteParameters.cpp @@ -180,9 +180,9 @@ static const rtosc::Ports non_realtime_ports = rOptions(Harmonic, ShiftU, ShiftL, PowerU, PowerL, Sine, Power, Shift), "Harmonic Overtone shifting mode"), - rParamZyn(Phrpos.par1, "Harmonic position parameter"), - rParamZyn(Phrpos.par2, "Harmonic position parameter"), - rParamZyn(Phrpos.par3, "Harmonic position parameter"), + rParamI(Phrpos.par1, rLinear(0,255), "Harmonic position parameter"), + rParamI(Phrpos.par2, rLinear(0,255), "Harmonic position parameter"), + rParamI(Phrpos.par3, rLinear(0,255), "Harmonic position parameter"), //Quality rOption(Pquality.samplesize, @@ -321,8 +321,8 @@ void PADnoteParameters::defaults() oscilgen->defaults(); Phrpos.type = 0; - Phrpos.par1 = 64; - Phrpos.par2 = 64; + Phrpos.par1 = 0; + Phrpos.par2 = 0; Phrpos.par3 = 0; Pquality.samplesize = 3; diff --git a/src/Synth/Envelope.cpp b/src/Synth/Envelope.cpp @@ -45,10 +45,11 @@ Envelope::Envelope(EnvelopeParams &pars, float basefreq, float bufferdt) if((mode == 2) && linearenvelope) mode = 1; //change to linear - for(int i = 0; i < MAX_ENVELOPE_POINTS; ++i) { + for(int i = 0; i < envpoints; ++i) { const float tmp = pars.getdt(i) / 1000.0f * envstretch; if(tmp > bufferdt) - envdt[i] = bufferdt / tmp; + envdt[i] = + i == envpoints ? bufferdt / tmp : 1 / ceil(tmp / bufferdt); else envdt[i] = 2.0f; //any value larger than 1 diff --git a/src/Synth/OscilGen.cpp b/src/Synth/OscilGen.cpp @@ -1265,6 +1265,7 @@ void OscilGen::add2XML(XMLwrapper& xml) xml.addpar("adaptive_harmonics", Padaptiveharmonics); xml.addpar("adaptive_harmonics_base_frequency", Padaptiveharmonicsbasefreq); xml.addpar("adaptive_harmonics_power", Padaptiveharmonicspower); + xml.addpar("adaptive_harmonics_par", Padaptiveharmonicspar); xml.beginbranch("HARMONICS"); for(int n = 0; n < MAX_AD_HARMONICS; ++n) { @@ -1356,6 +1357,10 @@ void OscilGen::getfromXML(XMLwrapper& xml) Padaptiveharmonicspower, 0, 200); + Padaptiveharmonicspar = xml.getpar("adaptive_harmonics_par", + Padaptiveharmonicspar, + 0, + 100); if(xml.enterbranch("HARMONICS")) { diff --git a/src/Tests/AdNoteTest.h b/src/Tests/AdNoteTest.h @@ -138,19 +138,19 @@ class AdNoteTest:public CxxTest::TestSuite note->noteout(outL, outR); sampleCount += synth->buffersize; - TS_ASSERT_DELTA(outL[255], -0.102197f, 0.0001f); + TS_ASSERT_DELTA(outL[255], -0.099167f, 0.0001f); note->noteout(outL, outR); sampleCount += synth->buffersize; - TS_ASSERT_DELTA(outL[255], -0.111261f, 0.0001f); + TS_ASSERT_DELTA(outL[255], -0.108730f, 0.0001f); note->noteout(outL, outR); sampleCount += synth->buffersize; - TS_ASSERT_DELTA(outL[255], -0.021375f, 0.0001f); + TS_ASSERT_DELTA(outL[255], -0.030751f, 0.0001f); note->noteout(outL, outR); sampleCount += synth->buffersize; - TS_ASSERT_DELTA(outL[255], 0.149149f, 0.0001f); + TS_ASSERT_DELTA(outL[255], 0.146882f, 0.0001f); while(!note->finished()) { note->noteout(outL, outR); diff --git a/src/Tests/PadNoteTest.h b/src/Tests/PadNoteTest.h @@ -166,15 +166,15 @@ class PadNoteTest:public CxxTest::TestSuite note->noteout(outL, outR); sampleCount += synth->buffersize; - TS_ASSERT_DELTA(outL[255], 0.060818f, 0.0005f); + TS_ASSERT_DELTA(outL[255], 0.062217f, 0.0005f); note->noteout(outL, outR); sampleCount += synth->buffersize; - TS_ASSERT_DELTA(outL[255], 0.036895f, 0.0005f); + TS_ASSERT_DELTA(outL[255], 0.038359f, 0.0005f); note->noteout(outL, outR); sampleCount += synth->buffersize; - TS_ASSERT_DELTA(outL[255], -0.006623f, 0.0001f); + TS_ASSERT_DELTA(outL[255], -0.006975f, 0.0001f); while(!note->finished()) { note->noteout(outL, outR); diff --git a/src/Tests/SubNoteTest.h b/src/Tests/SubNoteTest.h @@ -132,7 +132,7 @@ class SubNoteTest:public CxxTest::TestSuite note->noteout(outL, outR); sampleCount += synth->buffersize; - TS_ASSERT_DELTA(outL[255], -0.0013f, 0.0001f); + TS_ASSERT_DELTA(outL[255], -0.0014f, 0.0001f); note->noteout(outL, outR); sampleCount += synth->buffersize; diff --git a/src/Tests/guitar-adnote.xmz b/src/Tests/guitar-adnote.xmz @@ -220,6 +220,7 @@ version-revision="2" ZynAddSubFX-author="Nasca Octavian Paul"> <par name="adaptive_harmonics" value="0" /> <par name="adaptive_harmonics_base_frequency" value="128" /> <par name="adaptive_harmonics_power" value="100" /> +<par name="adaptive_harmonics_par" value="50" /> <HARMONICS> <HARMONIC id="1"> <par name="mag" value="74" /> @@ -413,6 +414,7 @@ version-revision="2" ZynAddSubFX-author="Nasca Octavian Paul"> <par name="adaptive_harmonics" value="0" /> <par name="adaptive_harmonics_base_frequency" value="128" /> <par name="adaptive_harmonics_power" value="100" /> +<par name="adaptive_harmonics_par" value="50" /> <HARMONICS> <HARMONIC id="1"> <par name="mag" value="127" /> @@ -470,6 +472,7 @@ version-revision="2" ZynAddSubFX-author="Nasca Octavian Paul"> <par name="adaptive_harmonics" value="0" /> <par name="adaptive_harmonics_base_frequency" value="128" /> <par name="adaptive_harmonics_power" value="100" /> +<par name="adaptive_harmonics_par" value="50" /> <HARMONICS> <HARMONIC id="1"> <par name="mag" value="127" /> @@ -555,6 +558,7 @@ version-revision="2" ZynAddSubFX-author="Nasca Octavian Paul"> <par name="adaptive_harmonics" value="0" /> <par name="adaptive_harmonics_base_frequency" value="128" /> <par name="adaptive_harmonics_power" value="100" /> +<par name="adaptive_harmonics_par" value="50" /> <HARMONICS> <HARMONIC id="1"> <par name="mag" value="127" /> @@ -640,6 +644,7 @@ version-revision="2" ZynAddSubFX-author="Nasca Octavian Paul"> <par name="adaptive_harmonics" value="0" /> <par name="adaptive_harmonics_base_frequency" value="128" /> <par name="adaptive_harmonics_power" value="100" /> +<par name="adaptive_harmonics_par" value="50" /> <HARMONICS> <HARMONIC id="2"> <par name="mag" value="127" /> @@ -1260,6 +1265,7 @@ version-revision="2" ZynAddSubFX-author="Nasca Octavian Paul"> <par name="adaptive_harmonics" value="0" /> <par name="adaptive_harmonics_base_frequency" value="128" /> <par name="adaptive_harmonics_power" value="100" /> +<par name="adaptive_harmonics_par" value="50" /> <HARMONICS> <HARMONIC id="1"> <par name="mag" value="127" /> diff --git a/src/UI/EnvelopeFreeEdit.cpp b/src/UI/EnvelopeFreeEdit.cpp @@ -87,17 +87,21 @@ int EnvelopeFreeEdit::getpointy(int n) const return (1.0-Penvval[n]/127.0)*ly; } +static inline int distance_fn(int dx, int dy) { + return dx*dx+dy*dy; +} + int EnvelopeFreeEdit::getnearest(int x,int y) const { x-=5;y-=5; int nearestpoint=0; - int nearestval=1000000;//a big value - for(int i=0; i<Penvpoints; ++i){ - int distance=abs(x-getpointx(i))+abs(y-getpointy(i)); - if (distance<nearestval) { + int nearest_distance_sq=distance_fn(x-getpointx(0), y-getpointy(0)); + for(int i=1; i<Penvpoints; ++i){ + int distance_sq=distance_fn(x-getpointx(i), y-getpointy(i)); + if (distance_sq<nearest_distance_sq) { nearestpoint=i; - nearestval=distance; + nearest_distance_sq=distance_sq; } } @@ -114,7 +118,7 @@ float EnvelopeFreeEdit::getdt(int i) const return dt(Penvdt[i]); } -static bool ctrldown; +static bool ctrldown, altdown; void EnvelopeFreeEdit::draw(void) { @@ -135,8 +139,9 @@ void EnvelopeFreeEdit::draw(void) //draw the lines fl_color(FL_GRAY); + const int midline = oy+ly*(1-64.0/127); fl_line_style(FL_SOLID); - fl_line(ox+2,oy+ly/2,ox+lx-2,oy+ly/2); + fl_line(ox+2,midline,ox+lx-2,midline); //draws the evelope points and lines Fl_Color alb=FL_WHITE; @@ -180,14 +185,18 @@ void EnvelopeFreeEdit::draw(void) time=getdt(lastpoint); } char tmpstr[20]; - if (time<1000.0) - snprintf((char *)&tmpstr,20,"%.1fms",time); - else - snprintf((char *)&tmpstr,20,"%.2fs",time/1000.0); - fl_draw(tmpstr,ox+lx-20,oy+ly-10,20,10,FL_ALIGN_RIGHT,NULL,0); - if (lastpoint>=0){ - snprintf((char *)&tmpstr,20,"%d", Penvval[lastpoint]); - fl_draw(tmpstr,ox+lx-20,oy+ly-23,20,10,FL_ALIGN_RIGHT,NULL,0); + if (!altdown || ctrldown) { + if (time<1000.0) + snprintf((char *)&tmpstr,20,"%.1fms",time); + else + snprintf((char *)&tmpstr,20,"%.2fs",time/1000.0); + fl_draw(tmpstr,ox+lx-20,oy+ly-10,20,10,FL_ALIGN_RIGHT,NULL,0); + } + if (!altdown || !ctrldown) { + if (lastpoint>=0){ + snprintf((char *)&tmpstr,20,"%d", Penvval[lastpoint]); + fl_draw(tmpstr,ox+lx-20,oy+ly-23,20,10,FL_ALIGN_RIGHT,NULL,0); + } } } @@ -196,7 +205,7 @@ int EnvelopeFreeEdit::handle(int event) const int x_=Fl::event_x()-x(); const int y_=Fl::event_y()-y(); static Fl_Widget *old_focus; - int key; + int key, old_mod_state; switch(event) { case FL_ENTER: @@ -211,6 +220,11 @@ int EnvelopeFreeEdit::handle(int event) case FL_KEYDOWN: case FL_KEYUP: key = Fl::event_key(); + if (key==FL_Alt_L || key==FL_Alt_R) { + altdown = (event==FL_KEYDOWN); + redraw(); + if (pair!=NULL) pair->redraw(); + } if (key==FL_Control_L || key==FL_Control_R){ ctrldown = (event==FL_KEYDOWN); redraw(); @@ -220,7 +234,9 @@ int EnvelopeFreeEdit::handle(int event) case FL_PUSH: currentpoint=getnearest(x_,y_); cpx=x_; + cpy=y_; cpdt=Penvdt[currentpoint]; + cpval=Penvval[currentpoint]; lastpoint=currentpoint; redraw(); if (pair) @@ -233,15 +249,18 @@ int EnvelopeFreeEdit::handle(int event) pair->redraw(); return 1; case FL_MOUSEWHEEL: + if (Fl::event_buttons()) + return 1; if (lastpoint>=0) { + int delta = Fl::event_dy() * (Fl::event_shift() ? 4 : 1); if (!ctrldown) { - int ny = Penvval[lastpoint] - Fl::event_dy(); + int ny = Penvval[lastpoint] - delta; ny = ny < 0 ? 0 : ny > 127 ? 127 : ny; Penvval[lastpoint] = ny; oscWrite(to_s("Penvval")+to_s(lastpoint), "c", ny); oscWrite("Penvval",""); } else if (lastpoint > 0) { - int newdt = Fl::event_dy() + Penvdt[lastpoint]; + int newdt = Penvdt[lastpoint] - delta; newdt = newdt < 0 ? 0 : newdt > 127 ? 127 : newdt; Penvdt[lastpoint] = newdt; oscWrite(to_s("Penvdt")+to_s(lastpoint), "c", newdt); @@ -253,22 +272,37 @@ int EnvelopeFreeEdit::handle(int event) } case FL_DRAG: if (currentpoint>=0){ - int ny=limit(127-(int) (y_*127.0/h()), 0, 127); + old_mod_state = mod_state; + mod_state = ctrldown << 1 | altdown; + if (old_mod_state != mod_state) { + cpx=x_; + cpy=y_; + cpdt=Penvdt[currentpoint]; + cpval=Penvval[currentpoint]; + old_mod_state = mod_state; + } + + if (!altdown || !ctrldown) { + const int dy=(int)((cpy-y_)/3.0); + const int newval=limit(cpval+dy, 0, 127); - Penvval[currentpoint]=ny; + Penvval[currentpoint]=newval; + oscWrite(to_s("Penvval")+to_s(currentpoint), "c", newval); + oscWrite("Penvval",""); + } - const int dx=(int)((x_-cpx)*0.1); - const int newdt=limit(cpdt+dx,0,127); + if (!altdown || ctrldown) { + const int dx=(int)((x_-cpx)*0.1); + const int newdt=limit(cpdt+dx,0,127); - if(currentpoint!=0) - Penvdt[currentpoint]=newdt; - else - Penvdt[currentpoint]=0; + if(currentpoint!=0) + Penvdt[currentpoint]=newdt; + else + Penvdt[currentpoint]=0; + oscWrite(to_s("Penvdt")+to_s(currentpoint), "c", newdt); + oscWrite("Penvdt",""); + } - oscWrite(to_s("Penvval")+to_s(currentpoint), "c", ny); - oscWrite(to_s("Penvdt")+to_s(currentpoint), "c", newdt); - oscWrite("Penvdt",""); - oscWrite("Penvval",""); redraw(); if(pair) diff --git a/src/UI/EnvelopeFreeEdit.h b/src/UI/EnvelopeFreeEdit.h @@ -40,11 +40,13 @@ class EnvelopeFreeEdit : public Fl_Box, public Fl_Osc_Widget Fl_Box *pair; //XXX what the heck is this? //cursor state - int currentpoint, cpx, cpdt; + int currentpoint, cpx, cpy, cpdt, cpval; //The Points char Penvdt[MAX_ENVELOPE_POINTS]; char Penvval[MAX_ENVELOPE_POINTS]; //The Sustain point char Penvsustain; + int button_state; + int mod_state; }; diff --git a/src/UI/EnvelopeUI.fl b/src/UI/EnvelopeUI.fl @@ -146,14 +146,12 @@ sustaincounter->update(); label frcR tooltip {Forced Release} xywh {410 165 40 15} down_box DOWN_BOX labelsize 10 code0 {o->init("Pforcedrelease");} - code1 {//TODO if (Pfreemode==0) o->hide();} class Fl_Osc_Check } Fl_Dial envstretchdial { label {Str.} tooltip {Envelope stretch (on lower notes make the envelope longer)} xywh {380 155 25 25} box ROUND_UP_BOX labelsize 10 align 4 maximum 127 step 1 code0 {o->init("Penvstretch");} - code1 {//TODO if (Pfreemode==0) o->hide();} class Fl_Osc_Dial } Fl_Button {} { @@ -165,7 +163,6 @@ sustaincounter->update(); label L tooltip {Linear Envelope} xywh {410 151 30 15} down_box DOWN_BOX labelsize 10 code0 {o->init("Plinearenvelope");} - code1 {//TODO if ((Pfreemode==0)||(Envmode>2)) o->hide();} class Fl_Osc_Check } Fl_Counter sustaincounter { @@ -616,8 +613,12 @@ refresh_display();} {} envstretchdial->value(Penvstretch); - linearenvelopecheck->value(Plinearenvelope); - linearenvelopecheck->show(); + if (Envmode > 2) + linearenvelopecheck->hide(); + else { + linearenvelopecheck->value(Plinearenvelope); + linearenvelopecheck->show(); + } forcedreleasecheck->value(Pforcedrelease); diff --git a/src/UI/PADnoteUI.fl b/src/UI/PADnoteUI.fl @@ -386,7 +386,7 @@ cbwidget->do_callback();}} callback {opui->update(); hpui->update(); cbwidget->do_callback();} - xywh {425 310 25 25} box ROUND_UP_BOX labelsize 10 align 1 maximum 127 step 1 + xywh {425 310 25 25} box ROUND_UP_BOX labelsize 10 align 1 maximum 255 step 1 code0 {o->init("Phrpos.par1");o->reset_value=64;} class Fl_Osc_Dial } @@ -394,7 +394,7 @@ cbwidget->do_callback();} label Par2 callback {opui->update(); cbwidget->do_callback();} - xywh {460 310 25 25} box ROUND_UP_BOX labelsize 10 align 1 maximum 127 step 1 + xywh {460 310 25 25} box ROUND_UP_BOX labelsize 10 align 1 maximum 255 step 1 code0 {o->init("Phrpos.par2");o->reset_value=64;} class Fl_Osc_Dial } @@ -402,7 +402,7 @@ cbwidget->do_callback();} label ForceH callback {opui->update(); cbwidget->do_callback();} - xywh {495 310 25 25} box ROUND_UP_BOX labelsize 10 align 1 maximum 127 step 1 + xywh {495 310 25 25} box ROUND_UP_BOX labelsize 10 align 1 maximum 255 step 1 code0 {o->init("Phrpos.par3");} class Fl_Osc_Dial }