Separate Volume Controls

An area for discussing new ideas and additions to Oolite.

Moderators: another_commander, winston

another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6552
Joined: Wed Feb 28, 2007 7:54 am

Re: Separate Volume Controls

Post 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.
User avatar
Svengali
Commander
Commander
Posts: 2370
Joined: Sat Oct 20, 2007 2:52 pm

Re: Separate Volume Controls

Post 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)
washuu_de
Average
Average
Posts: 8
Joined: Tue Dec 18, 2012 4:18 pm

Re: Separate Volume Controls

Post 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
User avatar
Svengali
Commander
Commander
Posts: 2370
Joined: Sat Oct 20, 2007 2:52 pm

Re: Separate Volume Controls

Post 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*
washuu_de
Average
Average
Posts: 8
Joined: Tue Dec 18, 2012 4:18 pm

Re: Separate Volume Controls

Post 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
User avatar
Cody
Sharp Shooter Spam Assassin
Sharp Shooter Spam Assassin
Posts: 16060
Joined: Sat Jul 04, 2009 9:31 pm
Location: The Lizard's Claw
Contact:

Re: Separate Volume Controls

Post 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!
I would advise stilts for the quagmires, and camels for the snowy hills
And any survivors, their debts I will certainly pay. There's always a way!
User avatar
Svengali
Commander
Commander
Posts: 2370
Joined: Sat Oct 20, 2007 2:52 pm

Re: Separate Volume Controls

Post 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 .-)
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6552
Joined: Wed Feb 28, 2007 7:54 am

Re: Separate Volume Controls

Post 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.
User avatar
Svengali
Commander
Commander
Posts: 2370
Joined: Sat Oct 20, 2007 2:52 pm

Re: Separate Volume Controls

Post 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°
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6552
Joined: Wed Feb 28, 2007 7:54 am

Re: Separate Volume Controls

Post 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
User avatar
Svengali
Commander
Commander
Posts: 2370
Joined: Sat Oct 20, 2007 2:52 pm

Re: Separate Volume Controls

Post by Svengali »

Muchas gracias, a_c! 8)
Post Reply