lilypond-user
[Top][All Lists]
Advanced

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

Re: MIDI: Automatic accent on notes starting bars


From: Lukas-Fabian Moser
Subject: Re: MIDI: Automatic accent on notes starting bars
Date: Mon, 11 Feb 2019 21:47:16 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0


is there a way of automagically adding some volume increase ("accent") in MIDI output to any note that happens to start on the first beat in a bar?

It seems a well-defined enough request to me so that it should be perfectly possible to do this in scheme, but I'm afraid this exceeds my very limited LilyPond-scheme abilites...

Slight complication (maybe): In my scores, the metre changes all the time, so one really would have to use the actual timing of a note.

Ok, so I tried to boldly dive into the hitherto unknown realm of engraver construction and came up with the following:

\version "2.19.82"

#(define (measure-position-from-context context)
   (ly:moment-main (ly:context-property context 'measurePosition)))

accent_downbeat_engraver =
#(lambda (ctx) (make-engraver
                (listeners
                 ((note-event engraver event)
                  (if (eq? 0 (measure-position-from-context ctx))
                      (ly:broadcast (ly:context-event-source ctx)
                        (ly:make-stream-event
                         (ly:make-event-class 'articulation-event)
                         (list
                          (cons 'midi-extra-velocity 20)
                          (cons 'articulation-type "accent")))))))))


\layout {
  \context {
    \Voice
    \consists \accent_downbeat_engraver
  }
}


\score {
  \relative {
    \time 2/4
    a8 b c b
    r8 a b4~
    \time 3/4
    b a8 b c d
    e4 e e
  }
  \layout {}
  \midi {}
}

This works fine in that it adds accents to any notes happening to start a new measure. But - and this would be crucial for my application - the accents do not survive in the MIDI output. (At first I thought that \consist'ing the engraver to the Voice context in the \midi might help, but alas...)

My guess is that I'm broadcasting an articulation event that suffices for the articulation being printed, but is either not "connected" to the actual note or is for some other reason missed by the MIDI performers.

How could I proceed?


Lukas




reply via email to

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