lilypond-user
[Top][All Lists]
Advanced

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

Re: Extended bar checking?


From: Valentin Petzel
Subject: Re: Extended bar checking?
Date: Mon, 19 Sep 2022 18:24:16 +0200

Hi Jean,

I just finished a small implementation for this, just to see that you already 
did a much better one yesterday!

Anyway. You can still achieve something like that for << ... >> constructs. 
You can do something like this:

\layout {
  \context {
    \Voice
    \accepts "Notes"
  }
  \context {
    \name "Notes"
    \type "Engraver_group"
  }
}

\layout {
   \context {
     \Notes
     \consists #Require_bar_check_engraver
   }
}

\new Voice << \new Notes { c'1 | d' | e' | } \new Notes { e'1 f' g' } >>

This does require that each part that should be checked is put into a Notes 
context (one could write a music function to do that automatically for each { 
... }). Also starting with some point in 2.21 things like this became harder 
to work with, because now overrides have the be specified on Voice level (this 
was not the case before!).

Cheers,
Valentin

Am Sonntag, 18. September 2022, 21:33:42 CEST schrieb Jean Abou Samra:
> Le 18/09/2022 à 20:32, Mats Bengtsson a écrit :
> > Hi,
> > 
> > I've been pondering about a missing feature in LilyPond, namely the
> > possibility to get a warning printout if there isn't an explicit bar
> > check ("|") in the input file at the end of each measure. This would
> > catch many of the typos I personally do when entering music, where I
> > happen to forget to change a duration, or enter the wrong duration, so
> > that the current default duration happens to be, say, double the
> > correct duration.
> > 
> > Example: Let's say I want to type
> > 
> > \relative c' {
> > c4 d e2 |
> > g1 |
> > g4 f e d |
> > c1
> > }
> > but forget to add the duration "4" in the third measure:\relative c' {
> > c4 d e2 |
> > g1 |
> > g f e d |
> > c1
> > }
> > Obviously, this will not give any bar check warning, but if there was
> > a possibility to get a warning also for missing bar checks, I would
> > immediately catch those mistakes. This feature should not be on by
> > default, but for those of us who consequently add bar checks in the
> > input files, it would be extremely helpful.
> > 
> > In another email thread today, Valentine provided an implementation of
> > a Bar_check_warning_egraver is somewhat along the same lines, but that
> > unfortunatly fails to catch the typo in the above example since it
> > only detects notes  where the duration crosses a bar line. As far as I
> > can see, the idea of Valentine's implementation cannot easily be
> > extended to do what I'm after and it's not immediately obvious to me
> > how hard it would be to implement it. Perhaps some of you clever
> > LilyPond hackers on the list have an idea, otherwise I will send it as
> > a feature request to the bug list.
> 
> Yes, it can be done.
> 
> 
> 
> \version "2.23.13"
> 
> #(define-event-class 'event 'StreamEvent) % cough
> 
> "|" = { | #(make-music 'Event 'is-bar-check #t) }
> 
> #(define (Require_bar_check_engraver context)
>     (let ((heard #f)
>           (previous-rhythmic-ev #f)
>           (now-rhythmic-ev #f))
>       (make-engraver
>        (listeners
>         ((event engraver event)
>          (when (ly:event-property event 'is-bar-check #f)
>            (set! heard #t)))
>         ((rhythmic-event engraver event)
>          (set! now-rhythmic-ev event)))
>        ((stop-translation-timestep engraver)
>         (when (and (not heard)
>                    (ly:context-property context 'measureStartNow #f))
>           (if previous-rhythmic-ev
>               (ly:event-warning previous-rhythmic-ev "missing bar check
> after this note/rest")
>               ;; maybe \skip <music>, for which it is hard to get a location
> (ly:warning "missing bar check at end of measure ~a" (1-
> (ly:context-property context
> 'currentBarNumber)))))
>         (set! heard #f)
>         (set! previous-rhythmic-ev now-rhythmic-ev)
>         (set! now-rhythmic-ev #f)))))
> 
> \layout {
>    \context {
>      \Voice
>      \consists #Require_bar_check_engraver
>    }
> }
> 
> 
> \relative c' {
>    c4 d e2 |
>    g1 |
>    g f e d | % notes wrongly entered
>    s1 % missing bar check
>    \skip {
>      c1 % missing bar check
>      c1
>    } |
> }
> 
> 
> 
> 
> However, be aware of the limitations. This only checks that
> in each voice, there is a bar check at every measure end.
> It does not check that every component of the music generating
> this voice has this bar check. For example, this gets accepted
> without warning:
> 
> \new Voice << { c'1 | d' | e' | } { e'1 f' g' } >>
> 
> 
> To my knowledge, it's not possible to also warn about this one without
> some serious modifications in LilyPond's internals.
> 
> Jean

Attachment: signature.asc
Description: This is a digitally signed message part.


reply via email to

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