PlayMusic / StopMusic with fadein/fadeout

Feature requests for future versions of Hollywood can be voiced here
Post Reply
Bugala
Posts: 1178
Joined: Sun Feb 14, 2010 7:11 pm

PlayMusic / StopMusic with fadein/fadeout

Post 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.
User avatar
airsoftsoftwair
Posts: 5443
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: PlayMusic / StopMusic with fadein/fadeout

Post 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.
User avatar
Allanon
Posts: 732
Joined: Sun Feb 14, 2010 7:53 pm
Location: Italy
Contact:

Re: PlayMusic / StopMusic with fadein/fadeout

Post 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

Bugala
Posts: 1178
Joined: Sun Feb 14, 2010 7:11 pm

Re: PlayMusic / StopMusic with fadein/fadeout

Post by Bugala »

Thanks, I might put it in use.
Post Reply