{- |
System Real Time messages
-}
module Sound.MIDI.Message.System.RealTime (
   T(..), get, put,
   ) where

import qualified Sound.MIDI.Parser.Class as Parser

import qualified Sound.MIDI.Writer.Basic as Writer

import Data.Ix(Ix)


data T =
     TimingClock                   -- F8
   | Start                         -- FA
   | Continue                      -- FB
   | Stop                          -- FC
   | ActiveSensing                 -- FE
   | Reset                         -- FF
   deriving (T -> T -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: T -> T -> Bool
$c/= :: T -> T -> Bool
== :: T -> T -> Bool
$c== :: T -> T -> Bool
Eq, Eq T
T -> T -> Bool
T -> T -> Ordering
T -> T -> T
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: T -> T -> T
$cmin :: T -> T -> T
max :: T -> T -> T
$cmax :: T -> T -> T
>= :: T -> T -> Bool
$c>= :: T -> T -> Bool
> :: T -> T -> Bool
$c> :: T -> T -> Bool
<= :: T -> T -> Bool
$c<= :: T -> T -> Bool
< :: T -> T -> Bool
$c< :: T -> T -> Bool
compare :: T -> T -> Ordering
$ccompare :: T -> T -> Ordering
Ord, Int -> T -> ShowS
[T] -> ShowS
T -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [T] -> ShowS
$cshowList :: [T] -> ShowS
show :: T -> String
$cshow :: T -> String
showsPrec :: Int -> T -> ShowS
$cshowsPrec :: Int -> T -> ShowS
Show, Int -> T
T -> Int
T -> [T]
T -> T
T -> T -> [T]
T -> T -> T -> [T]
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: T -> T -> T -> [T]
$cenumFromThenTo :: T -> T -> T -> [T]
enumFromTo :: T -> T -> [T]
$cenumFromTo :: T -> T -> [T]
enumFromThen :: T -> T -> [T]
$cenumFromThen :: T -> T -> [T]
enumFrom :: T -> [T]
$cenumFrom :: T -> [T]
fromEnum :: T -> Int
$cfromEnum :: T -> Int
toEnum :: Int -> T
$ctoEnum :: Int -> T
pred :: T -> T
$cpred :: T -> T
succ :: T -> T
$csucc :: T -> T
Enum, Ord T
(T, T) -> Int
(T, T) -> [T]
(T, T) -> T -> Bool
(T, T) -> T -> Int
forall a.
Ord a
-> ((a, a) -> [a])
-> ((a, a) -> a -> Int)
-> ((a, a) -> a -> Int)
-> ((a, a) -> a -> Bool)
-> ((a, a) -> Int)
-> ((a, a) -> Int)
-> Ix a
unsafeRangeSize :: (T, T) -> Int
$cunsafeRangeSize :: (T, T) -> Int
rangeSize :: (T, T) -> Int
$crangeSize :: (T, T) -> Int
inRange :: (T, T) -> T -> Bool
$cinRange :: (T, T) -> T -> Bool
unsafeIndex :: (T, T) -> T -> Int
$cunsafeIndex :: (T, T) -> T -> Int
index :: (T, T) -> T -> Int
$cindex :: (T, T) -> T -> Int
range :: (T, T) -> [T]
$crange :: (T, T) -> [T]
Ix)


-- * serialization

get :: Parser.C parser => Int -> Parser.Fragile parser T
get :: forall (parser :: * -> *). C parser => Int -> Fragile parser T
get Int
code =
   case Int
code of
      Int
0xF8 -> forall (m :: * -> *) a. Monad m => a -> m a
return T
TimingClock
      Int
0xFA -> forall (m :: * -> *) a. Monad m => a -> m a
return T
Start
      Int
0xFB -> forall (m :: * -> *) a. Monad m => a -> m a
return T
Continue
      Int
0xFC -> forall (m :: * -> *) a. Monad m => a -> m a
return T
Stop
      Int
0xFE -> forall (m :: * -> *) a. Monad m => a -> m a
return T
ActiveSensing
      Int
0xFF -> forall (m :: * -> *) a. Monad m => a -> m a
return T
Reset
      Int
_    -> forall (m :: * -> *) a. Monad m => String -> T m a
Parser.giveUp (String
"unknown System Real Time message code " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show Int
code)

put :: Writer.C writer => T -> writer
put :: forall writer. C writer => T -> writer
put T
msg =
   case T
msg of
      T
TimingClock   -> forall m. C m => Word8 -> m
Writer.putByte Word8
0xF8
      T
Start         -> forall m. C m => Word8 -> m
Writer.putByte Word8
0xFA
      T
Continue      -> forall m. C m => Word8 -> m
Writer.putByte Word8
0xFB
      T
Stop          -> forall m. C m => Word8 -> m
Writer.putByte Word8
0xFC
      T
ActiveSensing -> forall m. C m => Word8 -> m
Writer.putByte Word8
0xFE
      T
Reset         -> forall m. C m => Word8 -> m
Writer.putByte Word8
0xFF