Page 2 of 2

Re: Separate Volume Controls

Posted: Thu Oct 27, 2016 6:23 am
by another_commander
Just Sound.playMusic("trackFilename.ogg", true) works fine here. Not sure why you need the lines above and below the playMusic one.

Re: Separate Volume Controls

Posted: Thu Oct 27, 2016 10:07 am
by Svengali
another_commander wrote:
Just Sound.playMusic("trackFilename.ogg", true) works fine here. Not sure why you need the lines above and below the playMusic one.
Yep. Same here .-)

Just as sidenote: [wiki]Library[/wiki] contains a script Lib_Music.js which handles these things.
To add a file to the docking playlist use worldScripts.Lib_Music._addChannel({name:"docking",sounds:[{snd:"trackFilename.ogg",dur:10}]}); (dur is length in seconds)

Re: Separate Volume Controls

Posted: Thu Oct 27, 2016 7:15 pm
by washuu_de
another_commander wrote:
Just Sound.playMusic("trackFilename.ogg", true) works fine here. Not sure why you need the lines above and below the playMusic one.
I quoted the lines before and after the one I changed to give a little context.
The edits I made are in my downloaded version of RandomDockingMusic.js by Dennis Thony Pedersen (Frame).
I wanted to make as little changes as possible since it was my first oxp-script edit.

I wonder why it doesn't repeat as described in the doc of the Sound.PlayMusic method.
Instead I can play Blue Danube by clicking 's' and stop it like the description says.
Only after the random song has ended.

It is not so important. I can always substitute that short track with a bunch of longer pieces. I'm just curious.

Thank you for taking the time to help me.

washuu_de

Re: Separate Volume Controls

Posted: Fri Oct 28, 2016 1:44 pm
by Svengali
another_commander wrote:
... aaaand here we go. Commit 74bb815 should enable an optional third parameter in the JS Sound class function playMusic, representing the desired volume of the music to play. The parameter is a float capped between 0.0 and 1.0 and is relative to the master gain, which means that a value of 1.0 gives it its full gain at the current master volume setting. Feel free to test and let us know what you think.
Cool, a_c! Looks good .-)
washuu_de wrote:
Instead I can play Blue Danube by clicking 's' and stop it like the description says.
Scripts (like Frames RandomDockingMusic) would need a handler for the 's' toggle... *wink*

Re: Separate Volume Controls

Posted: Fri Oct 28, 2016 7:03 pm
by washuu_de
Svengali wrote:
washuu_de wrote:
Instead I can play Blue Danube by clicking 's' and stop it like the description says.
Scripts (like Frames RandomDockingMusic) would need a handler for the 's' toggle... *wink*
Ok, now I understand the concept. I think there is enough documentation on doing such stuff. I should be able to include a handler.
Maybe I will even learn how to write my own OXP/OKZ if fiddling with other works isn't enough for me.

washuu_de

Re: Separate Volume Controls

Posted: Fri Oct 28, 2016 7:18 pm
by Cody
washuu_de wrote:
Maybe I will even learn how to write my own OXP/OKZ if fiddling with other works isn't enough for me.
<chortles> That's how it starts - welcome to the Darkside!

Re: Separate Volume Controls

Posted: Sun Oct 30, 2016 11:24 am
by Svengali
@a_c: If I get this right, volume updates on playing music is not possible...? It's not a biggie, just something we should be aware of.

@washuu_de: Have a cookie .-)

Re: Separate Volume Controls

Posted: Sun Oct 30, 2016 12:51 pm
by another_commander
Svengali wrote:
@a_c: If I get this right, volume updates on playing music is not possible...? It's not a biggie, just something we should be aware of.
I was totally expecting this request next. :-)

I was planning to see what can be done about it during the weekend but some RL popped up and there you go. I'll see about it as soon as I manage to get a chance.

Re: Separate Volume Controls

Posted: Sun Oct 30, 2016 4:27 pm
by Svengali
another_commander wrote:
Svengali wrote:
@a_c: If I get this right, volume updates on playing music is not possible...? It's not a biggie, just something we should be aware of.
I was totally expecting this request next. :-)
°sigh°

Re: Separate Volume Controls

Posted: Mon Oct 31, 2016 7:49 pm
by another_commander
So, in the next nightly we should be able to control music volume, loop status, position etc in real time. Due to the way sound and music are set up internally, it is not entirely straightforward in the current implementation and it is possible that a better way to handle this exists, I just couldn't see it. Having said that, it's not difficult either, thankfully.

In order to enable this kind of control, I have exposed to Javascript the sound source object of the music currently playing. So, once we have access to that object, we can work with it like we do with any other sound source. The new function that does it is part of the Sound JS class and is called musicSoundSource. More specifically, if I want to adjust on the fly, say, the volume of the music currently playing, what I would do is something like this:

Code: Select all

myMusicSoundSource = Sound.musicSoundSource();
myMusicSoundSource.volume = 0.4;
If the music file is a 44KHz mono ogg, we can also do stuff like

Code: Select all

myMusicSoundSource.position = [-1,0,0]; // throw the currently playing music to the left channel

Re: Separate Volume Controls

Posted: Tue Nov 01, 2016 11:19 am
by Svengali
Muchas gracias, a_c! 8)