markovPat generates sequences driven by a probability transition matrix rather than a fixed pattern
A Markov chain models state transitions: each state has a probability distribution over which state follows. markovPat length startIndex matrix maps integers to sounds and uses the matrix rows as per-state transition probabilities. Values are normalised, so rows need not sum to 1. The result is a Pattern Int indexing any list of sounds, giving structured randomness: some transitions are frequent, others rare, so output has melodic or rhythmic tendencies without being fixed. Unlike wchoose, the next step depends on the current step — the pattern has memory. Use fmap to map integer indices to sound names or notes.
Examples
d1 $ s (fmap ([“bd”, “sd”, “clap”]!!) $ markovPat 16 0 [ [0.1, 0.7, 0.2] , [0.15, 0.1, 0.8] , [0.5, 0.3, 0.4] ] )
Assessment
Given a 2-state Markov chain for kick and snare where kick→kick=0.7 and snare→snare=0.3, write the markovPat call. Predict qualitatively whether the resulting pattern will feel more kick-heavy or snare-heavy.