\version "2.18.2" % "square" transpositions linked to the defined row #(define (squareNumber n) (squareTranspose row n)) % List the rows that will be written #(define (squareRows n) (pset-op 12transpose row (squareTranspose row n))) % Convert the numbers in the row to Lilypond pitches #(define (number->note n) (cond ((= n 0) (ly:make-pitch 1 0)) ((= n 1) (ly:make-pitch 1 0 1/2)) ((= n 2) (ly:make-pitch 1 1)) ((= n 3) (ly:make-pitch 1 1 1/2)) ((= n 4) (ly:make-pitch 0 2)) ((= n 5) (ly:make-pitch 0 3)) ((= n 6) (ly:make-pitch 0 3 1/2)) ((= n 7) (ly:make-pitch 0 4)) ((= n 8) (ly:make-pitch 0 4 1/2)) ((= n 9) (ly:make-pitch 0 5)) ((= n 10) (ly:make-pitch 0 5 1/2)) ((= n 11) (ly:make-pitch 0 6)) (else (error "Pitch not found")))) % Write elements (markups or note) writeElements = #(define-music-function (parser location sym1 sym2 fn1 ls) (symbol? symbol? procedure? list?) (make-music 'SequentialMusic 'elements (let loop ((ls ls)) (if (null? ls) '() (cons (make-music sym1 ;'LyricEvent / 'NoteEvent sym2 ; 'text / 'pitch (fn1 (car ls)) ; (markup #:concat (#:larger "RI" #:sub (number->string (car ls)))) / (number->note (car ls)) 'duration (ly:make-duration 2)) (loop (cdr ls))))))) % customBarLine by Janek WarchoĊ‚ % http://stackoverflow.com/questions/18538793/lilypond-markup-text-next-to-barline % changed to write the Retrograde inversion customBarLine = #(define-music-function (parser location n) (number?) #{ \once \override Staff.BarLine #'stencil = #(lambda (grob) (ly:stencil-combine-at-edge (ly:bar-line::print grob) X RIGHT (grob-interpret-markup grob #{ \markup { \whiteout \vcenter \concat { \larger "R" \sub #(number->string (squareNumber n))} } #}) 0))#}) % Write a new Staff with the transposition number: %% - As an instrument name on the left %% - As a custom bar line on the right writeRow = #(define-music-function (parser location n) (number?) #{ \new Staff \with { instrumentName = \markup { \concat { \larger O \sub #(number->string (squareNumber n)) } } } { \writeElements #'NoteEvent #'pitch #(lambda (x) (number->note x)) #(squareRows n) \stopStaff \bar "|" s4 \customBarLine #n } #}) % Write markups with a large string and a subtexted number writeRowMarkups = #(define-music-function (parser location str ls) (string? list?) #{ \writeElements #'LyricEvent #'text #(lambda (x) (markup #:concat (#:larger str #:sub (number->string x)))) #ls #}) % Use writeRowMarkups to write the inversion transpositions markupI = #(define-music-function (parser location) () #{ \writeRowMarkups #"I" #(zero-pset row 12) #}) % Use writeRowMarkups to write the retrograde-inversion transpositions markupRI = #(define-music-function (parser location) () #{ \writeRowMarkups #"RI" #(zero-pset row 12) #}) % Recursive function to write the 12 rows with all the transpositions writeRowRec = #(define-music-function (parser location n) (number?) (if (= 12 n) #{ #} #{ << \writeRow #n \writeRowRec #(+ n 1) >> #})) writeSquare = \writeRowRec #0