moduleCsound.Exp(E,RatedExp(..),RatedVar(..),onExp,Exp,toPrimOr,PrimOr(..),MainExp(..),Name,VarType(..),Var(..),Info(..),OpcType(..),Rate(..),Signature(..),isProcedure,isInfix,isPrefix,Prim(..),Tab(..),TabMap,Inline(..),InlineExp(..),PreInline(..),BoolExp,CondInfo,CondOp(..),isTrue,isFalse,NumExp,NumOp(..))whereimportControl.ApplicativeimportData.MonoidimportData.TraversableimportData.Foldablehiding(concat)importData.Map(Map)importqualifiedData.IntMapasIMimportqualifiedData.MapasMimportData.Fix-- | The inner representation of csound expressions.typeE=FixRatedExptypeName=StringdataRatedExpa=RatedExp{ratedExpRate::MaybeRate,ratedExpDepends::Maybea,ratedExpExp::Expa}deriving(Show,Eq,Ord)dataRatedVar=RatedVar{ratedVarRate::Rate,ratedVarId::Int}deriving(Show)onExp::(Expa->Expa)->RatedExpa->RatedExpaonExpfa=a{ratedExpExp=f(ratedExpExpa)}dataVarType=LocalVar|GlobalVarderiving(Show,Eq,Ord)typeExpa=MainExp(PrimOra)toPrimOr::E->PrimOrEtoPrimOra=PrimOr$caseratedExpExp$unFixaofExpPrim(PString_)->RightaExpPrimp->Leftp_->RightanewtypePrimOra=PrimOr{unPrimOr::EitherPrima}deriving(Show,Eq,Ord)dataMainExpa=ExpPrimPrim|TfmInfo[a]|ConvertRateRateRatea|SelectRateInta|If(CondInfoa)aa|ExpBool(BoolExpa)|ExpNum(NumExpa)|ReadVarVar|WriteVarVaraderiving(Show,Eq,Ord)dataVar=Var{varType::VarType,varRate::Rate,varName::Name}|VarVerbatim{varRate::Rate,varName::Name}deriving(Show,Eq,Ord)dataInfo=Info{infoName::Name,infoSignature::Signature,infoOpcType::OpcType,infoNextSE::MaybeInt}deriving(Show,Eq,Ord)isPrefix,isInfix,isProcedure::Info->BoolisPrefix=(Prefix==).infoOpcTypeisInfix=(Infix==).infoOpcTypeisProcedure=(Procedure==).infoOpcTypedataOpcType=Prefix|Infix|Procedurederiving(Show,Eq,Ord)-- | The Csound rates.dataRate=Xr|Ar|Kr|Ir|Sr|Frderiving(Show,Eq,Ord,Enum,Bounded)dataSignature=SingleRate(MapRate[Rate])|MultiRate{outMultiRate::[Rate],inMultiRate::[Rate]}deriving(Show,Eq,Ord)dataPrim=PInt|PStringInt-- >> p-string: |PrimIntInt|PrimDoubleDouble|PrimTabTab|PrimStringStringderiving(Show,Eq,Ord)typeTabMap=M.MapTabInt-- | Csound f-tables. You can make a value of 'Tab' with the function 'gen'.dataTab=Tab{tabSize::Int,tabGen::Int,tabArgs::[Double]}deriving(Show,Eq,Ord)-------------------------------------------------------------- types for arithmetic and boolean expressionsdataInlineab=Inline{inlineExp::InlineExpa,inlineEnv::IM.IntMapb}deriving(Show,Eq,Ord)dataInlineExpa=InlinePrimInt|InlineExpa[InlineExpa]deriving(Show,Eq,Ord)dataPreInlineab=PreInlinea[b]deriving(Show,Eq,Ord)-- booleanstypeBoolExpa=PreInlineCondOpatypeCondInfoa=InlineCondOpadataCondOp=TrueOp|FalseOp|Not|And|Or|Equals|NotEquals|Less|Greater|LessEquals|GreaterEqualsderiving(Show,Eq,Ord)isTrue,isFalse::CondInfoa->BoolisTrue=isCondOpTrueOpisFalse=isCondOpFalseOpisCondOpop=maybeFalse(op==).getCondInfoOpgetCondInfoOp::CondInfoa->MaybeCondOpgetCondInfoOpx=caseinlineExpxofInlineExpop_->Justop_->Nothing-- numberstypeNumExpa=PreInlineNumOpadataNumOp=Add|Sub|Neg|Mul|Div|Pow|Mod|Sin|Cos|Sinh|Cosh|Tan|Tanh|Sininv|Cosinv|Taninv|Abs|Ceil|ExpOp|Floor|Frac|IntOp|Log|Log10|Logbtwo|Round|Sqrt|Ampdb|Ampdbfs|Dbamp|Dbfsamp|Cpspchderiving(Show,Eq,Ord)--------------------------------------------------------- instances for cseinstanceFunctorRatedExpwherefmapf(RatedExprda)=RatedExpr(fmapfd)(fmap(fmapf)a)instanceFoldableRatedExpwherefoldMapf(RatedExp_da)=foldMapfd<>foldMap(foldMapf)ainstanceTraversableRatedExpwheretraversef(RatedExprda)=RatedExpr<$>traversefd<*>traverse(traversef)ainstanceFunctorPrimOrwherefmapf(PrimOra)=PrimOr(fmapfa)instanceFoldablePrimOrwherefoldMapfx=caseunPrimOrxofLeft_->memptyRighta->fainstanceTraversablePrimOrwheretraversefx=caseunPrimOrxofLeftp->pure$PrimOr$LeftpRighta->PrimOr.Right<$>fainstanceFunctorMainExpwherefmapfx=casexofExpPrimp->ExpPrimpTfmtxs->Tfmt$mapfxsConvertRaterarba->ConvertRaterarb$faSelectrna->Selectrn$faIfinfoab->If(fmapfinfo)(fa)(fb)ExpBoola->ExpBool$fmapfaExpNuma->ExpNum$fmapfaReadVarv->ReadVarvWriteVarva->WriteVarv(fa)instanceFoldableMainExpwherefoldMapfx=casexofExpPrimp->memptyTfmtxs->foldMapfxsConvertRaterarba->faSelectrna->faIfinfoab->foldMapfinfo<>fa<>fbExpBoola->foldMapfaExpNuma->foldMapfaReadVarv->memptyWriteVarva->fainstanceTraversableMainExpwheretraversefx=casexofExpPrimp->pure$ExpPrimpTfmtxs->Tfmt<$>traversefxsConvertRaterarba->ConvertRaterarb<$>faSelectrna->Selectrn<$>faIfinfoab->If<$>traversefinfo<*>fa<*>fbExpBoola->ExpBool<$>traversefaExpNuma->ExpNum<$>traversefaReadVarv->pure$ReadVarvWriteVarva->WriteVarv<$>fainstanceFunctor(Inlinea)wherefmapfa=a{inlineEnv=fmapf$inlineEnva}instanceFoldable(Inlinea)wherefoldMapfa=foldMapf$inlineEnvainstanceTraversable(Inlinea)wheretraversef(Inlineab)=Inlinea<$>traversefbinstanceFunctor(PreInlinea)wherefmapf(PreInlineopas)=PreInlineop$fmapfasinstanceFoldable(PreInlinea)wherefoldMapf(PreInline_as)=foldMapfasinstanceTraversable(PreInlinea)wheretraversef(PreInlineopas)=PreInlineop<$>traversefas-- comments-- -- p-string ---- separate p-param for strings (we need it to read strings from global table) -- Csound doesn't permits us to use more than four string params so we need to-- keep strings in the global table and use `strget` to read them