How does trigger's implementation work? (Is it possible to have patterns react to each other?)

#1

Hi,

I was wondering if anyone would be willing to walk me through how trigger works inside.

trigger :: Show a => a -> Pattern b -> Pattern b
trigger k pat = pat {query = q}
  where q st = query ((offset st) ~> pat) st
        offset st = fromMaybe (pure 0) $ do pat <- Map.lookup ctrl (controls st)
                                            return $ ((fromMaybe 0 . getR) <$> pat)
        ctrl = "_t_" ++ show k

The reason I’m curious is that it seems to allow a pattern running on d1 to interact with a pattern running on d2 by providing a different integer to the first argument. I would like to be able to have the patterns I’m writing interact with one another more. Fore example, say I write a drum pattern that I’m happy with and its fairly complex, and I want to have the bass hit only when the snare hits. If the bass pattern is on d2 and the drums on d1 I have to work out how to program a pattern of bass hits that sounds only when the snare does. What I would like to be able to do is have a function similar to fix act on the bass pattern whenever d1 has a snare event.

Does that make any sense?

Thanks,

David

0 Likes