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

fix(slice): support slice 1 _ #1086

Merged
merged 1 commit into from
Jun 9, 2024
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
10 changes: 7 additions & 3 deletions src/Sound/Tidal/Control.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import Prelude hiding ((*>), (<*))

import qualified Data.Map.Strict as Map
import Data.Maybe (fromJust, fromMaybe, isJust)

Check warning on line 30 in src/Sound/Tidal/Control.hs

View workflow job for this annotation

GitHub Actions / build (9.0.1, 3.4.0.0)

The import of ‘fromJust, isJust’

Check warning on line 30 in src/Sound/Tidal/Control.hs

View workflow job for this annotation

GitHub Actions / cabal latest - ghc latest

The import of ‘fromJust, isJust’

Check warning on line 30 in src/Sound/Tidal/Control.hs

View workflow job for this annotation

GitHub Actions / cabal 3.4.0.0 - ghc 9.0.1

The import of ‘fromJust, isJust’

Check warning on line 30 in src/Sound/Tidal/Control.hs

View workflow job for this annotation

GitHub Actions / cabal 3.4.0.0 - ghc 8.8.3

The import of ‘fromJust, isJust’

Check warning on line 30 in src/Sound/Tidal/Control.hs

View workflow job for this annotation

GitHub Actions / cabal 3.4.0.0 - ghc 8.10.1

The import of ‘fromJust, isJust’

Check warning on line 30 in src/Sound/Tidal/Control.hs

View workflow job for this annotation

GitHub Actions / cabal 3.8.1.0 - ghc 9.4.1

The import of ‘fromJust, isJust’

Check warning on line 30 in src/Sound/Tidal/Control.hs

View workflow job for this annotation

GitHub Actions / cabal 3.4.0.0 - ghc 8.6.5

The import of ‘fromJust, isJust’

Check warning on line 30 in src/Sound/Tidal/Control.hs

View workflow job for this annotation

GitHub Actions / build (9.0.1, 3.4.0.0)

The import of ‘fromJust, isJust’
import Data.Ratio

import Sound.Tidal.Core
Expand All @@ -35,7 +35,7 @@
import Sound.Tidal.Pattern
import Sound.Tidal.Stream.Types (patternTimeID)
import Sound.Tidal.UI
import Sound.Tidal.Utils

Check warning on line 38 in src/Sound/Tidal/Control.hs

View workflow job for this annotation

GitHub Actions / build (9.0.1, 3.4.0.0)

The import of ‘Sound.Tidal.Utils’ is redundant

Check warning on line 38 in src/Sound/Tidal/Control.hs

View workflow job for this annotation

GitHub Actions / cabal latest - ghc latest

The import of ‘Sound.Tidal.Utils’ is redundant

Check warning on line 38 in src/Sound/Tidal/Control.hs

View workflow job for this annotation

GitHub Actions / cabal 3.4.0.0 - ghc 9.0.1

The import of ‘Sound.Tidal.Utils’ is redundant

Check warning on line 38 in src/Sound/Tidal/Control.hs

View workflow job for this annotation

GitHub Actions / cabal 3.4.0.0 - ghc 8.8.3

The import of ‘Sound.Tidal.Utils’ is redundant

Check warning on line 38 in src/Sound/Tidal/Control.hs

View workflow job for this annotation

GitHub Actions / cabal 3.4.0.0 - ghc 8.10.1

The import of ‘Sound.Tidal.Utils’ is redundant

Check warning on line 38 in src/Sound/Tidal/Control.hs

View workflow job for this annotation

GitHub Actions / cabal 3.8.1.0 - ghc 9.4.1

The import of ‘Sound.Tidal.Utils’ is redundant

Check warning on line 38 in src/Sound/Tidal/Control.hs

View workflow job for this annotation

GitHub Actions / cabal 3.4.0.0 - ghc 8.6.5

The import of ‘Sound.Tidal.Utils’ is redundant

Check warning on line 38 in src/Sound/Tidal/Control.hs

View workflow job for this annotation

GitHub Actions / build (9.0.1, 3.4.0.0)

The import of ‘Sound.Tidal.Utils’ is redundant

{- | `spin` will "spin" and layer up a pattern the given number of times,
with each successive layer offset in time by an additional @1/n@ of a cycle,
Expand Down Expand Up @@ -293,9 +293,13 @@
-}
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")

Loading