{- | System messages -} module Sound.MIDI.Message.System ( T(..), get, getIncomplete, put, ) where import qualified Sound.MIDI.Message.System.Exclusive as Exclusive import qualified Sound.MIDI.Message.System.Common as Common import qualified Sound.MIDI.Message.System.RealTime as RealTime -- import Sound.MIDI.Parser.Primitive import Sound.MIDI.Parser.Class (PossiblyIncomplete, ) import qualified Sound.MIDI.Parser.Class as Parser import qualified Sound.MIDI.Writer.Basic as Writer import Control.Monad (liftM, ) import Sound.MIDI.Utility (mapSnd, ) data T = Exclusive Exclusive.T | Common Common.T | RealTime RealTime.T get :: Parser.C parser => Int -> parser T get code = if code == 0xF0 then liftM Exclusive Exclusive.get else if code >= 0xF1 && code <= 0xF6 then liftM Common $ Common.get code else if code >= 0xF8 && code <= 0xFF then liftM RealTime $ RealTime.get code else Parser.giveUp ("invalid System message code " ++ show code) getIncomplete :: Parser.C parser => Int -> parser (PossiblyIncomplete T) getIncomplete code = if code == 0xF0 then liftM (mapSnd Exclusive) Exclusive.getIncomplete else if code >= 0xF1 && code <= 0xF6 then liftM ((,) Nothing . Common) $ Common.get code else if code >= 0xF8 && code <= 0xFF then liftM ((,) Nothing . RealTime) $ RealTime.get code else Parser.giveUp ("invalid System message code " ++ show code) put :: Writer.C writer => T -> writer () put msg = case msg of Exclusive s -> Exclusive.put s Common s -> Common.put s RealTime s -> RealTime.put s