lilypond-user
[Top][All Lists]
Advanced

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

Re: filter the nth note


From: Jean Abou Samra
Subject: Re: filter the nth note
Date: Sun, 19 Jun 2022 11:15:27 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1



Le 19/06/2022 à 10:58, Stefan Thomas a écrit :
Dear community,
I would like to do something like the following, but automatically, without typing all the music again:
allNotes= { c'8 g' e' g' d' g' f' g' c' g' e' g'   }
someNotes = { c' d' c' }
In other words: I would like to filter out every 4th note of allNotes, so that I could do in combination with changePitch (see https://github.com/gilles-th/arranger.ly/blob/master/changePitch.ly) the following:
patI = { c8 r r4 }
someNotes =  { \cPI { \someNotes s } }
Thanks for Your help,
Stefan

I'd do

\version "2.22.2"

filterNth =
#(define-music-function (n music) (index? ly:music?)
   (music-filter
    (let ((i -1))
      (lambda (m)
        (set! i (1+ i))
        (zero? (modulo i n))))
    music)
   music)

\filterNth 4 \relative { c'8 e g e c e g e d f g f d f g f }

Note that if you use this with \relative, it must be outside the \relative body.

Best,
Jean




reply via email to

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