commit a63e2087cb3a84552fb827a6b14ebf2244556303
parent 09d5835ec07a8c41675b202bc7ad2d0cda77dbbc
Author: Daniel Sheeler <dsheeler@pobox.com>
Date: Tue, 19 Mar 2019 03:06:30 -0500
voice volume from 1-127 to dB
Diffstat:
4 files changed, 34 insertions(+), 10 deletions(-)
diff --git a/src/Params/ADnoteParameters.cpp b/src/Params/ADnoteParameters.cpp
@@ -130,6 +130,19 @@ static const Ports voicePorts = {
"Panning"),
rParamZyn(PVolume, rShort("vol."), rDefault(100),
"Volume"),
+ {"volume::f", rShort("volume") rProp(parameter) rUnit(dB) rDefault(-12.75) rLinear(-60.0f, 0.0f)
+ rDoc("Part Volume"), NULL,
+ [](const char *msg, RtData &d)
+ {
+ rObject *obj = (rObject *)d.obj;
+ if(!rtosc_narguments(msg)) {
+ d.reply(d.loc, "f", obj->volume);
+ } else if (rtosc_narguments(msg) == 1 && rtosc_type(msg, 0) == 'f') {
+ obj->PVolume = ((int) roundf(127.0f * (rtosc_argument(msg, 0).f / 60.0f + 1.0f)));
+ obj->volume = rtosc_argument(msg, 0).f;
+ d.broadcast(d.loc, "f", ((obj->volume)));
+ }
+ }},
rToggle(PVolumeminus, rShort("inv."), rDefault(false),
"Signal Inverter"), //do we really need this??
rParamZyn(PAmpVelocityScaleFunction, rShort("sense"), rDefault(127),
@@ -525,6 +538,7 @@ void ADnoteVoiceParam::defaults()
PFMoscilphase = 64;
PDelay = 0;
PVolume = 100;
+ volume = -60.0f* (1.0f - 100.0f / 127.0f);
PVolumeminus = 0;
PPanning = 64; //center
PDetune = 8192; //8192=0
@@ -735,7 +749,7 @@ void ADnoteVoiceParam::add2XML(XMLwrapper& xml, bool fmoscilused)
xml.beginbranch("AMPLITUDE_PARAMETERS");
xml.addpar("panning", PPanning);
- xml.addpar("volume", PVolume);
+ xml.addparreal("volume", volume);
xml.addparbool("volume_minus", PVolumeminus);
xml.addpar("velocity_sensing", PAmpVelocityScaleFunction);
@@ -1081,6 +1095,7 @@ void ADnoteVoiceParam::paste(ADnoteVoiceParam &a)
copy(PPanning);
copy(PVolume);
+ copy(volume);
copy(PVolumeminus);
copy(PAmpVelocityScaleFunction);
copy(PAmpEnvelopeEnabled);
@@ -1221,6 +1236,15 @@ void ADnoteVoiceParam::getfromXML(XMLwrapper& xml, unsigned nvoice)
if(xml.enterbranch("AMPLITUDE_PARAMETERS")) {
PPanning = xml.getpar127("panning", PPanning);
PVolume = xml.getpar127("volume", PVolume);
+ const bool upgrade_3_0_3 = (xml.fileversion() < version_type(3,0,3)) ||
+ (!xml.hasparreal("volume"));
+
+ if (upgrade_3_0_3) {
+ int vol = xml.getpar127("volume", 0);
+ volume = -60.0f * ( 1.0f - vol / 127.0f);
+ } else {
+ volume = xml.getparreal("volume", volume);
+ }
PVolumeminus = xml.getparbool("volume_minus", PVolumeminus);
PAmpVelocityScaleFunction = xml.getpar127("velocity_sensing",
PAmpVelocityScaleFunction);
diff --git a/src/Params/ADnoteParameters.h b/src/Params/ADnoteParameters.h
@@ -215,6 +215,7 @@ struct ADnoteVoiceParam {
/* Voice Volume */
unsigned char PVolume;
+ float volume;
/* If the Volume negative */
unsigned char PVolumeminus;
diff --git a/src/Synth/ADnote.cpp b/src/Synth/ADnote.cpp
@@ -694,11 +694,10 @@ void ADnote::legatonote(LegatoParams lpars)
NoteVoicePar[nvoice].noisetype = pars.VoicePar[nvoice].Type;
/* Voice Amplitude Parameters Init */
NoteVoicePar[nvoice].Volume =
- powf(0.1f, 3.0f
- * (1.0f - pars.VoicePar[nvoice].PVolume / 127.0f)) // -60 dB .. 0 dB
+ dB2rap(pars.VoicePar[nvoice].volume) // -60 dB .. 0 dB
* VelF(velocity,
pars.VoicePar[nvoice].PAmpVelocityScaleFunction); //velocity
- if(pars.VoicePar[nvoice].PVolume == 0)
+ if(pars.VoicePar[nvoice].volume == -60.0)
NoteVoicePar[nvoice].Volume = 0;
if(pars.VoicePar[nvoice].PVolumeminus != 0)
@@ -855,9 +854,9 @@ void ADnote::initparameters(WatchManager *wm, const char *prefix)
vce.noisetype = param.Type;
/* Voice Amplitude Parameters Init */
- vce.Volume = powf(0.1f, 3.0f * (1.0f - param.PVolume / 127.0f)) // -60dB..0dB
+ vce.Volume = dB2rap(param.volume) // -60dB..0dB
* VelF(velocity, param.PAmpVelocityScaleFunction);
- if(param.PVolume == 0)
+ if(param.volume == -60.0f)
vce.Volume = 0;
if(param.PVolumeminus)
diff --git a/src/Tests/guitar-adnote.xmz b/src/Tests/guitar-adnote.xmz
@@ -237,7 +237,7 @@ version-revision="4" ZynAddSubFX-author="Nasca Octavian Paul">
</OSCIL>
<AMPLITUDE_PARAMETERS>
<par name="panning" value="6" />
-<par name="volume" value="100" />
+<par_real name="volume" value="-12.7559" exact_value="0xC14C1832" />
<par_bool name="volume_minus" value="no" />
<par name="velocity_sensing" value="127" />
<par_bool name="amp_envelope_enabled" value="yes" />
@@ -485,7 +485,7 @@ version-revision="4" ZynAddSubFX-author="Nasca Octavian Paul">
</OSCIL>
<AMPLITUDE_PARAMETERS>
<par name="panning" value="0" />
-<par name="volume" value="100" />
+<par_real name="volume" value="-12.7559" exact_value="0xC14C1832" />
<par_bool name="volume_minus" value="no" />
<par name="velocity_sensing" value="127" />
<par_bool name="amp_envelope_enabled" value="no" />
@@ -571,7 +571,7 @@ version-revision="4" ZynAddSubFX-author="Nasca Octavian Paul">
</OSCIL>
<AMPLITUDE_PARAMETERS>
<par name="panning" value="127" />
-<par name="volume" value="100" />
+<par_real name="volume" value="-12.7559" exact_value="0xC14C1832" />
<par_bool name="volume_minus" value="no" />
<par name="velocity_sensing" value="127" />
<par_bool name="amp_envelope_enabled" value="no" />
@@ -665,7 +665,7 @@ version-revision="4" ZynAddSubFX-author="Nasca Octavian Paul">
</OSCIL>
<AMPLITUDE_PARAMETERS>
<par name="panning" value="64" />
-<par name="volume" value="127" />
+<par_real name="volume" value="-0" exact_value="0x80000000" />
<par_bool name="volume_minus" value="no" />
<par name="velocity_sensing" value="70" />
<par_bool name="amp_envelope_enabled" value="yes" />