Is there a stack from list function?

When I use i.e. a pattern with dots like n "[0 .. 3]" I receive something like this:

0>¼)|n: Note {unNote = 0.0}n
(¼>½)|n: Note {unNote = 1.0}n
(½>¾)|n: Note {unNote = 2.0}n
(¾>1)|n: Note {unNote = 3.0}n

I was wondering if there is an existing function for this shorthand with stack and not cat. I created something like this to achieve such a result:

stackFromList :: [a] -> Pattern a
stackFromList = stack . map pure

patternToList :: Pattern a -> [a]
patternToList pat = (map value (queryArc pat (Arc 0 1)))

cond pat = stackFromList $ patternToList pat

When I use it like n (cond "0 .. 3") I receive the result I was looking for.

This is useful, for example, to be able to conditionally specify a note range for the function fix which could be interesting with control functions like:

gitNote = pN "gitNote"

d1 $ (fix (# silence) (gitNote $ cond $ "[c5 .. d6]")) 
     $ s "808" 
     # gitNote (cN 0 "notes") -- incoming note from osc ctrl message

The Problem here is that I find it not very handsome to pattern the conditions (because it is not inside of the mini notation). That's why I need to use something like this:

d1 $ (fix (# cutoff 3000)
     (cat [gitNote $ cond $ "[c6 .. d6]", gitNote $ cond $ "[c5 .. d6]"]))
   $ s "supervibe" <| n "c a f e"
   # gitNote (cN 0 "notes")

That's why my initial question, whether there is an existing function (or maybe a better solution) to get a stack of notes in a range?

1 Like

Here's a quick hack:

stackRange :: (Read a, Enum a) => Pattern String -> Pattern a
stackRange pat = innerJoin $ (stack . map pure) <$> patRange pat
  where
        patRange :: (Read a, Enum a) => Pattern String -> Pattern [a]
        patRange pat = rangeToList <$> pat
        rangeToList :: (Read a, Enum a) => String -> [a]
        rangeToList str = [read a .. read b]
          where (a,b) = splt "" str
        splt as (':':bs) = (as,bs)
        splt as [] = (as,[])
        splt as (b:bs) = splt (as ++ [b]) bs

stackRange "4:8 10:12" :: Pattern Int
1 Like

Thanks a lot! That looks nice and is a very good starting point to experiment with :slight_smile:
The only practical question I have is how to turn the Pattern Int into a Pattern Note.

Hm well I expected this to work:

stackRange "4:8 10:12" :: Pattern Note

Unfortunately it doesn't, I'm not sure why.. This does though:

Note <$> stackRange "4:8 10:12" 
1 Like