module Dodge.SoundLogic.LoadSound where
import Sound.Data

import qualified Data.IntMap.Strict as IM
import qualified SDL.Mixer as Mix

loadSound :: (Int,String) -> IO (Int, Mix.Chunk)
loadSound (i,s) = do
    chnk <- Mix.load $ "./data/sound/" ++ s
    return (i,chnk)

loadSounds :: IO (IM.IntMap Mix.Chunk)
loadSounds = do
    Mix.openAudio Mix.defaultAudio 128
    fmap IM.fromList $ mapM loadSound $ zip [0..] soundPathList

soundToVol :: SoundID -> Float
soundToVol v = case _getSoundID v of
    0 -> 5000
    1 -> 8000
    2 -> 8000
    3 -> 5000
    4 -> 3000
    5 -> 3000
    6 -> 4000
    7 -> 5000
    8 -> 10000
    9 -> 8000
    10 -> 8000
    11 -> 8000
    12 -> 8000
    13 -> 10000
    14 -> 3000
    15 -> 4000
    16 -> 5000
    17 -> 5000
    18 -> 20000
    19 -> 4000
    20 -> 10000
    21 -> 8000
    22 -> 4000
    23 -> 2000
    24 -> 6000
    25 -> 500
    26 -> 5000
    27 -> 8000
    28 -> 8000
    29 -> 8000
    30 -> 5000
    31 -> 8000
    32 -> 4000
    33 -> 3000
    34 -> 8000
    35 -> 2000
    36 -> 10000
    37 -> 5000
    38 -> 2000
    39 -> 3000
    40 -> 12000
    41 -> 5000
    42 -> 10000
    43 -> 12000
    44 -> 2000
    45 -> 3000
    46 -> 8000
    47 -> 5000
    48 -> 2000
    49 -> 3000
    50 -> 10000
    51 -> 10000
    52 -> 3000
    53 -> 15000
    54 -> 10000
    55 -> 3000
    56 -> 15000
    57 -> 8000
    _ -> 50
soundToOnomato :: SoundID -> String
soundToOnomato v = case _getSoundID v of
    0 -> "HNH"
    1 -> "CRNKL"
    2 -> "ZMM"
    3 -> "KRTNKL"
    4 -> "DWAAH"
    5 -> "BWAH"
    6 -> "TIPTOP"
    7 -> "TINKLE"
    8 -> "TATATA"
    9 -> "CRSK"
    10 -> "CRNK"
    11 -> "TAKH"
    12 -> "CRUNK"
    13 -> "SCREE"
    14 -> "TNKTNKTNK"
    15 -> "TIPTAP"
    16 -> "WRR"
    17 -> "HSS"
    18 -> "BOOM"
    19 -> "CLNK"
    20 -> "BRAP"
    21 -> "CRSNK"
    22 -> "TAPP"
    23 -> "BLIH"
    24 -> "TAPTIP"
    25 -> "CLICK"
    26 -> "FWUMP"
    27 -> "RINGGG"
    28 -> "BRAP"
    29 -> "CRUMPLE"
    30 -> "TRINKL"
    31 -> "TAK"
    32 -> "SMACK"
    33 -> "DRR"
    34 -> "CRASH"
    35 -> "SWSH"
    36 -> "CRAKLE"
    37 -> "CRTINK"
    38 -> "FHP"
    39 -> "CHPCHPCHP"
    40 -> "BRPBRPBRP"
    41 -> "CHNKCHNKCHUNK"
    42 -> "WRRR"
    43 -> "BRDBRDBRD"
    44 -> "PHF"
    45 -> "BWAAH"
    46 -> "BEP"
    47 -> "HSSS"
    48 -> "SHUHP"
    49 -> "THUD"
    50 -> "WHSSH"
    51 -> "BRAHCHCH"
    52 -> "TIP"
    53 -> "BANGG"
    54 -> "ZHM"
    55 -> "TAP"
    56 -> "BANG"
    57 -> "CRISH"
    _ -> error "unitialised sound" 
soundPathList :: [String]
soundPathList =
    [ "grunt.HNH.5000.wav"
    , "glassShat2.CRNKL.8000.wav"
    , "buzz.ZMM.8000.wav"
    , "smallGlass2.KRTNKL.5000.wav"
    , "skwareFadeTwoSec.DWAAH.3000.wav"
    , "sineRaisePitchOneSec.BWAH.3000.wav"
    , "twoStepSlow.TIPTOP.4000.wav"
    , "smallGlass4.TINKLE.5000.wav"
    , "autoB.TATATA.10000.wav"
    , "glassShat4.CRSK.8000.wav"
    , "glassShat3.CRNK.8000.wav"
    , "tap2.TAKH.8000.wav"
    , "impact2.CRUNK.8000.wav"
    , "tone440sawtooth.SCREE.10000.wav"
    , "reload.TNKTNKTNK.3000.wav"
    , "twoStep.TIPTAP.4000.wav"
    , "fire.WRR.5000.wav"
    , "foamSprayFadeOut.HSS.5000.wav"
    , "explosion.BOOM.20000.wav"
    , "tapQuiet.CLNK.4000.wav"
    , "autoGun.BRAP.10000.wav"
    , "glassShat1.CRSNK.8000.wav"
    , "foot3.TAPP.4000.wav"
    , "heal.BLIH.2000.wav"
    , "twoStep1.TAPTIP.6000.wav"
    , "click1.CLICK.500.wav"
    , "tap4.FWUMP.5000.wav"
    , "tinitus.RINGGG.8000.wav"
    , "tap3.BRAP.8000.wav"
    , "impact3.CRUMPLE.8000.wav"
    , "smallGlass1.TRINKL.5000.wav"
    , "tap1.TAK.8000.wav"
    , "hit1.SMACK.4000.wav"
    , "slideDoor.DRR.3000.wav"
    , "impact1.CRASH.8000.wav"
    , "knife.SWSH.2000.wav"
    , "elecCrackle.CRAKLE.10000.wav"
    , "smallGlass3.CRTINK.5000.wav"
    , "whiteNoiseFadeIn.FHP.2000.wav"
    , "reload1.CHPCHPCHP.3000.wav"
    , "mini.BRPBRPBRP.12000.wav"
    , "crankSlow.CHNKCHNKCHUNK.5000.wav"
    , "fireLoud.WRRR.10000.wav"
    , "mini1.BRDBRDBRD.12000.wav"
    , "whiteNoiseFadeOut.PHF.2000.wav"
    , "sineRaisePitchTwoSec.BWAAH.3000.wav"
    , "tone440.BEP.8000.wav"
    , "foamSprayLoop.HSSS.5000.wav"
    , "pickUp.SHUHP.2000.wav"
    , "hit.THUD.3000.wav"
    , "missileLaunch.WHSSH.10000.wav"
    , "shotgun.BRAHCHCH.10000.wav"
    , "foot1.TIP.3000.wav"
    , "bangEcho.BANGG.15000.wav"
    , "tele.ZHM.10000.wav"
    , "foot2.TAP.3000.wav"
    , "bang.BANG.15000.wav"
    , "impact4.CRISH.8000.wav"
    ]
gruntS :: SoundID
gruntS = SoundID 0
glassShat2S :: SoundID
glassShat2S = SoundID 1
buzzS :: SoundID
buzzS = SoundID 2
smallGlass2S :: SoundID
smallGlass2S = SoundID 3
skwareFadeTwoSecS :: SoundID
skwareFadeTwoSecS = SoundID 4
sineRaisePitchOneSecS :: SoundID
sineRaisePitchOneSecS = SoundID 5
twoStepSlowS :: SoundID
twoStepSlowS = SoundID 6
smallGlass4S :: SoundID
smallGlass4S = SoundID 7
autoBS :: SoundID
autoBS = SoundID 8
glassShat4S :: SoundID
glassShat4S = SoundID 9
glassShat3S :: SoundID
glassShat3S = SoundID 10
tap2S :: SoundID
tap2S = SoundID 11
impact2S :: SoundID
impact2S = SoundID 12
tone440sawtoothS :: SoundID
tone440sawtoothS = SoundID 13
reloadS :: SoundID
reloadS = SoundID 14
twoStepS :: SoundID
twoStepS = SoundID 15
fireS :: SoundID
fireS = SoundID 16
foamSprayFadeOutS :: SoundID
foamSprayFadeOutS = SoundID 17
explosionS :: SoundID
explosionS = SoundID 18
tapQuietS :: SoundID
tapQuietS = SoundID 19
autoGunS :: SoundID
autoGunS = SoundID 20
glassShat1S :: SoundID
glassShat1S = SoundID 21
foot3S :: SoundID
foot3S = SoundID 22
healS :: SoundID
healS = SoundID 23
twoStep1S :: SoundID
twoStep1S = SoundID 24
click1S :: SoundID
click1S = SoundID 25
tap4S :: SoundID
tap4S = SoundID 26
tinitusS :: SoundID
tinitusS = SoundID 27
tap3S :: SoundID
tap3S = SoundID 28
impact3S :: SoundID
impact3S = SoundID 29
smallGlass1S :: SoundID
smallGlass1S = SoundID 30
tap1S :: SoundID
tap1S = SoundID 31
hit1S :: SoundID
hit1S = SoundID 32
slideDoorS :: SoundID
slideDoorS = SoundID 33
impact1S :: SoundID
impact1S = SoundID 34
knifeS :: SoundID
knifeS = SoundID 35
elecCrackleS :: SoundID
elecCrackleS = SoundID 36
smallGlass3S :: SoundID
smallGlass3S = SoundID 37
whiteNoiseFadeInS :: SoundID
whiteNoiseFadeInS = SoundID 38
reload1S :: SoundID
reload1S = SoundID 39
miniS :: SoundID
miniS = SoundID 40
crankSlowS :: SoundID
crankSlowS = SoundID 41
fireLoudS :: SoundID
fireLoudS = SoundID 42
mini1S :: SoundID
mini1S = SoundID 43
whiteNoiseFadeOutS :: SoundID
whiteNoiseFadeOutS = SoundID 44
sineRaisePitchTwoSecS :: SoundID
sineRaisePitchTwoSecS = SoundID 45
tone440S :: SoundID
tone440S = SoundID 46
foamSprayLoopS :: SoundID
foamSprayLoopS = SoundID 47
pickUpS :: SoundID
pickUpS = SoundID 48
hitS :: SoundID
hitS = SoundID 49
missileLaunchS :: SoundID
missileLaunchS = SoundID 50
shotgunS :: SoundID
shotgunS = SoundID 51
foot1S :: SoundID
foot1S = SoundID 52
bangEchoS :: SoundID
bangEchoS = SoundID 53
teleS :: SoundID
teleS = SoundID 54
foot2S :: SoundID
foot2S = SoundID 55
bangS :: SoundID
bangS = SoundID 56
impact4S :: SoundID
impact4S = SoundID 57

loadMusic :: IO (IM.IntMap Mix.Music)
loadMusic = do
    undercity <- Mix.load "./data/music/firstCompo.mid"
    return $ IM.fromList $ zip [0..]
        [ undercity
        ]
