\version "2.22.0" % some sequential music objects (to be concatenated with variation by gen-music function) xa = { g'4. a'8 g'4 f' e' f' g'2 d'4 e' f'2 e'4 f' g'2 g' a'4 g'8 f' e'4 f' g'2 } xb = { d'4 e' f'4 e' f' g'8 f' e'4 f'8 g' a'4 c'' e''4 d''8 c'' b'4 cis'' d''2 } xc = { a'4 b' c''4 b' c'' d''8 c'' b'4 c''8 d'' e''2~ e''4 d''8 c'' b'4 cis'' d''2 } xd = { a'4 b' c''4 b' c'' d''8 c'' b'4 g'8 f' e'4 d' cis'4 a'8 g' a'4 cis'' d''2 } xe = { d''4 c'' b'4 g'8 f' g'4 b' c''4 d'' e''2 d''4 c''8 b' a'4 b' c''2 } xf = { g'4 a' bes'4 a' bes' c''8 bes' a'2 b' c''4 b' c'' d''8 c'' b'4 a' bes'2 a'4 g'8 f' e'4 fis' g'2 } xg = { d'4 e' f'4 e' f' g'8 f' e'4 c''8 b' a'4 g' fis'4 d''8 c'' d''4 fis' g'2 } xh = { g'4 f' e'4 c''8 bes' c''4 e' f'4 a'8 g' f'4 e' d'2 g' e'4 c' } % list of sequential music objects smolist = #(list xa xb xc xd xe xf xg xh) % to get a scheme list of music elements from a music object #(define (get-elements mus) (ly:music-property mus 'elements)) % list of element-lists elists = #(map get-elements smolist) enum = #(length elists) % recursively concatenate a range of elists (0 <= m <= n, possibly > enum) #(define (cat-elists m n) (let ((elist-m (list-ref elists (modulo m enum)))) (if (< m n) (append elist-m (cat-elists (1+ m) n)) elist-m ))) % generate music by concatenating contiguous members from list. % i mod enum is the starting position in the list for the next gen-music. % mincat is the minimum number of concatenations (mincat >= 0) % maxcat is the max number of concatenations (maxcat >= mincat) % actual number of cats is random between mincat and maxcat. i = 0 mincat = 0 maxcat = 9 gen-music = #(define-music-function () () (let* ((m i) (n (+ m (+ mincat (random (1+ (- maxcat mincat))))))) (set! i (1+ n)) (make-sequential-music (cat-elists m n))))