A Markov chain trained on pitch and rhythm sequences generates new music with the same statistical patterns
SuperCollider’s PPMC class (Prediction by Partial Matching, a Markov-variant) trains on an integer sequence and generates new values with similar conditional distributions. Ch 25 trains separate models on pitch and rhythm sequences from a melody, then plays back generated sequences in a loop using Tdef. The order parameter controls how many past values predict the next; higher order captures more local pattern but may overfit short training sequences. The result: generated music sounds stylistically similar to the training data without being identical.
Examples
~mel = PPMC(3); ~mel.train(a); ~rhy = PPMC(3); ~rhy.train(b); Tdef(\gen, { loop { var nextmel = ~mel.generate(lastvals[0].reverse); Synth(\a, [\freq, nextmel]); (nextrhy * 0.25).wait; } }).play
Assessment
Train a PPMC model on a 16-note melodic fragment. Generate 32 notes and compare pitch-class distribution to the training data using a histogram. Try orders 1, 2, and 3; describe the trade-off between coherence and novelty.