tidalcycles / Tidal

Pattern language

Home Page:https://codeberg.org/uzu/tidal

Repository from Github https://github.comtidalcycles/TidalRepository from Github https://github.comtidalcycles/Tidal

Simplify rev

yaxu opened this issue · comments

I think @polymorphicengine pointed out that rev could just negate time, rather than the complex mirroring it's doing now.

Here's an implementation of that:

negateArc (Arc b e) = Arc (negate e) (negate b)
rev' = withQueryArc negateArc . withResultArc negateArc

Can we drop this in or does it have different behaviour? I think it's similar but the cycles are also in reverse order?

for comparison:

rev :: Pattern a -> Pattern a
rev p =
keepMeta p $
splitQueries $
p
{ query = \st ->
map makeWholeAbsolute $
mapParts (mirrorArc (midCycle $ arc st)) $
map
makeWholeRelative
( query
p
st
{ arc = mirrorArc (midCycle $ arc st) (arc st)
}
)
}
where
makeWholeRelative :: Event a -> Event a
makeWholeRelative e@Event {whole = Nothing} = e
makeWholeRelative (Event c (Just (Arc s e)) p'@(Arc s' e') v) =
Event c (Just $ Arc (s' - s) (e - e')) p' v
makeWholeAbsolute :: Event a -> Event a
makeWholeAbsolute e@Event {whole = Nothing} = e
makeWholeAbsolute (Event c (Just (Arc s e)) p'@(Arc s' e') v) =
Event c (Just $ Arc (s' - e) (e' + s)) p' v
midCycle :: Arc -> Time
midCycle (Arc s _) = sam s + 0.5
mapParts :: (Arc -> Arc) -> [Event a] -> [Event a]
mapParts f es = (\(Event c w p' v) -> Event c w (f p') v) <$> es
-- Returns the `mirror image' of a 'Arc' around the given point in time
mirrorArc :: Time -> Arc -> Arc
mirrorArc mid' (Arc s e) = Arc (mid' - (e - mid')) (mid' + (mid' - s))

A quick test worked great! Wow, what a simplification.

commented

i guess the difference comes in once a pattern is longer than one cycle:
currently rev <[1 2] [3 4]> == <[2 1] [4 3]>, but with the above (i think) it would be <[4 3] [2 1]>, so yes the cycles are also in reverse order

i think both behaviors are useful

Yes we could call the new one something like revall or revpat