From: Jan Nieuwenhuizen Date: Tue, 8 Mar 2005 10:48:51 +0000 (+0000) Subject: * Documentation/topdocs/NEWS.tely (Top): Mention markup text feature. X-Git-Tag: release/2.5.15~47 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=c93997ee6226dae036e411b39e5af873b8726293;p=lilypond.git * Documentation/topdocs/NEWS.tely (Top): Mention markup text feature. * scripts/lilypond-book.py (PREAMBLE_LY): toplevel-music-handler: Add texts parameter. --- diff --git a/ChangeLog b/ChangeLog index 740b8d3fd2..51b632aa41 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,29 @@ +2005-03-08 Jan Nieuwenhuizen + + * 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 + * 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. diff --git a/Documentation/topdocs/NEWS.tely b/Documentation/topdocs/NEWS.tely index eb0132c41e..81faaf2bf4 100644 --- a/Documentation/topdocs/NEWS.tely +++ b/Documentation/topdocs/NEWS.tely @@ -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. diff --git a/lily/book.cc b/lily/book.cc index 04380f615f..114fb04b32 100644 --- a/lily/book.cc +++ b/lily/book.cc @@ -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); } } diff --git a/lily/include/lily-lexer.hh b/lily/include/lily-lexer.hh index fbc06b6367..b5b4321969 100644 --- a/lily/include/lily-lexer.hh +++ b/lily/include/lily-lexer.hh @@ -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 (); diff --git a/lily/include/music.hh b/lily/include/music.hh index 12db78facd..6a0794092f 100644 --- a/lily/include/music.hh +++ b/lily/include/music.hh @@ -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 */ diff --git a/lily/include/paper-book.hh b/lily/include/paper-book.hh index ef9b540f01..4ee2911cee 100644 --- a/lily/include/paper-book.hh +++ b/lily/include/paper-book.hh @@ -19,6 +19,7 @@ struct Score_systems { SCM systems_; SCM header_; + SCM texts_; Score_systems () ; void gc_mark (); diff --git a/lily/include/score.hh b/lily/include/score.hh index 1413c80473..fac59eee38 100644 --- a/lily/include/score.hh +++ b/lily/include/score.hh @@ -26,6 +26,7 @@ public: String user_key_; Link_array 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 */ diff --git a/lily/lexer.ll b/lily/lexer.ll index 0914fee329..d17fc71026 100644 --- a/lily/lexer.ll +++ b/lily/lexer.ll @@ -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 } -{ +{ "%{" { yy_push_state (longcomment); } @@ -274,7 +275,7 @@ HYPHEN -- R { return MULTI_MEASURE_REST; } -# { //embedded scm +# { //embedded scm int n = 0; Input hi = here_input(); hi.step_forward (); @@ -474,7 +475,7 @@ HYPHEN -- } -{ +{ \" { 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); } diff --git a/lily/lily-parser-scheme.cc b/lily/lily-parser-scheme.cc index d50aa564ad..e85f258a7c 100644 --- a/lily/lily-parser-scheme.cc +++ b/lily/lily-parser-scheme.cc @@ -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 ()); } diff --git a/lily/paper-book.cc b/lily/paper-book.cc index c2b4b34fdc..c2ad1bf24f 100644 --- a/lily/paper-book.cc +++ b/lily/paper-book.cc @@ -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_); } diff --git a/lily/parser.yy b/lily/parser.yy index 722f299c83..f358cf9991 100644 --- a/lily/parser.yy +++ b/lily/parser.yy @@ -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 MARKUP_HEAD_SCM0_SCM1 %token MARKUP_HEAD_SCM0_SCM1_MARKUP2 %token MARKUP_HEAD_SCM0_SCM1_SCM2 -%token MARKUP_IDENTIFIER MARKUP_HEAD_LIST0 +%token LYRIC_MARKUP_IDENTIFIER MARKUP_IDENTIFIER MARKUP_HEAD_LIST0 %token MUSIC_FUNCTION %token MUSIC_FUNCTION_MUSIC %token MUSIC_FUNCTION_MUSIC_MUSIC @@ -446,7 +434,9 @@ or %type Generic_prefix_music_scm %type lyric_element %type Alternative_music -%type full_markup markup_list markup_composed_list markup_braced_list markup_braced_list_body +%type full_markup lyric_markup +%type markup_list markup_composed_list markup_braced_list markup_braced_list_body +%type optional_text %type markup_head_1_item markup_head_1_list markup simple_markup markup_top %type mode_changing_head %type 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; } diff --git a/lily/score-scheme.cc b/lily/score-scheme.cc index f5b4369971..2d6dbf7787 100644 --- a/lily/score-scheme.cc +++ b/lily/score-scheme.cc @@ -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 (); diff --git a/lily/score.cc b/lily/score.cc index 1a3209afb3..ed9a0aa5ee 100644 --- a/lily/score.cc +++ b/lily/score.cc @@ -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); diff --git a/scm/lily-library.scm b/scm/lily-library.scm index 39a9ab693b..786545cfad 100644 --- a/scm/lily-library.scm +++ b/scm/lily-library.scm @@ -60,13 +60,13 @@ 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))) diff --git a/scm/new-markup.scm b/scm/new-markup.scm index 69135d207a..3b5eb11fcd 100644 --- a/scm/new-markup.scm +++ b/scm/new-markup.scm @@ -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))))) diff --git a/scripts/lilypond-book.py b/scripts/lilypond-book.py index 559a08012e..495577ead1 100644 --- a/scripts/lilypond-book.py +++ b/scripts/lilypond-book.py @@ -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 t p)))) #(define version-seen? #t) %(preamble_string)s