Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.

Corrects the scaleWithList function #1193

Merged
merged 5 commits into from
Jun 6, 2025
Merged
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
23 changes: 18 additions & 5 deletions tidal-core/src/Sound/Tidal/Scales.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module Sound.Tidal.Scales (scale, scaleList, scaleTable, getScale, scaleWith, sc

import Data.Maybe (fromMaybe)
import Sound.Tidal.Core (slowcat)
import Sound.Tidal.Pattern (Pattern, (<*))
import Sound.Tidal.Pattern (Pattern, arc, (<*))
import Sound.Tidal.Utils ((!!!))
import Prelude hiding ((*>), (<*))

Expand Down Expand Up @@ -322,17 +322,30 @@ These are equivalent:

-}
scaleWith :: (Eq a, Fractional a) => Pattern String -> ([a] -> [a]) -> Pattern Int -> Pattern a
scaleWith = getScaleMod scaleTable
scaleWith = getScaleWith scaleTable

{- Variant of @scaleWith@ providing a list of modifier functions instead of a single function
-}
scaleWithList :: (Eq a, Fractional a) => Pattern String -> ([[a] -> [a]]) -> Pattern Int -> Pattern a
scaleWithList sp fs p = slowcat $ map (\f -> scaleWith sp f p) fs
scaleWithList _ [] _ = silence
scaleWithList sp (f : []) p = scaleWith sp f p
scaleWithList sp fs p = Pattern q
where
n = length fs
q st =
concatMap (ff st) $
arcCyclesZW (arc st)
ff st a = query pp $ st {arc = a}
where
f = fs !! i
cyc = (floor $ start a) :: Int
i = cyc `mod` n
pp = (scaleWith sp f p)

{- Variant of @getScale@ used to build the @scaleWith@ function
-}
getScaleMod :: (Eq a, Fractional a) => [(String, [a])] -> Pattern String -> ([a] -> [a]) -> Pattern Int -> Pattern a
getScaleMod table sp f p =
getScaleWith :: (Eq a, Fractional a) => [(String, [a])] -> Pattern String -> ([a] -> [a]) -> Pattern Int -> Pattern a
getScaleWith table sp f p =
( \n scaleName ->
noteInScale (uniq $ f $ fromMaybe [0] $ lookup scaleName table) n
)
Expand Down