module Music.Theory.Duration.RQ.Tied where
import Data.Maybe
import Music.Theory.Duration.Annotation
import Music.Theory.Duration.RQ
import Music.Theory.List
type Tied_Right = Bool
type RQ_T = (RQ,Tied_Right)
rqt :: Tied_Right -> RQ -> RQ_T
rqt t d = (d,t)
rqt_rq :: RQ_T -> RQ
rqt_rq = fst
rqt_tied :: RQ_T -> Tied_Right
rqt_tied = snd
is_tied_right :: RQ_T -> Bool
is_tied_right = snd
rqt_un_tuplet :: (Integer,Integer) -> RQ_T -> RQ_T
rqt_un_tuplet i (d,t) = (rq_un_tuplet i d,t)
rq_rqt :: RQ -> RQ_T
rq_rqt n = (n,False)
rq_tie_last :: [RQ] -> [RQ_T]
rq_tie_last = at_last rq_rqt (\d -> (d,True))
rqt_to_duration_a :: Bool -> [RQ_T] -> [Duration_A]
rqt_to_duration_a z x =
let rt = map is_tied_right x
lt = z : rt
f p e = if p then Just e else Nothing
g r l = catMaybes [f r Tie_Right,f l Tie_Left]
h = rq_to_duration_err (show ("rqt_to_duration_a",z,x)) . rqt_rq
in zip (map h x) (zipWith g rt lt)
rqt_can_notate :: [RQ_T] -> Bool
rqt_can_notate = rq_can_notate . map rqt_rq
rqt_to_cmn :: RQ_T -> Maybe (RQ_T,RQ_T)
rqt_to_cmn (k,t) =
let f (i,j) = ((i,True),(j,t))
in fmap f (rq_to_cmn k)
rqt_to_cmn_l :: RQ_T -> [RQ_T]
rqt_to_cmn_l x = maybe [x] (\(i,j) -> [i,j]) (rqt_to_cmn x)
rqt_set_to_cmn :: [RQ_T] -> [RQ_T]
rqt_set_to_cmn = concatMap rqt_to_cmn_l