On Fri, 2023-12-01 at 12:21 -0800, Stefano Antonelli wrote:
> The second issue is that the space-time-dumper in ly2video produces
> what I need, but there are no page transitions indicated.  I can
> probably work out the transitions from when the x coordinate wraps,
> but
> it would be nice to have the page change show up in the spacetime
> info
> output.  Ideally with the page number.

I played around with the event-listener.ly.  When I reduce it to:

#(define (printBar engraver event)
    (format #t "\nprintBar"))

#(define (printPage engraver event)
    (format #t "\nprintPage"))

#(define (printNote engraver event)
    (format #t "\nprintNote"))

#(define event-listener-engraver
  (make-engraver
    (listeners
     (note-event . printNote)
     (page-break-event . printPage)
     (bar-event . printBar))))

Only the note events fire and they do that after:

Interpreting music...

Whereas, done this way, as in dump-spacetime-info.ly:

#(define (printBar unused)
    (format #t "\nprintBar"))

#(define (printNote unused)
    (format #t "\nprintNote"))

\layout {
  \context {
    \Staff
    \override BarLine.after-line-breaking = #printBar
  }
  \context {
    \Voice
    \override NoteHead.after-line-breaking = #printNote
  }
}

The prints appear after:

Drawing systems...

Since ly2video needs it the second way, I need to figure out how to
make that work.

The page-break-event and the bar-event didn't fire in the first way
either.  The "bar event" did fire in the second way.  This may not make
sense, but I tried:

\layout {
  \context {
    \override PageBreakEvent.page-break-event = #printPage
  }
}

And there were no errors, but no output either.  I tried this too:

\paper {
  \context {
    \override PageBreakEvent.page-break-event = #printPage
  }
}

If it's not obvious, I don't know what I'm doing.

I tried looking in the lilypond internals for something analogous to
NoteHead and BarLine for page breaks, but I didn't see anything.
 Probably because page breaks aren't grobs.  There was a PaperColumn
object that I don't understand, but I tried it anyway:

\layout{
  \context {
    \Score
    \override PaperColumn.after-line-breaking = #printPage
  }
}

And it's printing way too often.

I read through a lot of threads without answers.  And I looked at
several other video generation lilypond projects and didn't see any
handling page breaks.

I found the page-break-event:

"Music event type page-break-event is in music objects of type
PageBreakEvent.

Not accepted by any engraver or performer."

That last line probably explains why it didn't work with the event
listener code.  At the same time I don't know how to access it.

There doesn't seem to be an after-page-breaking callback, so nothing
convenient there.

I came across "ly:add-listener" which looks promising, but I have no
idea how to invoke it:

"ly:add-listener callback  disp  cl

Add the single-argument procedure callback as listener to the
dispatcher disp.  Whenever disp hears an event of class cl, it calls
callback with it."

I don't know where to get the dispatcher.  I found ly:make-dispatcher
and tried this:

#(ly:add-listener printPage (ly:make-dispatcher) 'page-break-event)

And while no errors, there was no printPage output either.

I've reduced the MWE down to under 50 lines, hopefully it's easier to
digest:

#(define (printBar unused)
    (format #t "\nprintBar"))

#(define (printPage unused)
    (format #t "\nprintPage"))

#(define (printNote unused)
    (format #t "\nprintNote"))

%#(ly:add-listener printPage (ly:make-dispatcher) 'page-break-event)

\layout {
  \context {
    \Staff
    \override BarLine.after-line-breaking = #printBar
  }
  \context {
    \Voice
    \override NoteHead.after-line-breaking = #printNote
  }
%  \context {
%    \override PageBreakEvent.page-break-event = #printPage
%  }
}

\score {
    \new Staff {
        \relative c'' \repeat unfold 8 {
            c4 c c c~
        }
    }
    \layout { }
    \midi { }
}

#(set! paper-alist (cons '("vid-line" .
    (cons (* 90 mm) (* 26 mm))) paper-alist))

\paper {
    #(set-paper-size "vid-line")
    print-page-number = ##f
}

\version "2.20.0"

The output will show printNote and printBar, but not printPage.  If
anyone has any ideas on how to get printPage to print, I would be
grateful.

Thanks,
Stef

#(define (printBar unused)
    (format #t "\nprintBar"))

#(define (printPage unused)
    (format #t "\nprintPage"))

#(define (printNote unused)
    (format #t "\nprintNote"))

\layout {
  \context {
    \Staff
    \override BarLine.after-line-breaking = #printBar
  }
  \context {
    \Voice
    \override NoteHead.after-line-breaking = #printNote
  }
  \context {
    \override PageBreakEvent.page-break-event = #printPage
  }
}

\score {
    \new Staff {
        \relative c'' \repeat unfold 8 {
            c4 c c c~
        }
    }
    \layout { }
}

#(set! paper-alist (cons '("vid-line" .
    (cons (* 90 mm) (* 26 mm))) paper-alist))

\paper {
    #(set-paper-size "vid-line")
    print-page-number = ##f
}

% increase png resolution
#(ly:set-option 'resolution 300)

% lilypond --png mwe.ly

\version "2.20.0"

Reply via email to