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 09:21:18 -0800
User-agent: Roundcube Webmail/1.3.8

On 2020-01-25 8:45 am, Kieren MacMillan wrote:
Very helpful! Here’s an example of what I’m currently playing around with:

Neat, although I must confess I have no idea what row-reduction means in a musical context. Does it have any connection to the linear algebraic term? Regardless, it sounds like I missed a fun presentation. (:

Here's a "spicier" take on your code that uses an engraver:

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

rowrefs = #'(6 8 7 2 3 12 5 4 11 1 10 9)
test = { ef4. <fs' a'>8 g2 r4 <b d''>8 cs' }

RowReduce_engraver = #(lambda (...)
  `((listeners
      (note-event .
        ,(lambda (engraver event)
          (let* ((elem (ly:event-property event 'music-cause))
                 (pitch (ly:music-property elem 'pitch))
                 (semitone (ly:pitch-semitones pitch))
                 (index (modulo semitone (length rowrefs))))
            (ly:music-set-property! elem 'pitch
              (ly:make-pitch 0 (list-ref rowrefs index) 0))))))))

\layout {
  \context {
    \Staff
    \name RowReductionStaff
    \alias Staff
    \inherit-acceptability RowReductionStaff Staff
    \consists \RowReduce_engraver
    \omit Clef
    \omit TimeSignature
    \omit Stem
    \omit Flag
    \omit Beam
    \omit Dots
    \omit Rest
    \omit BarLine
    \override NoteHead.duration-log = #4
  }
}

\score {
  <<
    \new Staff { \test }
    \new RowReductionStaff { \test }
  >>
}
%%%%

To my eye, that looks cleaner from an end-user perspective, with everything wrapped up in the custom Staff context.

Note that one aspect of this that needs refactoring is the rowrefs array itself. This probably should be a context property rather than a global. That way you could say:

%%%%
  \new RowReductionStaff
    \with { rowrefs = #'(8 6 7 5 3 0 9) }
    { \test }
%%%%

I have posted about custom context properties before, but let me know if you need pointers.


-- Aaron Hill



reply via email to

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