]> git.donarmstrong.com Git - lilypond.git/commitdiff
* Documentation/topdocs/NEWS.tely (Top): Mention markup text feature.
authorJan Nieuwenhuizen <janneke@gnu.org>
Tue, 8 Mar 2005 10:48:51 +0000 (10:48 +0000)
committerJan Nieuwenhuizen <janneke@gnu.org>
Tue, 8 Mar 2005 10:48:51 +0000 (10:48 +0000)
* scripts/lilypond-book.py (PREAMBLE_LY): toplevel-music-handler:
Add texts parameter.

16 files changed:
ChangeLog
Documentation/topdocs/NEWS.tely
lily/book.cc
lily/include/lily-lexer.hh
lily/include/music.hh
lily/include/paper-book.hh
lily/include/score.hh
lily/lexer.ll
lily/lily-parser-scheme.cc
lily/paper-book.cc
lily/parser.yy
lily/score-scheme.cc
lily/score.cc
scm/lily-library.scm
scm/new-markup.scm
scripts/lilypond-book.py

index 740b8d3fd2b837256656b5fdef1c2a790892222b..51b632aa41d04bf1a5b2547c33822017dd2a8cf8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,29 @@
+2005-03-08  Jan Nieuwenhuizen  <janneke@gnu.org>
+
+       * Documentation/topdocs/NEWS.tely (Top): Mention markup text feature.
+
+       * scripts/lilypond-book.py (PREAMBLE_LY): toplevel-music-handler:
+       Add texts parameter.
+
 2005-03-07  Jan Nieuwenhuizen  <janneke@gnu.org>
 
+       * lily/lexer.ll (lyric_markup): New mode.
+       (Lily_lexer::push_lyric_markup_state): New method.
+       (MARKUPCOMMAND): Markup during lyric mode returns LYRIC_MARKUP.
+
+       * lily/parser.yy (book_body):
+       (toplevel_expression): Grok \markup texts.
+
+       * lily/score-scheme.cc (ly:music-scorify): 
+       * scm/lily-library.scm (collect-music-for-book): Take texts
+       parameter.
+
+       * lily/score.cc (texts_): New member.
+
+       * lily/paper-book.cc (systems): Format score texts.
+
+       * score-text.ly: New file.
+
        * ttftool/SConscript:
        * kpath-guile/SConscript: New file.
 
index eb0132c41e1ece5cddb50fe4bb10b961796985bc..81faaf2bf4ff77c746fac9a8981e37b7714f9881 100644 (file)
@@ -2,12 +2,6 @@
 @setfilename NEWS.info
 @settitle NEWS
 
-
-
-@node Top, , , 
-@top
-@unnumbered New features in 2.5 since 2.4
-
 @ifhtml
 @macro inputfileref{DIR,NAME}
 @uref{../../../\DIR\/out-www/collated-files.html#\NAME\,@file{\DIR\/\NAME\}}@c
@@ -28,7 +22,26 @@ See user manual, \NAME\
 
 
 
+@node Top, , , 
+@top
+@unnumbered New features in 2.5 since 2.4
+
+
 @itemize @bullet
+
+@item
+Markup texts can be appended to a @code{\score} block or toplevel
+music expression, for example,
+
+@lilypond[verbatim,relative=1,raggedright]
+\relative { c' d e }
+\markup { first text }
+\markup { second text }
+@end lilypond
+
+See @inputfileref{input/regression,score-text.ly}.
+
+
 @item
 @TeX{}'s @code{kpathsea} library is loaded dynamically, so installing
 LilyPond does not require installing @TeX{} anymore.
index 04380f615f6adc866c7418686dc6dc80e6a1dcf3..114fb04b32ec38ae9a27c3e2f8183ef21c004dfa 100644 (file)
@@ -107,6 +107,7 @@ Book::process (String outname, Output_def *default_def)
          Score_systems sc;
          sc.systems_ = systems;
          sc.header_ = scores_[i]->header_;
+         sc.texts_ = scores_[i]->texts_;
          paper_book->score_systems_.push (sc);
        }
     }
index fbc06b63676b85adf17fbfad9ce208fede807921..b5b43219693be8a469562cdc353e7de7badbb1a4 100644 (file)
@@ -71,6 +71,7 @@ public:
   void push_figuredbass_state ();
   void push_lyric_state ();
   void push_initial_state ();
+  void push_lyric_markup_state ();
   void push_markup_state ();
   void push_note_state (SCM tab);
   void pop_state ();
index 12db78facdca7d051d465614191f3398215ffb2f..6a0794092fe5ed056d1232b4c387ebada9b934c9 100644 (file)
@@ -61,6 +61,6 @@ DECLARE_UNSMOB(Music, music);
 
 Music *make_music_by_name (SCM sym);
 SCM ly_music_deep_copy (SCM);
-SCM ly_music_scorify (SCM, SCM);
+SCM ly_music_scorify (SCM, SCM, SCM);
 
 #endif /* MUSIC_HH */
index ef9b540f01e2b63595b795e4b25bd90ca230e747..4ee2911cee9654864fab65769d00a463a3779729 100644 (file)
@@ -19,6 +19,7 @@ struct Score_systems
 {
   SCM systems_;
   SCM header_;
+  SCM texts_;
 
   Score_systems () ;
   void gc_mark ();
index 1413c804732f3be31a838afda6cc52344e49a134..fac59eee38d43ee6ea0345e6d060d112f0cad07d 100644 (file)
@@ -26,6 +26,7 @@ public:
   String user_key_;
   Link_array<Output_def> defs_;
   SCM header_;
+  SCM texts_;
   bool error_found_;
   
   SCM get_music () const;
@@ -40,6 +41,6 @@ DECLARE_UNSMOB (Score, score);
 
 SCM ly_run_translator (SCM, SCM, SCM);
 SCM ly_render_output (SCM, SCM);
-void default_rendering (SCM, SCM, SCM, SCM, SCM, SCM);
+void default_rendering (SCM, SCM, SCM, SCM, SCM, SCM, SCM);
 
 #endif /* SCORE_HH */
index 0914fee3290361f3fb188d41e1f79c4ba5194da4..d17fc7102629f05f068b7730df9e9702e378d583 100644 (file)
@@ -107,9 +107,10 @@ SCM (* scm_parse_error_handler) (void *);
 %x figures
 %x incl
 %x lyrics
+%x lyric_markup
 %x lyric_quote
 %x longcomment
-%x markup 
+%x markup
 %x notes
 %x quote
 %x renameinput
@@ -149,7 +150,7 @@ HYPHEN              --
        // windows-suck-suck-suck
 }
 
-<INITIAL,chords,incl,markup,lyrics,notes,figures>{
+<INITIAL,chords,figures,incl,lyrics,lyric_markup,markup,notes>{
   "%{" {
        yy_push_state (longcomment);
   }
@@ -274,7 +275,7 @@ HYPHEN              --
 <chords,notes,figures>R                {
        return MULTI_MEASURE_REST;
 }
-<INITIAL,markup,chords,lyrics,notes,figures>#  { //embedded scm
+<INITIAL,chords,figures,lyrics,lyric_markup,markup,notes>#     { //embedded scm
        int n = 0;
        Input hi = here_input();
        hi.step_forward ();
@@ -474,7 +475,7 @@ HYPHEN              --
 }
 
 
-<markup>{
+<markup,lyric_markup>{
        \" {
                start_quote ();
        }
@@ -651,6 +652,12 @@ Lily_lexer::push_markup_state ()
        yy_push_state (markup);
 }
 
+void
+Lily_lexer::push_lyric_markup_state ()
+{
+       yy_push_state (lyric_markup);
+}
+
 void
 Lily_lexer::push_note_state (SCM tab)
 {
@@ -681,15 +688,16 @@ Lily_lexer::scan_escaped_word (String str)
 
 //     SCM sym = ly_symbol2scm (str.to_str0 ());
 
-       int l = lookup_keyword (str);
-       if (l != -1) {
-               return l;
-       }
+       int i = lookup_keyword (str);
+       if (i == MARKUP && is_lyric_state ())
+               return LYRIC_MARKUP;
+       if (i != -1)
+               return i;
+
        SCM sid = lookup_identifier (str);
        if (is_music_function (sid))
        {
                yylval.scm = get_music_function_transform (sid);
-               
                return music_function_type (yylval.scm);
        }
 
index d50aa564ad6163a1e1c910fb6912d76d7845b3c9..e85f258a7ce40289d66344007e41596009d8cd78 100644 (file)
@@ -205,16 +205,16 @@ LY_DEFINE (ly_parser_print_score, "ly:parser-print-score",
   SCM paper = get_paper (parser)->self_scm ();
   for (int i = 0; i < score->defs_.size (); i++)
     default_rendering (score->get_music (), score->defs_[i]->self_scm (),
-                      paper,
-                      header, os,
-                      key->self_scm ());
+                      paper, header, score->texts_,
+                      os, key->self_scm ());
 
   if (score->defs_.is_empty ())
     {
       Output_def *layout = get_layout (parser);
       default_rendering (score->get_music(), layout->self_scm (),
                         get_paper (parser)->self_scm (),
-                        header, os, key->self_scm ());
+                        header, score->texts_,
+                        os, key->self_scm ());
       scm_gc_unprotect_object (layout->self_scm ());
     }
 
index c2b4b34fdc661e25274e33a8fb84f8dae2fb1d54..c2ad1bf24f581903ea50b867f1d085410fa295e5 100644 (file)
@@ -12,6 +12,7 @@
 #include "output-def.hh"
 #include "paper-score.hh"
 #include "paper-system.hh"
+#include "text-item.hh"
 #include "warn.hh"
 
 #include "ly-smobs.icc"
@@ -236,6 +237,9 @@ Paper_book::systems ()
       systems_ = scm_cons (ps->self_scm (), systems_);
       scm_gc_unprotect_object (ps->self_scm ());
     }
+
+  SCM page_properties = scm_call_1 (ly_lily_module_constant ("page-properties"),
+                                   paper_->self_scm ());
   
   int score_count = score_systems_.size ();
   for (int i = 0; i < score_count; i++)
@@ -259,6 +263,19 @@ Paper_book::systems ()
          system_list = scm_reverse (system_list);
          systems_ = scm_append (scm_list_2 (system_list, systems_));
        }
+
+      for (SCM s = score_systems_[i].texts_; s != SCM_EOL; s = scm_cdr (s))
+       {
+         SCM t = Text_interface::interpret_markup (paper_->self_scm (),
+                                                   page_properties,
+                                                   scm_car (s));
+         // FIXME: title=true?
+         Paper_system *ps = new Paper_system (*unsmob_stencil (t), true);
+         systems_ = scm_cons (ps->self_scm (), systems_);
+         scm_gc_unprotect_object (ps->self_scm ());
+         // FIXME: figure out penalty.
+         //set_system_penalty (ps, score_systems_[i].header_);
+       }
     }
   
   systems_ = scm_reverse (systems_);
@@ -299,6 +316,7 @@ Score_systems::Score_systems ()
 {
   systems_ = SCM_EOL;
   header_ = SCM_EOL;
+  texts_ = SCM_EOL;
 }
 
 void
@@ -306,5 +324,6 @@ Score_systems::gc_mark ()
 {
   scm_gc_mark (systems_);
   scm_gc_mark (header_);
+  scm_gc_mark (texts_);
 }
 
index 722f299c83cc05cd36c9aa02acd68dcec42c8bee..f358cf9991223d138faf4117a789b95f43f86c35 100644 (file)
@@ -231,32 +231,19 @@ yylex (YYSTYPE *s, YYLTYPE *l, void *v)
 
 %}
 
-%expect 3
+%expect 1
 
-/*
-  Three shift/reduce problems:
-
-2. \markup identifier.
-
-  (what? --hwn)
-
-3. \markup { }
+/* One shift/reduce problem
 
-  (what? --hwn)
-
-
-4.  \repeat
+1.  \repeat
        \repeat .. \alternative
 
-
     \repeat { \repeat .. \alternative }
 
 or
 
     \repeat { \repeat } \alternative 
-
-)
- */
+*/
 
 
 %pure_parser
@@ -294,6 +281,7 @@ or
 %token KEY
 %token LAYOUT
 %token LYRICS
+%token LYRIC_MARKUP
 %token LYRICMODE
 %token MARK
 %token MIDI
@@ -373,7 +361,7 @@ or
 %token <scm> MARKUP_HEAD_SCM0_SCM1
 %token <scm> MARKUP_HEAD_SCM0_SCM1_MARKUP2
 %token <scm> MARKUP_HEAD_SCM0_SCM1_SCM2
-%token <scm> MARKUP_IDENTIFIER MARKUP_HEAD_LIST0
+%token <scm> LYRIC_MARKUP_IDENTIFIER MARKUP_IDENTIFIER MARKUP_HEAD_LIST0
 %token <scm> MUSIC_FUNCTION
 %token <scm> MUSIC_FUNCTION_MUSIC 
 %token <scm> MUSIC_FUNCTION_MUSIC_MUSIC 
@@ -446,7 +434,9 @@ or
 %type <scm>    Generic_prefix_music_scm 
 %type <scm>    lyric_element
 %type <scm>     Alternative_music
-%type <scm>    full_markup markup_list markup_composed_list markup_braced_list markup_braced_list_body 
+%type <scm>    full_markup lyric_markup
+%type <scm>    markup_list markup_composed_list markup_braced_list markup_braced_list_body 
+%type <scm>    optional_text
 %type <scm>    markup_head_1_item markup_head_1_list markup simple_markup markup_top
 %type <scm>    mode_changing_head
 %type <scm>    mode_changing_head_with_context
@@ -502,10 +492,10 @@ toplevel_expression:
                scm_call_2 (proc, THIS->self_scm (), score->self_scm ());
                scm_gc_unprotect_object (score->self_scm ());
        }
-       | toplevel_music {
+       | toplevel_music optional_text {
                Music *music = $1;
                SCM proc = THIS->lexer_->lookup_identifier ("toplevel-music-handler");
-               scm_call_2 (proc, THIS->self_scm (), music->self_scm ());
+               scm_call_3 (proc, THIS->self_scm (), music->self_scm (), $2);
                scm_gc_unprotect_object (music->self_scm ());
        }
        | output_def {
@@ -551,6 +541,14 @@ lilypond_header:
        }
        ;
 
+optional_text:
+       /* empty */ {
+               $$ = SCM_EOL
+       }
+       | optional_text full_markup {
+               $$ = ly_snoc ($2, $1);
+       }
+       ;
 
 /*
        DECLARATIONS
@@ -673,10 +671,19 @@ book_body:
                $$->paper_ = $2;
                scm_gc_unprotect_object ($2->self_scm ());
        }
-       | book_body score_block {
+       | book_body score_block optional_text {
                Score *score = $2;
+               score->texts_ = $3;
                $$->add_score (score);
        }
+       /* let's do optional
+       | book_body full_markup {
+               if (!$$->scores_.size ())
+                       THIS->parser_error (@2, _("\\markup cannot be used before \\score."));
+               Score *score = $$->scores_.top ();
+               score->texts_ = ly_snoc ($2, score->texts_);
+       }
+       */
        | book_body lilypond_header {
                $$->header_ = $2;
        }
@@ -2254,8 +2261,7 @@ simple_element:
        ;
 
 lyric_element:
-       /* FIXME: lyric flavoured markup would be better */
-       full_markup {
+       lyric_markup {
                $$ = $1;
        }
        | LYRICS_STRING {
@@ -2423,6 +2429,18 @@ questions:
 This should be done more dynamically if possible.
 */
 
+lyric_markup:
+       LYRIC_MARKUP_IDENTIFIER {
+               $$ = $1;
+       }
+       | LYRIC_MARKUP
+               { THIS->lexer_->push_lyric_markup_state (); }
+       markup_top {
+               $$ = $3;
+               THIS->lexer_->pop_state ();
+       }
+       ;
+
 full_markup:
        MARKUP_IDENTIFIER {
                $$ = $1;
@@ -2507,6 +2525,9 @@ simple_markup:
        | MARKUP_IDENTIFIER {
                $$ = $1;
        }
+       | LYRIC_MARKUP_IDENTIFIER {
+               $$ = $1;
+       }
        | STRING_IDENTIFIER {
                $$ = $1;
        }
@@ -2631,6 +2652,8 @@ Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
                return OUTPUT_DEF_IDENTIFIER;
        } else if (Text_interface::markup_p (sid)) {
                *destination = sid;
+               if (is_lyric_state ())
+                       return LYRIC_MARKUP_IDENTIFIER;
                return MARKUP_IDENTIFIER;
        }
 
index f5b4369971ef58845a670116d4972c0ffdf84ed0..2d6dbf77871ad828fadfd0fbbecbfce7023e75c2 100644 (file)
@@ -14,9 +14,9 @@
 #include "global-context.hh"
 
 LY_DEFINE (ly_music_scorify, "ly:music-scorify",
-          2, 0, 0,
-          (SCM music, SCM parser),
-          "Return MUSIC encapsulated in SCORE.")
+          3, 0, 0,
+          (SCM music, SCM texts, SCM parser),
+          "Return MUSIC with TEXTS encapsulated in SCORE.")
 {
 #if 0
   SCM_ASSERT_TYPE (ly_c_music_p (music), music, SCM_ARG1, __FUNCTION__, "music");
@@ -24,6 +24,7 @@ LY_DEFINE (ly_music_scorify, "ly:music-scorify",
   Score *score = new Score;
 
   score->set_music (music, parser);
+  score->texts_ = texts;
 
   scm_gc_unprotect_object (score->self_scm ());
   return score->self_scm ();
index 1a3209afb343d3d2423e6eb0f07f9fffdc7343de..ed9a0aa5eeb31352594efaff8fe6d5e279ec0ecc 100644 (file)
@@ -30,6 +30,7 @@ Score::Score ()
   : Input ()
 {
   header_ = SCM_EOL;
+  texts_ = SCM_EOL;
   music_ = SCM_EOL;
   error_found_ = false;
   smobify_self ();
@@ -55,6 +56,8 @@ Score::mark_smob (SCM s)
   
   if (sc->header_)
     scm_gc_mark (sc->header_);
+  if (sc->texts_)
+    scm_gc_mark (sc->texts_);
   for (int i = sc->defs_.size (); i--;)
     scm_gc_mark (sc->defs_[i]->self_scm ());
   return sc->music_;
@@ -76,6 +79,7 @@ Score::Score (Score const &s)
   
   /* FIXME: SCM_EOL? */
   header_ = 0;
+  texts_ = 0;
 
   smobify_self ();
 
@@ -89,13 +93,17 @@ Score::Score (Score const &s)
   header_ = ly_make_anonymous_module (false);
   if (ly_c_module_p (s.header_))
     ly_module_copy (header_, s.header_);
+
+  if (s.texts_)
+    texts_ = s.texts_;
 }
 
 
 void
 default_rendering (SCM music, SCM outdef,
                   SCM book_outputdef,
-                  SCM header, SCM outname,
+                  SCM header, SCM texts,
+                  SCM outname,
                   SCM key)
 {
   SCM scaled_def = outdef;
@@ -135,6 +143,7 @@ default_rendering (SCM music, SCM outdef,
          Score_systems sc;
          sc.systems_ = systems;
          sc.header_ = header;
+         sc.texts_ = texts;
 
          paper_book->score_systems_.push (sc);
          
index 39a9ab693bfd54ee49a14f08e26ccc9e3864d6a6..786545cfad68a79f2d19facf5b4af40635a18447 100644 (file)
                             head score)))
     (ly:parser-print-score parser book)))
                
-(define-public (collect-scores-for-book  parser score)
+(define-public (collect-scores-for-book parser score)
   (ly:parser-define
    parser 'toplevel-scores
    (cons score (ly:parser-lookup parser 'toplevel-scores))))
     
-(define-public (collect-music-for-book parser music)
-  (collect-scores-for-book parser (ly:music-scorify music parser)))
+(define-public (collect-music-for-book parser music texts)
+  (collect-scores-for-book parser (ly:music-scorify music texts parser)))
 
 
   
index 69135d207a991d91ac93687b3e1ce60ce9d747ca..3b5eb11fcdbdf453578fe75f51855304ee05928e 100644 (file)
@@ -355,7 +355,7 @@ eg: ((italic) (raise 4) (bold)), maps the commands on each markup argument, eg:
 (define (markup-function? x)
   (not (not (markup-command-signature x))))
 
-(define (markup-list? arg)
+(define-public (markup-list? arg)
   (define (markup-list-inner? lst)
     (or (null? lst)
         (and (markup? (car lst)) (markup-list-inner? (cdr lst)))))
index 559a08012e031fba7121b10bc30e3eeccd018425..495577ead10237be92dc05c5ec28c89e631d8745 100644 (file)
@@ -532,9 +532,9 @@ PREAMBLE_LY = r'''%%%% Generated by %(program_name)s
 %%%% Options: [%(option_string)s]
 
 #(set! toplevel-score-handler ly:parser-print-score)
-#(set! toplevel-music-handler (lambda (p m)
+#(set! toplevel-music-handler (lambda (p m t)
                               (ly:parser-print-score
-                               p (ly:music-scorify m p))))
+                               p (ly:music-scorify m p))))
 
 #(define version-seen? #t)
 %(preamble_string)s