Tidal
Tidal copied to clipboard
use keys for events to deal with vertical structure (chords)
currently it is not possible to regard the stack construct as an alternative to lists, since too much information is lost in the transformation to signals, for example a lookup operator wouldn't be possible:
"[1,2 3,4]" !!! 2 --> "2 3"
there is just no way of knowing that the events corresponding to value 2 and 3 respectively "belong together".
my suggestion is to add a new field in the Event type representing this information, i'm thinking of the type
data Key = Key [Int]
where the list of integers represents the path in the "stacktree" (for dealing with nested stacks). for example the keys in
"[1 2, [3, 4 5], 6"
would be
1 -> [0]
2 -> [0]
3 -> [1,0]
4 -> [1,1]
5 -> [1,1]
6 -> [2]
since tidal doesn't have many functions dealing with vertical structures it is a pretty easy addition, i think only overlay
and stack
should be really affected, which can be defined as:
overlay :: Pattern a -> Pattern a -> Pattern a
overlay p p' = Pattern $ \st -> map (\e -> e {key = addKey 0 (key e)}) (query p st) ++ map (\e -> e {key = addKey 1 (key e)}) (query p' st)
stack :: [Pattern a] -> Pattern a
stack xs = Pattern $ \st -> concatMap (\i -> map (\e -> e {key = addKey i (key e)}) $ query (xs!!i) st ) [0..length xs - 1]
i made a working branch of the additions (without tying the changes into the parser) here:
https://github.com/polymorphicengine/Tidal/tree/1.9-stack-try
let me know what you think! i will happily add these changes to the current tidal 2.0 branch if everyone agrees