home/ atoms/ sc-12-tone-matrix

SuperCollider can generate a complete 12-tone row matrix using nested iteration over a scrambled pitch-class array

The 12-tone matrix (prime, inversion, retrograde, retrograde-inversion) is generated by: (1) choose a row P, (2) compute inversion I = 12 - P, (3) for each I[i], print the transposition P + I[i] mod 12. SC’s do{} iterates rows; wrapAt handles modular indexing. The example uses Array.series(11,1).scramble to generate a random row, or you can hard-code a historical row (e.g., Webern’s Op 27). The compact one-liner ((1,2..11).scramble.insert(0,0).neg) shows SC’s expressive shorthand for the same operation.

Examples

row = Array.series(11, 1).scramble.insert(0, 0); inversion = 12 - row; inversion.do({ |eachInv| var trans = (row + eachInv); trans.do({ |deg| pitchClass.wrapAt(deg).post }); "".postln })

Assessment

Enter Webern’s row [0, 11, 8, 2, 1, 7, 9, 10, 4, 3, 5, 6] and generate the full 12x12 matrix. Identify which transpositions share more than 3 consecutive pitch classes with the prime.

“row = Array.series(11, 1).scramble.insert(0, 0); // or enter your own row, e.g., Webern's Op 27 // row = [0, 11, 8, 2, 1, 7, 9, 10, 4, 3, 5, 6];”
corpus · the-supercollider-book-official-code-examples-scbookcode-gpl · chunk 1