lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Defining event classes


From: Nathan Ho
Subject: Re: Defining event classes
Date: Tue, 31 Mar 2015 13:53:57 -0700

On Mon, Mar 30, 2015 at 1:44 PM, Nathan Ho <address@hidden> wrote:
Hi list,

What is the most up-to-date way to define my own event classes?

I've looked at frameEngraver as a model but none of the old versions
seem to be working. The most up-to-date one I could find
(https://lists.gnu.org/archive/html/lilypond-user/2013-07/msg00373.html)
gives me numerous "Event class should be a list" errors and the frames
don't show up in the output, while this one
(https://lists.gnu.org/archive/html/lilypond-user/2013-07/msg00554.html)
spits out a few errors and segfaults. I'm using 2.19.17.

Not hugely surprised to see that didn't get a quick answer :)

With some trial and error and fumbling around I came up with the following code. Unlike the frame engraver code, this returns no errors or warnings, but the engraver doesn't seem to notice the BangEvent at all. If I change the listener to listen to music-event, then bang-trigger calls four times (once per note) seemingly ignoring the \bang. What's going on here?

\version "2.19.17"

#(define-event-class 'bang-event 'music-event)

#(define bang-types
   '(
     (BangEvent
      . ((description . "BANG!")
         (types . (bang-event music-event))
         ))
     ))

#(set!
  bang-types
  (map (lambda (x)
         (set-object-property! (car x)
                               'music-description
                               (cdr (assq 'description (cdr x))))
         (let ((lst (cdr x)))
           (set! lst (assoc-set! lst 'name (car x)))
           (set! lst (assq-remove! lst 'description))
           (hashq-set! music-name-to-property-table (car x) lst)
           (cons (car x) lst)))
       bang-types))

#(set! music-descriptions
       (append bang-types music-descriptions))

#(set! music-descriptions
       (sort music-descriptions alist<?))

#(define (bang-trigger engraver event)
   ; use ly:warning as a quick hack to get it to show up in the output log
   (ly:warning "helloooo"))

#(define Bang_engraver
   (make-engraver
     (listeners (bang-event . bang-trigger))))

bang = #(make-music 'BangEvent)

\new Staff \with {
  \consists #Bang_engraver
} {
  c1 c1 \bang c1 c1
} 

Regards,
Nathan

reply via email to

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