{- |
Channel mode messages
-}moduleSound.MIDI.Message.Channel.Mode(T(..),get,put,fromControllerValue,toControllerValue,)whereimportSound.MIDI.Parser.PrimitiveimportqualifiedSound.MIDI.Parser.ClassasParserimportqualifiedSound.MIDI.Writer.BasicasWriterimportSound.MIDI.Parser.Report(UserMessage,)importqualifiedControl.Monad.Exception.AsynchronousasAsyncimportSound.MIDI.Utility(toMaybe,)importControl.Monad.Trans.Class(lift,)importControl.Monad(liftM,)importTest.QuickCheck(Arbitrary(arbitrary),)importqualifiedTest.QuickCheckasQCdataT=AllSoundOff|ResetAllControllers|LocalControlBool|AllNotesOff|OmniModeBool|MonoModeInt|PolyModederiving(Show,Eq,Ord)instanceArbitraryTwherearbitrary=QC.oneof$returnAllSoundOff:returnResetAllControllers:liftMLocalControlarbitrary:returnAllNotesOff:liftMOmniModearbitrary:liftMMonoMode(QC.choose(0,16)):returnPolyMode:[]-- * serializationget::Parser.Cparser=>Int->Parser.FallibleparserTgetmode=dox<-get1lift$Parser.warnIncomplete$uncurryAsync.Exceptional$fromControllerValue(mode,x){- |
This function is also used in alsa-midi,
we could give it the result type @Parser.PossiblyIncomplete T@ otherwise.
-}fromControllerValue::(Showa,Integrala)=>(a,a)->(MaybeUserMessage,T)fromControllerValue(mode,x)=casemodeof0x78->(checkValidValue"AllSoundOff"[0]x,AllSoundOff)0x79->(checkValidValue"ResetAllControllers"[0]x,ResetAllControllers)0x7A->(checkValidValue"LocalControl"[0,127]x,LocalControl(x/=0))0x7B->(checkValidValue"AllNotesOff"[0]x,AllNotesOff)0x7C->(checkValidValue"OmniMode Off"[0]x,OmniModeFalse)0x7D->(checkValidValue"OmniMode On"[0]x,OmniModeTrue)0x7E->(Nothing,MonoMode(fromIntegralx))0x7F->(checkValidValue"PolyMode On"[0]x,PolyMode)_->error("Channel.Mode.get: mode value out of range: "++showmode)checkValidValue::(Showa,Integrala)=>String->[a]->a->MaybeUserMessagecheckValidValuenamevalidValuesvalue=toMaybe(not(elemvaluevalidValues))("Invalid value for "++name++": "++showvalue)put::Writer.Cwriter=>T->writerputmode=let(code,value)=toControllerValuemodeinWriter.putByteList[code,value]toControllerValue::Integrala=>T->(a,a)toControllerValuemode=casemodeofAllSoundOff->(,)0x780ResetAllControllers->(,)0x790LocalControlb->(,)0x7A(ifbthen127else0)AllNotesOff->(,)0x7B0OmniModeb->(,)(ifbthen0x7Delse0x7C)0MonoModex->(,)0x7E(fromIntegralx)PolyMode->(,)0x7F0