module Sound.MikMod.Module where
import Foreign.Ptr
import Foreign.Storable
import Foreign.C.Types
import Foreign.C.String
import Data.Functor
import Control.Applicative
import Sound.MikMod.Synonyms
import Sound.MikMod.Types
import Sound.MikMod.Flags
getModuleInfo :: ModuleHandle -> IO ModuleInfo
getModuleInfo ptr = ModuleInfo <$>
(peekCStringError =<< (((\hsc_ptr -> peekByteOff hsc_ptr 0)) ptr :: IO CString)) <*>
(peekCStringError =<< (((\hsc_ptr -> peekByteOff hsc_ptr 8)) ptr :: IO CString)) <*>
(peekCStringMaybe =<< (((\hsc_ptr -> peekByteOff hsc_ptr 16)) ptr :: IO CString)) <*>
(unpackFlags <$> (((\hsc_ptr -> peekByteOff hsc_ptr 24)) ptr :: IO UWORD)) <*>
(fromIntegral <$> (((\hsc_ptr -> peekByteOff hsc_ptr 26)) ptr :: IO UBYTE)) <*>
(fromIntegral <$> (((\hsc_ptr -> peekByteOff hsc_ptr 27)) ptr :: IO UBYTE)) <*>
(fromIntegral <$> (((\hsc_ptr -> peekByteOff hsc_ptr 28)) ptr :: IO UWORD)) <*>
(fromIntegral <$> (((\hsc_ptr -> peekByteOff hsc_ptr 30)) ptr :: IO UWORD)) <*>
(fromIntegral <$> (((\hsc_ptr -> peekByteOff hsc_ptr 32)) ptr :: IO UWORD)) <*>
(fromIntegral <$> (((\hsc_ptr -> peekByteOff hsc_ptr 34)) ptr :: IO UWORD)) <*>
unpackInstrumentNames ptr
peekCStringMaybe :: CString -> IO (Maybe String)
peekCStringMaybe cstr | cstr == nullPtr = return Nothing
| otherwise = Just <$> peekCString cstr
peekCStringError :: CString -> IO String
peekCStringError cstr | cstr == nullPtr = error "peekCStringError NULL"
| otherwise = peekCString cstr
unpackInstrumentNames :: Ptr Module -> IO (Maybe [String])
unpackInstrumentNames mod = do
n <- fromIntegral <$> (((\hsc_ptr -> peekByteOff hsc_ptr 32)) mod :: IO UWORD)
ins0 <- ((\hsc_ptr -> peekByteOff hsc_ptr 40)) mod :: IO (Ptr Instrument)
if (ins0 == nullPtr)
then return Nothing
else do
let ptrs = map (\i -> ins0 `plusPtr` (sizeOfInstrument * i)) [0..n1]
Just <$> mapM getInstrumentName ptrs
getInstrumentName :: Ptr Instrument -> IO String
getInstrumentName ptr = peekCString =<< (((\hsc_ptr -> peekByteOff hsc_ptr 0)) ptr :: IO CString)
getModuleSamples :: ModuleHandle -> IO [SampleHandle]
getModuleSamples mod = do
nsamps <- moduleNumSamples <$> getModuleInfo mod
samps <- ((\hsc_ptr -> peekByteOff hsc_ptr 48)) mod
let stride = ((88))
return (map (\i -> samps `plusPtr` (i*stride)) [0..nsamps1])
sizeOfInstrument :: Int
sizeOfInstrument = ((784))
getModuleRealChannels :: ModuleHandle -> IO Int
getModuleRealChannels mod = fromIntegral <$> (((\hsc_ptr -> peekByteOff hsc_ptr 56)) mod :: IO UBYTE)
getModuleTotalChannels :: ModuleHandle -> IO Int
getModuleTotalChannels mod = fromIntegral <$> (((\hsc_ptr -> peekByteOff hsc_ptr 57)) mod :: IO UBYTE)
getModuleSongTime :: ModuleHandle -> IO Integer
getModuleSongTime mod = fromIntegral <$> (((\hsc_ptr -> peekByteOff hsc_ptr 288)) mod :: IO ULONG)
getModuleSongPosition :: ModuleHandle -> IO Int
getModuleSongPosition mod = fromIntegral <$> (((\hsc_ptr -> peekByteOff hsc_ptr 286)) mod :: IO SWORD)
getModulePatternPosition :: ModuleHandle -> IO Int
getModulePatternPosition mod = fromIntegral <$> (((\hsc_ptr -> peekByteOff hsc_ptr 284)) mod :: IO UWORD)
setModuleInitSpeed :: ModuleHandle -> Int -> IO ()
setModuleInitSpeed mod s = ((\hsc_ptr -> pokeByteOff hsc_ptr 60)) mod (fromIntegral s :: UBYTE)
getModuleInitSpeed :: ModuleHandle -> IO Int
getModuleInitSpeed mod = fromIntegral <$> (((\hsc_ptr -> peekByteOff hsc_ptr 60)) mod :: IO UBYTE)
setModuleInitTempo :: ModuleHandle -> Int -> IO ()
setModuleInitTempo mod temp = ((\hsc_ptr -> pokeByteOff hsc_ptr 62)) mod (fromIntegral temp :: UBYTE)
getModuleInitTempo :: ModuleHandle -> IO Int
getModuleInitTempo mod = fromIntegral <$> (((\hsc_ptr -> peekByteOff hsc_ptr 62)) mod :: IO UBYTE)
setModulePanning :: ModuleHandle
-> Int
-> Int
-> IO ()
setModulePanning mod ch pan = do
nchans <- moduleNumChannels <$> getModuleInfo mod
chans <- ((\hsc_ptr -> peekByteOff hsc_ptr 66)) mod :: IO (Ptr UWORD)
if (ch >= 0 && ch < nchans)
then pokeElemOff chans ch (fromIntegral pan)
else return ()
getModulePanning :: ModuleHandle -> Int -> IO Int
getModulePanning mod ch = do
nchans <- moduleNumChannels <$> getModuleInfo mod
chans <- ((\hsc_ptr -> peekByteOff hsc_ptr 66)) mod :: IO (Ptr UWORD)
if (ch >= 0 && ch < nchans)
then fromIntegral <$> peekElemOff chans ch
else return 0
setModuleChannelVolume :: ModuleHandle
-> Int
-> Int
-> IO ()
setModuleChannelVolume mod ch vol = do
nchans <- moduleNumChannels <$> getModuleInfo mod
chans <- ((\hsc_ptr -> peekByteOff hsc_ptr 194)) mod :: IO (Ptr UBYTE)
if (ch >= 0 && ch < nchans)
then pokeElemOff chans ch (fromIntegral vol)
else return ()
getModuleChannelVolume :: ModuleHandle -> Int -> IO Int
getModuleChannelVolume mod ch = do
nchans <- moduleNumChannels <$> getModuleInfo mod
chans <- ((\hsc_ptr -> peekByteOff hsc_ptr 194)) mod :: IO (Ptr UBYTE)
if (ch >= 0 && ch < nchans)
then fromIntegral <$> peekElemOff chans ch
else return 0
setModuleBPM :: ModuleHandle -> Int -> IO ()
setModuleBPM mod bpm = ((\hsc_ptr -> pokeByteOff hsc_ptr 258)) mod (fromIntegral bpm :: UWORD)
getModuleBPM :: ModuleHandle -> IO Int
getModuleBPM mod = fromIntegral <$> (((\hsc_ptr -> peekByteOff hsc_ptr 258)) mod :: IO UWORD)
setModuleSongSpeed :: ModuleHandle -> Int -> IO ()
setModuleSongSpeed mod spd = ((\hsc_ptr -> pokeByteOff hsc_ptr 260)) mod (fromIntegral spd :: UBYTE)
getModuleSongSpeed :: ModuleHandle -> IO Int
getModuleSongSpeed mod = fromIntegral <$> (((\hsc_ptr -> peekByteOff hsc_ptr 260)) mod :: IO UBYTE)
setModuleExtSpeed :: ModuleHandle -> Bool -> IO ()
setModuleExtSpeed mod flag = ((\hsc_ptr -> pokeByteOff hsc_ptr 264)) mod (encodeBool flag)
getModuleExtSpeed :: ModuleHandle -> IO Bool
getModuleExtSpeed mod = decodeBool <$> ((\hsc_ptr -> peekByteOff hsc_ptr 264)) mod
setModulePanFlag :: ModuleHandle -> Bool -> IO ()
setModulePanFlag mod flag = ((\hsc_ptr -> pokeByteOff hsc_ptr 268)) mod (encodeBool flag)
getModulePanFlag :: ModuleHandle -> IO Bool
getModulePanFlag mod = decodeBool <$> ((\hsc_ptr -> peekByteOff hsc_ptr 268)) mod
setModuleWrap :: ModuleHandle -> Bool -> IO ()
setModuleWrap mod flag = ((\hsc_ptr -> pokeByteOff hsc_ptr 272)) mod (encodeBool flag)
getModuleWrap :: ModuleHandle -> IO Bool
getModuleWrap mod = decodeBool <$> ((\hsc_ptr -> peekByteOff hsc_ptr 272)) mod
setModuleRepeatPosition :: ModuleHandle -> Int -> IO ()
setModuleRepeatPosition mod pos = ((\hsc_ptr -> pokeByteOff hsc_ptr 58)) mod (fromIntegral pos :: UBYTE)
getModuleRepeatPosition :: ModuleHandle -> IO Int
getModuleRepeatPosition mod = fromIntegral <$> (((\hsc_ptr -> peekByteOff hsc_ptr 58)) mod :: IO UBYTE)
setModuleLoop :: ModuleHandle -> Bool -> IO ()
setModuleLoop mod flag = ((\hsc_ptr -> pokeByteOff hsc_ptr 276)) mod (encodeBool flag :: BOOL)
getModuleLoop :: ModuleHandle -> IO Bool
getModuleLoop mod = decodeBool <$> ((\hsc_ptr -> peekByteOff hsc_ptr 276)) mod
setModuleFadeout :: ModuleHandle -> Bool -> IO ()
setModuleFadeout mod flag = ((\hsc_ptr -> pokeByteOff hsc_ptr 280)) mod (encodeBool flag)
getModuleFadeout :: ModuleHandle -> IO Bool
getModuleFadeout mod = decodeBool <$> (((\hsc_ptr -> peekByteOff hsc_ptr 280)) mod :: IO BOOL)
setModuleRelativeSpeed :: ModuleHandle -> Int -> IO ()
setModuleRelativeSpeed mod s = ((\hsc_ptr -> pokeByteOff hsc_ptr 292)) mod (fromIntegral s :: SWORD)
getModuleRelativeSpeed :: ModuleHandle -> IO Int
getModuleRelativeSpeed mod = fromIntegral <$> (((\hsc_ptr -> peekByteOff hsc_ptr 292)) mod :: IO SWORD)