module Sound.OSC.Datum where
import qualified Data.ByteString.Lazy as B
import qualified Data.ByteString.Char8 as C
import Data.Int
import Data.Word
import Sound.OSC.Type
datum_int32 :: Datum -> Maybe Int32
datum_int32 = d_get
datum_int64 :: Datum -> Maybe Int64
datum_int64 = d_get
datum_float :: Datum -> Maybe Float
datum_float = d_get
datum_double :: Datum -> Maybe Double
datum_double = d_get
datum_ascii :: Datum -> Maybe ASCII
datum_ascii = d_get
datum_string :: Datum -> Maybe String
datum_string = fmap C.unpack . datum_ascii
datum_blob :: Datum -> Maybe B.ByteString
datum_blob = d_get
datum_timestamp :: Datum -> Maybe Time
datum_timestamp d = case d of {TimeStamp x -> Just x;_ -> Nothing}
datum_midi :: Datum -> Maybe MIDI
datum_midi = d_get
datum_sequence :: Datum -> Maybe [Word8]
datum_sequence d =
case d of
ASCII_String s -> Just (map (fromIntegral . fromEnum) (C.unpack s))
Blob s -> Just (B.unpack s)
Midi (MIDI p q r s) -> Just [p,q,r,s]
_ -> Nothing