Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simplify definition of cat, based on compressArc #826

Open
wants to merge 1 commit into
base: 2.0-beatmode-retired
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions src/Sound/Tidal/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import Data.Fixed (mod')
import qualified Data.Map.Strict as Map
import Data.Maybe (fromMaybe)
import Sound.Tidal.Pattern
import Data.Ratio ((%))
import Sound.Tidal.Utils (enumerate)

-- ** Elemental patterns

Expand Down Expand Up @@ -259,14 +261,7 @@ append a b = cat [a,b]
-- in turn, then the second cycle from each, and so on.
cat :: [Pattern a] -> Pattern a
cat [] = silence
cat ps = Pattern q
where n = length ps
q st = concatMap (f st) $ arcCyclesZW (arc st)
f st a = query (withResultTime (+offset) p) $ st {arc = Arc (subtract offset (start a)) (subtract offset (stop a))}
where p = ps !! i
cyc = (floor $ start a) :: Int
i = cyc `mod` n
offset = (fromIntegral $ cyc - ((cyc - i) `div` n)) :: Time
cat ps = _slow (toTime $ length ps) $ fastcat ps

-- | Alias for 'cat'
slowCat :: [Pattern a] -> Pattern a
Expand All @@ -290,7 +285,10 @@ fastappend = fastAppend
-- patterns there are, so the cycles from each are squashed to fit a
-- single cycle.
fastCat :: [Pattern a] -> Pattern a
fastCat ps = _fast (toTime $ length ps) $ cat ps
fastCat [] = silence
fastCat xs = stack $ map (\(i, x) -> compressArc (a i) x) $ enumerate xs
where a i = Arc (i % len) ((i+1) % len)
len = fromIntegral $ length xs

fastcat :: [Pattern a] -> Pattern a
fastcat = fastCat
Expand Down
4 changes: 2 additions & 2 deletions src/Sound/Tidal/UI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,7 @@ randStruct n = splitQueries $ Pattern {query = f}
where as = map (\(i, Arc s' e') ->
(Arc (s' + sam s) (e' + sam s),
subArc (Arc s e) (Arc (s' + sam s) (e' + sam s)), i)) $
enumerate $ value $ head $
enumerateI $ value $ head $
queryArc (randArcs n) (Arc (sam s) (nextSam s))
(Arc s e) = arc st

Expand Down Expand Up @@ -1398,7 +1398,7 @@ arpg = arpeggiate
arpWith :: ([EventF (ArcF Time) a] -> [EventF (ArcF Time) b]) -> Pattern a -> Pattern b
arpWith f p = withEvents munge p
where munge es = concatMap (spreadOut . f) (groupBy (\a b -> whole a == whole b) $ sortOn whole es)
spreadOut xs = mapMaybe (\(n, x) -> shiftIt n (length xs) x) $ enumerate xs
spreadOut xs = mapMaybe (\(n, x) -> shiftIt n (length xs) x) $ enumerateI xs
shiftIt n d (Event c (Just (Arc s e)) a' v) =
do
a'' <- subArc (Arc newS newE) a'
Expand Down
5 changes: 4 additions & 1 deletion src/Sound/Tidal/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,12 @@ accumulate (x:xs) = scanl (+) x xs
>>> enumerate ["foo","bar","baz"]
[(1,"foo"), (2,"bar"), (3,"baz")]
-}
enumerate :: [a] -> [(Int, a)]
enumerate :: (Num a, Enum a) => [b] -> [(a, b)]
enumerate = zip [0..]

enumerateI :: [b] -> [(Int, b)]
enumerateI = enumerate

{- | split given list of @a@ by given single a, e.g.

>>> wordsBy (== ':') "bd:3"
Expand Down