me.TR(me);
s = makeXonoticDecibelsSlider(-40, 0, 1, "mastervolume");
- me.TD(me, 1, 1, e = makeXonoticSliderCheckBox(-1000000, 1, s, _("Master:")));
- if(s.value != e.savedValue)
- e.savedValue = 0; // default
+ me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Master:")));
me.TD(me, 1, 2, s);
me.TR(me);
me.TDempty(me, 0.2);
s = makeXonoticDecibelsSlider(-40, 0, 1, "bgmvolume");
makeMulti(s, "snd_channel8volume");
- me.TD(me, 1, 0.8, e = makeXonoticSliderCheckBox(-1000000, 1, s, _("Music:")));
- if(s.value != e.savedValue)
- e.savedValue = 0; // default
+ me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Music:")));
me.TD(me, 1, 2, s);
setDependentStringNotEqual(e, "mastervolume", "0");
setDependentStringNotEqual(s, "mastervolume", "0");
me.TDempty(me, 0.2);
s = makeXonoticDecibelsSlider(-40, 0, 1, "snd_staticvolume");
makeMulti(s, "snd_channel9volume");
- me.TD(me, 1, 0.8, e = makeXonoticSliderCheckBox(-1000000, 1, s, ZCTX(_("VOL^Ambient:"))));
- if(s.value != e.savedValue)
- e.savedValue = 0; // default
+ me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, ZCTX(_("VOL^Ambient:"))));
me.TD(me, 1, 2, s);
setDependentStringNotEqual(e, "mastervolume", "0");
setDependentStringNotEqual(s, "mastervolume", "0");
me.TR(me);
me.TDempty(me, 0.2);
s = makeXonoticDecibelsSlider(-40, 0, 1, "snd_channel0volume");
- me.TD(me, 1, 0.8, e = makeXonoticSliderCheckBox(-1000000, 1, s, _("Info:")));
- if(s.value != e.savedValue)
- e.savedValue = 0; // default
+ me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Info:")));
me.TD(me, 1, 2, s);
setDependentStringNotEqual(e, "mastervolume", "0");
setDependentStringNotEqual(s, "mastervolume", "0");
me.TR(me);
me.TDempty(me, 0.2);
s = makeXonoticDecibelsSlider(-40, 0, 1, "snd_channel3volume");
- me.TD(me, 1, 0.8, e = makeXonoticSliderCheckBox(-1000000, 1, s, _("Items:")));
- if(s.value != e.savedValue)
- e.savedValue = 0; // default
+ me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Items:")));
me.TD(me, 1, 2, s);
setDependentStringNotEqual(e, "mastervolume", "0");
setDependentStringNotEqual(s, "mastervolume", "0");
me.TR(me);
me.TDempty(me, 0.2);
s = makeXonoticDecibelsSlider(-40, 0, 1, "snd_channel6volume");
- me.TD(me, 1, 0.8, e = makeXonoticSliderCheckBox(-1000000, 1, s, _("Pain:")));
- if(s.value != e.savedValue)
- e.savedValue = 0; // default
+ me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Pain:")));
me.TD(me, 1, 2, s);
setDependentStringNotEqual(e, "mastervolume", "0");
setDependentStringNotEqual(s, "mastervolume", "0");
me.TR(me);
me.TDempty(me, 0.2);
s = makeXonoticDecibelsSlider(-40, 0, 1, "snd_channel7volume");
- me.TD(me, 1, 0.8, e = makeXonoticSliderCheckBox(-1000000, 1, s, _("Player:")));
- if(s.value != e.savedValue)
- e.savedValue = 0; // default
+ me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Player:")));
me.TD(me, 1, 2, s);
setDependentStringNotEqual(e, "mastervolume", "0");
setDependentStringNotEqual(s, "mastervolume", "0");
me.TR(me);
me.TDempty(me, 0.2);
s = makeXonoticDecibelsSlider(-40, 0, 1, "snd_channel4volume");
- me.TD(me, 1, 0.8, e = makeXonoticSliderCheckBox(-1000000, 1, s, _("Shots:")));
- if(s.value != e.savedValue)
- e.savedValue = 0; // default
+ me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Shots:")));
me.TD(me, 1, 2, s);
setDependentStringNotEqual(e, "mastervolume", "0");
setDependentStringNotEqual(s, "mastervolume", "0");
me.TR(me);
me.TDempty(me, 0.2);
s = makeXonoticDecibelsSlider(-40, 0, 1, "snd_channel2volume");
- me.TD(me, 1, 0.8, e = makeXonoticSliderCheckBox(-1000000, 1, s, _("Voice:")));
- if(s.value != e.savedValue)
- e.savedValue = 0; // default
+ me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Voice:")));
me.TD(me, 1, 2, s);
setDependentStringNotEqual(e, "mastervolume", "0");
setDependentStringNotEqual(s, "mastervolume", "0");
me.TDempty(me, 0.2);
s = makeXonoticDecibelsSlider(-40, 0, 1, "snd_channel1volume");
makeMulti(s, "snd_channel5volume"); // @!#%'n Tuba
- me.TD(me, 1, 0.8, e = makeXonoticSliderCheckBox(-1000000, 1, s, _("Weapons:")));
- if(s.value != e.savedValue)
- e.savedValue = 0; // default
+ me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Weapons:")));
me.TD(me, 1, 2, s);
setDependentStringNotEqual(e, "mastervolume", "0");
setDependentStringNotEqual(s, "mastervolume", "0");
#ifdef IMPLEMENTATION
-float toDecibelOfSquare(float f)
+float toDecibelOfSquare(float f, float mi)
{
- return 20.0 * log10(f);
+ float A = log(10) / 20; // note: about 0.115; inverse: about 8.686
+ if(mi != 0)
+ {
+ // linear scale part
+ float t = 1 / A + mi;
+ float y = exp(1 + A * mi);
+ if(f <= y)
+ return mi + (t - mi) * (f / y);
+ }
+ return log(f) / A;
}
-float fromDecibelOfSquare(float f)
+float fromDecibelOfSquare(float f, float mi)
{
- return pow(10, f / 20.0);
+ float A = log(10) / 20; // note: about 0.115; inverse: about 8.686
+ if(mi != 0)
+ {
+ // linear scale part
+ float t = 1 / A + mi;
+ float y = exp(1 + A * mi);
+ if(f <= t)
+ return y * ((f - mi) / (t - mi));
+ }
+ return exp(A * f);
}
entity makeXonoticDecibelsSlider(float theValueMin, float theValueMax, float theValueStep, string theCvar)
v = cvar(me.cvarName);
// snapping
- if(v > fromDecibelOfSquare(me.valueMax - 0.5 * me.valueStep))
+ if(v > fromDecibelOfSquare(me.valueMax - 0.5 * me.valueStep, me.valueMin))
Slider_setValue(me, me.valueMax);
- else if(v < fromDecibelOfSquare(me.valueMin - 0.5 * me.valueStep))
- Slider_setValue(me, -1000000); // virtually infinite
else
- Slider_setValue(me, me.valueStep * floor(0.5 + toDecibelOfSquare(v) / me.valueStep) );
+ Slider_setValue(me, me.valueStep * floor(0.5 + toDecibelOfSquare(v, me.valueMin) / me.valueStep) );
}
void XonoticDecibelsSlider_saveCvars(entity me)
{
return;
if(me.value > me.valueMax - 0.5 * me.valueStep)
- cvar_set(me.cvarName, ftos(fromDecibelOfSquare(me.valueMax)));
- else if(me.value < me.valueMin - 0.5 * me.valueStep)
- cvar_set(me.cvarName, "0");
+ cvar_set(me.cvarName, ftos(fromDecibelOfSquare(me.valueMax, me.valueMin)));
else
- cvar_set(me.cvarName, ftos(fromDecibelOfSquare(me.value)));
+ cvar_set(me.cvarName, ftos(fromDecibelOfSquare(me.value, me.valueMin)));
}
+float autocvar_menu_snd_sliderscale;
string XonoticDecibelsSlider_valueToText(entity me, float v)
{
if(v > me.valueMax - 0.5 * me.valueStep)
return CTX(_("VOL^MAX"));
- else if(v < me.valueMin - 0.5 * me.valueStep)
+ else if(v <= me.valueMin)
return CTX(_("VOL^OFF"));
- return sprintf(_("%s dB"), SUPER(XonoticDecibelsSlider).valueToText(me, v));
+ else if(autocvar_menu_snd_sliderscale == 2) // 0..10 scale
+ return sprintf(_("%.1f"), (v - me.valueMin) / (me.valueMax - me.valueMin) * 10);
+ else if(autocvar_menu_snd_sliderscale == 1) // percent scale
+ return sprintf(_("%.2f %%"), fromDecibelOfSquare(v, me.valueMin));
+ else // decibel scale
+ return sprintf(_("%s dB"), ftos_decimals(toDecibelOfSquare(fromDecibelOfSquare(v, me.valueMin), 0), me.valueDigits));
}
#endif