Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.
Merged
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
11 changes: 7 additions & 4 deletions src/Sound/Tidal/UI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ rand :: Fractional a => Pattern a
rand = Pattern (\(State a@(Arc s e) _) -> [Event (Context []) Nothing a (realToFrac $ (timeToRand ((e + s)/2) :: Double))])

-- | Boolean rand - a continuous stream of true/false values, with a 50/50 chance.
brand :: Pattern Bool
brand :: Pattern Bool
brand = _brandBy 0.5

-- | Boolean rand with probability as input, e.g. brandBy 0.25 is 25% chance of being true.
Expand Down Expand Up @@ -718,6 +718,8 @@ In the above, three sounds are picked from the pattern on the right according
to the structure given by the `e 3 8`. It ends up picking two `bd` sounds, a
`cp` and missing the `sn` entirely.

A negative first argument provides the inverse of the euclidean pattern.

These types of sequences use "Bjorklund's algorithm", which wasn't made for
music but for an application in nuclear physics, which is exciting. More
exciting still is that it is very similar in structure to the one of the first
Expand Down Expand Up @@ -755,7 +757,8 @@ euclid :: Pattern Int -> Pattern Int -> Pattern a -> Pattern a
euclid = tParam2 _euclid

_euclid :: Int -> Int -> Pattern a -> Pattern a
_euclid n k a = fastcat $ fmap (bool silence a) $ bjorklund (n,k)
_euclid n k a | n >= 0 = fastcat $ fmap (bool silence a) $ bjorklund (n,k)
| otherwise = fastcat $ fmap (bool a silence) $ bjorklund (-n,k)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this correct? bjorklund should be called with (n,k)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is correct, this is the case of n < 0, so -n > 0 (otherwise bjorklund wouldn't produce anything). Note the reversed order of a and silence

Copy link
Copy Markdown
Contributor

@ndr-brt ndr-brt May 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, right, I did a wrong assumption! So ok for me 👍


{- | `euclidfull n k pa pb` stacks @e n k pa@ with @einv n k pb@ -}
euclidFull :: Pattern Int -> Pattern Int -> Pattern a -> Pattern a -> Pattern a
Expand Down Expand Up @@ -809,7 +812,7 @@ euclidInv :: Pattern Int -> Pattern Int -> Pattern a -> Pattern a
euclidInv = tParam2 _euclidInv

_euclidInv :: Int -> Int -> Pattern a -> Pattern a
_euclidInv n k a = fastcat $ fmap (bool a silence) $ bjorklund (n,k)
_euclidInv n k a = _euclid (-n) k a

index :: Real b => b -> Pattern b -> Pattern c -> Pattern c
index sz indexpat pat =
Expand Down Expand Up @@ -1468,7 +1471,7 @@ rolledBy "<1 -0.5 0.25 -0.125>" $ note "c'maj9" # s "superpiano"
rolledWith :: Ratio Integer -> Pattern a -> Pattern a
rolledWith t = withEvents aux
where aux es = concatMap (steppityIn) (groupBy (\a b -> whole a == whole b) $ ((isRev t) es))
isRev b = (\x -> if x > 0 then id else reverse ) b
isRev b = (\x -> if x > 0 then id else reverse ) b
steppityIn xs = mapMaybe (\(n, ev) -> (timeguard n xs ev t)) $ enumerate xs
timeguard _ _ ev 0 = return ev
timeguard n xs ev _ = (shiftIt n (length xs) ev)
Expand Down
9 changes: 9 additions & 0 deletions test/Sound/Tidal/UITest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,15 @@ run =
(euclid 11 24 "x", "x ~ ~ x ~ x ~ x ~ x ~ x ~ ~ x ~ x ~ x ~ x ~ x ~"),
(euclid 13 24 "x", "x ~ x x ~ x ~ x ~ x ~ x ~ x x ~ x ~ x ~ x ~ x ~")
] :: [(Pattern String, String)])
it "can be called with a negative first value to give the inverse" $ do
compareP (Arc 0 1)
(euclid (-3) 8 ("bd" :: Pattern String))
(euclidInv 3 8 ("bd" :: Pattern String))
it "can be called with a negative first value to give the inverse (patternable)" $ do
compareP (Arc 0 1)
(euclid (-3) 8 ("bd" :: Pattern String))
("bd(-3,8)" :: Pattern String)


describe "wedge" $ do
it "should not freeze tidal amount is 1" $ do
Expand Down