Mapping a pattern value to another value

I'm not sure if there isn't already a solution to my problem, but I'm trying to replace the values of a pattern with another value. The time per event should remain the same.

I think my first quick hack should make my problem more understandable:

-- This is my list of tuples
rev_map = [("spring", 0), ("hall", 127)]

-- This is my first quick hack
rev_type p = (fromMaybe 0 $ lookup p rev_map) :: Pattern Note

-- This:
rev_type "hall"
-- will translated to this
-- (0>1)|Note {unNote = 127.0}

-- But obviously I can not use patterns for multiple values
-- because my quick hack is only mapping one value to another
rev_type "[hall spring]"

-- But it would be awesome to have this result:
-- (0>1/2)|Note {unNote = 127.0}
-- (1/2>1)|Note {unNote = 0.0}

Can someone please help me here how I can possibly implement this? Any approach would be a great help. :slight_smile:

It's not documented, but there's a way to bind variables into patterns like this (I'm on the phone, not sure at all, but you can check the codebase):

setF "hall" $ 127
setF "spring" $ 0

n "[^hall ^spring]"
1 Like

This looks like the correct direction. Thank you very much!

Tomorrow I will test whether it will create the correct behaviour. On my first look I was wondering, that this will not print the pattern in the console:

-- :t setF
-- setF :: String -> Pattern Double -> IO ()

setF "hall" 127

n "^hall"
-- nothing is printed

Works like a charm! Thx @ndr_brt!

Here is the working example:

do
setF "bubu" 0
setF "lala" 1
d1 $ s "808" <| n "[^bubu ^lala]*2"
1 Like