Help - Search - Members - Calendar
Full Version: help with wsh panel and volume control
Hydrogenaudio Forums > Hosted Forums > foobar2000 > 3rd Party Plugins - (fb2k)
zhdali
Hi, i am using wsh panel like slidebar of the volume control.

All work, but the steps of the slidebar are linear, in this way when i move the bar i do not feel null until the 3/4 and after the volume it is raised of blow.

I don't know nothing of javascript and i not have the minimal idea how to modify the script which control this behavior.

This is the code:

CODE

function RGB(r,g,b){ return (0xff000000|(r<<16)|(g<<8)|(b)); }

var g_font = gdi.Font(-12, 400, 1, 0, "MeiryoKe_PGothic");
var g_drag = 0;

function on_paint(gr){
var ww = window.Width;
var wh = window.Height;
var volume = fb.Volume;
var pos = window.Width * ((50+volume)/100);
var txt = (Math.ceil(volume)) + "dB";

gr.FillGradRect( 0, 0, pos, wh, 90, RGB(0,0,0), RGB(255,167,47));
gr.FillGradRect(pos, 0, ww-pos, wh, 90, RGB(0,0,0), RGB(0,0,0));

gr.DrawString(txt, g_font, RGB(0,255,0), 0, 0, ww, wh, 0x11005000);
gr.DrawRect(0,0, ww-1, wh-1, 1.0, RGB(255,167,47));
}
function on_mouse_lbtn_down(x,y){
g_drag = 1;
}
function on_mouse_lbtn_up(x,y){
on_mouse_move(x,y);
g_drag = 0;
}
function on_mouse_move(x,y){
if(g_drag){
var v = x / window.Width;
v = (v<0) ? 0 : (v<1) ? v : 1;
v = -100 * (1-v);
if(fb.Volume != v)
fb.Volume = v;
}
}
function on_mouse_wheel(delta){
if(delta>0)
fb.VolumeUp();
else
fb.VolumeDown();
}
function on_volume_change(val){
window.Repaint();
}
//EOF


someone can help me?
Purple Monkey
You want to change this line:
CODE
v = -100 * (1-v);
I'm guessing that you want it so that the "low" end has larger increments than the "high" end. Thus you want to SquareRoot the v like so:
CODE
v = -100 * (1- sqrt(v) );
I'm not sure if sqrt if the right command though, look it up if it doesn't work.
If you want the reverse then Square v:
CODE
v = -100 * (1-(v*v));
zhdali
I see your answerback only now. Thanks.
Meantime I have resolved in an other way, I do not know if mathematically it is corrected but it works similarly of the original foobar's volume. I use the logarithmic function.

This is the whole code:

CODE

function RGB(r,g,b){ return (0xff000000|(r<<16)|(g<<8)|(b)); }

var g_font = gdi.Font(-12, 400, 1, 0, "MeiryoKe_PGothic");
var g_drag = 0;
function on_paint(gr){
var ww = window.Width;
var wh = window.Height;
var volume =-fb.Volume;
var pos =Math.exp((-(volume-100)*Math.log(100))/100);
var x = pos * ww /100
var txt = (Math.ceil(volume)) + "dB";
gr.FillGradRect( 0, 0, x, wh, 90, RGB(0,0,0), RGB(255,167,47)); //avanzamento volume arancione
gr.FillGradRect(x, 0, ww-x, wh, 90, RGB(0,0,0), RGB(0,0,0)); //ritorno volume nero
gr.DrawString(txt, g_font, RGB(0,255,0), 0, 0, ww, wh, 0x11005000); //scritta
gr.DrawRect(0,0, ww-1, wh-1, 1.0, RGB(255,167,47)); //bordo esterno




}
function on_mouse_lbtn_down(x,y){
g_drag = 1;
}
function on_mouse_lbtn_up(x,y){
on_mouse_move(x,y);
g_drag = 0;
}
function on_mouse_move(x,y){
if(g_drag){
var pos = x * 100 / window.Width;
var v =100-(Math.log(pos)*100)/Math.log(100);
v = (v<0) ? 0 : (v<100) ? v : 100;
v = -v
if(fb.Volume != v)
fb.Volume = v;
}
}
function on_mouse_wheel(delta){
if(delta>0)
fb.VolumeUp();
else
fb.VolumeDown();
}
function on_volume_change(val){
window.Repaint();
}
//EOF


This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.