{- |
System Common messages
-}moduleSound.MIDI.Message.System.Common(T(..),TimeNibbleType(..),get,put,)whereimportSound.MIDI.Parser.PrimitiveimportqualifiedSound.MIDI.Parser.ClassasParserimportControl.Monad.Trans.Class(lift,)importControl.Monad(liftM,liftM2,)importqualifiedSound.MIDI.Writer.BasicasWriterimportSound.MIDI.Monoid((+#+))importqualifiedSound.MIDI.BitasBitimportData.Ix(Ix)dataT=TimeCodeQuarterFrameTimeNibbleTypeInt|SongPositionPointerInt|SongSelectInt|TuneRequest-- | EndOfSystemExclusivedataTimeNibbleType=FrameLS|FrameMS|SecondsLS|SecondsMS|MinutesLS|MinutesMS|HoursLS|HoursMS-- ^ also includes SMPTE typederiving(Eq,Ord,Show,Enum,Ix)-- * serializationget::Parser.Cparser=>Int->Parser.FallibleparserTgetcode=casecodeof0xF1->dodat<-get1let(nib,value)=Bit.splitAt4datlet(msb,nibble)=Bit.splitAt3niblift$Parser.warnIf(msb/=0)"TimeCodeQuarterFrame: most significant bit must 0"return$TimeCodeQuarterFrame(toEnumnibble)value0xF2->liftM2(\lsbmsb->SongPositionPointer(lsb+Bit.shiftL7msb))get1get10xF3->liftMSongSelectget10xF6->returnTuneRequest_->Parser.giveUp("invalid System Common code:"++showcode)put::Writer.Cwriter=>T->writerputmsg=casemsgofTimeCodeQuarterFramenibblevalue->Writer.putByte0xF1+#+Writer.putIntAsByte(Bit.shiftL4(fromEnumnibble)+value)SongPositionPointerpos->Writer.putByte0xF2+#+let(msb,lsb)=Bit.splitAt7posinWriter.putIntAsBytelsb+#+Writer.putIntAsBytemsbSongSelectsong->Writer.putByte0xF3+#+Writer.putIntAsBytesongTuneRequest->Writer.putByte0xF6