From 44cb92dc2b44fdb80d0f053a962c29f945ea8194 Mon Sep 17 00:00:00 2001 From: Ben Gold Date: Mon, 1 Nov 2021 16:15:41 -0500 Subject: [PATCH 1/4] Add "Moddable" class to allow general |%| usage --- src/Sound/Tidal/Core.hs | 12 ++++++------ src/Sound/Tidal/Pattern.hs | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/Sound/Tidal/Core.hs b/src/Sound/Tidal/Core.hs index 1eb1b1cfa..160dfa406 100644 --- a/src/Sound/Tidal/Core.hs +++ b/src/Sound/Tidal/Core.hs @@ -179,12 +179,12 @@ a |- b = (-) <$> a <* b ( -|) :: Num a => Pattern a -> Pattern a -> Pattern a a -| b = (-) <$> a *> b -(|%|) :: (Applicative a, Real b) => a b -> a b -> a b -a |%| b = mod' <$> a <*> b -(|% ) :: Real a => Pattern a -> Pattern a -> Pattern a -a |% b = mod' <$> a <* b -( %|) :: Real a => Pattern a -> Pattern a -> Pattern a -a %| b = mod' <$> a *> b +(|%|) :: (Applicative a, Moddable b) => a b -> a b -> a b +a |%| b = gmod <$> a <*> b +(|% ) :: Moddable a => Pattern a -> Pattern a -> Pattern a +a |% b = gmod <$> a <* b +( %|) :: Moddable a => Pattern a -> Pattern a -> Pattern a +a %| b = gmod <$> a *> b (|**|) :: (Applicative a, Floating b) => a b -> a b -> a b a |**| b = (**) <$> a <*> b diff --git a/src/Sound/Tidal/Pattern.hs b/src/Sound/Tidal/Pattern.hs index e7046abf2..467082d80 100644 --- a/src/Sound/Tidal/Pattern.hs +++ b/src/Sound/Tidal/Pattern.hs @@ -40,6 +40,7 @@ import Data.List (delete, findIndex, sort) import Data.Word (Word8) import Data.Data (Data) -- toConstr import Data.Typeable (Typeable) +import Data.Fixed (mod') import Sound.Tidal.Time @@ -297,6 +298,21 @@ instance Fractional ValueMap where recip = fmap (applyFIS recip id id) fromRational r = Map.singleton "speed" $ VF (fromRational r) +class Moddable a where + gmod :: a -> a -> a + +instance Moddable Double where + gmod = mod' + +instance Moddable Note where + gmod (Note a) (Note b) = Note (mod' a b) + +instance Moddable Int where + gmod = mod + +instance Moddable ValueMap where + gmod = Map.unionWith (fNum2 mod mod') + instance Floating ValueMap where pi = noOv "pi" exp _ = noOv "exp" From 6a6cc8abae80cd46e95400278afc8977d80b3cfe Mon Sep 17 00:00:00 2001 From: Ben Gold Date: Mon, 1 Nov 2021 16:29:06 -0500 Subject: [PATCH 2/4] Rational is also an instance of Moddable --- src/Sound/Tidal/Pattern.hs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Sound/Tidal/Pattern.hs b/src/Sound/Tidal/Pattern.hs index 467082d80..f752f898c 100644 --- a/src/Sound/Tidal/Pattern.hs +++ b/src/Sound/Tidal/Pattern.hs @@ -303,13 +303,12 @@ class Moddable a where instance Moddable Double where gmod = mod' - +instance Moddable Rational where + gmod = mod' instance Moddable Note where gmod (Note a) (Note b) = Note (mod' a b) - instance Moddable Int where gmod = mod - instance Moddable ValueMap where gmod = Map.unionWith (fNum2 mod mod') From f174c9c03976c672142e99ed1e79d735cb56eac1 Mon Sep 17 00:00:00 2001 From: Ben Gold Date: Mon, 1 Nov 2021 22:32:22 -0500 Subject: [PATCH 3/4] Update tidal-parse with new signature for |%| --- tidal-parse/src/Sound/Tidal/Parse.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tidal-parse/src/Sound/Tidal/Parse.hs b/tidal-parse/src/Sound/Tidal/Parse.hs index 8eea4b0bb..4da327892 100644 --- a/tidal-parse/src/Sound/Tidal/Parse.hs +++ b/tidal-parse/src/Sound/Tidal/Parse.hs @@ -523,7 +523,7 @@ numMergeOperator = $(fromHaskell "*") <|> $(fromHaskell "-") -realMergeOperator :: Real a => H (Pattern a -> Pattern a -> Pattern a) +realMergeOperator :: Moddable a => H (Pattern a -> Pattern a -> Pattern a) realMergeOperator = $(fromTidal "|%|") <|> $(fromTidal "|%") <|> From f57863fad879e6035e2d335af21f3953b8f10f0d Mon Sep 17 00:00:00 2001 From: Ben Gold Date: Mon, 1 Nov 2021 22:40:48 -0500 Subject: [PATCH 4/4] spellcheck --- tidal-parse/src/Sound/Tidal/Parse.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tidal-parse/src/Sound/Tidal/Parse.hs b/tidal-parse/src/Sound/Tidal/Parse.hs index 4da327892..d828154dd 100644 --- a/tidal-parse/src/Sound/Tidal/Parse.hs +++ b/tidal-parse/src/Sound/Tidal/Parse.hs @@ -523,7 +523,7 @@ numMergeOperator = $(fromHaskell "*") <|> $(fromHaskell "-") -realMergeOperator :: Moddable a => H (Pattern a -> Pattern a -> Pattern a) +realMergeOperator :: T.Moddable a => H (Pattern a -> Pattern a -> Pattern a) realMergeOperator = $(fromTidal "|%|") <|> $(fromTidal "|%") <|>