Skip to content

Commit

Permalink
Merge pull request #1086 from grddavies/slice-by-1
Browse files Browse the repository at this point in the history
fix(slice): support `slice 1 _`
  • Loading branch information
yaxu authored Jun 9, 2024
2 parents e6cb7cf + 766f1fe commit c69162e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/Sound/Tidal/Control.hs
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,13 @@ en ns p = stack $ map (\(i, (k, n)) -> _e k n (samples p (pure i))) $ enumerate
-}
slice :: Pattern Int -> Pattern Int -> ControlPattern -> ControlPattern
slice pN pI p = P.begin b # P.end e # p
where b = div' <$> pI <* pN
e = (\i n -> div' i n + div' 1 n) <$> pI <* pN
div' num den = fromIntegral (num `mod` den) / fromIntegral den
where
b = div' <$> pI <* pN
e = b + pWidth
pWidth = (\x -> 1.0 / fromIntegral x) <$> pN
div' :: Int -> Int -> Double
div' num den = fromIntegral (num `mod` den) / fromIntegral den


_slice :: Int -> Int -> ControlPattern -> ControlPattern
_slice n i p =
Expand Down
14 changes: 13 additions & 1 deletion test/Sound/Tidal/ControlTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,21 @@ run =
comparePD (Arc 0 1)
(filterOnsets $ stutWith 4 0.25 (# gain 1) $ sound "bd")
(filterOnsets $ stut 4 1 0.25 $ sound "bd")

describe "splice" $ do
it "can beatslice" $ do
comparePD (Arc 0 1)
(splice "4 8" "0 1" $ sound "bev")
(begin "0 0.125" # end "0.25 0.25" # speed "0.5 0.25" # sound "bev" # unit "c")

describe "slice" $ do
it "can slice samples" $ do
compareP (Arc 0 1)
(slice "8 4" "7 5 0 3 2 4 1 6" $ sound "sn bd")
(begin "0.875 0.625 0.0 0.375 0.5 0.0 0.25 0.5" # end "1.0 0.75 0.125 0.5 0.75 0.25 0.5 0.75" # sound "sn bd")

it "can slice by 1" $ do
compareP (Arc 0 1)
(slice "1 4" "1 [2 4 1 6]" $ sound "sn bd")
(begin "0.0 [0.5 0.0 0.25 0.5]" # end "1.0 [0.75 0.25 0.5 0.75]" # sound "sn bd")

0 comments on commit c69162e

Please sign in to comment.