module Sound.OSC.Normalise where
import Sound.OSC.Type as O
normalise_datum :: Datum -> Datum
normalise_datum d =
case d of
Int32 n -> Int64 (fromIntegral n)
Float n -> Double (realToFrac n)
_ -> d
normalise_message :: Message -> Message
normalise_message = message_coerce normalise_datum
normalise_bundle :: Bundle -> Bundle
normalise_bundle = bundle_coerce normalise_datum
message_coerce :: (Datum -> Datum) -> Message -> Message
message_coerce f (Message s xs) = Message s (map f xs)
bundle_coerce :: (Datum -> Datum) -> Bundle -> Bundle
bundle_coerce f (Bundle t xs) = Bundle t (map (message_coerce f) xs)
datum_promote :: Datum -> Datum
datum_promote d =
case d of
Int32 n -> Double (fromIntegral n)
Int64 n -> Double (fromIntegral n)
Float n -> Double (realToFrac n)
_ -> d
datum_floor :: Datum -> Datum
datum_floor d =
case d of
Int32 x -> Int64 (fromIntegral x)
Float x -> Int64 (fromInteger (floor x))
Double x -> Int64 (fromInteger (floor x))
_ -> d