]> git.donarmstrong.com Git - lilypond.git/commitdiff
Loglevels: Add ly:input-warning, ly:music-warning Scheme functions
authorReinhold Kainhofer <reinhold@kainhofer.com>
Fri, 5 Aug 2011 18:25:12 +0000 (20:25 +0200)
committerReinhold Kainhofer <reinhold@kainhofer.com>
Sun, 14 Aug 2011 12:55:11 +0000 (14:55 +0200)
-) Add ly:input-warning, ly:music-warning Scheme functions (also
   print location of the warning)
-) improve warnings from Scheme

lily/input-scheme.cc
ly/music-functions-init.ly
scm/music-functions.scm
scm/part-combiner.scm

index 1325c8e1514e2fa76852d7eb45fe181b314e04f2..19131271d3f38a9ab78dcca04b0a6855a2142f94 100644 (file)
@@ -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"
index 2278f85a266387dbedef8a3d3192917b2193d126..f82ac0b4e350c9328efe85784632862cff5ccff7 100644 (file)
@@ -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)
index 3394ed1b3b78c3489de22ceef025be00b76dedc1..defe293619717cb5e1fc52cd65e06c74f6b060f7 100644 (file)
@@ -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))
 
 
index 8c779a91ee19944affc53ee95d8848e5f1582724..c492701c9142087bb6c44ac65deabf1a41d0a224 100644 (file)
@@ -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)))))