[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Extended bar checking?
From: |
Mats Bengtsson |
Subject: |
Re: Extended bar checking? |
Date: |
Sun, 18 Sep 2022 22:16:39 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 |
Brilliant! This will be in an include file that I will use for
all my future projects (until it gets included in the LilyPond
distribution).
/Mats
On 2022-09-18 21:33, Jean Abou Samra
wrote:
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
Re: Extended bar checking?, Valentin Petzel, 2022/09/19