From: Reinhold Kainhofer Date: Fri, 5 Aug 2011 18:25:12 +0000 (+0200) Subject: Loglevels: Add ly:input-warning, ly:music-warning Scheme functions X-Git-Tag: release/2.15.9-1~10^2~9 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=1c231128c18b2ac63c293f48ab4b5bc02e92c8ac;p=lilypond.git Loglevels: Add ly:input-warning, ly:music-warning Scheme functions -) Add ly:input-warning, ly:music-warning Scheme functions (also print location of the warning) -) improve warnings from Scheme --- diff --git a/lily/input-scheme.cc b/lily/input-scheme.cc index 1325c8e151..19131271d3 100644 --- a/lily/input-scheme.cc +++ b/lily/input-scheme.cc @@ -29,6 +29,24 @@ LY_DEFINE (ly_input_location_p, "ly:input-location?", 1, 0, 0, return unsmob_input (x) ? SCM_BOOL_T : SCM_BOOL_F; } +LY_DEFINE (ly_input_warning, "ly:input-warning", 2, 0, 1, (SCM sip, SCM msg, SCM rest), + "Print @var{msg} as a GNU compliant warning message, pointing" + " to the location in @var{sip}. @var{msg} is interpreted" + " similar to @code{format}'s argument, using @var{rest}.") +{ + Input *ip = unsmob_input (sip); + + LY_ASSERT_TYPE (unsmob_input, sip, 1); + LY_ASSERT_TYPE (scm_is_string, msg, 2); + + msg = scm_simple_format (SCM_BOOL_F, msg, rest); + + string m = ly_scm2string (msg); + ip->warning (m); + + return SCM_UNSPECIFIED; +} + LY_DEFINE (ly_input_message, "ly:input-message", 2, 0, 1, (SCM sip, SCM msg, SCM rest), "Print @var{msg} as a GNU compliant error message, pointing" " to the location in @var{sip}. @var{msg} is interpreted" diff --git a/ly/music-functions-init.ly b/ly/music-functions-init.ly index 2278f85a26..f82ac0b4e3 100644 --- a/ly/music-functions-init.ly +++ b/ly/music-functions-init.ly @@ -172,7 +172,7 @@ barNumberCheck = (lambda (c) (let ((cbn (ly:context-property c 'currentBarNumber))) (if (and (number? cbn) (not (= cbn n))) - (ly:input-message location + (ly:input-warning location "Barcheck failed got ~a expect ~a" cbn n)))))) @@ -433,7 +433,7 @@ instrumentSwitch = (instrument-def (if handle (cdr handle) '()))) (if (not handle) - (ly:input-message location "No such instrument: ~a" name)) + (ly:input-warning location "No such instrument: ~a" name)) (context-spec-music (make-music 'SimultaneousMusic 'elements @@ -501,7 +501,7 @@ languageRestore = (begin (set! pitchnames previous-pitchnames) (ly:parser-set-note-names parser pitchnames)) - (ly:warning (_ "No other language was defined previously. Ignoring."))) + (ly:input-warning location (_ "No other language was defined previously. Ignoring."))) (make-music 'Music 'void #t)) @@ -725,7 +725,7 @@ Example: (let ((moment-reference (ly:music-length (car seqs)))) (for-each (lambda (seq moment) (if (not (equal? moment moment-reference)) - (ly:music-message seq + (ly:music-warning seq "Bars in parallel music don't have the same length"))) seqs (map-in-order ly:music-length seqs)))) voices) @@ -808,7 +808,7 @@ print @var{secondary-note} as a stemless note head in parentheses.") (for-each (lambda (m) (ly:music-set-property! m 'pitch trill-pitch)) trill-events) (begin - (ly:warning (_ "Second argument of \\pitchedTrill should be single note: ")) + (ly:input-warning location (_ "Second argument of \\pitchedTrill should be single note: ")) (display sec-note-events))) (if (eq? forced #t) @@ -973,7 +973,7 @@ tweak = (if (equal? (object-property sym 'backend-type?) #f) (begin - (ly:warning (_ "cannot find property type-check for ~a") sym) + (ly:input-warning location (_ "cannot find property type-check for ~a") sym) (ly:warning (_ "doing assignment anyway")))) (set! (ly:music-property arg 'tweaks) diff --git a/scm/music-functions.scm b/scm/music-functions.scm index 3394ed1b3b..defe293619 100644 --- a/scm/music-functions.scm +++ b/scm/music-functions.scm @@ -650,21 +650,6 @@ NUMBER is 0-base, i.e., Voice=1 (upstems) has number 0. (set! (ly:grob-property grob symbol) val)))) -;; -(define-public (smart-bar-check n) - "Make a bar check that checks for a specific bar number." - (let ((m (make-music 'ApplyContext))) - (define (checker tr) - (let* ((bn (ly:context-property tr 'currentBarNumber))) - (or (= bn n) - (ly:error - ;; FIXME: uncomprehensable message - (_ "Bar check failed. Expect to be at ~a, instead at ~a") - n bn)))) - (set! (ly:music-property m 'procedure) checker) - m)) - - (define-public (skip->rest mus) "Replace @var{mus} by @code{RestEvent} of the same duration if it is a @code{SkipEvent}. Useful for extracting parts from crowded scores." @@ -692,12 +677,17 @@ NUMBER is 0-base, i.e., Voice=1 (upstems) has number 0. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; warn for bare chords at start. - (define-public (ly:music-message music msg) (let ((ip (ly:music-property music 'origin))) (if (ly:input-location? ip) - (ly:input-message ip msg) - (ly:warning msg)))) + (ly:input-message ip msg) + (ly:message msg)))) + +(define-public (ly:music-warning music msg) + (let ((ip (ly:music-property music 'origin))) + (if (ly:input-location? ip) + (ly:input-warning ip msg) + (ly:warning msg)))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; @@ -842,7 +832,7 @@ Syntax: (set! (ly:music-property music 'quoted-events) quoted-vector) (set! (ly:music-property music 'iterator-ctor) ly:quote-iterator::constructor)) - (ly:music-message music (ly:format (_ "cannot find quoted music: `~S'") quoted-name)))) + (ly:music-warning music (ly:format (_ "cannot find quoted music: `~S'") quoted-name)))) music)) diff --git a/scm/part-combiner.scm b/scm/part-combiner.scm index 8c779a91ee..c492701c91 100644 --- a/scm/part-combiner.scm +++ b/scm/part-combiner.scm @@ -594,4 +594,4 @@ the mark when there are no spanners active. (if (not (null? quote-contents)) (hash-set! tab name (list->vector (reverse! quote-contents '()))) - (ly:music-message mus (ly:format (_ "quoted music `~a' is empty") name))))) + (ly:music-warning mus (ly:format (_ "quoted music `~a' is empty") name)))))