What is the 'context' in an Event?

Hello! I looked into the definition of the Event type, and noticed that it contains a type Context which is a list of tuples of tuples of integers. I couldn't really find any description what it is needed for, so I looked at some examples:

queryArc (("1 1 1 1"::Pattern Double)) (Arc 0 1)

returns: [[((1,1),(3,1))](0>¼)|1.0,[((3,1),(5,1))](¼>½)|1.0,[((5,1),(7,1))](½>¾)|1.0,[((7,1),(8,1))](¾>1)|1.0]

but queryArc (("1(4,4)"::Pattern Double)) (Arc 0 1)

returns: [[((1,1),(2,1)),((3,1),(4,1)),((5,1),(6,1))](0>¼)|1.0,[((1,1),(2,1)),((3,1),(4,1)),((5,1),(6,1))](¼>½)|1.0,[((1,1),(2,1)),((3,1),(4,1)),((5,1),(6,1))](½>¾)|1.0,[((1,1),(2,1)),((3,1),(4,1)),((5,1),(6,1))](¾>1)|1.0]

I hope someone can explain? All the best!

Hi @onthepeakofnormal. It's used in the experimental 'feedforward' editor. It points to things in the mininotation that are used by the event. To make this useful, feedforward pre-processes tidal code with the 'deltaMini' function found in Sound.Tidal.Utils, which adds a function to each mininotation instance so that the context is relative to the whole pattern and not just the mininotation. It's a bit of a hack but works!

Hey @yaxu ! Thanks for your quick response! I kind of understand. Actually the reason I looked into it, is because I want to find a way to uniquely indentify each event playing in a pattern over one cycle. For example

queryArc (("1 2 3 4"::Pattern Double)) (Arc 0 1)


queryArc (("1 2 3 4"::Pattern Double)) (Arc 0.25 0.3)

returns [[((3,1),(5,1))](¼>3/10)-½|2.0]

and I want some way of telling, that the second event in the first example corresponds to the single event in the second example (without using the values). So in this example I could use the context, but it unfortunately doesn't work for euclidian patterns, as you can see in my first post. Is there some (easy) way of doing this?

I think you'll need to share some wider context for the problem you're trying to solve

ok! so I want to define a function ( I called it mask' temporarily) that takes two patterns and takes the structure of the first pattern and the values of the second pattern, but not in the usual way, but rather in this way:

mask' "[t t] t t" "0 4 7 14"

would be equivalent to the pattern "[0 4] 7 14"

This is my code:

mask':: Eq a => Pattern Bool -> Pattern a -> Pattern a
mask' b pat = b' {query = \st -> _mask' l1 l2 (query b' st) }
            where b' = filterValues (\x -> x) b
                  l1 = queryArc b' (Arc 0 1)
                  l2 = queryArc pat (Arc 0 1)

_mask':: [Event Bool] -> [Event a]-> [Event Bool] -> [Event a]
_mask' l1 l2 [] = []
_mask' l1 l2 (x:xs) = (x {value = value $ l2!!index}):(_mask' l1 l2 xs)
                 where index = [i | i <- [0..(length l1 -1)], (sameContext (l1!!i) x)]!!0
                       sameContext (Event c1 w1 p1 v1) (Event c2 w2 p2 v2) = c1 == c2

my idea here was to first look at all the events (modulo False events) in both patterns over one cycle (l1 and l2) and uniquely identify them over their context, so basically for each state return the set of events that are active in the first pattern, but modfiy their values. This code actually works as expected for non euclidean patterns, but doesn't for euclidian patterns. So I need some other way to uniquely identify each event over one cycle. I hope this makes sense!

So you want to treat the second pattern like a list, to fill in the values in the first pattern?

There used to be a function 'preplace' (pattern replace) for this, there is some discussion about how to reintroduce it here:

yes, exactly. Thanks! I'll look into it!