Tweak sound

This commit is contained in:
jgk
2021-03-27 15:23:16 +01:00
parent 2011728de5
commit eb2a1a0edb
6 changed files with 49 additions and 115 deletions
+21 -9
View File
@@ -15,29 +15,40 @@ resumeSound w = w
soundOnce :: Int -> World -> World
soundOnce i = over soundQueue ((:) i)
continueSoundFrom :: SoundOrigin -> Int -> Int -> Int -> World -> World
continueSoundFrom so sType time fadeTime w = over sounds (M.insertWith f so sound) w
--continueSoundFrom :: SoundOrigin -> Int -> Int -> Int -> World -> World
--continueSoundFrom so sType time fadeTime w = over sounds (M.insertWith f so sound) w
-- where
-- sound = Sound
-- { _soundType = sType
-- , _soundTime = time
-- , _soundFadeTime = fadeTime
-- , _soundChannel = Nothing
-- , _soundPos = Nothing
-- }
-- f _ s = s {_soundTime = time, _soundFadeTime = fadeTime}
soundOnceOrigin :: Int -> SoundOrigin -> World -> World
soundOnceOrigin sType so = over sounds (M.insertWith (flip const) so sound)
where
sound = Sound
{ _soundType = sType
, _soundTime = time
, _soundFadeTime = fadeTime
, _soundTime = Nothing
, _soundFadeTime = 0
, _soundChannel = Nothing
, _soundPos = Nothing
}
f _ s = s {_soundTime = time, _soundFadeTime = fadeTime}
soundFrom :: SoundOrigin -> Int -> Int -> Int -> World -> World
soundFrom so sType time fadeTime w = over sounds (M.insertWith f so sound) w
where
sound = Sound
{ _soundType = sType
, _soundTime = time
, _soundTime = Just time
, _soundFadeTime = fadeTime
, _soundChannel = Nothing
, _soundPos = Nothing
}
f _ s = s {_soundTime = time, _soundFadeTime = fadeTime}
f _ s = s {_soundTime = Just time, _soundFadeTime = fadeTime}
soundMultiFrom :: [SoundOrigin] -> Int -> Int -> Int -> World -> World
soundMultiFrom [] _ _ _ w = w
@@ -45,14 +56,15 @@ soundMultiFrom (so:sos) sType time fadeTime w
| so `M.member` _sounds w = soundMultiFrom sos sType time fadeTime w
| otherwise = over sounds (M.insert so sound) w
where sound = Sound { _soundType = sType
, _soundTime = time
, _soundTime = Nothing
, _soundFadeTime = fadeTime
, _soundChannel = Nothing
, _soundPos = Nothing
}
stopSoundFrom :: SoundOrigin -> World -> World
stopSoundFrom so = over (sounds . ix so . soundTime) (min 0)
stopSoundFrom so = over (sounds . ix so . soundTime) (fmap $ min 0)
-- idea: pass the id of the sound to the world and send it to some queue for
-- playback