Leitereigene Mehrklänge mittels Scheme erzeugen/code

Zur Navigation springen Zur Suche springen
#(define (pitches->chord plist)
   (make-music 'EventChord 'elements
     (if (list? plist)
         (map (lambda (p)
                (make-music
                 'NoteEvent 'duration (ly:make-duration 0)
                 'pitch p))
           plist)
         (make-music
          'NoteEvent 'duration (ly:make-duration 0)
          'pitch plist)
         )))

%% convert pitchlist to plain music
#(define (pitches->music plist)
   (if (list? plist)
       (make-music 'SequentialMusic 'elements
         (map (lambda (p)
                (make-music
                 'NoteEvent 'duration (ly:make-duration 0)
                 'pitch p))
           plist))
       (make-music 'SequentialMusic 'elements
         (make-music
          'NoteEvent 'duration (ly:make-duration 0)
          'pitch plist))))

%% create all n-th chords from scale
%% actually we staple every other pitch from the-scale
%% until we reach n

%% create chords with arbitraty intervals from the scale
%% input: scale
%% list: the distances of the notes, 3=terz, 4=quart ...

#(define (stacked-intervals the-scale list-or-number-or-pair)
   ;; the-scale: music from which the pitchlist is constructed
   ;; usually a scale, but could be any music
   ;; duplicate pitches are removed and sorting according to pitch height is done
   ;; list-or-number-or-pair: tells the programm which intervals to produce
   ;; list: a list of chords, 3=third, 4=forth etc. '(2 4) creates a quart-sext chord
   ;; pair: '(a . b)  a: how many notes the chord contains, b: the interval, 3=third, 4=forth
   ;; number: terzes are stapled, 3=triad, 4=tetrads, 5=pentachord etc
   ;; actually the program does not much counting
   ;; a list of intervals is created by picking notes in the order they appear
   ;; in the scale leaving gaps defined by the list
   (let* ((scpi (music-pitches the-scale))
          (pili (sort
                 (delete-duplicates scpi) ly:pitch<?))
          (m (length pili))
          (elist (cond
                  ((list? list-or-number-or-pair)
                   ;; we need to add an element to the list
                   ;; otherwise the last element of the list would not appear
                   ;; in the result
                   (append list-or-number-or-pair '(1)))
                  ((pair? list-or-number-or-pair)
                   ;; car: number of notes
                   ;; cdr: distance, 3=third, 4=forth etc.
                   (make-list  (car list-or-number-or-pair) (cdr list-or-number-or-pair)))
                  ((number? list-or-number-or-pair)
                   ;; standard definition: chord consists of thirds
                   (make-list list-or-number-or-pair 3))))
          (n (length elist)))
     (map
      (lambda (w)
        (let ((u 0))
          (map
           (lambda (x)
             (let* ((y (modulo (+ u w) m))
                    (q (quotient (+ u w) m))
                    (z (list-ref pili y))
                    (a (ly:pitch-alteration z))
                    (o (ly:pitch-octave z))
                    (n (ly:pitch-notename z))
                    (p (ly:make-pitch (+ o q) n a)))
               (set! u (+ u (list-ref elist x) -1))
               p))
           (iota n))))
      (iota m))))