lilypond-devel
[Top][All Lists]
Advanced

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

music-map doesn't map all the music !


From: Gilles Thibault
Subject: music-map doesn't map all the music !
Date: Fri, 14 May 2021 19:39:07 +0200
User-agent: Webmail Free/1.3.3

I have been using the music-map function for years.
I was very surprised to find, with the French list, that this function did not behave in the way I had always thought it would.

%%%%%%%%%%%
\version "2.22.0"
music = c4->
#(display-scheme-music music)
#(display "--------------\n")
#(music-map (lambda(m)
              (format #t "\n~a" (ly:music-property m 'name))
              m)
            music)
%%%%%%%%%%%%

display-scheme-music shows 2 music events : a NoteEvent and a ArticulationEvent
=>
(make-music
  'NoteEvent
  'articulations
  (list (make-music
          'ArticulationEvent
  ...

music-map returns only one event !
=>
NoteEvent

in Lilypondond 2.22, music-map is defined in scm/music-functions.scm as :

%%%%%%%
(define-public (music-map function music)
  "..."
  (let ((es (ly:music-property music 'elements))
        (e (ly:music-property music 'element)))
    (if (pair? es)
        (set! (ly:music-property music 'elements)
              (map (lambda (y) (music-map function y)) es)))
    (if (ly:music? e)
        (set! (ly:music-property music 'element)
              (music-map function  e)))
    (function music)))
%%%%%%%

It seems that other functions as filter-map, map-some-music, for-some-music etc... walk though 'articulations property but not music-map
The simple code below should do the job.

%%%%%%%
(define-public (music-map function music)
  "..."
  (let ((es (ly:music-property music 'elements))
        (as (ly:music-property music 'articulations))
        (e (ly:music-property music 'element)))
    (if (pair? es)
        (set! (ly:music-property music 'elements)
              (map (lambda (y) (music-map function y)) es)))
    (if (pair? as)
        (set! (ly:music-property music 'articulations)
              (map (lambda (y) (music-map function y)) as)))
    (if (ly:music? e)
        (set! (ly:music-property music 'element)
              (music-map function e)))
    (function music)))
%%%%%%%


--
Gilles



reply via email to

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