{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances #-}
    
module CsoundExpr.Base.Types 
    (X(..), K,
     Arate, Krate, Irate, SignalOut, 
     itime, idur, num, double, string
    )
where

import Text.PrettyPrint(Doc, vcat, text, space)

import qualified CsoundExpr.Translator.Cs.CsTree as La

import CsoundExpr.Translator.Cs.IM
import CsoundExpr.Translator.Types

import CsoundExpr.Base.Imperative 
import CsoundExpr.Base.UserDefined(opcode, prefixOperation)
import CsoundExpr.Translator.Csd

-------------------------------------------
--  constructors

-- | @p2@ p-field
itime :: Irate
itime = La.param 2

-- | @p3@ p-field
idur :: Irate
idur = La.param 3

-- | auxiliary function, to write (num n) instead of (n :: Irate)
num :: Irate -> Irate
num = id

-- | Lift 'Double' to 'Irate'
double :: Double -> Irate
double = La.double

-- | Lift 'String' to 'Irate'
string :: String -> Irate
string = La.string

---------------------------------------------
-- show instances

instance Show Arate where
    show x = show $ vcat [title , ppCsTrees $ fromSignalOut (ar "Out" <=> x)]
        where title = text "; Arate expression :"

instance Show Krate where
    show x = show $ vcat [title , ppCsTrees $ fromSignalOut (kr "Out" <=> x)]
        where title = text "; Krate expression :"

instance Show Irate where
    show x = show $ vcat [title , ppCsTrees $ fromSignalOut (ir "Out" <=> x)]
        where title = text "; Irate expression :"

instance Show SignalOut where
    show x = show $ vcat [title , ppCsTrees $ fromSignalOut x]
        where title = text "; SignalOut expression :"