// requires JQuery sS hjs_humWithFade(double humVolume default 0.25) { ret hjs_playHum() + hjs(replaceDollarVars([[ humSound.volume = 0; var humVolume = $humVolume; // level when on var humShouldBeOn = false; $.extend($.easing, { easeOutExpo: function(x, t, b, c, d) { return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b; }, easeInOutQuint: function (x, t, b, c, d) { if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b; return c/2*((t-=2)*t*t*t*t + 2) + b; } }); function humOn() { if (humShouldBeOn) return; humShouldBeOn = true; hum(humSound.volume); // start playing console.log("hum on (vol=" + humVolume + ")"); fadeHumTo(humVolume); } // TODO: actually turn off in the end function humOff() { if (!humShouldBeOn) return; humShouldBeOn = false; console.log("hum off"); fadeHumTo(0); } function fadeHumTo(vol) { $(humSound).animate({ volume: vol }, { duration: vol < humSound.volume ? 250 : 500, //easing: vol < humSound.volume ? 'easeOutExpo' : 'easeInOutQuint', }); } function updateHumVolume(vol) { if (isNaN(vol) || humVolume == vol) return; humVolume = vol; console.log("New hum volume: " + vol); // fade to new value if (humShouldBeOn) { humShouldBeOn = false; humOn(); } } ]], +humVolume); }