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

slice of 1 doesn't work #979

Closed
matthewkaney opened this issue Dec 21, 2022 · 2 comments · Fixed by #1086
Closed

slice of 1 doesn't work #979

matthewkaney opened this issue Dec 21, 2022 · 2 comments · Fixed by #1086

Comments

@matthewkaney
Copy link
Contributor

slice "1" "0" $ s "bd" produces the following pattern (0>1)|begin: 0.0f, end: 0.0f, s: "bd". This doesn't seem to be correct—a slice of 1 should produce the full sample.

Incidentally, randslice behaves correctly: randslice "1" $ s "bd" produces (0>1)|begin: 0.0f, end: 1.0f, s: "bd"

@grddavies
Copy link
Contributor

I took a look at this today and came up with two possible fixes:

I didn't like this as much as it handles n = 1 as a special case, but it 'does less':

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 -> if n == 1 then 1 else div' i n + div' 1 n) <$> pI) <* pN
        div' num den = fromIntegral (num `mod` den) / fromIntegral den

Then I tried patterning the sample width to calculate the end parameter pattern:

slice'' :: Pattern Int -> Pattern Int -> ControlPattern -> ControlPattern
slice'' pN pI p = P.begin b |> P.end e |> p
  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

It looks like this issue is also true for splice:

λ> splice 1 0 $ s "bev"
(0>1)|begin: 0.0f, end: 0.0f, s: "bev", speed: 1.0f, unit: "c"

I can put a PR together if this will work with tidal 2.0

@yaxu
Copy link
Member

yaxu commented Jun 3, 2024

Hi @grddavies, a PR would be very welcome. Please target the dev branch, thanks!

grddavies added a commit to grddavies/Tidal that referenced this issue Jun 4, 2024
grddavies added a commit to grddavies/Tidal that referenced this issue Jun 4, 2024
@yaxu yaxu closed this as completed in #1086 Jun 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants