lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Scheme coding] how to turn pitches into music


From: Aaron Hill
Subject: Re: [Scheme coding] how to turn pitches into music
Date: Sat, 25 Jan 2020 07:29:55 -0800
User-agent: Roundcube Webmail/1.3.8

On 2020-01-25 6:42 am, Kieren MacMillan wrote:
Having previously used

#(display
  (map (lambda (n) (ly:make-pitch 0 n 0))
    (map (lambda (l) (list-ref rowrefs l))
      (map (lambda (m) (modulo m 12))
        (map ly:pitch-semitones (music-pitches test))))))

I know that the scheme function is returning a set of pitches, and
they are the correct ones [based on how I want to manipulate the
"test" music]. The errors I got when I tried to create a music
function led me to find ly:make-music, which eliminated the errors.
But now I can’t display the pitches. How do I fix the row-staff-notes
function so that it displays pitches on a staff?

Perhaps the simplest option is to avoid ly:music and instead use splicing to let the parser do the heavy lifting:

%%%%
\version "2.19.83"
\language "english"

rowrefs = #'(6 8 7 2 3 12 5 4 11 1 10 9)
test = { ef, fs' g d'' cs' }

row-staff-notes =
#(define-music-function (mus) (ly:music?)
  #{ $@(map (lambda (pitch)
              (let* ((semitone (ly:pitch-semitones pitch))
                     (index (modulo semitone (length rowrefs))))
                (ly:make-pitch 0 (list-ref rowrefs index) 0)))
            (music-pitches mus)) #})

{ <>8 \row-staff-notes \test }
%%%%

Note that I refactored your nested maps into a single one.


-- Aaron Hill



reply via email to

[Prev in Thread] Current Thread [Next in Thread]