zynaddsubfx

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

commit 5076a43da48372806b6e34d5fda71b0188b5b2ed
parent 57ea725f5d67d8c8de28db8220fad62dd47fcb0b
Author: Johannes Lorenz <johannes89@ist-einmalig.de>
Date:   Thu, 21 Jul 2016 18:23:51 +0200

Merge branch 'env_tail_compat'

Diffstat:
Msrc/Misc/XMLwrapper.cpp | 8++++----
Msrc/Misc/XMLwrapper.h | 8++++++--
Msrc/Params/EnvelopeParams.cpp | 48+++++++++++++++++++++++++++++++++++++++++++-----
Msrc/Params/EnvelopeParams.h | 4++++
Msrc/Synth/Envelope.cpp | 16++++------------
Msrc/Synth/Envelope.h | 2--
Msrc/version.cpp | 14--------------
Msrc/zyn-version.h.in | 16+++++++++++++---
8 files changed, 74 insertions(+), 42 deletions(-)

diff --git a/src/Misc/XMLwrapper.cpp b/src/Misc/XMLwrapper.cpp @@ -323,13 +323,13 @@ int XMLwrapper::loadXMLfile(const string &filename) return -3; //the XML doesnt embbed zynaddsubfx data //fetch version information - fileversion.set_major(stringTo<int>(mxmlElementGetAttr(root, "version-major"))); - fileversion.set_minor(stringTo<int>(mxmlElementGetAttr(root, "version-minor"))); - fileversion.set_revision( + _fileversion.set_major(stringTo<int>(mxmlElementGetAttr(root, "version-major"))); + _fileversion.set_minor(stringTo<int>(mxmlElementGetAttr(root, "version-minor"))); + _fileversion.set_revision( stringTo<int>(mxmlElementGetAttr(root, "version-revision"))); if(verbose) - cout << "loadXMLfile() version: " << fileversion << endl; + cout << "loadXMLfile() version: " << _fileversion << endl; return 0; } diff --git a/src/Misc/XMLwrapper.h b/src/Misc/XMLwrapper.h @@ -233,6 +233,10 @@ class XMLwrapper std::vector<XmlNode> getBranch(void) const; + const version_type& fileversion() const { + return _fileversion; + } + private: /** @@ -272,8 +276,8 @@ class XMLwrapper */ mxml_node_t *addparams(const char *name, unsigned int params, ...) const; - - version_type fileversion; +public: + version_type _fileversion; }; #endif diff --git a/src/Params/EnvelopeParams.cpp b/src/Params/EnvelopeParams.cpp @@ -17,6 +17,7 @@ #include <rtosc/ports.h> #include <rtosc/port-sugar.h> +#include "version.h" #include "EnvelopeParams.h" #include "../Misc/Util.h" #include "../Misc/Time.h" @@ -358,7 +359,42 @@ void EnvelopeParams::add2XML(XMLwrapper& xml) } } +float EnvelopeParams::env_dB2rap(float db) { + return (powf(10.0f, db / 20.0f) - 0.01)/.99f; +} + +float EnvelopeParams::env_rap2dB(float rap) { + return 20.0f * log10f(rap * 0.99f + 0.01); +} +/** + since commit 5334d94283a513ae42e472aa020db571a3589fb9, i.e. between + versions 2.4.3 and 2.4.4, the amplitude envelope has been converted + differently from dB to rap for AmplitudeEnvelope (mode 2) + this converts the values read from an XML file once +*/ +struct version_fixer_t +{ + const bool mismatch; +public: + int operator()(int input) const + { + return (mismatch) + // The errors occured when calling env_dB2rap. Let f be the + // conversion function for mode 2 (see Envelope.cpp), then we + // load values with (let "o" be the function composition symbol): + // f^{-1} o (env_dB2rap^{-1}) o dB2rap o f + // from the xml file. This results in the following formula: + ? roundf(127.0f * (0.5f * + log10f( 0.01f + 0.99f * + powf(100, input/127.0f - 1)) + + 1)) + : input; + } + version_fixer_t(const version_type& fileversion, int env_mode) : + mismatch(fileversion < version_type(2,4,4) && + (env_mode == 2)) {} +}; void EnvelopeParams::getfromXML(XMLwrapper& xml) { @@ -369,20 +405,22 @@ void EnvelopeParams::getfromXML(XMLwrapper& xml) Pforcedrelease = xml.getparbool("forced_release", Pforcedrelease); Plinearenvelope = xml.getparbool("linear_envelope", Plinearenvelope); + version_fixer_t version_fix(xml.fileversion(), Envmode); + PA_dt = xml.getpar127("A_dt", PA_dt); PD_dt = xml.getpar127("D_dt", PD_dt); PR_dt = xml.getpar127("R_dt", PR_dt); - PA_val = xml.getpar127("A_val", PA_val); - PD_val = xml.getpar127("D_val", PD_val); - PS_val = xml.getpar127("S_val", PS_val); - PR_val = xml.getpar127("R_val", PR_val); + PA_val = version_fix(xml.getpar127("A_val", PA_val)); + PD_val = version_fix(xml.getpar127("D_val", PD_val)); + PS_val = version_fix(xml.getpar127("S_val", PS_val)); + PR_val = version_fix(xml.getpar127("R_val", PR_val)); for(int i = 0; i < Penvpoints; ++i) { if(xml.enterbranch("POINT", i) == 0) continue; if(i != 0) Penvdt[i] = xml.getpar127("dt", Penvdt[i]); - Penvval[i] = xml.getpar127("val", Penvval[i]); + Penvval[i] = version_fix(xml.getpar127("val", Penvval[i])); xml.exitbranch(); } diff --git a/src/Params/EnvelopeParams.h b/src/Params/EnvelopeParams.h @@ -70,6 +70,10 @@ class EnvelopeParams:public Presets int64_t last_update_timestamp; static const rtosc::Ports &ports; + + static float env_rap2dB(float rap); + static float env_dB2rap(float db); + private: void store2defaults(); diff --git a/src/Synth/Envelope.cpp b/src/Synth/Envelope.cpp @@ -173,14 +173,6 @@ float Envelope::envout(bool doWatch) return out; } -inline float Envelope::env_dB2rap(float db) { - return (powf(10.0f, db / 20.0f) - 0.01)/.99f; -} - -inline float Envelope::env_rap2dB(float rap) { - return 20.0f * log10f(rap * 0.99f + 0.01); -} - /* * Envelope Output (dB) */ @@ -191,8 +183,8 @@ float Envelope::envout_dB() return envout(true); if((currentpoint == 1) && (!keyreleased || !forcedrelease)) { //first point is always lineary interpolated - float v1 = env_dB2rap(envval[0]); - float v2 = env_dB2rap(envval[1]); + float v1 = EnvelopeParams::env_dB2rap(envval[0]); + float v2 = EnvelopeParams::env_dB2rap(envval[1]); out = v1 + (v2 - v1) * t; t += inct; @@ -204,11 +196,11 @@ float Envelope::envout_dB() } if(out > 0.001f) - envoutval = env_rap2dB(out); + envoutval = EnvelopeParams::env_rap2dB(out); else envoutval = MIN_ENVELOPE_DB; } else - out = env_dB2rap(envout(false)); + out = EnvelopeParams::env_dB2rap(envout(false)); float pos[2] = {(float)currentpoint + t, out}; watchOut(pos, 2); diff --git a/src/Synth/Envelope.h b/src/Synth/Envelope.h @@ -36,8 +36,6 @@ class Envelope * @return returns 1 if the envelope is finished*/ bool finished(void) const; private: - float env_rap2dB(float rap); - float env_dB2rap(float db); int envpoints; int envsustain; //"-1" means disabled float envdt[MAX_ENVELOPE_POINTS]; //millisecons diff --git a/src/version.cpp b/src/version.cpp @@ -15,20 +15,6 @@ #include "zyn-version.h" -constexpr int version_type::v_strcmp(const version_type& v2, int i) const -{ - return (i == sizeof(version)) - ? 0 - : ((version[i] == v2.version[i]) - ? v_strcmp(v2, i+1) - : (version[i] - v2.version[i])); -} - -constexpr bool version_type::operator<(const version_type& other) const -{ - return v_strcmp(other, 0) < 0; -} - std::ostream& operator<< (std::ostream& os, const version_type& v) { diff --git a/src/zyn-version.h.in b/src/zyn-version.h.in @@ -23,8 +23,15 @@ class version_type char version[3]; // strcmp-like comparison against another version_type - constexpr int v_strcmp(const version_type& v2, int i) const; - + constexpr int v_strcmp(const version_type& v2, int i) const + { + return (i == sizeof(version)) + ? 0 + : ((version[i] == v2.version[i]) + ? v_strcmp(v2, i+1) + : (version[i] - v2.version[i])); + } + public: constexpr version_type(char maj, char min, char rev) : version{maj, min, rev} @@ -47,7 +54,10 @@ public: int minor() const { return version[1]; } int revision() const { return version[2]; } - constexpr bool operator<(const version_type& other) const; + constexpr bool operator<(const version_type& other) const + { + return v_strcmp(other, 0) < 0; + } //! prints version as <major>.<minor>.<revision> friend std::ostream& operator<< (std::ostream& os,