Page 1 of 1

PlayMusic / StopMusic with fadein/fadeout

Posted: Sun Mar 06, 2016 6:56 pm
by Bugala
Just realised it would sometimes be handy if you could choose instead of simply using StopMusic to use StopMusicFX or something like that to fadein or fadeout the music.

Naturally I can make a piece of code to handle that, but it is quite a lot of lines and would need to be took into consideration that it doesnt collide with something else.

Especially if you take into consideration the possiblity that pressimg mouse button once would start fading the music, and second press (for impatient ones) woudl completely stop the music, it would be much simpler if Hollywood woudl itself be hadnligh that fading in / fading out part instead of having to program it myself.

Re: PlayMusic / StopMusic with fadein/fadeout

Posted: Mon Mar 07, 2016 10:18 pm
by airsoftsoftwair
That's quite some work and the sound driver is complex stuff and highly system dependent so it's rather unlikely because the gain is not that great in comparison to the amount of work this would require.

Re: PlayMusic / StopMusic with fadein/fadeout

Posted: Wed Mar 16, 2016 9:53 pm
by Allanon
Hi Bugala, this is just an idea, quick & dirty & untested but it should work since this idea has been used in GEMZ, you can expand the concept and implement easily crossfades between musics, you should also check if the music is playing or not, it may contain errors since I have no way to test it right now :

Code: Select all

OpenMusic(1, "mysong.mp3")

Global musicVolume = 64
Global musicFadeID = -1

Function FadeMusic(fadeIn, speed)
   ; Check if a fade is already running
   If GetType(musicFadeID) <> #NUMBER
      ; Fade in progress, stop it
      ClearInterval(musicFadeID)
   EndIf
 
   ; Start a fade FX
   musicFadeID = SetInterval(Nil, handleFadeFX, speed, { fadeInFX = fadeIn } )

EndFunction

Function handleFadeFX(userdata)
   If userdata.fadeInFX
      ; Handle a fade in fx
      musicVolume = musicVolume + 1
      If musicVolume > 64
         ClearInterval(musicFadeID)
         MusicFadeID = -1
         musicVolume = 64
      EndIf
   Else
      ; Handle a fade out fx
      musicVolume = musicVolume - 1
      If musicVolume < 0
         ClearInterval(musicFadeID)
         MusicFadeID = -1
         musicVolume = 0
      EndIf
   EndIf

   SetMusicVolume(1, musicVolume)
EndFunction

PlayMusic(1, { volume = 64 })

; starts a fadeout decreasing one volume unit every 100ms
FadeMusic(False, 100)

Repeat
   WaitEvent()
Forever


Re: PlayMusic / StopMusic with fadein/fadeout

Posted: Thu Mar 17, 2016 8:30 am
by Bugala
Thanks, I might put it in use.