]> git.donarmstrong.com Git - lilypond.git/commitdiff
Lets auto numbering of footnotes kick in from commands alone.
authorMike Solomon <mike@apollinemike.com>
Mon, 29 Aug 2011 15:08:02 +0000 (17:08 +0200)
committerMike Solomon <mike@apollinemike.com>
Mon, 29 Aug 2011 15:08:02 +0000 (17:08 +0200)
This patch gets rid of footnote-auto-numbering in the paper
bloc, allowing footnotes to kick in from commands alone.
These commands are:

auto-footnote (for top-level markups)
autoFootnote (for inside chords)
autoFootnoteGrob (for normal grob-footnoting grob situations)

Their homologues remain the same - to wit:

footnote
footnote
footnoteGrob

Currently, if one mixes automatic and non-automatic footnotes, the
automatic footnotes skip over the non-automatic ones.  So,

\auto-footnote foo
\footnote 42 bar
\auto-footnote hello

Will number the items 1, 42, 3: not 1, 42, 2.  The option to make it
1, 42, 2 should be the subject of a future patch.

The problem of get_footnotes_from_lines being called twice still
remains and also should be solved in a separate patch.

16 files changed:
input/regression/footnote-auto-numbering-page-reset.ly
input/regression/footnote-auto-numbering.ly
input/regression/footnote-break-visibility.ly
input/regression/footnote-footer-padding.ly
input/regression/footnote-spanner.ly
input/regression/footnote.ly
lily/constrained-breaking.cc
lily/page-breaking.cc
lily/page-layout-problem.cc
ly/music-functions-init.ly
ly/paper-defaults-init.ly
scm/define-grob-interfaces.scm
scm/define-grob-properties.scm
scm/define-grobs.scm
scm/define-markup-commands.scm
scm/define-music-properties.scm

index dc3fa468b5c10de78b3391929d478e847ae9f8e2..0663f5e80a5e1b0b2ed5256d3273d78b45788da5 100644 (file)
@@ -16,9 +16,9 @@ have been reached.
 \book {
 
 \markup {
-  a \footnote b c
-  \footnote d e
-  \footnote f g
+  a \auto-footnote b c
+  \auto-footnote d e
+  \auto-footnote f g
 }
 
 \markup { h i }
@@ -29,7 +29,7 @@ a b c d }
 
 \pageBreak
 
-\markup { k \footnote l m }
+\markup { k \auto-footnote l m }
 
 \relative c' { a1 }
 
index 3c0b410956082d0ec5d38d124c942d6e14c37123..790278288b3f21a99f2b167aca8b55caa12648e2 100644 (file)
@@ -15,9 +15,9 @@ footnotes.
 \book {
 
 \markup {
-  a \footnote b c
-  \footnote d e
-  \footnote f g
+  a \auto-footnote b c
+  \auto-footnote d e
+  \auto-footnote f g
 }
 
 \markup { h i }
@@ -28,7 +28,7 @@ a b c d }
 
 \pageBreak
 
-\markup { k \footnote l m }
+\markup { k \auto-footnote l m }
 
 \relative c' { a1 }
 
index 6159b5dc5f35cf3ad6caaebd26ebc297dec71570..23e9035a7128688ffb8ab050ab39291fb6ed843c 100644 (file)
@@ -7,10 +7,6 @@ can be overrided."
 
 #(set-default-paper-size "a6")
 
-\paper {
-  footnote-auto-numbering = ##f
-}
-
 \book {
 
 \new Staff \with { \consists "Footnote_engraver" }
index ce37e71426ad0e6d053bbc25e3e47fdf04894bde..b0fd84a30987283e44df50226ff84a4d2252daf6 100644 (file)
@@ -5,10 +5,6 @@
 
 #(set-default-paper-size "a6")
 
-\paper {
-  footnote-footer-padding = 1\in
-}
-
 \book {
 
   \relative c' {
index 8129d6fd4b982e369d8c7aa83dcb0d96666cb8a3..ec27ba7f360f0e7d52a83b5c8e0d23ec9a6f43af 100644 (file)
@@ -8,7 +8,6 @@ annotation goes to the correct page."
 
 \paper {
   ragged-last-bottom = ##f
-  footnote-auto-numbering = ##f
 }
 
 \book {
index a2b1c658034654c93efb5a85e77b2e2bdd00595d..f13347d31aeb3f73ef988fa96ae59732bfe27357 100644 (file)
@@ -3,10 +3,6 @@
   texidoc = "Lilypond does footnotes."
 }
 
-\paper {
-  footnote-auto-numbering = ##f
-}
-
 #(set-default-paper-size "a6")
 \book {
 
index bff8e79df9dfee4e8e459da2fbe8876ea6f9d267..d269cff48571d91fcfda5bd25a8ade3a0863d86b 100644 (file)
@@ -554,7 +554,7 @@ Line_details::Line_details (Prob *pb, Output_def *paper)
 
   if (scm_is_pair (footnotes))
     for (SCM s = footnotes; scm_is_pair (s); s = scm_cdr (s))
-      footnotes_.push_back (unsmob_stencil (scm_cadar (s)));
+      footnotes_.push_back (unsmob_stencil (scm_caddar (s)));
 
   last_column_ = 0;
   force_ = 0;
index f81683a2573277f2de404409219cba8d31aef005..c46a04efa5c363b596da1fbf0ee83b91732cfa25 100644 (file)
@@ -265,9 +265,7 @@ Page_breaking::Page_breaking (Paper_book *pb, Break_predicate is_break, Prob_bre
   footnote_padding_ = robust_scm2double (pb->paper_->c_variable ("footnote-padding"), 0.0);
   footnote_footer_padding_ = robust_scm2double (pb->paper_->c_variable ("footnote-footer-padding"), 0.0);
 
-  footnote_number_raise_ = (to_boolean (pb->paper_->c_variable ("footnote-auto-numbering"))
-                            ? robust_scm2double (pb->paper_->c_variable ("footnote-number-raise"), 0.0)
-                            : 0.0);
+  footnote_number_raise_ = robust_scm2double (pb->paper_->c_variable ("footnote-number-raise"), 0.0);
 
   if (systems_per_page_ && (max_systems_per_page_ || min_systems_per_page_))
     {
index 2988a091b69436f377c54f4e618584703c9dbaff..82c0dc7181fd92893b4c73006d73f4344ed9dc51 100644 (file)
@@ -106,8 +106,6 @@ Page_layout_problem::get_footnotes_from_lines (SCM lines, int counter, Paper_boo
   // now, make the footnote stencils with the numbering function
   SCM numbers = SCM_EOL;
   SCM in_text_numbers = SCM_EOL;
-  bool do_numbering = to_boolean (paper->c_variable ("footnote-auto-numbering"));
-  // if there's no numbering, skip all this
   /*
     TODO: This recalculates numbering every time this function is called, including once
     after the balloon prints are called.  Although it is not a huge computational drain,
@@ -118,45 +116,42 @@ Page_layout_problem::get_footnotes_from_lines (SCM lines, int counter, Paper_boo
     in duplicated work, either by making this process less complicated or (preferably)
     by passing its results downstream.
   */
-  if (do_numbering)
+  vector<SCM> footnote_number_markups; // Holds the numbering markups.
+  vector<Stencil *> footnote_number_stencils; // Holds translated versions of the stencilized numbering markups.
+  for (vsize i = 0; i < fn_count; i++)
     {
-      vector<SCM> footnote_number_markups; // Holds the numbering markups.
-      vector<Stencil *> footnote_number_stencils; // Holds translated versions of the stencilized numbering markups.
-      for (vsize i = 0; i < fn_count; i++)
+      SCM markup = scm_call_1 (numbering_function, scm_from_int (counter));
+      Stencil *s = unsmob_stencil (Text_interface::interpret_markup (layout, props, markup));
+      if (!s)
         {
-          SCM markup = scm_call_1 (numbering_function, scm_from_int (counter));
-          Stencil *s = unsmob_stencil (Text_interface::interpret_markup (layout, props, markup));
-          if (!s)
-            {
-              programming_error ("Your numbering function needs to return a stencil.");
-              markup = SCM_EOL;
-              s = new Stencil (Box (Interval (0, 0), Interval (0, 0)), SCM_EOL);
-            }
-          footnote_number_markups.push_back (markup);
-          footnote_number_stencils.push_back (s);
-          counter++;
+          programming_error ("Your numbering function needs to return a stencil.");
+          markup = SCM_EOL;
+          s = new Stencil (Box (Interval (0, 0), Interval (0, 0)), SCM_EOL);
         }
+      footnote_number_markups.push_back (markup);
+      footnote_number_stencils.push_back (s);
+      counter++;
+    }
 
-      // find the maximum X_AXIS length
-      Real max_length = -infinity_f;
-      for (vsize i = 0; i < fn_count; i++)
-        max_length = max (max_length, footnote_number_stencils[i]->extent (X_AXIS).length ());
+  // find the maximum X_AXIS length
+  Real max_length = -infinity_f;
+  for (vsize i = 0; i < fn_count; i++)
+    max_length = max (max_length, footnote_number_stencils[i]->extent (X_AXIS).length ());
 
-      /*
-        translate each stencil such that it attains the correct maximum length and bundle the
-        footnotes into a scheme object.
-      */
-      SCM *tail = &numbers;
-      SCM *in_text_tail = &in_text_numbers;
+  /*
+    translate each stencil such that it attains the correct maximum length and bundle the
+    footnotes into a scheme object.
+  */
+  SCM *tail = &numbers;
+  SCM *in_text_tail = &in_text_numbers;
 
-      for (vsize i = 0; i < fn_count; i++)
-        {
-          *in_text_tail = scm_cons (footnote_number_markups[i], SCM_EOL);
-          in_text_tail = SCM_CDRLOC (*in_text_tail);
-          footnote_number_stencils[i]->translate_axis (max_length - footnote_number_stencils[i]->extent (X_AXIS).length (), X_AXIS);
-          *tail = scm_cons (footnote_number_stencils[i]->smobbed_copy (), SCM_EOL);
-          tail = SCM_CDRLOC (*tail);
-        }
+  for (vsize i = 0; i < fn_count; i++)
+    {
+      *in_text_tail = scm_cons (footnote_number_markups[i], SCM_EOL);
+      in_text_tail = SCM_CDRLOC (*in_text_tail);
+      footnote_number_stencils[i]->translate_axis (max_length - footnote_number_stencils[i]->extent (X_AXIS).length (), X_AXIS);
+      *tail = scm_cons (footnote_number_stencils[i]->smobbed_copy (), SCM_EOL);
+      tail = SCM_CDRLOC (*tail);
     }
   // build the footnotes
 
@@ -193,6 +188,13 @@ Page_layout_problem::get_footnotes_from_lines (SCM lines, int counter, Paper_boo
                                                                    props, footnote_markup);
 
               Stencil *footnote_stencil = unsmob_stencil (footnote_stl);
+              bool do_numbering = to_boolean (footnote->get_property ("automatically-numbered"));
+              if (Spanner *orig = dynamic_cast<Spanner *>(footnote))
+                {
+                  if (orig->is_broken ())
+                    for (vsize i = 0; i < orig->broken_intos_.size (); i++)
+                      do_numbering = do_numbering || to_boolean (orig->broken_intos_[i]->get_property ("automatically-numbered"));
+                }
               if (do_numbering)
                 {
                   SCM annotation_scm = scm_car (in_text_numbers);
@@ -226,21 +228,23 @@ Page_layout_problem::get_footnotes_from_lines (SCM lines, int counter, Paper_boo
           for (SCM st = stencils; scm_is_pair (st); st = scm_cdr (st))
             {
               Stencil mol;
-              Stencil *footnote = unsmob_stencil (scm_cadar (st));
+              Stencil *footnote = unsmob_stencil (scm_caddar (st));
               mol.add_stencil (*footnote);
+              bool do_numbering = to_boolean (scm_cadar (st));
+              SCM in_text_stencil = Stencil ().smobbed_copy ();
               if (do_numbering)
                 {
                   Stencil *annotation = unsmob_stencil (scm_car (numbers));
                   SCM in_text_annotation = scm_car (in_text_numbers);
-                  SCM in_text_stencil = Text_interface::interpret_markup (layout, props, in_text_annotation);
+                  in_text_stencil = Text_interface::interpret_markup (layout, props, in_text_annotation);
                   if (!unsmob_stencil (in_text_stencil))
                     in_text_stencil = SCM_EOL;
-                  number_footnote_table = scm_cons (scm_cons (scm_caar (st), in_text_stencil), number_footnote_table);
                   annotation->translate_axis (mol.extent (Y_AXIS)[UP] + number_raise - annotation->extent (Y_AXIS)[UP], Y_AXIS);
                   mol.add_at_edge (X_AXIS, LEFT, *annotation, 0.0);
                   numbers = scm_cdr (numbers);
                   in_text_numbers = scm_cdr (in_text_numbers);
                 }
+              number_footnote_table = scm_cons (scm_cons (scm_caar (st), in_text_stencil), number_footnote_table);
               footnote_stencil.add_at_edge (Y_AXIS, DOWN, mol, padding);
             }
           footnotes = scm_cons (footnote_stencil.smobbed_copy (), footnotes);
index e6b8a97f58eaf45b88b1496a44bfb80428b8562f..b3a009860753c54d7ab7549617ab4ba6f32d3ae5 100644 (file)
@@ -346,6 +346,7 @@ footnoteGrob =
    (_i "Attach @var{text} to @var{grob-name} at offset @var{offset},
 with @var{text} referring to @var{footnote} (use like @code{\\once})")
    (make-music 'FootnoteEvent
+               'automatically-numbered #f
               'symbol grob-name
               'X-offset (car offset)
               'Y-offset (cdr offset)
@@ -360,9 +361,14 @@ allowing for the footnote to be automatically numbered such that
 the number appears at @var{offset}.  Note that, for this to take effect,
 auto-numbering must be turned on in the paper block.  Otherwise, no
 number will appear.  Use like @code{\\once})")
-   #{
-     \footnoteGrob $grob-name $offset \markup { \null } $footnote
-   #})
+   (make-music 'FootnoteEvent
+               'automatically-numbered #t
+              'symbol grob-name
+              'X-offset (car offset)
+              'Y-offset (cdr offset)
+               'text (make-null-markup)
+              'footnote-text footnote))
+
 
 footnote =
 #(define-music-function (parser location offset text footnote)
@@ -370,14 +376,12 @@ footnote =
    (_i "Attach @var{text} at @var{offset} with @var{text} referring
 to @var{footnote} (use like @code{\\tweak})")
    (make-music 'FootnoteEvent
+               'automatically-numbered #f
               'X-offset (car offset)
               'Y-offset (cdr offset)
               'text text
               'footnote-text footnote))
 
-% this function can't be a simple copy and past of the above because
-% it needs to be encapsulated in a Sequential Music.
-% so, there's a code dup of above :-(
 autoFootnote =
 #(define-music-function (parser location offset footnote)
    (number-pair? markup?)
@@ -387,6 +391,7 @@ such that the number appears at @var{offset}.  Note that, for this to
 take effect, auto-numbering must be turned on in the paper block.
 Otherwise, no number will appear.  Use like @code{\\tweak})")
    (make-music 'FootnoteEvent
+               'automatically-numbered #t
               'X-offset (car offset)
               'Y-offset (cdr offset)
               'text (make-null-markup)
index c68652d8a403778c1c490e4a13672dd90de60190..d08c665f570767712e02f2dad6a836d0a8e82fea 100644 (file)
   footnote-padding = 0.5\mm
   footnote-footer-padding = 0.5\mm
   footnote-number-raise = 0.5\mm
-  footnote-auto-numbering = ##t
   footnote-numbering-function = #numbered-footnotes
   reset-footnotes-on-new-page = ##t
 
index 735b9c78956e4e602f41478525379bb344880232..7b6535f1e38ef069e7464e32b856673f4df3b6cc 100644 (file)
@@ -84,7 +84,7 @@ note)."
 (ly:add-interface
  'footnote-interface
  "Make a footnote."
- '(footnote-text))
+ '(automatically-numbered footnote-text))
 
 (ly:add-interface
  'footnote-spanner-interface
index c8619d9afe4e33da418d11e231a980bd41ef022c..cd3fd6ec979b2e4dde93ec2fb59aec8d1d19ef78 100644 (file)
@@ -58,6 +58,8 @@ arpeggio squiggly line.")
      (auto-knee-gap ,ly:dimension? "If a gap is found between note
 heads where a horizontal beam fits that is larger than this number,
 make a kneed beam.")
+     (automatically-numbered ,boolean? "Should a footnote be automatically
+numbered?")
      (average-spacing-wishes ,boolean? "If set, the spacing wishes are
 averaged over staves.")
      (avoid-note-head ,boolean? "If set, the stem of a chord does not
index 4bbe29beb1d90b888d6ae2cc7403b30a43360d27..1591d108bbc813dbc488d6f08e3146d736084572 100644 (file)
      . (
        (annotation-balloon . #f)
        (annotation-line . #t)
+       (automatically-numbered . ,(grob::calc-property-by-copy 'automatically-numbered))
        (break-visibility . ,inherit-y-parent-visibility)
        (footnote-text . ,(grob::calc-property-by-copy 'footnote-text))
        (stencil . ,ly:balloon-interface::print)
      . (
        (annotation-balloon . #f)
        (annotation-line . #t)
+       (automatically-numbered . ,(grob::calc-property-by-copy 'automatically-numbered))
        (footnote-text . ,(grob::calc-property-by-copy 'footnote-text))
        (spanner-placement . ,LEFT)
        (stencil . ,ly:balloon-interface::print-spanner)
index cdfaf1f9f87d20687d0b0769857c32b5f8c39389..18728e57d9809de9b1865209cfb5e7677103b59d 100644 (file)
@@ -1900,6 +1900,29 @@ returns an empty markup.
     (interpret-markup layout props (list anonymous-with-signature arg))))
 
 (define-markup-command (footnote layout props mkup note)
+  (markup? markup?)
+  #:category other
+  "Have footnote @var{note} act as an annotation to the markup @var{mkup}.
+
+@lilypond[verbatim,quote]
+\\markup {
+  \\auto-footnote a b
+  \\override #'(padding . 0.2)
+  \\auto-footnote c d
+}
+@end lilypond
+The footnote will not be annotated automatically."
+  (ly:stencil-combine-at-edge
+    (interpret-markup layout props mkup)
+    X
+    RIGHT
+    (ly:make-stencil
+      `(footnote (gensym "footnote") #f ,(interpret-markup layout props note))
+      '(0 . 0)
+      '(0 . 0))
+    0.0))
+
+(define-markup-command (auto-footnote layout props mkup note)
   (markup? markup?)
   #:category other
   #:properties ((raise 0.5)
@@ -1908,11 +1931,12 @@ returns an empty markup.
 
 @lilypond[verbatim,quote]
 \\markup {
-  \\footnote a b
+  \\auto-footnote a b
   \\override #'(padding . 0.2)
-  \\footnote c d
+  \\auto-footnote c d
 }
-@end lilypond"
+@end lilypond
+The footnote will be annotated automatically."
   (let* ((markup-stencil (interpret-markup layout props mkup))
          (auto-numbering (ly:output-def-lookup layout
                                                'footnote-auto-numbering))
@@ -1970,7 +1994,7 @@ returns an empty markup.
   (ly:stencil-add
     main-stencil
     (ly:make-stencil
-      `(footnote ,footnote-hash ,(interpret-markup layout props note))
+      `(footnote ,footnote-hash #t ,(interpret-markup layout props note))
       '(0 . 0)
       '(0 . 0)))))
 
index 5e1159363654e42981a8677b67ff785cf91d3dc9..a6b910c7db6c60527c3ffeaef8bff2792696f211 100644 (file)
@@ -41,6 +41,8 @@ this @code{\\lyricsto} section.")
 (with @code{+} sign).")
      (augmented-slash ,boolean? "This figure is for an augmented figured bass
 (back-slashed number).")
+     (automatically-numbered ,boolean? "Should a footnote be automatically
+numbered?")
      (autosplit-end ,boolean? "Duration of event was truncated by automatic
 splitting in @code{Completion_heads_engraver}.")