module Sound.MIDI.Parser.Status
(T, Status, set, get, run, State.lift,
Channel, fromChannel, toChannel, ) where
import qualified Sound.MIDI.Parser.State as ParserState
import Control.Monad.State (evalStateT, )
import qualified Control.Monad.State as State
import Sound.MIDI.Utility (checkRange, )
import Data.Ix (Ix)
type T parser a = ParserState.T Status parser a
type Status = Maybe (Int,Channel)
set :: Monad parser => Status -> T parser ()
set = State.put
get :: Monad parser => T parser Status
get = State.get
run :: Monad parser => T parser a -> parser a
run = flip evalStateT Nothing
newtype Channel = Channel {fromChannel :: Int} deriving (Show, Eq, Ord, Ix)
toChannel :: Int -> Channel
toChannel = checkRange "Channel" Channel
instance Enum Channel where
toEnum = toChannel
fromEnum = fromChannel
instance Bounded Channel where
minBound = Channel 0
maxBound = Channel 15