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

[Script] Fade

1530268340

Edited 1530268703
MyRoll20Stuffs
API Scripter
Here's a simple script to fade in or fade out tracks. I use !sfx for all my sound effect / music needs but it doesn't have the ability to fade in / out a track so I wrote this script. Syntax: !fade [in|out] [trackname] Version 0.2.1 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Planned Features: Ability to set level of volume to lower/raise by each tick (currently 10 seconds) Duration of each tick (currently 2 seconds) Script: /* Custom Fade In/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 in [track name] | !fade out [track name] */ function fadeOutTrack(trackname) { var song = findObjs({ _type: 'jukeboxtrack', title: trackname.trim(), })[0]; if (!song) { sendChat("fadeTrack", "/w gm Could not find track named '" + trackname + "' - please check the track name and try again.") return; } var trackID = song.get("_id"), level = song.get("volume"), prev_level = song.get("volume"), loops = song.get("loop"); var timer = setInterval(function(){ if (level &gt;= 10) { 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 ); } function fadeInTrack(trackname) { var song = findObjs({ _type: 'jukeboxtrack', title: trackname.trim() })[0]; if (!song) { sendChat("fadeTrack", "/w gm Could not find track named '" + trackname + "'- please check the track name and try again.") return; } var trackID = song.get("_id"), level = 0, loops = song.get("loop"); var timer = setInterval(function(){ song.set({ 'playing' : true, 'softstop' : false, 'loop' : loops, 'volume' : level }); if (level &lt; 100) { level = level + 10; song.set({volume:level}); } else { clearTimeout(timer); } }, 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': { switch (args[0].toLowerCase()) { case 'in': fadeInTrack(args[1]); break; case 'out': fadeOutTrack(args[1]); break; } } break; } } }); log("-=&gt; Fade command loaded (!fade) &lt;=-") }); I created this command specifically to work with the !delay script located here in the API section of the forums. If you have any issues or feature suggestions please feel free to post them in this thread.
I've added some new features to the !fade command. You can now specify the level to fade in/out at and the interval to fade by the specified level. Syntax: !fade [in|out] [level] [interval] [track name] Version: 0.3.1 /* Custom Fade In/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 [in|out] [level] [interval] [track name] */ function fadeOutTrack(lvl, interval, trackname) { if (trackname) { var song = findObjs({ _type: 'jukeboxtrack', title: trackname.trim() })[0]; } else { sendChat("fadeTrack", "/w gm &lt;br&gt;No track name was specified.&lt;br&gt;&lt;code&gt;Syntax: !fade [in|out] [level] [interval] [track name]&lt;/code&gt;"); return; } if (!song) { sendChat("fadeTrack", "/w gm Could not find track named '" + trackname + "' - please check the track name and try again."); return; } else if (isNaN(lvl) || lvl &lt; 5 || lvl &gt; 50) { sendChat("fadeTrack", "/w gm &lt;br&gt;Level increment must be between 5 and 50.&lt;br&gt;&lt;code&gt;Syntax: !fade [in|out] [level] [interval] [track name]&lt;/code&gt;"); return; } else if (isNaN(interval) || interval &lt; 1 || interval &gt; 10) { sendChat("fadeTrack", "/w gm &lt;br&gt;Interval must be between 1 and 10.&lt;br&gt;&lt;code&gt;Syntax: !fade [in|out] [level] [interval] [track name]&lt;/code&gt;"); return; } var trackID = song.get("_id"), level = song.get("volume"), prev_level = song.get("volume"), loops = song.get("loop"), delay = (interval * 1000); var timer = setInterval(function(){ if (level &gt;= lvl) { level = level - lvl; if (level &lt; 0) level = 0; 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); } }, delay ); } function fadeInTrack(lvl, interval, trackname) { if (trackname) { var song = findObjs({ _type: 'jukeboxtrack', title: trackname.trim() })[0]; } else { sendChat("fadeTrack", "/w gm &lt;br&gt;No track name was specified.&lt;br&gt;&lt;code&gt;Syntax: !fade [in|out] [level] [interval] [track name]&lt;/code&gt;"); return; } if (!song) { sendChat("fadeTrack", "/w gm Could not find track named '" + trackname + "'- please check the track name and try again.") return; } else if (isNaN(lvl) || lvl &lt; 5 || lvl &gt; 50) { sendChat("fadeTrack", "/w gm &lt;br&gt;Level increment must be between 5 and 50.&lt;br&gt;&lt;code&gt;Syntax: !fade [in|out] [level] [interval] [track name]&lt;/code&gt;"); return; } else if (isNaN(interval) || interval &lt; 1 || interval &gt; 10) { sendChat("fadeTrack", "/w gm &lt;br&gt;Interval must be between 1 and 10.&lt;br&gt;&lt;code&gt;Syntax: !fade [in|out] [level] [interval] [track name]&lt;/code&gt;"); return; } var trackID = song.get("_id"), level = 0, loops = song.get("loop"), delay = (interval * 1000); var timer = setInterval(function(){ song.set({ 'playing' : true, 'softstop' : false, 'loop' : loops, 'volume' : level }); if (level &lt; 100) { level = level + lvl; if (level &gt; 100) level = 100; song.set({volume:level}); } else { clearTimeout(timer); } }, delay ); } 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': { switch (args[0].toLowerCase()) { case 'in': fadeInTrack(args[1], args[2], args[3]); break; case 'out': fadeOutTrack(args[1], args[2], args[3]); break; } } break; } } }); log("-=&gt; Fade command loaded (!fade) [Last Edited by Kastion 29/06/2018] &lt;=-") }); Example: !fade out 20 1 Music1 This will reduce the volume of the music playing "Music1"&nbsp; by 20% every second until it reduces the volume to 0% . So if your volume is set to 100% prior to running the command it will go from 100 to 0 in 5 seconds. If you have any issues with the script or have suggestions / feature requests please post them here in this thread.
1530303231
vÍnce
Pro
Sheet Author
Thanks for posting these Kastion. One can never have too many scripts. ;-)
Great work Kastion.
1530502336

Edited 1530504605
Victor B.
Pro
Sheet Author
API Scripter
I have to ask.&nbsp; Why aren't you using Roll20AM on this since you took the code and modified it?&nbsp; Why add yet another API to the mix?&nbsp; Your delay command is excellent.&nbsp; Just wondering why you are recreating wheels?&nbsp; The bigger issue here is the sheer number of APIs to choose from.&nbsp; Just look at a post from prior to today.&nbsp; Where do I start?&nbsp; Then let's take existing scripts and copy them and modify them and then post more?&nbsp; Think that's going to make things easier for someone diving into the API world? Better solution is to reach out to the people who are supporting these scripts and find ways to work with them.&nbsp; Keep the API count down to more manageable levels.&nbsp;&nbsp;
1530532590

Edited 1530532657
MyRoll20Stuffs
API Scripter
Victor B. said: I have to ask.&nbsp; Why aren't you using Roll20AM on this since you took the code and modified it?&nbsp; Why add yet another API to the mix?&nbsp; Your delay command is excellent.&nbsp; Just wondering why you are recreating wheels?&nbsp; The bigger issue here is the sheer number of APIs to choose from.&nbsp; Just look at a post from prior to today.&nbsp; Where do I start?&nbsp; Then let's take existing scripts and copy them and modify them and then post more?&nbsp; Think that's going to make things easier for someone diving into the API world? Better solution is to reach out to the people who are supporting these scripts and find ways to work with them.&nbsp; Keep the API count down to more manageable levels.&nbsp;&nbsp; First I want to say I've never even seen Roll20AM's code so any similarities are just there because that's how the fading is done. Second, I created this for personal use only to use with !sfx because Roll20AM is too complicated for what I wanted to do. It's pretty presumptuous of you to say I copied your script when I've never even seen it and you're coming at me pretty hostile. Third, this originally was posted in a thread where I had 4 different scripts in the thread. I only had created separate threads because it was requested. Go ahead and get a mod to delete this thread I really don't care - I didn't make the script for anyone's use but my own. Either way I don't appreciate you get hostile with me and assuming I copied your code.
1530535726
Victor B.
Pro
Sheet Author
API Scripter
Right, so even though your function names are identical to Roll20AM and your code follows the exact same logic as Roll20AM with minor changes, you're missing the point.&nbsp; 30 year of technology is telling me that copying existing code that who knows how many people are using and making changes to support a single script is not the way to go.&nbsp; Your adding more rather than simplifying.&nbsp; Why don't you get !delay to work with existing stuff.&nbsp; The Aaron is about as helpful a person as I've ever met.&nbsp; No reason to copy and change.&nbsp;&nbsp;
1530538035
Victor B.
Pro
Sheet Author
API Scripter
Really, you've never read the Roll20AM code?&nbsp; You can do anything you want with any code I publish.&nbsp; I have absolutely no issues with that.&nbsp; But I still will question why you are copying, making your own versions for a single script.&nbsp; !delay is a great concept.&nbsp; Make it work with the existing stuff and it will be a must have.&nbsp; &nbsp;&nbsp; Kastion &nbsp;said: keithcurtis &nbsp;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.
1530553206
The Aaron
Roll20 Production Team
API Scripter
Please remember that opposing opinions aren't necessarily hostile and can lead to constructive conversations.&nbsp; Don't assume a challenge is automatically an attack--attempt to defuse misunderstandings.&nbsp; This could be a good conversation, provided everyone participates in good faith and adheres to the Civil Discussions portion of the CoC.