Hi Michael,

Wow – what a clever approach! Using NoteNames with a custom
noteNameFunction is absolutely brilliant. I love how elegant and
lightweight your solution is. It works perfectly and is exactly the kind of
creative thinking I admire. Thank you so much for sharing it!

Warmly,
Peter

Parsing...
Interpreting music...
🎵 Found Pitch: c3 → MIDI: 60
🎵 Found Pitch: d3 → MIDI: 62
🎵 Found Pitch: e3 → MIDI: 64
🎵 Found Pitch: f3 → MIDI: 65
🎵 Found Pitch: g3 → MIDI: 67
🎵 Found Pitch: a3 → MIDI: 69
🎵 Found Pitch: g3 → MIDI: 67


On Wed, Apr 23, 2025 at 9:52 AM Michael Werner <[email protected]> wrote:

> Hi Peter,
>
> On Tue, Apr 22, 2025 at 11:42 PM Peter X <[email protected]> wrote:
>
>> 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.
>>
> %< snip >%
>
>> What is the proper or recommended way to extract and print the MIDI
>> number of each note in a LilyPond score?
>
>
>> I’d really appreciate any working examples or pointers. Thank you very
>> much!
>
>
> Engravers are something I never have been able to figure out - still
> working my way through learning Scheme. However, I was able to put together
> some code that runs in a NoteName context that comes pretty close to what
> you asked for. Whether it's proper or recommended I doubt. But it works ...
> more or less. The output is:
>
>
> Starting lilypond 2.24.4 [test_midi_numberV2.ly]...
>
> Processing `/home/michael/Downloads/test_midi_numberV2.ly'
>
> Parsing...
>
> Interpreting music...
>
> 🎵 Found Pitch: c3 → MIDI: 60
>
> 🎵 Found Pitch: d3 → MIDI: 62
>
> 🎵 Found Pitch: e3 → MIDI: 64
>
> 🎵 Found Pitch: f3 → MIDI: 65
>
> 🎵 Found Pitch: g3 → MIDI: 67
>
> 🎵 Found Pitch: a3 → MIDI: 69
>
> 🎵 Found Pitch: g3 → MIDI: 67
>
> If that's close enough, then the code is:
>
> \version "2.24.4"
>
> simplePitchDebugTwo =
> #(lambda (pitch ctx)
>    (ly:message "🎵 Found Pitch: ~a~a → MIDI: ~a"
>                (note-name->string pitch)
>                ; Next line sets middle C to C3 - change 3 to 4 to get C4
> as middle C
>                (+ (ly:pitch-octave pitch) 3)
>                (+ (ly:pitch-semitones pitch) 60))
>    ; LilyPond complains about missing markup list without the next line
>    (markup #:null))
>
>
> music = {
>   \clef treble
>   \key c \major
>   \time 4/4
>   c'4 d'4 e'4 f'4 |
>   g'4 a'4 g'2 |
> }
>
> \score {
>   \new Staff <<
>     \new Voice {
>       \music
>     }
>     \new NoteNames {
>       \set noteNameFunction = #simplePitchDebugTwo
>       \music
>     }
>   >>
> }
>
> Still trying to get my head wrapped around the whole engraver thing. Ah
> well ... someday. Hopefully this'll be close enough to serve for now.
> --
> Michael
>
>

Reply via email to