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

[breaking change] sample signals at query onsets instead of midpoint #1148

Merged
merged 2 commits into from
Feb 13, 2025
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
2 changes: 1 addition & 1 deletion src/Sound/Tidal/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ sig f = pattern q
where
q (State (Arc s e) _)
| s > e = []
| otherwise = [Event (Context []) Nothing (Arc s e) (f (s + ((e - s) / 2)))]
| otherwise = [Event (Context []) Nothing (Arc s e) (f s)]

-- | @sine@ - unipolar sinewave. A pattern of continuous values following a
-- sinewave with frequency of one cycle, and amplitude from 0 to 1.
Expand Down
20 changes: 10 additions & 10 deletions test/Sound/Tidal/CoreTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -296,21 +296,21 @@ run =
map value (queryArc ((+ 1) <$> saw) (Arc 0.5 0.5)) `shouldBe` [1.5 :: Float]
it "works on the left of <*>" $
queryArc ((+) <$> saw <*> pure 3) (Arc 0 1)
`shouldBe` [Event (Context []) Nothing (Arc 0 1) 3.5 :: Event Double]
`shouldBe` [Event (Context []) Nothing (Arc 0 1) 3 :: Event Double]
it "works on the right of <*>" $
queryArc (fast 4 (pure (+ 3)) <*> saw) (Arc 0 1)
`shouldBe` [ Event (Context []) Nothing (Arc 0 0.25) 3.5 :: Event Double,
Event (Context []) Nothing (Arc 0.25 0.5) 3.5,
Event (Context []) Nothing (Arc 0.5 0.75) 3.5,
Event (Context []) Nothing (Arc 0.75 1) 3.5
`shouldBe` [ Event (Context []) Nothing (Arc 0 0.25) 3 :: Event Double,
Event (Context []) Nothing (Arc 0.25 0.5) 3,
Event (Context []) Nothing (Arc 0.5 0.75) 3,
Event (Context []) Nothing (Arc 0.75 1) 3
]
it "can be reversed" $ do
it "works with whole cycles" $
queryArc (rev saw) (Arc 0 1)
`shouldBe` [Event (Context []) Nothing (Arc 0 1) 0.5 :: Event Double]
`shouldBe` [Event (Context []) Nothing (Arc 0 1) 0 :: Event Double]
it "works with half cycles" $
queryArc (rev saw) (Arc 0 0.5)
`shouldBe` [Event (Context []) Nothing (Arc 0 0.5) 0.75 :: Event Double]
queryArc (rev saw) (Arc 0.5 1)
`shouldBe` [Event (Context []) Nothing (Arc 0.5 1) 0 :: Event Double]
it "works with inset points" $
queryArc (rev saw) (Arc 0.25 0.25)
`shouldBe` [Event (Context []) Nothing (Arc 0.25 0.25) 0.75 :: Event Double]
Expand All @@ -320,12 +320,12 @@ run =
comparePD
(Arc 0 1)
(struct "t*8" (tri :: Pattern Double))
"0.125 0.375 0.625 0.875 0.875 0.625 0.375 0.125"
"0 0.25 0.5 0.75 1 0.75 0.5 0.25"
it "can be added to" $
comparePD
(Arc 0 1)
(struct "t*8" $ (tri :: Pattern Double) + 1)
"1.125 1.375 1.625 1.875 1.875 1.625 1.375 1.125"
"1 1.25 1.5 1.75 2 1.75 1.5 1.25"
describe "every" $
it "`every n id` doesn't change the pattern's structure" $ do
comparePD
Expand Down
4 changes: 2 additions & 2 deletions test/Sound/Tidal/PatternTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ run =
]
it "preserves cycle number of inner patterns" $ do
(map value $ queryArc (squeezeJoin (pure $ struct "1" $ (sig $ id))) (Arc 3 4))
`shouldBe` [3.5]
`shouldBe` [3]

describe ">>=" $ do
it "can apply functions to patterns" $ do
Expand Down Expand Up @@ -530,7 +530,7 @@ run =
it "filter above given threshold" $ do
let fil = stripContext $ filterWhen (> 0.5) $ struct "t*4" $ (tri :: Pattern Double) + 1
let res = queryArc fil (Arc 0.5 1.5)
property $ fmap toEvent [(((3 % 4, 1), (3 % 4, 1)), 1.25), (((1, 5 % 4), (1, 5 % 4)), 1.25), (((5 % 4, 3 % 2), (5 % 4, 3 % 2)), 1.75)] === res
property $ fmap toEvent [(((3 % 4, 1), (3 % 4, 1)), 1.5), (((1, 5 % 4), (1, 5 % 4)), 1), (((5 % 4, 3 % 2), (5 % 4, 3 % 2)), 1.5)] === res

describe "compressArc" $ do
it "return empty if start time is greater than end time" $ do
Expand Down
6 changes: 3 additions & 3 deletions test/Sound/Tidal/UITest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ run =
compareP
(Arc 0 3)
(segment 4 saw)
("0.125 0.375 0.625 0.875" :: Pattern Double)
("0 0.25 0.5 0.75" :: Pattern Double)
it "can hold a value over multiple cycles" $ do
comparePD
(Arc 0 8)
Expand Down Expand Up @@ -377,7 +377,7 @@ run =
compareP
(Arc 0 4)
("0" |+ chooseBy (sig fromRational) [0, 1, 2, 3])
("2" :: Pattern Int)
("0" :: Pattern Int)

describe "arpeggiate" $ do
it "can arpeggiate" $ do
Expand Down Expand Up @@ -479,4 +479,4 @@ run =
compareP
(Arc 0 1)
(segment 2 $ quantise 1 $ sine :: Pattern Note)
("1 0" :: Pattern Note)
("0 1" :: Pattern Note)
Loading