commit 46341e5bd909710d0c2f3921d95c3f53227d1378
parent 5f420f5622d084d4f0fa1dda878bd38eafed9efe
Author: Johannes Lorenz <johannes89@ist-einmalig.de>
Date: Wed, 20 Jul 2016 00:30:34 +0200
Preparations, handling XML version.
Diffstat:
8 files changed, 57 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,10 +359,30 @@ void EnvelopeParams::add2XML(XMLwrapper& xml)
}
}
+static float EnvelopeParams::env_dB2rap(float db) {
+ return (powf(10.0f, db / 20.0f) - 0.01)/.99f;
+}
+
+static float EnvelopeParams::env_rap2dB(float rap) {
+ return 20.0f * log10f(rap * 0.99f + 0.01);
+}
+
+int value(int input, bool mismatch)
+{
+ int res = input;
+ if(mismatch)
+ {
+ // the errors occured when calling env_dB2rap,
+ // thus, we use this formula:
+ }
+ return res;
+}
void EnvelopeParams::getfromXML(XMLwrapper& xml)
{
+ bool mismatch = xml.fileversion() < version_type(2,4,4);
+
Pfreemode = xml.getparbool("free_mode", Pfreemode);
Penvpoints = xml.getpar127("env_points", Penvpoints);
Penvsustain = xml.getpar127("env_sustain", Penvsustain);
@@ -372,17 +393,17 @@ void EnvelopeParams::getfromXML(XMLwrapper& xml)
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 = value(xml.getpar127("A_val", PA_val), mismatch);
+ PD_val = value(xml.getpar127("D_val", PD_val), mismatch);
+ PS_val = value(xml.getpar127("S_val", PS_val), mismatch);
+ PR_val = value(xml.getpar127("R_val", PR_val), mismatch);
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] = value(xml.getpar127("val", Penvval[i]), mismatch);
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 "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/version.h.in b/src/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,