]> git.donarmstrong.com Git - lilypond.git/commitdiff
figured bass: Implement backslashed figures (raised 6th steps)
authorReinhold Kainhofer <reinhold@kainhofer.com>
Tue, 10 Jun 2008 17:44:47 +0000 (19:44 +0200)
committerReinhold Kainhofer <reinhold@kainhofer.com>
Tue, 17 Jun 2008 20:48:28 +0000 (22:48 +0200)
raised 6th steps are typically shown as 6 with a backslash through it
(rather than with a '+'). This patch implements this by adding the
\\ modifier to bass figures: <6\\>

The back-slashed digit is printed out using the new markup function
backslashed-digit (copied from slashed-digit and adapted to backslashes).
Both forward and backward slashes uses the same internal function.

I also increased the slope of forward slashes to make it easier to
distinguish the direction of the slash.

For some numbers I also enlarge the slash in X directions to make it
more visible (my hand-engraved scores use an even larger slash than
lilypond, anyway). I also move the slash up/down for some numbers
to make it more visible.

Also use the real Y extents of the slash rather than the whole interval
for the number. As we shift the slash for some numbers, otherwise
it would make the whole digit larger and shift it down for no apparent
visual reason.

Signed-off-by: Reinhold Kainhofer <reinhold@kainhofer.com>
input/regression/figured-bass-slashed-numbers.ly [new file with mode: 0644]
input/regression/figured-bass.ly
lily/parser.yy
scm/define-markup-commands.scm
scm/define-music-properties.scm
scm/translation-functions.scm

diff --git a/input/regression/figured-bass-slashed-numbers.ly b/input/regression/figured-bass-slashed-numbers.ly
new file mode 100644 (file)
index 0000000..257170b
--- /dev/null
@@ -0,0 +1,32 @@
+\version "2.11.47"
+
+bassfigures = \figuremode {
+  <0/ 1/ 2/> <3/ 4/ 5/> <6/ 7/ 8/> <9/ 10/ 11/> <12/ 13/ 100/>
+  <0\\ 1\\ 2\\> <3\\ 4\\ 5\\> <6\\ 7\\ 8\\> <9\\ 10\\ 11\\> <12\\ 13\\ 100\\>
+  <3\\\+ 6\\/ 7\\+! >
+}
+
+<<
+  \new FiguredBass \bassfigures
+>>
+
+%{
+% Override the exceptions:
+
+#(define (horizontal-slash-interval-default num forward number-interval mag)
+    (interval-widen number-interval (* mag 0.25)))
+
+#(define (adjust-slash-stencil-default num forward stencil mag)
+    stencil)
+
+unsetExceptions = #(define-music-function (parser location) ()
+;  (set! horizontal-slash-interval horizontal-slash-interval-default)
+;  (set! adjust-slash-stencil adjust-slash-stencil-default)
+  (make-music 'Music 'void #t)
+)
+
+<<
+  \unsetExceptions
+  \new FiguredBass <<\unsetExceptions \bassfigures>>
+>>
+%}
index b710399117905f6c74d807d1c2743bc776740958..a78a197a9b23a88835ec09a136ce2cb89365e7be 100644 (file)
@@ -6,7 +6,7 @@
   texidoc = " Figured bass is created by the FiguredBass context which
 responds to figured bass events and rest events.  You must enter these
 using the special @code{\figuremode @{ @}} mode, which allows you to
-type numbers, like @code{<4 6+>} and add slashes and pluses.
+type numbers, like @code{<4 6+>} and add slashes, backslashes and pluses.
 
 You can also enter markup strings. The vertical alignment may also be tuned.
 
@@ -32,6 +32,7 @@ You can also enter markup strings. The vertical alignment may also be tuned.
     <3 _! 5 _- 7>
     <3 _ 5 _ 7>
     <3 6/ >
+    <3 6\\ >
     <"V7" ["bla" 6] \markup{ \musicglyph #"rests.2"} >
 
     \once \override BassFigureAlignment #'stacking-dir = #UP
index 3b690e8980890b7ef3900723e8bf97ec8b6c7c60..9a78c74437038cf361333fba44d9dd0ad1db3816 100644 (file)
@@ -1907,6 +1907,10 @@ bass_figure:
                        {
                        m->set_property ("no-continuation", SCM_BOOL_T);
                        }
+               else if ($2 == ly_symbol2scm ("backslash"))
+                       {
+                       m->set_property ("augmented-slash", SCM_BOOL_T);
+                       }
        }
        ;
 
@@ -1921,6 +1925,9 @@ figured_bass_modification:
        | '/'           {
                $$ = ly_symbol2scm ("slash");
        }
+       | E_BACKSLASH {
+               $$ = ly_symbol2scm ("backslash");
+       }
        ;
 
 br_bass_figure:
index eb96aee8453df5bc8840ee03715b2869f529f5a7..d09df9e0a5cbfca8e3a5bb9e1482445c918062d8 100644 (file)
@@ -1709,6 +1709,71 @@ and continue with double letters.
    (ly:text-interface::interpret-markup layout props
      (number->markletter-string number->mark-alphabet-vector num)))
 
+(define-public (horizontal-slash-interval num forward number-interval mag)
+  (ly:message "Mag step: ~a" mag)
+  (if forward
+    (cond ;((= num 6) (interval-widen number-interval (* mag 0.5)))
+          ;((= num 5) (interval-widen number-interval (* mag 0.5)))
+          (else (interval-widen number-interval (* mag 0.25))))
+    (cond ((= num 6) (interval-widen number-interval (* mag 0.5)))
+          ;((= num 5) (interval-widen number-interval (* mag 0.5)))
+          (else (interval-widen number-interval (* mag 0.25))))
+  ))
+
+(define-public (adjust-slash-stencil num forward stencil mag)
+  (if forward
+    (cond ((= num 2)
+              (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
+          ((= num 3)
+              (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
+          ;((= num 5)
+              ;(ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.07))))
+          ;((= num 7)
+          ;    (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
+          (else stencil))
+    (cond ((= num 6)
+              (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.15))))
+          ;((= num 8)
+          ;    (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
+          (else stencil))
+  )
+)
+
+(define (slashed-digit-internal layout props num forward font-size thickness)
+  (let* ((mag (magstep font-size))
+         (thickness (* mag
+                       (ly:output-def-lookup layout 'line-thickness)
+                       thickness))
+         ; backward slashes might use slope and point in the other direction!
+         (dy (* mag (if forward 0.4 -0.4)))
+         (number-stencil (interpret-markup layout
+                                           (prepend-alist-chain 'font-encoding 'fetaNumber props)
+                                           (number->string num)))
+         (num-x (horizontal-slash-interval num forward (ly:stencil-extent number-stencil X) mag))
+         (center (interval-center (ly:stencil-extent number-stencil Y)))
+         ; Use the real extents of the slash, not the whole number, because we
+         ; might translate the slash later on!
+         (num-y (interval-widen (cons center center) (abs dy)))
+         (is-sane (and (interval-sane? num-x) (interval-sane? num-y)))
+         (slash-stencil (if is-sane
+                            (ly:make-stencil
+                             `(draw-line ,thickness
+                                         ,(car num-x) ,(- (interval-center num-y) dy)
+                                         ,(cdr num-x) ,(+ (interval-center num-y) dy))
+                             num-x num-y)
+                            #f)))
+(ly:message "Num: ~a, X-interval: ~a" num num-x)
+    (if (ly:stencil? slash-stencil)
+      (begin
+        ; for some numbers we need to shift the slash/backslash up or down to make
+        ; the slashed digit look better
+        (set! slash-stencil (adjust-slash-stencil num forward slash-stencil mag))
+        (set! number-stencil
+          (ly:stencil-add number-stencil slash-stencil)))
+      (ly:warning "Unable to create slashed digit ~a" num))
+    number-stencil))
+
+
 (define-builtin-markup-command (slashed-digit layout props num)
   (integer?)
   other
@@ -1727,42 +1792,28 @@ figured bass notation.
   \\slashed-digit #7
 }
 @end lilypond"
-  (let* ((mag (magstep font-size))
-         (thickness (* mag
-                       (ly:output-def-lookup layout 'line-thickness)
-                       thickness))
-         (dy (* mag 0.15))
-         (number-stencil (interpret-markup layout
-                                           (prepend-alist-chain 'font-encoding 'fetaNumber props)
-                                           (number->string num)))
-         (num-x (interval-widen (ly:stencil-extent number-stencil X)
-                                (* mag 0.2)))
-         (num-y (ly:stencil-extent number-stencil Y))
-         (is-sane (and (interval-sane? num-x) (interval-sane? num-y)))
-         (slash-stencil (if is-sane
-                            (ly:make-stencil
-                             `(draw-line ,thickness
-                                         ,(car num-x) ,(- (interval-center num-y) dy)
-                                         ,(cdr num-x) ,(+ (interval-center num-y) dy))
-                             num-x num-y)
-                            #f)))
-    (set! slash-stencil
-          (cond ((not (ly:stencil? slash-stencil)) #f)
-                ((= num 5)
-                 (ly:stencil-translate slash-stencil
-                                       ;;(cons (* mag -0.05) (* mag 0.42))
-                                       (cons (* mag -0.00) (* mag -0.07))))
-                ((= num 7)
-                 (ly:stencil-translate slash-stencil
-                                       ;;(cons (* mag -0.05) (* mag 0.42))
-                                       (cons (* mag -0.00) (* mag -0.15))))
-                (else slash-stencil)))
-    (if slash-stencil
-        (set! number-stencil
-              (ly:stencil-add number-stencil slash-stencil))
-        (ly:warning "invalid number for slashed digit ~a" num))
-    number-stencil))
+  (slashed-digit-internal layout props num #t font-size thickness))
+\f
+(define-builtin-markup-command (backslashed-digit layout props num)
+  (integer?)
+  other
+  ((font-size 0)
+   (thickness 1.6))
+  "
+@cindex backslashed digits
 
+A feta number, with backslash.  This is for use in the context of
+figured bass notation.
+@lilypond[verbatim,quote]
+\\markup {
+  \\backslashed-digit #5
+  \\hspace #2
+  \\override #'(thickness . 3)
+  \\backslashed-digit #7
+}
+@end lilypond"
+  (slashed-digit-internal layout props num #f font-size thickness))
+\f
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; the note command.
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
index d6202d79ff48679ed601b2b6cfcf2357f93e47cb..357dd73f04f4d4fbfb6bb50c149556bfa3d81642 100644 (file)
@@ -31,6 +31,8 @@
 TODO: Consider making type into symbol.")
      (augmented ,boolean? "This figure is for an augmented figured bass
 (with @code{+} sign).")
+     (augmented-slash ,boolean? "This figure is for an augmented figured bass
+(back-slashed number).")
      (associated-context ,string? "Name of the Voice context associated with
 this @code{\\newaddlyrics} section.")
 
index 366f44fa3baf095b706501c6a21d045f985b2b85..2ceee74ab77f767d5d875d41d479597fedf0cf48 100644 (file)
                              (lambda (y) (make-translate-scaled-markup (cons -0.7 0) y))
                              identity)
 
-                         (if (eq? #t (ly:event-property event 'diminished))
-                             (markup #:slashed-digit figure)
-                             (markup #:number (number->string figure 10))))
+                         (cond
+                               ((eq? #t (ly:event-property event 'diminished))
+                                        (markup #:slashed-digit figure))
+                               ((eq? #t (ly:event-property event 'augmented-slash))
+                                        (markup #:backslashed-digit figure))
+                               (else (markup #:number (number->string figure 10)))))
                         #f
                         ))
         (alt (ly:event-property event 'alteration))