-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/

-- | Haskell Open Sound Control
--   
--   hosc implements a subset of the Open Sound Control byte
--   protocol, http://opensoundcontrol.org/.
--   
--   See Sound.OSC.Core or Sound.OSC or Sound.OSC.FD.
@package hosc
@version 0.17

-- | Bit-level type casts and byte layout string typecasts.
module Sound.OSC.Coding.Cast

-- | The IEEE byte representation of a float.
f32_w32 :: Float -> Word32

-- | Inverse of f32_w32.
w32_f32 :: Word32 -> Float

-- | The IEEE byte representation of a double.
f64_w64 :: Double -> Word64

-- | Inverse of f64_i64.
w64_f64 :: Word64 -> Double

-- | Transform a haskell string into a C string (a null suffixed byte
--   string).
str_cstr :: String -> [Word8]

-- | Inverse of str_cstr.
cstr_str :: [Word8] -> String

-- | Transform a haskell string to a pascal string (a length prefixed byte
--   string).
str_pstr :: String -> [Word8]

-- | Inverse of str_pstr.
pstr_str :: [Word8] -> String

-- | Type conversion.
module Sound.OSC.Coding.Convert

-- | Type specialised fromIntegral
int_to_word8 :: Int -> Word8

-- | Type specialised fromIntegral
int_to_word32 :: Int -> Word32

-- | Type specialised fromIntegral.
int_to_word16 :: Int -> Word16

-- | Type specialised fromIntegral
int_to_int8 :: Int -> Int8

-- | Type specialised fromIntegral
int_to_int16 :: Int -> Int16

-- | Type specialised fromIntegral
int_to_int32 :: Int -> Int32

-- | Type specialised fromIntegral
int8_to_int :: Int8 -> Int

-- | Type specialised fromIntegral
int16_to_int :: Int16 -> Int

-- | Type specialised fromIntegral
int32_to_int :: Int32 -> Int

-- | Type specialised fromIntegral
word8_to_int :: Word8 -> Int

-- | Type specialised fromIntegral
word16_to_int :: Word16 -> Int

-- | Type specialised fromIntegral
word32_to_int :: Word32 -> Int

-- | Byte-level coding utility functions. Plain forms are big-endian,
--   little-endian forms have _le suffix.
module Sound.OSC.Coding.Byte

-- | Encode a signed 8-bit integer.
encode_i8 :: Int -> ByteString

-- | Encode an un-signed 8-bit integer.
encode_u8 :: Int -> ByteString

-- | Type specialised encode.
--   
--   
--   encode_w16 0x0102 == L.pack [1,2]
--   
encode_w16 :: Word16 -> ByteString

-- | Little-endian.
--   
--   
--   encode_w16_le 0x0102 == L.pack [2,1]
--   
encode_w16_le :: Word16 -> ByteString

-- | Encode an un-signed 16-bit integer.
--   
--   
--   encode_u16 0x0102 == L.pack [1,2]
--   
encode_u16 :: Int -> ByteString

-- | Little-endian.
--   
--   
--   encode_u16_le 0x0102 == L.pack [2,1]
--   
encode_u16_le :: Int -> ByteString

-- | Encode a signed 16-bit integer.
encode_i16 :: Int -> ByteString

-- | Encode a signed 32-bit integer.
encode_i32 :: Int -> ByteString

-- | Type specialised encode.
encode_w32 :: Word32 -> ByteString

-- | Encode an unsigned 32-bit integer.
--   
--   
--   encode_u32 0x01020304 == L.pack [1,2,3,4]
--   
encode_u32 :: Int -> ByteString

-- | Little-endian variant of encode_w32.
encode_w32_le :: Word32 -> ByteString

-- | Little-endian.
--   
--   
--   encode_u32_le 0x01020304 == L.pack [4,3,2,1]
--   
encode_u32_le :: Int -> ByteString

-- | Encode a signed 64-bit integer.
encode_i64 :: Int64 -> ByteString

-- | Encode an unsigned 64-bit integer.
encode_u64 :: Word64 -> ByteString

-- | Encode a 32-bit IEEE floating point number.
encode_f32 :: Float -> ByteString

-- | Little-endian variant of encode_f32.
encode_f32_le :: Float -> ByteString

-- | Encode a 64-bit IEEE floating point number.
encode_f64 :: Double -> ByteString

-- | Encode an ASCII string (ASCII at Datum is an alias for a Char8
--   Bytetring).
encode_str :: ByteString -> ByteString

-- | Decode an un-signed 8-bit integer.
decode_u8 :: ByteString -> Int

-- | Decode a signed 8-bit integer.
decode_i8 :: ByteString -> Int

-- | Type specialised decode.
decode_word16 :: ByteString -> Word16

-- | Decode an unsigned 8-bit integer.
decode_u16 :: ByteString -> Int

-- | Little-endian variant of decode_word16.
decode_word16_le :: ByteString -> Word16

-- | Little-endian variant of decode_u16.
decode_u16_le :: ByteString -> Int

-- | Type specialised decode.
decode_int16 :: ByteString -> Int16

-- | Decode a signed 16-bit integer.
decode_i16 :: ByteString -> Int

-- | Little-endian variant of decode_i16.
decode_i16_le :: ByteString -> Int

-- | Decode a signed 32-bit integer.
decode_i32 :: ByteString -> Int

-- | Type specialised decode.
decode_word32 :: ByteString -> Word32

-- | Decode an unsigned 32-bit integer.
--   
--   
--   decode_u32 (L.pack [1,2,3,4]) == 0x01020304
--   
decode_u32 :: ByteString -> Int

-- | Little-endian variant of decode_word32.
decode_word32_le :: ByteString -> Word32

-- | Little-endian variant of decode_u32.
--   
--   
--   decode_u32_le (L.pack [1,2,3,4]) == 0x04030201
--   
decode_u32_le :: ByteString -> Int

-- | Type specialised decode.
decode_i64 :: ByteString -> Int64

-- | Type specialised decode.
decode_u64 :: ByteString -> Word64

-- | Decode a 32-bit IEEE floating point number.
decode_f32 :: ByteString -> Float

-- | Little-endian variant of decode_f32.
decode_f32_le :: ByteString -> Float

-- | Decode a 64-bit IEEE floating point number.
decode_f64 :: ByteString -> Double

-- | Decode an ASCII string, inverse of encode_str.
decode_str :: ByteString -> ByteString

-- | decode_i8 of hGet.
read_i8 :: Handle -> IO Int

-- | decode_i16 of hGet.
read_i16 :: Handle -> IO Int

-- | decode_i32 of hGet.
read_i32 :: Handle -> IO Int

-- | decode_u32 of hGet.
read_u32 :: Handle -> IO Int

-- | decode_u32_le of hGet.
read_u32_le :: Handle -> IO Int

-- | decode_f32 of hGet.
read_f32 :: Handle -> IO Float

-- | Read u8 length prefixed ASCII string (pascal string).
read_pstr :: Handle -> IO ByteString

-- | hPut of encode_u32.
write_u32 :: Handle -> Int -> IO ()

-- | hPut of encode_u32_le.
write_u32_le :: Handle -> Int -> IO ()

-- | Bundle header as a (strict) ByteString.
bundleHeader_strict :: ByteString

-- | Bundle header as a lazy ByteString.
bundleHeader :: ByteString

-- | The number of bytes required to align an OSC value to the next 4-byte
--   boundary.
--   
--   
--   map align [0::Int .. 7] == [0,3,2,1,0,3,2,1]
--   
align :: (Num i, Bits i) => i -> i

-- | OSC related timing functions. OSC timestamps are 64-bit NTP
--   values, http://ntp.org/.
module Sound.OSC.Time

-- | Type for binary (integeral) representation of a 64-bit NTP
--   timestamp (ie. ntpi). The NTP epoch is January 1, 1900. NTPv4
--   also includes a 128-bit format, which is not used by OSC.
type NTP64 = Word64

-- | NTP time in real-valued (fractional) form (ie.
--   ntpr). This is the primary form of timestamp used by hosc.
type Time = Double

-- | Constant indicating a bundle to be executed immediately. It has the
--   NTP64 representation of 1.
immediately :: Time

-- | Unix/Posix time in real-valued (fractional) form. The
--   Unix/Posix epoch is January 1, 1970.
type UT = Double

-- | Convert a real-valued NTP timestamp to an NTPi timestamp.
--   
--   
--   ntpr_to_ntpi immediately == 1
--   fmap ntpr_to_ntpi time
--   
ntpr_to_ntpi :: RealFrac n => n -> NTP64

-- | Convert an NTPi timestamp to a real-valued NTP timestamp.
ntpi_to_ntpr :: Fractional n => NTP64 -> n

-- | Difference (in seconds) between NTP and UT epochs.
--   
--   
--   ntp_ut_epoch_diff / (24 * 60 * 60) == 25567
--   25567 `div` 365 == 70
--   
ntp_ut_epoch_diff :: Num n => n

-- | Convert a UT timestamp to an NTPi timestamp.
ut_to_ntpi :: UT -> NTP64

-- | Convert Unix/Posix to NTP.
ut_to_ntpr :: Num n => n -> n

-- | Convert NTP to Unix/Posix.
ntpr_to_ut :: Num n => n -> n

-- | Convert NTPi to Unix/Posix.
ntpi_to_ut :: NTP64 -> UT

-- | Convert Time to POSIXTime.
ntpr_to_posixtime :: Time -> POSIXTime

-- | Convert POSIXTime to Time.
posixtime_to_ntpr :: POSIXTime -> Time

-- | The time at 1970-01-01:00:00:00.
ut_epoch :: UTCTime

-- | Convert UTCTime to Unix/Posix.
utc_to_ut :: Fractional n => UTCTime -> n

-- | Read current real-valued NTP timestamp.
--   
--   
--   get_ct = fmap utc_to_ut T.getCurrentTime
--   get_pt = fmap realToFrac T.getPOSIXTime
--   (ct,pt) <- get_ct >>= \t0 -> get_pt >>= \t1 -> return (t0,t1)
--   print (pt - ct,pt - ct < 1e-5)
--   
time :: MonadIO m => m Time

-- | The pauseThread limit (in seconds). Values larger than this
--   require a different thread delay mechanism, see sleepThread.
--   The value is the number of microseconds in maxBound::Int.
pauseThreadLimit :: Fractional n => n

-- | Pause current thread for the indicated duration (in seconds), see
--   pauseThreadLimit.
pauseThread :: (MonadIO m, RealFrac n) => n -> m ()

-- | Type restricted pauseThread.
wait :: MonadIO m => Double -> m ()

-- | Pause current thread until the given Time, see
--   pauseThreadLimit.
pauseThreadUntil :: MonadIO m => Time -> m ()

-- | Sleep current thread for the indicated duration (in seconds). Divides
--   long sleeps into parts smaller than pauseThreadLimit.
sleepThread :: (RealFrac n, MonadIO m) => n -> m ()

-- | Sleep current thread until the given Time. Divides long sleeps
--   into parts smaller than pauseThreadLimit.
sleepThreadUntil :: MonadIO m => Time -> m ()

-- | Detailed 37-character ISO 8601 format, including fractional seconds
--   and '+0000' suffix.
iso_8601_fmt :: String

-- | Parse time according to iso_8601_fmt
--   
--   
--   iso_8601_to_utctime "2015-11-26T00:29:37,145875000000+0000"
--   
iso_8601_to_utctime :: String -> Maybe UTCTime

-- | UTC time in iso_8601_fmt.
--   
--   
--   tm <- fmap (utctime_to_iso_8601 . T.posixSecondsToUTCTime) T.getPOSIXTime
--   (length tm,sum [4+1+2+1+2,1,2+1+2+1+2,1,12,1,4],sum [10,1,8,1,12,1,4]) == (37,37,37)
--   
utctime_to_iso_8601 :: UTCTime -> String

-- | ISO 8601 of Time.
--   
--   
--   tm <- fmap ntpr_to_iso_8601 time
--   import System.Process {- process -}
--   rawSystem "date" ["-d",tm]
--   
--   
--   
--   t = 15708783354150518784
--   s = "2015-11-26T00:22:19,366058349609+0000"
--   ntpr_to_iso_8601 (ntpi_to_ntpr t) == s
--   
ntpr_to_iso_8601 :: Time -> String

-- | Time of ISO 8601.
--   
--   
--   t = 15708783354150518784
--   s = "2015-11-26T00:22:19,366058349609+0000"
--   fmap ntpr_to_ntpi (iso_8601_to_ntpr s) == Just t
--   
iso_8601_to_ntpr :: String -> Maybe Time

-- | Alias for ntpr_to_iso_8601.
--   
--   
--   time_pp immediately == "1900-01-01T00:00:00,000000000000+0000"
--   fmap time_pp time
--   
time_pp :: Time -> String

-- | Data type for OSC datum.
module Sound.OSC.Datum

-- | Type enumerating Datum categories.
type Datum_Type = Char

-- | Type for ASCII strings (strict Char8 ByteString).
type ASCII = ByteString

-- | Type-specialised pack.
ascii :: String -> ASCII

-- | Type-specialised unpack.
ascii_to_string :: ASCII -> String

-- | Type for Word8 arrays, these are stored with an Int32
--   length prefix.
type BLOB = ByteString

-- | Type-specialised pack.
blob_pack :: [Word8] -> BLOB

-- | Type-specialised unpack.
blob_unpack :: BLOB -> [Word8]

-- | Four-byte midi message: port-id, status-byte, data, data.
data MIDI
MIDI :: Word8 -> Word8 -> Word8 -> Word8 -> MIDI

-- | The basic elements of OSC messages.
data Datum
Int32 :: Int32 -> Datum
[d_int32] :: Datum -> Int32
Int64 :: Int64 -> Datum
[d_int64] :: Datum -> Int64
Float :: Float -> Datum
[d_float] :: Datum -> Float
Double :: Double -> Datum
[d_double] :: Datum -> Double
ASCII_String :: ASCII -> Datum
[d_ascii_string] :: Datum -> ASCII
Blob :: BLOB -> Datum
[d_blob] :: Datum -> BLOB
TimeStamp :: Time -> Datum
[d_timestamp] :: Datum -> Time
Midi :: MIDI -> Datum
[d_midi] :: Datum -> MIDI

-- | List of required data types (tag,name).
osc_types_required :: [(Datum_Type, String)]

-- | List of optional data types (tag,name).
osc_types_optional :: [(Datum_Type, String)]

-- | List of all data types (tag,name).
osc_types :: [(Datum_Type, String)]

-- | Lookup name of type.
osc_type_name :: Datum_Type -> Maybe String

-- | Erroring variant.
osc_type_name_err :: Datum_Type -> String

-- | Single character identifier of an OSC datum.
datum_tag :: Datum -> Datum_Type

-- | Type and name of Datum.
datum_type_name :: Datum -> (Datum_Type, String)

-- | Datum as Integral if Int32 or Int64.
--   
--   
--   let d = [Int32 5,Int64 5,Float 5.5,Double 5.5]
--   map datum_integral d == [Just (5::Int),Just 5,Nothing,Nothing]
--   
datum_integral :: Integral i => Datum -> Maybe i

-- | Datum as Floating if Int32, Int64, Float, Double or
--   TimeStamp.
--   
--   
--   let d = [Int32 5,Int64 5,Float 5,Double 5,TimeStamp 5]
--   mapMaybe datum_floating d == replicate 5 (5::Double)
--   
datum_floating :: Floating n => Datum -> Maybe n

-- | Type generalised Int32.
--   
--   
--   int32 (1::Int32) == int32 (1::Integer)
--   d_int32 (int32 (maxBound::Int32)) == maxBound
--   int32 (((2::Int) ^ (64::Int))::Int) == Int32 0
--   
int32 :: Integral n => n -> Datum

-- | Type generalised Int64.
--   
--   
--   int64 (1::Int32) == int64 (1::Integer)
--   d_int64 (int64 (maxBound::Int64)) == maxBound
--   
int64 :: Integral n => n -> Datum

-- | Type generalised Float.
--   
--   
--   float (1::Int) == float (1::Double)
--   floatRange (undefined::Float) == (-125,128)
--   isInfinite (d_float (float (encodeFloat 1 256 :: Double))) == True
--   
float :: Real n => n -> Datum

-- | Type generalised Double.
--   
--   
--   double (1::Int) == double (1::Double)
--   double (encodeFloat 1 256 :: Double) == Double 1.157920892373162e77
--   
double :: Real n => n -> Datum

-- | ASCII_String of pack.
--   
--   
--   string "string" == ASCII_String (Char8.pack "string")
--   
string :: String -> Datum

-- | Four-tuple variant of Midi . MIDI.
--   
--   
--   midi (0,0,0,0) == Midi (MIDI 0 0 0 0)
--   
midi :: (Word8, Word8, Word8, Word8) -> Datum

-- | Message argument types are given by a descriptor.
--   
--   
--   descriptor [Int32 1,Float 1,string "1"] == ascii ",ifs"
--   
descriptor :: [Datum] -> ASCII

-- | Descriptor tags are comma prefixed.
descriptor_tags :: ASCII -> ASCII

-- | Perhaps a precision value for floating point numbers.
type FP_Precision = Maybe Int

-- | Variant of showFFloat that deletes trailing zeros.
--   
--   
--   map (floatPP (Just 4)) [1,pi] == ["1.0","3.1416"]
--   
floatPP :: RealFloat n => Maybe Int -> n -> String

-- | Pretty printer for Time.
--   
--   
--   timePP (Just 4) (1/3) == "0.3333"
--   
timePP :: FP_Precision -> Time -> String

-- | Pretty printer for vectors.
--   
--   
--   vecPP [1::Int,2,3] == "<1,2,3>"
--   
vecPP :: Show a => [a] -> String

-- | Pretty printer for Datum.
--   
--   
--   let d = [Int32 1,Float 1.2,string "str",midi (0,0x90,0x40,0x60)]
--   in map (datumPP (Just 5)) d ==  ["1","1.2","\"str\"","<0,144,64,96>"]
--   
datumPP :: FP_Precision -> Datum -> String

-- | Variant of datumPP that appends the datum_type_name.
datum_pp_typed :: FP_Precision -> Datum -> String

-- | Given Datum_Type attempt to parse Datum at
--   String.
--   
--   
--   parse_datum 'i' "42" == Just (Int32 42)
--   parse_datum 'h' "42" == Just (Int64 42)
--   parse_datum 'f' "3.14159" == Just (Float 3.14159)
--   parse_datum 'd' "3.14159" == Just (Double 3.14159)
--   parse_datum 's' "\"pi\"" == Just (string "pi")
--   parse_datum 'b' "[112,105]" == Just (Blob (blob_pack [112,105]))
--   parse_datum 'm' "(0,144,60,90)" == Just (midi (0,144,60,90))
--   
parse_datum :: Datum_Type -> String -> Maybe Datum

-- | Erroring variant of parse_datum.
parse_datum_err :: Datum_Type -> String -> Datum
instance GHC.Show.Show Sound.OSC.Datum.Datum
instance GHC.Read.Read Sound.OSC.Datum.Datum
instance GHC.Classes.Eq Sound.OSC.Datum.Datum
instance GHC.Read.Read Sound.OSC.Datum.MIDI
instance GHC.Show.Show Sound.OSC.Datum.MIDI
instance GHC.Classes.Eq Sound.OSC.Datum.MIDI

-- | Data types for OSC messages, bundles and packets.
module Sound.OSC.Packet

-- | OSC address pattern. This is strictly an ASCII value, however it is
--   very common to pattern match on addresses and matching on
--   ByteString requires OverloadedStrings.
type Address_Pattern = String

-- | An OSC message, an Address_Pattern and a sequence of
--   Datum.
data Message
Message :: Address_Pattern -> [Datum] -> Message
[messageAddress] :: Message -> Address_Pattern
[messageDatum] :: Message -> [Datum]

-- | Message constructor. It is an error if the
--   Address_Pattern doesn't conform to the OSC specification.
message :: Address_Pattern -> [Datum] -> Message

-- | An OSC bundle, a Time and a sequence of Messages.
data Bundle
Bundle :: Time -> [Message] -> Bundle
[bundleTime] :: Bundle -> Time
[bundleMessages] :: Bundle -> [Message]

-- | Bundle constructor. It is an error if the Message
--   list is empty.
bundle :: Time -> [Message] -> Bundle

-- | An OSC Packet is either a Message or a Bundle.
data Packet
Packet_Message :: Message -> Packet
[packetMessage] :: Packet -> Message
Packet_Bundle :: Bundle -> Packet
[packetBundle] :: Packet -> Bundle

-- | Packet_Bundle of bundle.
p_bundle :: Time -> [Message] -> Packet

-- | Packet_Message of message.
p_message :: Address_Pattern -> [Datum] -> Packet

-- | The Time of Packet, if the Packet is a
--   Message this is immediately.
packetTime :: Packet -> Time

-- | Retrieve the set of Messages from a Packet.
packetMessages :: Packet -> [Message]

-- | If Packet is a Message add immediately timestamp,
--   else id.
packet_to_bundle :: Packet -> Bundle

-- | If Packet is a Message or a Bundle with an
--   immediate time tag and with one element, return the
--   Message, else Nothing.
packet_to_message :: Packet -> Maybe Message

-- | Is Packet immediate, ie. a Bundle with timestamp
--   immediately, or a plain Message.
packet_is_immediate :: Packet -> Bool

-- | Variant of either for Packet.
at_packet :: (Message -> a) -> (Bundle -> a) -> Packet -> a

-- | Does Message have the specified Address_Pattern.
message_has_address :: Address_Pattern -> Message -> Bool

-- | Do any of the Messages at Bundle have the specified
--   Address_Pattern.
bundle_has_address :: Address_Pattern -> Bundle -> Bool

-- | Does Packet have the specified Address_Pattern, ie.
--   message_has_address or bundle_has_address.
packet_has_address :: Address_Pattern -> Packet -> Bool

-- | Pretty printer for Message.
messagePP :: FP_Precision -> Message -> String

-- | Pretty printer for Bundle.
bundlePP :: FP_Precision -> Bundle -> String

-- | Pretty printer for Packet.
packetPP :: FP_Precision -> Packet -> String
instance GHC.Show.Show Sound.OSC.Packet.Packet
instance GHC.Read.Read Sound.OSC.Packet.Packet
instance GHC.Classes.Eq Sound.OSC.Packet.Packet
instance GHC.Show.Show Sound.OSC.Packet.Bundle
instance GHC.Read.Read Sound.OSC.Packet.Bundle
instance GHC.Classes.Eq Sound.OSC.Packet.Bundle
instance GHC.Show.Show Sound.OSC.Packet.Message
instance GHC.Read.Read Sound.OSC.Packet.Message
instance GHC.Classes.Eq Sound.OSC.Packet.Message
instance GHC.Classes.Ord Sound.OSC.Packet.Bundle

-- | Optimised encode function for OSC packets.
module Sound.OSC.Coding.Encode.Builder

-- | Builder for an OSC Packet.
build_packet :: Packet -> Builder

-- | Encode an OSC Message, ie. encodePacket of
--   Packet_Message.
--   
--   
--   let m = [47,103,95,102,114,101,101,0,44,105,0,0,0,0,0,0]
--   encodeMessage (Message "/g_free" [Int32 0]) == L.pack m
--   
encodeMessage :: Message -> ByteString

-- | Encode an OSC Bundle, ie. encodePacket of
--   Packet_Bundle.
--   
--   
--   let m = [47,103,95,102,114,101,101,0,44,105,0,0,0,0,0,0]
--   let b = [35,98,117,110,100,108,101,0,0,0,0,0,0,0,0,1,0,0,0,16] ++ m
--   encodeBundle (Bundle immediately [Message "/g_free" [Int32 0]]) == L.pack b
--   
encodeBundle :: Bundle -> ByteString

-- | Encode an OSC Packet.
encodePacket :: Packet -> ByteString

-- | Encode an OSC Packet to a strict ByteString.
encodePacket_strict :: Packet -> ByteString

-- | Base-level encode function for OSC packets (slow). For ordinary use
--   see Builder.
module Sound.OSC.Coding.Encode.Base

-- | Align byte string, if required.
extend :: Word8 -> ByteString -> ByteString

-- | Encode OSC Datum.
encode_datum :: Datum -> ByteString

-- | Encode OSC Message.
encodeMessage :: Message -> ByteString

-- | Encode OSC Message as an OSC blob.
encode_message_blob :: Message -> Datum

-- | Encode OSC Bundle.
encodeBundle :: Bundle -> ByteString

-- | Encode OSC Packet.
encodePacket :: Packet -> ByteString

-- | Optimised decode function for OSC packets.
module Sound.OSC.Coding.Decode.Binary

-- | Get an OSC Packet.
get_packet :: Get Packet

-- | Decode an OSC Message from a lazy ByteString.
--   
--   
--   let b = B.pack [47,103,95,102,114,101,101,0,44,105,0,0,0,0,0,0]
--   decodeMessage b == Message "/g_free" [Int32 0]
--   
decodeMessage :: ByteString -> Message

-- | Decode an OSC Bundle from a lazy ByteString.
decodeBundle :: ByteString -> Bundle

-- | Decode an OSC packet from a lazy ByteString.
--   
--   
--   let b = B.pack [47,103,95,102,114,101,101,0,44,105,0,0,0,0,0,0]
--   decodePacket b == Packet_Message (Message "/g_free" [Int32 0])
--   
decodePacket :: ByteString -> Packet

-- | Decode an OSC packet from a strict ByteString.
decodePacket_strict :: ByteString -> Packet

-- | Base-level decode function for OSC packets. For ordinary use see
--   Binary.
module Sound.OSC.Coding.Decode.Base

-- | Decode an OSC Message.
decodeMessage :: ByteString -> Message

-- | Decode an OSC Bundle.
decodeBundle :: ByteString -> Bundle

-- | Decode an OSC Packet.
--   
--   
--   let b = B.pack [47,103,95,102,114,101,101,0,44,105,0,0,0,0,0,0]
--   in decodePacket b == Message "/g_free" [Int 0]
--   
decodePacket :: ByteString -> Packet

-- | Waiting (for replies).
module Sound.OSC.Wait

-- | Variant of timeout where time is given in fractional seconds.
timeout_r :: Double -> IO a -> IO (Maybe a)

-- | Repeat action until predicate f is True when applied to
--   result.
untilPredicate :: Monad m => (a -> Bool) -> m a -> m a

-- | Repeat action until f does not give Nothing when applied
--   to result.
untilMaybe :: Monad m => (a -> Maybe b) -> m a -> m b

-- | An abstract transport layer with implementations for UDP and
--   TCP transport.
module Sound.OSC.Transport.FD

-- | Abstract over the underlying transport protocol.
class Transport t

-- | Encode and send an OSC packet.
sendPacket :: Transport t => t -> Packet -> IO ()

-- | Receive and decode an OSC packet.
recvPacket :: Transport t => t -> IO Packet

-- | Close an existing connection.
close :: Transport t => t -> IO ()

-- | Bracket OSC communication.
withTransport :: Transport t => IO t -> (t -> IO a) -> IO a

-- | sendPacket of Packet_Message.
sendMessage :: Transport t => t -> Message -> IO ()

-- | sendPacket of Packet_Bundle.
sendBundle :: Transport t => t -> Bundle -> IO ()

-- | Variant of recvPacket that runs packet_to_bundle.
recvBundle :: Transport t => t -> IO Bundle

-- | Variant of recvPacket that runs packet_to_message.
recvMessage :: Transport t => t -> IO (Maybe Message)

-- | Variant of recvPacket that runs packetMessages.
recvMessages :: Transport t => t -> IO [Message]

-- | Variant of recvPacket that implements an n second
--   timeout.
recvPacketTimeout :: Transport t => Double -> t -> IO (Maybe Packet)

-- | Wait for a Packet where the supplied predicate is True,
--   discarding intervening packets.
waitUntil :: Transport t => t -> (Packet -> Bool) -> IO Packet

-- | Wait for a Packet where the supplied function does not give
--   Nothing, discarding intervening packets.
waitFor :: Transport t => t -> (Packet -> Maybe a) -> IO a

-- | waitUntil packet_is_immediate.
waitImmediate :: Transport t => t -> IO Packet

-- | waitFor packet_to_message, ie. an incoming
--   Message or immediate mode Bundle with one element.
waitMessage :: Transport t => t -> IO Message

-- | A waitFor for variant using packet_has_address to match
--   on the Address_Pattern of incoming Packets.
waitAddress :: Transport t => t -> Address_Pattern -> IO Packet

-- | Variant on waitAddress that returns matching Message.
waitReply :: Transport t => t -> Address_Pattern -> IO Message

-- | Variant of waitReply that runs messageDatum.
waitDatum :: Transport t => t -> Address_Pattern -> IO [Datum]

-- | Monad class implementing an Open Sound Control transport.
module Sound.OSC.Transport.Monad

-- | Sender monad.
class Monad m => SendOSC m

-- | Encode and send an OSC packet.
sendPacket :: SendOSC m => Packet -> m ()

-- | Receiver monad.
class Monad m => RecvOSC m

-- | Receive and decode an OSC packet.
recvPacket :: RecvOSC m => m Packet

-- | DuplexOSC is the union of SendOSC and RecvOSC.
class (SendOSC m, RecvOSC m) => DuplexOSC m

-- | Transport is DuplexOSC with a MonadIO
--   constraint.
class (DuplexOSC m, MonadIO m) => Transport m

-- | Transport connection.
type Connection t a = ReaderT t IO a

-- | Bracket Open Sound Control communication.
withTransport :: Transport t => IO t -> Connection t a -> IO a

-- | Type restricted synonym for sendOSC.
sendMessage :: SendOSC m => Message -> m ()

-- | Type restricted synonym for sendOSC.
sendBundle :: SendOSC m => Bundle -> m ()

-- | Variant of recvPacket that runs packet_to_bundle.
recvBundle :: RecvOSC m => m Bundle

-- | Variant of recvPacket that runs packet_to_message.
recvMessage :: RecvOSC m => m (Maybe Message)

-- | Erroring variant.
recvMessage_err :: RecvOSC m => m Message

-- | Variant of recvPacket that runs packetMessages.
recvMessages :: RecvOSC m => m [Message]

-- | Wait for a Packet where the supplied predicate is
--   True, discarding intervening packets.
waitUntil :: RecvOSC m => (Packet -> Bool) -> m Packet

-- | Wait for a Packet where the supplied function does not give
--   Nothing, discarding intervening packets.
waitFor :: RecvOSC m => (Packet -> Maybe a) -> m a

-- | waitUntil packet_is_immediate.
waitImmediate :: RecvOSC m => m Packet

-- | waitFor packet_to_message, ie. an incoming
--   Message or immediate mode Bundle with one element.
waitMessage :: RecvOSC m => m Message

-- | A waitFor for variant using packet_has_address to
--   match on the Address_Pattern of incoming Packets.
waitAddress :: RecvOSC m => Address_Pattern -> m Packet

-- | Variant on waitAddress that returns matching Message.
waitReply :: RecvOSC m => Address_Pattern -> m Message

-- | Variant of waitReply that runs messageDatum.
waitDatum :: RecvOSC m => Address_Pattern -> m [Datum]
instance (Sound.OSC.Transport.FD.Transport t, Control.Monad.IO.Class.MonadIO io) => Sound.OSC.Transport.Monad.Transport (Control.Monad.Trans.Reader.ReaderT t io)
instance (Sound.OSC.Transport.FD.Transport t, Control.Monad.IO.Class.MonadIO io) => Sound.OSC.Transport.Monad.DuplexOSC (Control.Monad.Trans.Reader.ReaderT t io)
instance (Sound.OSC.Transport.FD.Transport t, Control.Monad.IO.Class.MonadIO io) => Sound.OSC.Transport.Monad.RecvOSC (Control.Monad.Trans.Reader.ReaderT t io)
instance (Sound.OSC.Transport.FD.Transport t, Control.Monad.IO.Class.MonadIO io) => Sound.OSC.Transport.Monad.SendOSC (Control.Monad.Trans.Reader.ReaderT t io)

-- | OSC over UDP implementation.
module Sound.OSC.Transport.FD.UDP

-- | The UDP transport handle data type.
data UDP
UDP :: Socket -> UDP
[udpSocket] :: UDP -> Socket

-- | Return the port number associated with the UDP socket.
udpPort :: Integral n => UDP -> IO n

-- | Send packet over UDP.
upd_send_packet :: UDP -> Packet -> IO ()

-- | Receive packet over UDP.
udp_recv_packet :: UDP -> IO Packet

-- | Close UDP.
udp_close :: UDP -> IO ()

-- | Bracket UDP communication.
with_udp :: IO UDP -> (UDP -> IO t) -> IO t

-- | Create and initialise UDP socket.
udp_socket :: (Socket -> SockAddr -> IO ()) -> String -> Int -> IO UDP

-- | Set option, ie. Broadcast or RecvTimeOut.
set_udp_opt :: SocketOption -> Int -> UDP -> IO ()

-- | Get option.
get_udp_opt :: SocketOption -> UDP -> IO Int

-- | Make a UDP connection.
openUDP :: String -> Int -> IO UDP

-- | Trivial UDP server socket.
--   
--   
--   import Control.Concurrent 
--   
--   
--   
--   let t0 = udpServer "127.0.0.1" 57300
--   forkIO (FD.withTransport t0 (\fd -> forever (FD.recvMessage fd >>= print)))
--   
--   
--   
--   let t1 = openUDP "127.0.0.1" 57300
--   FD.withTransport t1 (\fd -> FD.sendMessage fd (Packet.message "/n" []))
--   
udpServer :: String -> Int -> IO UDP

-- | Variant of udpServer that doesn't require the host address.
udp_server :: Int -> IO UDP

-- | Send variant to send to specified address.
sendTo :: UDP -> Packet -> SockAddr -> IO ()

-- | Recv variant to collect message source address.
recvFrom :: UDP -> IO (Packet, SockAddr)
instance Sound.OSC.Transport.FD.Transport Sound.OSC.Transport.FD.UDP.UDP

-- | OSC over TCP implementation.
module Sound.OSC.Transport.FD.TCP

-- | The TCP transport handle data type.
data TCP
TCP :: Handle -> TCP
[tcpHandle] :: TCP -> Handle

-- | Send packet over TCP.
tcp_send_packet :: TCP -> Packet -> IO ()

-- | Receive packet over TCP.
tcp_recv_packet :: TCP -> IO Packet

-- | Close TCP.
tcp_close :: TCP -> IO ()

-- | Bracket UDP communication.
with_tcp :: IO TCP -> (TCP -> IO t) -> IO t

-- | Create and initialise TCP socket.
tcp_socket :: (Socket -> SockAddr -> IO ()) -> Maybe String -> Int -> IO Socket

-- | Convert Socket to TCP.
socket_to_tcp :: Socket -> IO TCP

-- | Create and initialise TCP.
tcp_handle :: (Socket -> SockAddr -> IO ()) -> String -> Int -> IO TCP

-- | Make a TCP connection.
--   
--   
--   import Sound.OSC.Datum 
--   import Sound.OSC.Time 
--   let t = openTCP "127.0.0.1" 57110
--   let m1 = Packet.message "/dumpOSC" [Int32 1]
--   let m2 = Packet.message "/g_new" [Int32 1]
--   FD.withTransport t (\fd -> let f = FD.sendMessage fd in f m1 >> pauseThread 0.25 >> f m2)
--   
openTCP :: String -> Int -> IO TCP

-- | accept connection at s and run f.
tcp_server_f :: Socket -> (TCP -> IO ()) -> IO ()

-- | sequence_ of repeat.
repeatM_ :: Monad m => m a -> m ()

-- | A trivial TCP OSC server.
tcp_server :: Int -> (TCP -> IO ()) -> IO ()
instance Sound.OSC.Transport.FD.Transport Sound.OSC.Transport.FD.TCP.TCP

-- | Composite of non-transport related modules.
--   
--   Provides the Datum, Message, Time, Bundle
--   and Packet types and the coding functions encodePacket
--   and decodePacket.
--   
--   
--   import Sound.OSC.Core 
--   
--   let o = bundle immediately [message "/g_free" [Int32 0]]
--   let e = encodeBundle o
--   decodePacket e == Packet_Bundle o
--   
module Sound.OSC.Core

-- | Composite of Sound.OSC.Core and Sound.OSC.Transport.FD.
module Sound.OSC.FD

-- | Composite of Sound.OSC.Core and
--   Sound.OSC.Transport.Monad.
module Sound.OSC
class Monad m => MonadIO (m :: Type -> Type)
liftIO :: MonadIO m => IO a -> m a

-- | Unix/Posix time in real-valued (fractional) form. The
--   Unix/Posix epoch is January 1, 1970.
type UT = Double

-- | NTP time in real-valued (fractional) form (ie.
--   ntpr). This is the primary form of timestamp used by hosc.
type Time = Double

-- | Type for binary (integeral) representation of a 64-bit NTP
--   timestamp (ie. ntpi). The NTP epoch is January 1, 1900. NTPv4
--   also includes a 128-bit format, which is not used by OSC.
type NTP64 = Word64

-- | Constant indicating a bundle to be executed immediately. It has the
--   NTP64 representation of 1.
immediately :: Time

-- | Convert a real-valued NTP timestamp to an NTPi timestamp.
--   
--   
--   ntpr_to_ntpi immediately == 1
--   fmap ntpr_to_ntpi time
--   
ntpr_to_ntpi :: RealFrac n => n -> NTP64

-- | Convert an NTPi timestamp to a real-valued NTP timestamp.
ntpi_to_ntpr :: Fractional n => NTP64 -> n

-- | Difference (in seconds) between NTP and UT epochs.
--   
--   
--   ntp_ut_epoch_diff / (24 * 60 * 60) == 25567
--   25567 `div` 365 == 70
--   
ntp_ut_epoch_diff :: Num n => n

-- | Convert a UT timestamp to an NTPi timestamp.
ut_to_ntpi :: UT -> NTP64

-- | Convert Unix/Posix to NTP.
ut_to_ntpr :: Num n => n -> n

-- | Convert NTP to Unix/Posix.
ntpr_to_ut :: Num n => n -> n

-- | Convert NTPi to Unix/Posix.
ntpi_to_ut :: NTP64 -> UT

-- | Convert Time to POSIXTime.
ntpr_to_posixtime :: Time -> POSIXTime

-- | Convert POSIXTime to Time.
posixtime_to_ntpr :: POSIXTime -> Time

-- | The time at 1970-01-01:00:00:00.
ut_epoch :: UTCTime

-- | Convert UTCTime to Unix/Posix.
utc_to_ut :: Fractional n => UTCTime -> n

-- | Read current real-valued NTP timestamp.
--   
--   
--   get_ct = fmap utc_to_ut T.getCurrentTime
--   get_pt = fmap realToFrac T.getPOSIXTime
--   (ct,pt) <- get_ct >>= \t0 -> get_pt >>= \t1 -> return (t0,t1)
--   print (pt - ct,pt - ct < 1e-5)
--   
time :: MonadIO m => m Time

-- | The pauseThread limit (in seconds). Values larger than this
--   require a different thread delay mechanism, see sleepThread.
--   The value is the number of microseconds in maxBound::Int.
pauseThreadLimit :: Fractional n => n

-- | Pause current thread for the indicated duration (in seconds), see
--   pauseThreadLimit.
pauseThread :: (MonadIO m, RealFrac n) => n -> m ()

-- | Type restricted pauseThread.
wait :: MonadIO m => Double -> m ()

-- | Pause current thread until the given Time, see
--   pauseThreadLimit.
pauseThreadUntil :: MonadIO m => Time -> m ()

-- | Sleep current thread for the indicated duration (in seconds). Divides
--   long sleeps into parts smaller than pauseThreadLimit.
sleepThread :: (RealFrac n, MonadIO m) => n -> m ()

-- | Sleep current thread until the given Time. Divides long sleeps
--   into parts smaller than pauseThreadLimit.
sleepThreadUntil :: MonadIO m => Time -> m ()

-- | Detailed 37-character ISO 8601 format, including fractional seconds
--   and '+0000' suffix.
iso_8601_fmt :: String

-- | Parse time according to iso_8601_fmt
--   
--   
--   iso_8601_to_utctime "2015-11-26T00:29:37,145875000000+0000"
--   
iso_8601_to_utctime :: String -> Maybe UTCTime

-- | UTC time in iso_8601_fmt.
--   
--   
--   tm <- fmap (utctime_to_iso_8601 . T.posixSecondsToUTCTime) T.getPOSIXTime
--   (length tm,sum [4+1+2+1+2,1,2+1+2+1+2,1,12,1,4],sum [10,1,8,1,12,1,4]) == (37,37,37)
--   
utctime_to_iso_8601 :: UTCTime -> String

-- | ISO 8601 of Time.
--   
--   
--   tm <- fmap ntpr_to_iso_8601 time
--   import System.Process {- process -}
--   rawSystem "date" ["-d",tm]
--   
--   
--   
--   t = 15708783354150518784
--   s = "2015-11-26T00:22:19,366058349609+0000"
--   ntpr_to_iso_8601 (ntpi_to_ntpr t) == s
--   
ntpr_to_iso_8601 :: Time -> String

-- | Time of ISO 8601.
--   
--   
--   t = 15708783354150518784
--   s = "2015-11-26T00:22:19,366058349609+0000"
--   fmap ntpr_to_ntpi (iso_8601_to_ntpr s) == Just t
--   
iso_8601_to_ntpr :: String -> Maybe Time

-- | Alias for ntpr_to_iso_8601.
--   
--   
--   time_pp immediately == "1900-01-01T00:00:00,000000000000+0000"
--   fmap time_pp time
--   
time_pp :: Time -> String

-- | Perhaps a precision value for floating point numbers.
type FP_Precision = Maybe Int

-- | The basic elements of OSC messages.
data Datum
Int32 :: Int32 -> Datum
[d_int32] :: Datum -> Int32
Int64 :: Int64 -> Datum
[d_int64] :: Datum -> Int64
Float :: Float -> Datum
[d_float] :: Datum -> Float
Double :: Double -> Datum
[d_double] :: Datum -> Double
ASCII_String :: ASCII -> Datum
[d_ascii_string] :: Datum -> ASCII
Blob :: BLOB -> Datum
[d_blob] :: Datum -> BLOB
TimeStamp :: Time -> Datum
[d_timestamp] :: Datum -> Time
Midi :: MIDI -> Datum
[d_midi] :: Datum -> MIDI

-- | Four-byte midi message: port-id, status-byte, data, data.
data MIDI
MIDI :: Word8 -> Word8 -> Word8 -> Word8 -> MIDI

-- | Type for Word8 arrays, these are stored with an Int32
--   length prefix.
type BLOB = ByteString

-- | Type for ASCII strings (strict Char8 ByteString).
type ASCII = ByteString

-- | Type enumerating Datum categories.
type Datum_Type = Char

-- | Type-specialised pack.
ascii :: String -> ASCII

-- | Type-specialised unpack.
ascii_to_string :: ASCII -> String

-- | Type-specialised pack.
blob_pack :: [Word8] -> BLOB

-- | Type-specialised unpack.
blob_unpack :: BLOB -> [Word8]

-- | List of required data types (tag,name).
osc_types_required :: [(Datum_Type, String)]

-- | List of optional data types (tag,name).
osc_types_optional :: [(Datum_Type, String)]

-- | List of all data types (tag,name).
osc_types :: [(Datum_Type, String)]

-- | Lookup name of type.
osc_type_name :: Datum_Type -> Maybe String

-- | Erroring variant.
osc_type_name_err :: Datum_Type -> String

-- | Single character identifier of an OSC datum.
datum_tag :: Datum -> Datum_Type

-- | Type and name of Datum.
datum_type_name :: Datum -> (Datum_Type, String)

-- | Datum as Integral if Int32 or Int64.
--   
--   
--   let d = [Int32 5,Int64 5,Float 5.5,Double 5.5]
--   map datum_integral d == [Just (5::Int),Just 5,Nothing,Nothing]
--   
datum_integral :: Integral i => Datum -> Maybe i

-- | Datum as Floating if Int32, Int64, Float, Double or
--   TimeStamp.
--   
--   
--   let d = [Int32 5,Int64 5,Float 5,Double 5,TimeStamp 5]
--   mapMaybe datum_floating d == replicate 5 (5::Double)
--   
datum_floating :: Floating n => Datum -> Maybe n

-- | Type generalised Int32.
--   
--   
--   int32 (1::Int32) == int32 (1::Integer)
--   d_int32 (int32 (maxBound::Int32)) == maxBound
--   int32 (((2::Int) ^ (64::Int))::Int) == Int32 0
--   
int32 :: Integral n => n -> Datum

-- | Type generalised Int64.
--   
--   
--   int64 (1::Int32) == int64 (1::Integer)
--   d_int64 (int64 (maxBound::Int64)) == maxBound
--   
int64 :: Integral n => n -> Datum

-- | Type generalised Float.
--   
--   
--   float (1::Int) == float (1::Double)
--   floatRange (undefined::Float) == (-125,128)
--   isInfinite (d_float (float (encodeFloat 1 256 :: Double))) == True
--   
float :: Real n => n -> Datum

-- | Type generalised Double.
--   
--   
--   double (1::Int) == double (1::Double)
--   double (encodeFloat 1 256 :: Double) == Double 1.157920892373162e77
--   
double :: Real n => n -> Datum

-- | ASCII_String of pack.
--   
--   
--   string "string" == ASCII_String (Char8.pack "string")
--   
string :: String -> Datum

-- | Four-tuple variant of Midi . MIDI.
--   
--   
--   midi (0,0,0,0) == Midi (MIDI 0 0 0 0)
--   
midi :: (Word8, Word8, Word8, Word8) -> Datum

-- | Message argument types are given by a descriptor.
--   
--   
--   descriptor [Int32 1,Float 1,string "1"] == ascii ",ifs"
--   
descriptor :: [Datum] -> ASCII

-- | Descriptor tags are comma prefixed.
descriptor_tags :: ASCII -> ASCII

-- | Variant of showFFloat that deletes trailing zeros.
--   
--   
--   map (floatPP (Just 4)) [1,pi] == ["1.0","3.1416"]
--   
floatPP :: RealFloat n => Maybe Int -> n -> String

-- | Pretty printer for Time.
--   
--   
--   timePP (Just 4) (1/3) == "0.3333"
--   
timePP :: FP_Precision -> Time -> String

-- | Pretty printer for vectors.
--   
--   
--   vecPP [1::Int,2,3] == "<1,2,3>"
--   
vecPP :: Show a => [a] -> String

-- | Pretty printer for Datum.
--   
--   
--   let d = [Int32 1,Float 1.2,string "str",midi (0,0x90,0x40,0x60)]
--   in map (datumPP (Just 5)) d ==  ["1","1.2","\"str\"","<0,144,64,96>"]
--   
datumPP :: FP_Precision -> Datum -> String

-- | Variant of datumPP that appends the datum_type_name.
datum_pp_typed :: FP_Precision -> Datum -> String

-- | Given Datum_Type attempt to parse Datum at
--   String.
--   
--   
--   parse_datum 'i' "42" == Just (Int32 42)
--   parse_datum 'h' "42" == Just (Int64 42)
--   parse_datum 'f' "3.14159" == Just (Float 3.14159)
--   parse_datum 'd' "3.14159" == Just (Double 3.14159)
--   parse_datum 's' "\"pi\"" == Just (string "pi")
--   parse_datum 'b' "[112,105]" == Just (Blob (blob_pack [112,105]))
--   parse_datum 'm' "(0,144,60,90)" == Just (midi (0,144,60,90))
--   
parse_datum :: Datum_Type -> String -> Maybe Datum

-- | Erroring variant of parse_datum.
parse_datum_err :: Datum_Type -> String -> Datum

-- | An OSC Packet is either a Message or a Bundle.
data Packet
Packet_Message :: Message -> Packet
[packetMessage] :: Packet -> Message
Packet_Bundle :: Bundle -> Packet
[packetBundle] :: Packet -> Bundle

-- | An OSC bundle, a Time and a sequence of Messages.
data Bundle
Bundle :: Time -> [Message] -> Bundle
[bundleTime] :: Bundle -> Time
[bundleMessages] :: Bundle -> [Message]

-- | An OSC message, an Address_Pattern and a sequence of
--   Datum.
data Message
Message :: Address_Pattern -> [Datum] -> Message
[messageAddress] :: Message -> Address_Pattern
[messageDatum] :: Message -> [Datum]

-- | OSC address pattern. This is strictly an ASCII value, however it is
--   very common to pattern match on addresses and matching on
--   ByteString requires OverloadedStrings.
type Address_Pattern = String

-- | Message constructor. It is an error if the
--   Address_Pattern doesn't conform to the OSC specification.
message :: Address_Pattern -> [Datum] -> Message

-- | Bundle constructor. It is an error if the Message
--   list is empty.
bundle :: Time -> [Message] -> Bundle

-- | Packet_Bundle of bundle.
p_bundle :: Time -> [Message] -> Packet

-- | Packet_Message of message.
p_message :: Address_Pattern -> [Datum] -> Packet

-- | The Time of Packet, if the Packet is a
--   Message this is immediately.
packetTime :: Packet -> Time

-- | Retrieve the set of Messages from a Packet.
packetMessages :: Packet -> [Message]

-- | If Packet is a Message add immediately timestamp,
--   else id.
packet_to_bundle :: Packet -> Bundle

-- | If Packet is a Message or a Bundle with an
--   immediate time tag and with one element, return the
--   Message, else Nothing.
packet_to_message :: Packet -> Maybe Message

-- | Is Packet immediate, ie. a Bundle with timestamp
--   immediately, or a plain Message.
packet_is_immediate :: Packet -> Bool

-- | Variant of either for Packet.
at_packet :: (Message -> a) -> (Bundle -> a) -> Packet -> a

-- | Does Message have the specified Address_Pattern.
message_has_address :: Address_Pattern -> Message -> Bool

-- | Do any of the Messages at Bundle have the specified
--   Address_Pattern.
bundle_has_address :: Address_Pattern -> Bundle -> Bool

-- | Does Packet have the specified Address_Pattern, ie.
--   message_has_address or bundle_has_address.
packet_has_address :: Address_Pattern -> Packet -> Bool

-- | Pretty printer for Message.
messagePP :: FP_Precision -> Message -> String

-- | Pretty printer for Bundle.
bundlePP :: FP_Precision -> Bundle -> String

-- | Pretty printer for Packet.
packetPP :: FP_Precision -> Packet -> String

-- | Builder for an OSC Packet.
build_packet :: Packet -> Builder

-- | Encode an OSC Packet.
encodePacket :: Packet -> ByteString

-- | Encode an OSC Message, ie. encodePacket of
--   Packet_Message.
--   
--   
--   let m = [47,103,95,102,114,101,101,0,44,105,0,0,0,0,0,0]
--   encodeMessage (Message "/g_free" [Int32 0]) == L.pack m
--   
encodeMessage :: Message -> ByteString

-- | Encode an OSC Bundle, ie. encodePacket of
--   Packet_Bundle.
--   
--   
--   let m = [47,103,95,102,114,101,101,0,44,105,0,0,0,0,0,0]
--   let b = [35,98,117,110,100,108,101,0,0,0,0,0,0,0,0,1,0,0,0,16] ++ m
--   encodeBundle (Bundle immediately [Message "/g_free" [Int32 0]]) == L.pack b
--   
encodeBundle :: Bundle -> ByteString

-- | Encode an OSC Packet to a strict ByteString.
encodePacket_strict :: Packet -> ByteString

-- | Get an OSC Packet.
get_packet :: Get Packet

-- | Decode an OSC Message from a lazy ByteString.
--   
--   
--   let b = B.pack [47,103,95,102,114,101,101,0,44,105,0,0,0,0,0,0]
--   decodeMessage b == Message "/g_free" [Int32 0]
--   
decodeMessage :: ByteString -> Message

-- | Decode an OSC Bundle from a lazy ByteString.
decodeBundle :: ByteString -> Bundle

-- | Decode an OSC packet from a lazy ByteString.
--   
--   
--   let b = B.pack [47,103,95,102,114,101,101,0,44,105,0,0,0,0,0,0]
--   decodePacket b == Packet_Message (Message "/g_free" [Int32 0])
--   
decodePacket :: ByteString -> Packet

-- | Decode an OSC packet from a strict ByteString.
decodePacket_strict :: ByteString -> Packet

-- | Variant of timeout where time is given in fractional seconds.
timeout_r :: Double -> IO a -> IO (Maybe a)

-- | Repeat action until predicate f is True when applied to
--   result.
untilPredicate :: Monad m => (a -> Bool) -> m a -> m a

-- | Repeat action until f does not give Nothing when applied
--   to result.
untilMaybe :: Monad m => (a -> Maybe b) -> m a -> m b

-- | Transport connection.
type Connection t a = ReaderT t IO a

-- | Transport is DuplexOSC with a MonadIO
--   constraint.
class (DuplexOSC m, MonadIO m) => Transport m

-- | DuplexOSC is the union of SendOSC and RecvOSC.
class (SendOSC m, RecvOSC m) => DuplexOSC m

-- | Receiver monad.
class Monad m => RecvOSC m

-- | Receive and decode an OSC packet.
recvPacket :: RecvOSC m => m Packet

-- | Sender monad.
class Monad m => SendOSC m

-- | Encode and send an OSC packet.
sendPacket :: SendOSC m => Packet -> m ()

-- | Bracket Open Sound Control communication.
withTransport :: Transport t => IO t -> Connection t a -> IO a

-- | Type restricted synonym for sendOSC.
sendMessage :: SendOSC m => Message -> m ()

-- | Type restricted synonym for sendOSC.
sendBundle :: SendOSC m => Bundle -> m ()

-- | Variant of recvPacket that runs packet_to_bundle.
recvBundle :: RecvOSC m => m Bundle

-- | Variant of recvPacket that runs packet_to_message.
recvMessage :: RecvOSC m => m (Maybe Message)

-- | Erroring variant.
recvMessage_err :: RecvOSC m => m Message

-- | Variant of recvPacket that runs packetMessages.
recvMessages :: RecvOSC m => m [Message]

-- | Wait for a Packet where the supplied predicate is
--   True, discarding intervening packets.
waitUntil :: RecvOSC m => (Packet -> Bool) -> m Packet

-- | Wait for a Packet where the supplied function does not give
--   Nothing, discarding intervening packets.
waitFor :: RecvOSC m => (Packet -> Maybe a) -> m a

-- | waitUntil packet_is_immediate.
waitImmediate :: RecvOSC m => m Packet

-- | waitFor packet_to_message, ie. an incoming
--   Message or immediate mode Bundle with one element.
waitMessage :: RecvOSC m => m Message

-- | A waitFor for variant using packet_has_address to
--   match on the Address_Pattern of incoming Packets.
waitAddress :: RecvOSC m => Address_Pattern -> m Packet

-- | Variant on waitAddress that returns matching Message.
waitReply :: RecvOSC m => Address_Pattern -> m Message

-- | Variant of waitReply that runs messageDatum.
waitDatum :: RecvOSC m => Address_Pattern -> m [Datum]

-- | The UDP transport handle data type.
data UDP
UDP :: Socket -> UDP
[udpSocket] :: UDP -> Socket

-- | Return the port number associated with the UDP socket.
udpPort :: Integral n => UDP -> IO n

-- | Send packet over UDP.
upd_send_packet :: UDP -> Packet -> IO ()

-- | Receive packet over UDP.
udp_recv_packet :: UDP -> IO Packet

-- | Close UDP.
udp_close :: UDP -> IO ()

-- | Bracket UDP communication.
with_udp :: IO UDP -> (UDP -> IO t) -> IO t

-- | Create and initialise UDP socket.
udp_socket :: (Socket -> SockAddr -> IO ()) -> String -> Int -> IO UDP

-- | Set option, ie. Broadcast or RecvTimeOut.
set_udp_opt :: SocketOption -> Int -> UDP -> IO ()

-- | Get option.
get_udp_opt :: SocketOption -> UDP -> IO Int

-- | Make a UDP connection.
openUDP :: String -> Int -> IO UDP

-- | Trivial UDP server socket.
--   
--   
--   import Control.Concurrent 
--   
--   
--   
--   let t0 = udpServer "127.0.0.1" 57300
--   forkIO (FD.withTransport t0 (\fd -> forever (FD.recvMessage fd >>= print)))
--   
--   
--   
--   let t1 = openUDP "127.0.0.1" 57300
--   FD.withTransport t1 (\fd -> FD.sendMessage fd (Packet.message "/n" []))
--   
udpServer :: String -> Int -> IO UDP

-- | Variant of udpServer that doesn't require the host address.
udp_server :: Int -> IO UDP

-- | Send variant to send to specified address.
sendTo :: UDP -> Packet -> SockAddr -> IO ()

-- | Recv variant to collect message source address.
recvFrom :: UDP -> IO (Packet, SockAddr)

-- | The TCP transport handle data type.
data TCP
TCP :: Handle -> TCP
[tcpHandle] :: TCP -> Handle

-- | Send packet over TCP.
tcp_send_packet :: TCP -> Packet -> IO ()

-- | Receive packet over TCP.
tcp_recv_packet :: TCP -> IO Packet

-- | Close TCP.
tcp_close :: TCP -> IO ()

-- | Bracket UDP communication.
with_tcp :: IO TCP -> (TCP -> IO t) -> IO t

-- | Create and initialise TCP socket.
tcp_socket :: (Socket -> SockAddr -> IO ()) -> Maybe String -> Int -> IO Socket

-- | Convert Socket to TCP.
socket_to_tcp :: Socket -> IO TCP

-- | Create and initialise TCP.
tcp_handle :: (Socket -> SockAddr -> IO ()) -> String -> Int -> IO TCP

-- | Make a TCP connection.
--   
--   
--   import Sound.OSC.Datum 
--   import Sound.OSC.Time 
--   let t = openTCP "127.0.0.1" 57110
--   let m1 = Packet.message "/dumpOSC" [Int32 1]
--   let m2 = Packet.message "/g_new" [Int32 1]
--   FD.withTransport t (\fd -> let f = FD.sendMessage fd in f m1 >> pauseThread 0.25 >> f m2)
--   
openTCP :: String -> Int -> IO TCP

-- | accept connection at s and run f.
tcp_server_f :: Socket -> (TCP -> IO ()) -> IO ()

-- | sequence_ of repeat.
repeatM_ :: Monad m => m a -> m ()

-- | A trivial TCP OSC server.
tcp_server :: Int -> (TCP -> IO ()) -> IO ()
