Jump to content

Lowest and highest pitch as chord: Difference between revisions

From LilyPond wiki
Manuela (talk | contribs)
Created page with "This code returns the lowest and the highest pitch of a music expression as chord. The duration of the chord can be chosen arbitrarily. You can easily change the chord to a fixed duration. <lilypond version="2.26.0" > %% This snippets returns the lowest and the highest pitch %% of a music expression als chord %% the duration of the chord is passed as argument myambitus = #(define-music-function (mus dur)(ly:music? ly:duration?) (let* ( (alle-pitches..."
 
Manuela (talk | contribs)
mNo edit summary
Line 1: Line 1:
This code returns the lowest and the highest pitch of a music expression as chord.
This code returns the lowest and the highest pitch of a music expression as chord.


The duration of the chord can be chosen arbitrarily.
The duration of the chord can be chosen arbitrarily as input parameter.


You can easily change the chord to a fixed duration.
You can easily change the chord to a fixed duration. You can even chose different durations for the pitches in the chord.


<lilypond version="2.26.0" >
<lilypond version="2.26.0" >

Revision as of 07:58, 3 May 2026

This code returns the lowest and the highest pitch of a music expression as chord.

The duration of the chord can be chosen arbitrarily as input parameter.

You can easily change the chord to a fixed duration. You can even chose different durations for the pitches in the chord.

\version "2.26.0"


%% This snippets returns the lowest and the highest pitch
%% of a music expression als chord
%% the duration of the chord is passed as argument

myambitus =
#(define-music-function (mus dur)(ly:music? ly:duration?)
   (let*
    (
      (alle-pitches
       (let loop ((mus mus) (pitches '()))
         (let ((p  (ly:music-property mus 'pitch)))
           (if (ly:pitch? p)
               (cons p pitches)
               (let ((elt (ly:music-property mus 'element)))
                 (fold loop
                       (if (ly:music? elt)
                           (loop elt pitches)
                           pitches)
                       (ly:music-property mus 'elements)))))))
      (alle-sortiert (sort alle-pitches ly:pitch<?))
      (tief (car alle-sortiert))
      (hoch (car (reverse alle-sortiert)))
      )
    ;     (display tief )(display hoch)
    ;     (write-me "alle pitches----> " (list? alle-pitches))
    (make-music
     'EventChord 'elements
     (list
      (make-music
       'NoteEvent
       'duration
       dur
       'pitch
       tief)
      (make-music
       'NoteEvent
       'pitch
       hoch
       'duration
       dur)))
    ))

mymus = \relative { c' c f,, }
{ \clef bass \myambitus \mymus #(ly:make-duration 0) }
{ \clef bass \myambitus \transpose c e \mymus 2. }