Hi Peter,

Am 23.04.25 um 05:41 schrieb Peter X:
I’m trying to figure out how to print the MIDI number of each note in a score using a Scheme engraver — for example, I’d like c' to print as 60, d' as 62, etc., during compilation.

Here is a simplified example of the kind of input I’m working with:

\version "2.24.4"

\score {
  \new Staff {
    \new Voice {
      \clef treble \key c \major \time 4/4
      c'4 d'4 e'4 f'4 |
      g'4 a'4 g'2 |
    }
  }
}

My goal is: When this file compiles, each note’s MIDI number is printed to the terminal.

🎵 Found pitch c' → MIDI: 60
🎵 Found pitch d' → MIDI: 62

This is actually a nice example for a really simple engraver.

\version "2.24"

MIDI_pitch_engraver =
#(lambda (context)
   (make-engraver
    (listeners
     ((note-event engraver event)
      (let ((pitch (ly:event-property event 'pitch)))
            (format #t "- Found pitch ~a~a → MIDI: ~a\n"
                    (note-name->string pitch)
                    (1+ (ly:pitch-octave pitch))
                    (+ 60 (ly:pitch-semitones pitch))))))))

\layout {
  \context {
    \Voice
    \consists #MIDI_pitch_engraver
  }
}

\score {
  \new Staff {
    \new Voice {
      \clef treble
      \key c \major
      \time 4/4
      c'4 d'4 e'4 f'4 |
      g'4 a'4 g'2 |
    }
  }
}

Lukas

Reply via email to