lilypond-user
[Top][All Lists]
Advanced

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

Re: Count the number of notes


From: Gilles Thibault
Subject: Re: Count the number of notes
Date: Thu, 05 Jan 2023 18:22:15 +0100
User-agent: Webmail Free/1.3.3

Le 2022-12-20 22:20, | || | | a écrit :
I need to count the number of notes between to functions. For Example:

\new Staff{

     c4-- \startCount d8-> e8-> f8-> g8-> \stopCount

     #(display how-much-notes-selected)

}

This will be develop for more complex function that will change
proportionally scale of every notehead in that kind of block, do the
same as cresc. hairpins  but will act on every notehead instead of
using spanner.


Sorry to answer so late.
One of the file provided with "arranger.ly" (link below) is called addAt.ly, which has been designed for this kind of thing (If I understood correctly your request).

%%%%%%%%%%

\version "2.24.0"

\include "addAt.ly"

#(define (events-count mus event) ; event as a symbol or a list of symbols
   (length (extract-named-music mus event)))

music = \relative {
  c4 c c c
  \anchor #'A
  d d d <d f>
  \anchor #'B
  e e e e
}

musicAtoB = \musicAt #'A \music  % music between A and the next anchor

#(format #t "Number of notes between A and B : ~a\n"
                (events-count musicAtoB 'NoteEvent))              % 5
#(format #t "Number of chords or notes between A and B : ~a\n"
                (events-count musicAtoB '(EventChord NoteEvent))) % 4

\new Staff { \musicAtoB }

%%%%%%%%%%

You need to download 2 files : addAt.ly and extractMusic.ly (called by addAt.ly)

Link for downloading :

    http://gillesth.free.fr/Lilypond/arranger.ly/


Hope that helps.

--
Gilles



reply via email to

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