Rounding Float patterns

How can I turn a Pattern Float into a Pattern Int by rounding the values inside the Pattern Float? For example, I could have a process that yields floating-point values in the form of a pattern (this could be for example sine), and I want to feed such values to up, but only as notes from the twelve-tones scale.

I have tried to use round <$> myPattern (where myPattern is of type Pattern Double), but I don't seem to have luck when plugging it in up (apparently the types don't match).

Does anyone have any clue what I could do about it?

If up and sine are decent proxies for your end goal/custom function, how about something like this?

d1 $ (# up (fromIntegral <$> round <$> sine)) $ s "pluck"

Actually, checking the types I can see that
(round <$> sine) :: Integral b => Pattern b
up :: Pattern Double -> ControlPattern

The problem isn't getting Pattern Float into a Pattern Int, but getting Pattern Int to Pattern Double, hence fromIntegral. Not sure if this was the real problem you were up against.

1 Like

round <$> should work for that. If you can share a pattern that doesn't run, with its error message, we can have a look

1 Like

Thanks, that was exactly my problem, I didn't realize that up took a Pattern Double as an argument, in my mind it was more polymorphic!