Hi all,
I’m building a visual guide (“How to write music for violin with LilyPond”)
for my violin friends and I’d like each example line to look like this:

   -

   *Left:* rendered staff (the result)
   -

   *Middle:* small arrow
   -

   *Right:* the *LilyPond source text* that produced the staff (wrapped,
   typewriter font)

I’d like to define helper markup commands so I can write compact examples
and (ideally) avoid repeating the same fragment twice.

If anyone has ideas, best practices, or knows of an existing helper or
snippet that does this, I’d be super grateful!

Thanks so much,
Marc


Here’s what I’ve tried so far:


\version "2.24.4"

% --- Helper: render music inside markup (no % inside the Scheme form) ---
#(define-markup-command (writeMusic layout props music) (ly:music?)
  (let* ((score (ly:make-score music))
         (lydef (ly:output-def-clone $defaultlayout)))
    (ly:score-add-output-def! score lydef)
    (interpret-markup layout props (markup #:score score))))

% --- Example row: left = music object, right = code string  ---
#(define-markup-command (example_A layout props mus codestr)
  (ly:music? string?)
  (interpret-markup layout props
    #{
      \markup \fill-line {
        \column { \writeMusic #mus }
        \column { \typewriter "⇨" }
        \column { \typewriter \wordwrap-string #codestr }
      }
    #}))


#(define-markup-command (example_B layout props mus) (ly:music?)
  (let ((musicAsString (format #f "~S" mus)))
    (interpret-markup layout props
      #{
        \markup \fill-line {
          \column { \writeMusic #mus }
          \column {  "=>" }
          \column { \typewriter  #musicAsString  }
        }
      #})))

% ====== Function example_A forces to type music TWICE ======
example_bowing = \relative c'' { c4(\downbow d) e(\upbow f) }
\markup \example_A #example_bowing "c''4(\\downbow d) e(\\upbow f)"

% ====== Function example_B shows scheme code and not lilypond music notes
======
\markup \example_B #example_bowing

Reply via email to