Skip to content

Commit

Permalink
committing some things I was working on a while ago and lost my way w…
Browse files Browse the repository at this point in the history
…ith..
  • Loading branch information
yaxu committed Nov 12, 2023
1 parent d347b65 commit c5cc1e2
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 324 deletions.
295 changes: 0 additions & 295 deletions old/Sound/Tidal/Scales.hs

This file was deleted.

4 changes: 2 additions & 2 deletions tidal-core/src/Sound/Tidal/Compose.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Data.Bits
import Data.Bool (bool)
import qualified Data.Map.Strict as Map
import Prelude hiding (Applicative (..))
import Sound.Tidal.Pattern (filterJusts, flexBind)
import Sound.Tidal.Pattern (filterJusts)
import Sound.Tidal.Types

-- ************************************************************ --
Expand All @@ -30,7 +30,7 @@ instance {-# OVERLAPPING #-} Unionable ValueMap where
union = Map.union

liftP2 :: Pattern p => (a -> b -> c) -> (p a -> p b -> p c)
liftP2 op apat bpat = apat `flexBind` \a -> op a <$> bpat
liftP2 op apat bpat = apat `mixBind` \a -> op a <$> bpat

set, keep :: Pattern p => p a -> p a -> p a
set = liftA2 (flip union)
Expand Down
2 changes: 1 addition & 1 deletion tidal-core/src/Sound/Tidal/InstanceHacks.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import qualified Data.Map.Strict as Map
-- import Sound.Tidal.Compose (liftA2)
import Sound.Tidal.Sequence ()
import Sound.Tidal.Signal ()
import Sound.Tidal.Span (withSpanTime)
-- import Sound.Tidal.Span (withSpanTime)
import Sound.Tidal.Types
import Sound.Tidal.Value

Expand Down
34 changes: 23 additions & 11 deletions tidal-core/src/Sound/Tidal/Pattern.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,34 @@ alignify f = \apat bpat -> uncurry f (patAlign apat bpat)

patternify_P :: Pattern p => (a -> p b) -> (p a -> p b)
patternify_P f apat = apat `bind` f
where bind = patBind apat
where bind = patBindMix apat

patternify' :: Pattern p => BindSpec p -> (a -> p b) -> (p a -> p b)
patternify' spec f apat = apat `bind` f
where bind = specToBind spec


-- patternify_P' :: (Pattern p) => BindSpec (p a) -> (a -> p b) -> (p a -> p b)
-- patternify_P' spec f apat = apat `bind` f
-- where bind = patBindMix apat

patternify_P_n :: Pattern p => (a -> b -> p c) -> (p a -> b -> p c)
patternify_P_n f apat b = apat `bind` \a -> f a b
where bind = patBind apat
where bind = patBindMix apat

patternify_P_p :: Pattern p => (a -> p b -> p c) -> (p a -> p b -> p c)
patternify_P_p = alignify . patternify_P_n

patternify_P_P :: Pattern p => (a -> b -> p c) -> (p a -> p b -> p c)
patternify_P_P f = alignify $ patternify_P_n $ patternify_P <$> f

patternify_P_n_n :: Pattern p => (a -> b -> c -> p d) -> (p a -> b -> c -> p d)
patternify_P_n_n f apat b c = apat `bind` \a -> f a b c
where bind = patBind apat
where bind = patBindMix apat

patternify_P_n_n_n :: Pattern p => (a -> b -> c -> d -> p e) -> (p a -> b -> c -> d -> p e)
patternify_P_n_n_n f apat b c d = apat `bind` \a -> f a b c d
where bind = patBind apat

patternify_P_P :: Pattern p => (a -> b -> p c) -> (p a -> p b -> p c)
patternify_P_P f = alignify $ patternify_P_n $ patternify_P <$> f
where bind = patBindMix apat

patternify_P_P_n :: Pattern p => (a -> b -> c -> p d) -> (p a -> p b -> c -> p d)
patternify_P_P_n f = alignify $ patternify_P_n_n $ patternify_P_n <$> f
Expand All @@ -53,12 +62,15 @@ patternify_P_P_P_n :: Pattern p => (a -> b -> c -> d -> p e) -> p a -> p b -> p
patternify_P_P_P_n f = alignify $ patternify_P_n_n_n $ patternify_P_P_n <$> f

(<*), (*>) :: Pattern p => p (t -> b) -> p t -> p b
pf <* px = pf `innerBind` \f -> px `innerBind` \x -> pure $ f x
pf *> px = pf `outerBind` \f -> px `outerBind` \x -> pure $ f x
pf <* px = pf `innerBind` (<$> px)
pf *> px = pf `outerBind` (<$> px)
infixl 4 <*, *>

flexBind :: Pattern p => p b -> (b -> p c) -> p c
flexBind a b = (patBind a) a b
(|>>=), (>>=|), (|>>=|) :: Pattern p => p a -> (a -> p b) -> p b
(|>>=) = innerBind
(>>=|) = outerBind
(|>>=|) = (>>=) -- mixBind
infixl 4 |>>=, >>=|, |>>=|

filterJusts :: Pattern p => p (Maybe a) -> p a
filterJusts = fmap fromJust . filterValues isJust
Expand Down
Loading

0 comments on commit c5cc1e2

Please sign in to comment.