Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Audio Fade Script Acting Strangly

I wrote the following script to fade out jukebox tracks so I can transition into new tracks without it sounding abrupt or choppy. Here is my code /* Custom Fade Out Track Function / Command by Kastion the Scriptomancer Profile: <a href="https://app.roll20.net/users/3173313/kastion" rel="nofollow">https://app.roll20.net/users/3173313/kastion</a> Syntax: !fade [track name] */ function fadeOutTrack(trackname) { var song = findObjs({ _type: 'jukeboxtrack', title: trackname, playing: true, })[0]; var trackID = song.get("_id"); if (!song.get("playing")) { sendChat('fadeOutTrack','/w gm In order to fade a track, it must be playing.'); return; } var level = song.get("volume"), prev_level = song.get("volume"), loops = song.get("loop"); var timer = setInterval(function(){ &nbsp;&nbsp;&nbsp;&nbsp;if (level &gt;= 10)&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;level = level - 10; song.set({volume:level}); } else { song.set({softstop:true,loop:false}); clearTimeout(timer); setTimeout(function(){ song.set({volume:prev_level}); if (loops) song.set({loop:true}); }, 10000); } }, 2000 ); } on('ready',()=&gt;{ on('chat:message',(msg)=&gt;{ if('api' !== msg.type ) { return; } if (!state.fade_pid) state.fade_pid = "API"; if (msg.playerid !== "API") state.fade_pid = msg.playerid; else msg.playerid = state.fade_pid; var cmdName = "!fade"; var msgTxt = msg.content; if (msg.type == "api" &amp;&amp; msgTxt.indexOf(cmdName) !== -1 &amp;&amp; playerIsGM(msg.playerid)) { let args = msg.content.split(/\s+/); switch(args.shift().toLowerCase()){ case '!fade': { fadeOutTrack(args[0]); } break; } } }); log("-=&gt; Fade command loaded (!fade) &lt;=-") }); I'm having some strange behavior with the script. Each time I lower the volume, it doesn't apply the fade to the track even though the bar has been moved. Only at set specific points will it lower the volume. Also when I get to the 30% to 40% volume level it jumps all the way to in-between 0% and 10% and abruptly lowers the volume. Is there any way to force an update on a tracks volume bar so it will lower the volume at what ever percentage it is at? I can seriously go from 100% to 60% or 70% before a change in volume takes effect.
1530032960
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
I believe Victor posted something about htis early in his takeover of the Roll20 Audio Master script. Something to do with linear vs logarithmic?
keithcurtis said: I believe Victor posted something about htis early in his takeover of the Roll20 Audio Master script. Something to do with linear vs logarithmic? I actually read his script and used it for inspiration. I use !sfx and it meets ALL my needs and is very compact and unobtrusive but is missing fade in / out functionality. I made this script for that purpose as I would rather keep the simplicity of !sfx instead of switching to Roll20AM.