From d519250e6ba979578b1bc9406dcd70576f5652d5 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Fri, 28 May 2004 16:30:10 +0000 Subject: [PATCH] (output_def): push scope of parent_ Output_def too. --- ChangeLog | 18 +++ input/mutopia/R.Schumann/romanze-op28-2.ly | 1 + lily/book-paper-def.cc | 147 +++++++------------- lily/book.cc | 35 +++-- lily/font-select.cc | 10 +- lily/include/book-paper-def.hh | 17 +-- lily/include/book.hh | 2 +- lily/include/lily-proto.hh | 2 +- lily/include/ly-module.hh | 4 +- lily/include/my-lily-parser.hh | 2 +- lily/include/output-def.hh | 6 + lily/include/page.hh | 2 +- lily/include/paper-book.hh | 9 +- lily/include/score.hh | 2 +- lily/ly-module.cc | 30 ++-- lily/my-lily-parser.cc | 20 ++- lily/{music-output-def.cc => output-def.cc} | 30 +++- lily/page.cc | 12 +- lily/paper-book.cc | 86 ++++++------ lily/paper-line.cc | 2 + lily/paper-outputter.cc | 2 +- lily/parser.yy | 24 ++-- lily/score.cc | 75 +++++++--- ly/book-paper-defaults.ly | 100 +++++-------- ly/declarations-init.ly | 54 ++----- ly/engraver-init.ly | 5 +- scm/lily.scm | 13 +- scm/output-tex.scm | 7 +- scm/page-layout.scm | 69 +++++++++ scm/paper.scm | 43 +++--- 30 files changed, 447 insertions(+), 382 deletions(-) rename lily/{music-output-def.cc => output-def.cc} (88%) diff --git a/ChangeLog b/ChangeLog index 2888b0c575..440a0742ce 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,9 +1,27 @@ +2004-05-28 Han-Wen Nienhuys + + * lily/parser.yy (output_def): push scope of parent_ Output_def + too. + 2004-05-28 Jan Nieuwenhuizen * scm/output-gnome.scm: Update info. 2004-05-28 Han-Wen Nienhuys + * lily/book-paper-def.cc: collapse Book_output_def to Output_def. + + * scm/lily.scm (ly:modules-lookup): handle empty list, and more + than 1 module. + + * lily/include/ly-module.hh (ly_use_module): rename is_module to + ly_c_module_p. + + * scm/page-layout.scm (default-book-title): move Scheme titling + functions to here. + + * lily/parser.yy (book_paper_block): remove scope too. + * ly/engraver-init.ly (EasyNotation): remove OrchestralScoreContext * lily/rest.cc: add direction to rest properties. diff --git a/input/mutopia/R.Schumann/romanze-op28-2.ly b/input/mutopia/R.Schumann/romanze-op28-2.ly index e6b133d3d8..f9db7969a2 100644 --- a/input/mutopia/R.Schumann/romanze-op28-2.ly +++ b/input/mutopia/R.Schumann/romanze-op28-2.ly @@ -4,6 +4,7 @@ \include "deutsch.ly" #(set-global-staff-size 16) + \version "2.3.2" \header { diff --git a/lily/book-paper-def.cc b/lily/book-paper-def.cc index 5dae02d31b..517887939e 100644 --- a/lily/book-paper-def.cc +++ b/lily/book-paper-def.cc @@ -1,5 +1,5 @@ /* - book-paper-def.cc -- implement Book_output_def + book-paper-def.cc -- implement Output_def source file of the GNU LilyPond music typesetter @@ -10,49 +10,43 @@ #include "ly-module.hh" #include "output-def.hh" #include "dimensions.hh" -#include "book-paper-def.hh" #include "ly-smobs.icc" #include "font-metric.hh" #include "virtual-font-metric.hh" #include "scaled-font-metric.hh" -Book_output_def::Book_output_def () -{ - output_scale_ = 1.0; - scaled_fonts_ = SCM_EOL; - scaled_fonts_ = scm_c_make_hash_table (11); -} - Real -Book_output_def::output_scale () const -{ - return output_scale_; -} - -Book_output_def::Book_output_def (Book_output_def const & src) - : Output_def (src) +output_scale (Output_def * od) { - output_scale_ = src.output_scale_; - scaled_fonts_ = SCM_EOL; - scaled_fonts_ = scm_c_make_hash_table (11); // copying is not done with live defs. hopefully. + return ly_scm2double (od->lookup_variable (ly_symbol2scm ("outputscale"))); } -void -Book_output_def::derived_mark () -{ - scm_gc_mark (scaled_fonts_); -} - - - +/* + TODO: should add nesting for Output_def here too. + */ Font_metric* -Book_output_def::find_scaled_font (Font_metric *f, Real m, SCM input_enc_name) +find_scaled_font (Output_def * mod, + Font_metric *f, Real m, SCM input_enc_name) { + if (mod->parent_) + { + return find_scaled_font (mod->parent_, + f, m, input_enc_name); + } + Real lookup_mag = m; if (!dynamic_cast (f)) - lookup_mag /= output_scale (); + lookup_mag /= output_scale (mod); + + SCM font_table = mod->lookup_variable (ly_symbol2scm ("scaled-fonts")); + if (scm_hash_table_p (font_table) != SCM_BOOL_T) + { + font_table = scm_c_make_hash_table (11); + mod->set_variable (ly_symbol2scm ("scaled-fonts"), font_table); + } + - SCM sizes = scm_hashq_ref (scaled_fonts_, f->self_scm (), SCM_BOOL_F); + SCM sizes = scm_hashq_ref (font_table, f->self_scm (), SCM_BOOL_F); if (sizes != SCM_BOOL_F) { SCM met = scm_assoc (scm_make_real (lookup_mag), sizes); @@ -83,7 +77,8 @@ Book_output_def::find_scaled_font (Font_metric *f, Real m, SCM input_enc_name) SCM *t = &lst; for (SCM s = vf->get_font_list (); ly_c_pair_p (s); s = ly_cdr (s)) { - Font_metric *scaled = find_scaled_font (unsmob_metrics (ly_car (s)), + Font_metric *scaled = find_scaled_font (mod, + unsmob_metrics (ly_car (s)), m, input_enc_name); *t = scm_cons (scaled->self_scm (), SCM_EOL); t = SCM_CDRLOC (*t); @@ -96,7 +91,7 @@ Book_output_def::find_scaled_font (Font_metric *f, Real m, SCM input_enc_name) { if (!ly_c_symbol_p (input_enc_name)) { - SCM var = ly_module_lookup (scope_, ly_symbol2scm ("inputencoding")); + SCM var = ly_module_lookup (mod->scope_, ly_symbol2scm ("inputencoding")); if (var != SCM_BOOL_F) input_enc_name = scm_variable_ref (var); if (!ly_c_symbol_p (input_enc_name)) @@ -109,43 +104,24 @@ Book_output_def::find_scaled_font (Font_metric *f, Real m, SCM input_enc_name) sizes = scm_acons (scm_make_real (lookup_mag), val, sizes); scm_gc_unprotect_object (val); - scm_hashq_set_x (scaled_fonts_, f->self_scm (), sizes); + scm_hashq_set_x (font_table, f->self_scm (), sizes); return unsmob_metrics (val); } +/* + TODO: this is a nasty interface. During formatting, + the Output_def should be scaled to the output_scale_ + specified in the toplevel Output_def. + */ Output_def* -Book_output_def::scale_paper (Output_def *pd) const +scale_output_def (Output_def * o, Real amount) { SCM proc = ly_scheme_function ("scale-paper"); - SCM new_pap = scm_call_2 (proc, pd->self_scm (), self_scm ()); - + SCM new_pap = scm_call_2 (proc, o->self_scm (), + scm_double2num (amount)); scm_gc_protect_object (new_pap); - Output_def *p = unsmob_output_def (new_pap); - - p->parent_ = (Output_def*) this; - return p; -} - -LY_DEFINE (ly_make_bookpaper, "ly:make-bookpaper", - 1, 0, 0, - (SCM size), - "Make a paperbook, for staff space SIZE, which is in INTERNAL_UNIT.") -{ - Book_output_def *bp = new Book_output_def ; - - SCM_ASSERT_TYPE (ly_c_number_p (size), size, - SCM_ARG1, __FUNCTION__, "number"); - - bp->output_scale_ = (ly_scm2double (size)) MM; - - return scm_gc_unprotect_object (bp->self_scm ()); -} - -Book_output_def * -unsmob_book_output_def (SCM bp) -{ - return dynamic_cast (unsmob_output_def (bp)); + return unsmob_output_def (new_pap); } LY_DEFINE (ly_bookpaper_fonts, "ly:bookpaper-fonts", @@ -153,46 +129,29 @@ LY_DEFINE (ly_bookpaper_fonts, "ly:bookpaper-fonts", (SCM bp), "Return fonts scaled up BP") { - Book_output_def *b = unsmob_book_output_def (bp); + Output_def *b = unsmob_output_def (bp); + + SCM font_table = b->lookup_variable (ly_symbol2scm ("scaled-fonts")); SCM_ASSERT_TYPE (b, bp, SCM_ARG1, __FUNCTION__, "bookpaper"); - SCM func = ly_scheme_function ("hash-table->alist"); - SCM ell = SCM_EOL; - for (SCM s = scm_call_1 (func, b->scaled_fonts_); ly_c_pair_p (s); - s = ly_cdr (s)) + if (scm_hash_table_p (font_table) == SCM_BOOL_T) { - SCM entry = ly_car (s); - for (SCM t = ly_cdr (entry); ly_c_pair_p (t); t = ly_cdr (t)) - { - Font_metric *fm = unsmob_metrics (ly_cdar (t)); + SCM func = ly_scheme_function ("hash-table->alist"); - if (dynamic_cast (fm)) - ell = scm_cons (fm->self_scm (), ell); + for (SCM s = scm_call_1 (func, font_table); ly_c_pair_p (s); + s = ly_cdr (s)) + { + SCM entry = ly_car (s); + for (SCM t = ly_cdr (entry); ly_c_pair_p (t); t = ly_cdr (t)) + { + Font_metric *fm = unsmob_metrics (ly_cdar (t)); + + if (dynamic_cast (fm)) + ell = scm_cons (fm->self_scm (), ell); + } } } return ell; } - - -LY_DEFINE (ly_bookpaper_outputscale, "ly:bookpaper-outputscale", - 1, 0, 0, - (SCM bp), - "Get outputscale for BP.") -{ - Book_output_def *b = unsmob_book_output_def (bp); - SCM_ASSERT_TYPE (b, bp, SCM_ARG1, __FUNCTION__, "bookpaper"); - return scm_make_real (b->output_scale_); -} - - - -LY_DEFINE (ly_book_output_def_scope, "ly:bookpaper-def-scope", - 1, 0,0, (SCM def), - "Get the variable scope inside @var{def}.") -{ - Book_output_def *op = unsmob_book_output_def (def); - SCM_ASSERT_TYPE (op, def, SCM_ARG1, __FUNCTION__, "Output definition"); - return op->scope_; -} diff --git a/lily/book.cc b/lily/book.cc index c970a964fe..50fee8f48e 100644 --- a/lily/book.cc +++ b/lily/book.cc @@ -8,7 +8,7 @@ #include -#include "book-paper-def.hh" + #include "ly-smobs.icc" #include "stencil.hh" #include "book.hh" @@ -65,25 +65,32 @@ void Book::process (String outname, Output_def *default_def, SCM header) { Paper_book *paper_book = new Paper_book (); - paper_book->bookpaper_ = bookpaper_; + + + Real scale = ly_scm2double (bookpaper_->c_variable ("outputscale")); + + Output_def * scaled_bookdef = scale_output_def (bookpaper_, scale); + + paper_book->bookpaper_ = scaled_bookdef; int score_count = scores_.size (); for (int i = 0; i < score_count; i++) { - Output_def *paper = 0; SCM systems = scores_[i]->book_rendering (outname, - bookpaper_, - default_def, &paper); + paper_book->bookpaper_, + default_def); if (systems != SCM_UNDEFINED) { Score_lines sc; - sc.paper_ = paper; sc.lines_ = systems; sc.header_ = header; paper_book->score_lines_.push (sc); } } + paper_book->output (outname); + + scm_gc_unprotect_object (paper_book->bookpaper_->self_scm ()); scm_gc_unprotect_object (paper_book->self_scm ()); } @@ -92,19 +99,22 @@ SCM Book::to_stencil (Output_def *default_def, SCM header) { Paper_book *paper_book = new Paper_book (); - paper_book->bookpaper_ = bookpaper_; + Real scale = ly_scm2double (bookpaper_->c_variable ("outputscale")); + + Output_def * scaled_bookdef = scale_output_def (bookpaper_, scale); + + paper_book->bookpaper_ = scaled_bookdef; + int score_count = scores_.size (); for (int i = 0; i < score_count; i++) { - Output_def *paper = 0; SCM systems = scores_[i]->book_rendering ("", bookpaper_, - default_def, - &paper); + default_def); + if (systems != SCM_UNDEFINED) { Score_lines sc; - sc.paper_ = paper; sc.lines_ = systems; sc.header_ =header; @@ -121,5 +131,8 @@ Book::to_stencil (Output_def *default_def, SCM header) progress_indication (_f ("paper output to `%s'...", "")); return (unsmob_page (ly_car (pages)))->to_stencil ().smobbed_copy (); } + + scm_gc_unprotect_object (paper_book->bookpaper_->self_scm ()); + return SCM_EOL; } diff --git a/lily/font-select.cc b/lily/font-select.cc index 45a5b9e749..ef6ab87107 100644 --- a/lily/font-select.cc +++ b/lily/font-select.cc @@ -9,7 +9,7 @@ #include -#include "book-paper-def.hh" + #include "all-font-metrics.hh" #include "output-def.hh" #include "font-interface.hh" @@ -84,9 +84,8 @@ get_font_by_design_size (Output_def* paper, Real requested, } Font_metric *fm = unsmob_metrics (scm_force (SCM_VECTOR_REF (font_vector, i))); - return dynamic_cast (paper->parent_) - // ugh. - ->find_scaled_font (fm, requested / size, input_encoding_name); + return + find_scaled_font (paper, fm, requested / size, input_encoding_name); } @@ -131,8 +130,7 @@ select_encoded_font (Output_def *paper, SCM chain, SCM encoding_name) Font_metric * fm = all_fonts_global->find_font (ly_scm2string (name)); - return dynamic_cast (paper->parent_) - ->find_scaled_font (fm, rmag, encoding_name); + return find_scaled_font (paper, fm, rmag, encoding_name); } else if (scm_instance_p (name)) { diff --git a/lily/include/book-paper-def.hh b/lily/include/book-paper-def.hh index 2d4386b927..9ae39edb6e 100644 --- a/lily/include/book-paper-def.hh +++ b/lily/include/book-paper-def.hh @@ -1,5 +1,5 @@ /* - book-paper-def.hh -- declare Book_output_def + book-paper-def.hh -- declare Output_def source file of the GNU LilyPond music typesetter @@ -12,22 +12,15 @@ #include "lily-proto.hh" #include "output-def.hh" -class Book_output_def : public Output_def +class Output_def : public Output_def { public: - VIRTUAL_COPY_CONSTRUCTOR (Output_def, Book_output_def); - Book_output_def (Book_output_def const &); - SCM scaled_fonts_; - Real output_scale_; - Real output_scale () const; + VIRTUAL_COPY_CONSTRUCTOR (Output_def, Output_def); + Output_def (Output_def const &); - Book_output_def (); + Output_def (); virtual void derived_mark (); - Font_metric *find_scaled_font (Font_metric *f, Real m, SCM input_enc_name); - Output_def *scale_paper (Output_def *pd) const; }; -Book_output_def *unsmob_book_output_def (SCM bp); - #endif /* BOOK_PAPER_DEF_HH */ diff --git a/lily/include/book.hh b/lily/include/book.hh index 0c5e46863b..f3255ed8f6 100644 --- a/lily/include/book.hh +++ b/lily/include/book.hh @@ -20,7 +20,7 @@ class Book : public Input public: SCM header_; - Book_output_def *bookpaper_; + Output_def *bookpaper_; Link_array scores_; Book (); diff --git a/lily/include/lily-proto.hh b/lily/include/lily-proto.hh index b1fa3c44aa..9988d989c1 100644 --- a/lily/include/lily-proto.hh +++ b/lily/include/lily-proto.hh @@ -37,7 +37,7 @@ class Beaming_info_list; class Bezier; class Bezier_bow; class Book; -class Book_output_def; +class Output_def; class Break_algorithm; class Change_iterator; class Change_translator; diff --git a/lily/include/ly-module.hh b/lily/include/ly-module.hh index 2619ccfec5..89d13eb8a6 100644 --- a/lily/include/ly-module.hh +++ b/lily/include/ly-module.hh @@ -16,10 +16,10 @@ SCM ly_make_anonymous_module (bool safe); void ly_import_module (SCM dest, SCM src); SCM ly_module_to_alist (SCM mod); SCM ly_module_lookup (SCM module, SCM sym); -SCM ly_modules_lookup (SCM modules, SCM sym); +SCM ly_modules_lookup (SCM modules, SCM sym, SCM); SCM ly_module_symbols (SCM mod); void ly_reexport_module (SCM mod); -inline bool is_module (SCM x) { return SCM_MODULEP(x); } +inline bool ly_c_module_p (SCM x) { return SCM_MODULEP(x); } void ly_clear_anonymous_modules (); SCM ly_use_module (SCM mod, SCM used); diff --git a/lily/include/my-lily-parser.hh b/lily/include/my-lily-parser.hh index 0f97dabf0f..1d98879da9 100644 --- a/lily/include/my-lily-parser.hh +++ b/lily/include/my-lily-parser.hh @@ -81,6 +81,6 @@ SCM ly_parser_scorify (SCM, SCM); Output_def *get_paper (My_lily_parser *parser); Output_def *get_midi (My_lily_parser *parser); -Book_output_def *get_bookpaper (My_lily_parser *parser); +Output_def *get_bookpaper (My_lily_parser *parser); #endif /* MY_LILY_PARSER_HH */ diff --git a/lily/include/output-def.hh b/lily/include/output-def.hh index e18326f845..8b5ab341ea 100644 --- a/lily/include/output-def.hh +++ b/lily/include/output-def.hh @@ -56,4 +56,10 @@ Font_metric *select_font (Output_def *paper, SCM chain); DECLARE_UNSMOB (Output_def, output_def); + +Font_metric *find_scaled_font (Output_def * od, + Font_metric *f, Real m, SCM input_enc_name); +Output_def *scale_output_def (Output_def *def, Real scale); +Real output_scale (Output_def*); + #endif /* MUSIC_OUTPUT_DEF_HH */ diff --git a/lily/include/page.hh b/lily/include/page.hh index 07d76d909c..338bec2941 100644 --- a/lily/include/page.hh +++ b/lily/include/page.hh @@ -19,7 +19,7 @@ class Page public: Output_def *paper_; // todo: make private? - Book_output_def * bookpaper () const; + Output_def * bookpaper () const; static int page_count_; static Real MIN_COVERAGE_; int number_; diff --git a/lily/include/paper-book.hh b/lily/include/paper-book.hh index 2e0d3863b3..4733dc2ef4 100644 --- a/lily/include/paper-book.hh +++ b/lily/include/paper-book.hh @@ -17,12 +17,9 @@ struct Score_lines { SCM lines_; SCM header_; - SCM global_header_; - Output_def *paper_; Score_lines () ; void gc_mark (); - SCM scopes (); }; class Paper_book @@ -32,15 +29,15 @@ class Paper_book Real height_; SCM copyright_; SCM tagline_; + SCM global_header_; public: Array score_lines_; - Book_output_def *bookpaper_; - + Output_def *bookpaper_; + Paper_book (); SCM lines (); SCM pages (); - SCM scopes (int); Stencil title (int); void classic_output (String); void init (); diff --git a/lily/include/score.hh b/lily/include/score.hh index d9a81f79e8..0f015a0139 100644 --- a/lily/include/score.hh +++ b/lily/include/score.hh @@ -27,7 +27,7 @@ public: Score (); Score (Score const&); - SCM book_rendering (String, Book_output_def*, Output_def*, Output_def**); + SCM book_rendering (String, Output_def*, Output_def*); }; DECLARE_UNSMOB (Score, score); diff --git a/lily/ly-module.cc b/lily/ly-module.cc index 754e144bfa..9c30b6ed96 100644 --- a/lily/ly-module.cc +++ b/lily/ly-module.cc @@ -104,12 +104,11 @@ entry_to_alist (void *closure, SCM key, SCM val, SCM result) return scm_cons (scm_cons (key, scm_variable_ref (val)), result); } -SCM -ly_module_to_alist (SCM mod) +LY_DEFINE(ly_module_to_alist, "ly:module->alist", + 1,0,0, (SCM mod), + "Dump the contents of module @var{mod} as an alist.") { SCM_VALIDATE_MODULE (1, mod); - - SCM obarr= SCM_MODULE_OBARRAY (mod); return scm_internal_hash_fold ((Hash_cl_func) &entry_to_alist, NULL, SCM_EOL, obarr); @@ -130,18 +129,25 @@ ly_module_lookup (SCM module, SCM sym) Lookup SYM in a list of modules, which do not have to be related. Return the first instance. */ -SCM -ly_modules_lookup (SCM modules, SCM sym) +LY_DEFINE(ly_modules_lookup, "ly:modules-lookup", + 2, 1, 0, + (SCM modules, SCM sym, SCM def), + "Lookup @var{sym} in the list @var{modules}, returning the " + "first occurence. If not found, return @var{default}, or @code{#f}.") { - for (SCM s = ly_car (modules); SCM_MODULEP (s); s = ly_cdr (s)) + for (SCM s = modules; SCM_MODULEP (s); s = ly_cdr (s)) { - SCM v = scm_sym2var (sym, scm_module_lookup_closure (s), SCM_UNDEFINED); - if (v != SCM_UNDEFINED) - return v; + SCM mod = ly_car (s); + SCM v = scm_sym2var (sym, scm_module_lookup_closure (mod), SCM_UNDEFINED); + if (SCM_VARIABLEP(v) && SCM_VARIABLE_REF(v) != SCM_UNDEFINED) + return SCM_VARIABLE_REF(v); } - return SCM_UNDEFINED; -} + if (def != SCM_UNDEFINED) + return def; + else + return SCM_BOOL_F; +} void ly_export (SCM module, SCM namelist) diff --git a/lily/my-lily-parser.cc b/lily/my-lily-parser.cc index c6bdec50c3..bca0f45592 100644 --- a/lily/my-lily-parser.cc +++ b/lily/my-lily-parser.cc @@ -8,7 +8,7 @@ */ #include "book.hh" -#include "book-paper-def.hh" + #include "file-name.hh" #include "file-path.hh" #include "lily-version.hh" @@ -378,6 +378,8 @@ get_paper (My_lily_parser *parser) Output_def *paper = unsmob_output_def (id); paper = paper ? paper->clone () : new Output_def; paper->set_variable (ly_symbol2scm ("is-paper"), SCM_BOOL_T); + + paper->parent_ =unsmob_output_def (parser->lexer_->lookup_identifier ("$defaultbookpaper")); return paper; } @@ -393,13 +395,13 @@ get_midi (My_lily_parser *parser) } -Book_output_def* +Output_def* get_bookpaper (My_lily_parser *parser) { SCM id = parser->lexer_->lookup_identifier ("$defaultbookpaper"); - Book_output_def *paper = unsmob_book_output_def (id); + Output_def *paper = unsmob_output_def (id); - paper = paper ? dynamic_cast (paper->clone ()) : new Book_output_def; + paper = paper ? dynamic_cast (paper->clone ()) : new Output_def; paper->set_variable (ly_symbol2scm ("is-bookpaper"), SCM_BOOL_T); return paper; } @@ -420,7 +422,7 @@ LY_DEFINE (ly_parser_print_score, "ly:parser-print-score", SCM_ASSERT_TYPE (parser, parser_smob, SCM_ARG1, __FUNCTION__, "parser"); SCM_ASSERT_TYPE (score, score_smob, SCM_ARG2, __FUNCTION__, "score"); - SCM header = is_module (score->header_) ? score->header_ + SCM header = ly_c_module_p (score->header_) ? score->header_ : parser->header_.to_SCM (); File_name outname (parser->output_basename_); @@ -430,9 +432,10 @@ LY_DEFINE (ly_parser_print_score, "ly:parser-print-score", (*c)++; SCM os = scm_makfrom0str (outname.to_string ().to_str0 ()); + SCM bookpaper = get_bookpaper (parser)->self_scm (); for (int i = 0; i < score->defs_.size (); i++) default_rendering (score->music_, score->defs_[i]->self_scm (), - get_bookpaper (parser)->self_scm (), + bookpaper, header, os); if (score->defs_.is_empty ()) @@ -453,7 +456,7 @@ LY_DEFINE (ly_parser_print_book, "ly:parser-print-book", { My_lily_parser *parser = unsmob_my_lily_parser (parser_smob); Book *book = unsmob_book (book_smob); - Book_output_def *bp = unsmob_book_output_def (parser->lexer_->lookup_identifier ("$defaultbookpaper")); + Output_def *bp = unsmob_output_def (parser->lexer_->lookup_identifier ("$defaultbookpaper")); SCM_ASSERT_TYPE (parser, parser_smob, SCM_ARG1, __FUNCTION__, "Lilypond parser"); SCM_ASSERT_TYPE (book, book_smob, SCM_ARG2, __FUNCTION__, "Book"); @@ -467,8 +470,11 @@ LY_DEFINE (ly_parser_print_book, "ly:parser-print-book", if (*c) outname.base_ += "-" + to_string (*c); (*c)++; + Output_def *paper = get_paper (parser); + book->process (outname.to_string (), paper, header); + scm_gc_unprotect_object (paper->self_scm ()); return SCM_UNDEFINED; } diff --git a/lily/music-output-def.cc b/lily/output-def.cc similarity index 88% rename from lily/music-output-def.cc rename to lily/output-def.cc index 95ca709533..0363aef752 100644 --- a/lily/music-output-def.cc +++ b/lily/output-def.cc @@ -6,7 +6,7 @@ (c) 1997--2004 Han-Wen Nienhuys */ -#include "book-paper-def.hh" + #include "context-def.hh" #include "file-path.hh" #include "global-context.hh" @@ -39,8 +39,9 @@ Output_def::Output_def (Output_def const &s) parent_ = 0; smobify_self (); + input_origin_ = s.input_origin_; scope_= ly_make_anonymous_module (false); - if (is_module (s.scope_)) + if (ly_c_module_p (s.scope_)) ly_import_module (scope_, s.scope_); } @@ -116,7 +117,7 @@ SCM Output_def::lookup_variable (SCM sym) const { SCM var = ly_module_lookup (scope_, sym); - if (SCM_VARIABLEP (var)) + if (SCM_VARIABLEP (var) && SCM_VARIABLE_REF(var) != SCM_UNDEFINED) return SCM_VARIABLE_REF (var); if (parent_) @@ -224,3 +225,26 @@ LY_DEFINE (ly_paper_def_p, "ly:paper-def?", { return ly_bool2scm (unsmob_output_def (def)); } + + + +LY_DEFINE (ly_bookpaper_outputscale, "ly:bookpaper-outputscale", + 1, 0, 0, + (SCM bp), + "Get outputscale for BP.") +{ + Output_def *b = unsmob_output_def (bp); + SCM_ASSERT_TYPE (b, bp, SCM_ARG1, __FUNCTION__, "bookpaper"); + return scm_make_real (output_scale (b)); +} + + + +LY_DEFINE (ly_make_output_def, "ly:make-output-def", + 0, 0, 0, (), + "Make a output def.") +{ + Output_def *bp = new Output_def ; + return scm_gc_unprotect_object (bp->self_scm ()); +} + diff --git a/lily/page.cc b/lily/page.cc index 104f0052f9..a3dcdb6d10 100644 --- a/lily/page.cc +++ b/lily/page.cc @@ -14,17 +14,11 @@ #include "paper-line.hh" #include "stencil.hh" #include "warn.hh" -#include "book-paper-def.hh" + int Page::page_count_ = 0; Real Page::MIN_COVERAGE_ = 0.66; -Book_output_def * -Page::bookpaper () const -{ - return dynamic_cast ( paper_->parent_); -} - Page::Page (Output_def *paper, int number) { copyright_ = SCM_EOL; @@ -76,10 +70,6 @@ Page::mark_smob (SCM smob) if (p->paper_) { scm_gc_mark (p->paper_->self_scm ()); - if (p->bookpaper ()) - { - scm_gc_mark (p->bookpaper ()->self_scm ()); - } } scm_gc_mark (p->copyright_); diff --git a/lily/paper-book.cc b/lily/paper-book.cc index b95b614c3e..0667ed1583 100644 --- a/lily/paper-book.cc +++ b/lily/paper-book.cc @@ -16,7 +16,7 @@ #include "paper-score.hh" #include "stencil.hh" #include "warn.hh" -#include "book-paper-def.hh" + // JUNKME SCM @@ -39,6 +39,8 @@ Paper_book::Paper_book () { copyright_ = SCM_EOL; tagline_ = SCM_EOL; + global_header_ = SCM_EOL; + bookpaper_ = 0; smobify_self (); } @@ -63,7 +65,7 @@ Paper_book::mark_smob (SCM smob) scm_gc_mark (b->copyright_); if (b->bookpaper_) scm_gc_mark (b->bookpaper_->self_scm ()); - + scm_gc_mark (b->global_header_); return b->tagline_; } @@ -80,6 +82,12 @@ Paper_book::print_smob (SCM smob, SCM port, scm_print_state*) return 1; } + +/* + TODO: there is too much code dup, and the interface is not + clear. FIXME. + */ + void Paper_book::output (String outname) { @@ -90,11 +98,10 @@ Paper_book::output (String outname) /* Generate all stencils to trigger font loads. */ SCM pages = this->pages (); - Output_def *paper = score_lines_[0].paper_; Paper_outputter *out = get_paper_outputter (outname); int page_count = scm_ilength (pages); - out->output_header (paper->parent_, scopes (0), page_count, false); + out->output_header (bookpaper_, global_header_, page_count, false); for (SCM s = pages; s != SCM_EOL; s = ly_cdr (s)) { @@ -108,12 +115,6 @@ Paper_book::output (String outname) progress_indication ("\n"); } -SCM -Paper_book::scopes (int i) -{ - return score_lines_[i].scopes (); -} - Stencil Paper_book::title (int i) @@ -125,16 +126,25 @@ Paper_book::title (int i) : ly_symbol2scm ("scoreTitle")); Stencil title; - SCM scopes = this->scopes (i); - SCM s = ly_modules_lookup (scopes, field); - if (s != SCM_UNDEFINED && scm_variable_bound_p (s) == SCM_BOOL_T) + + // ugh code dup + SCM scopes = SCM_EOL; + if (ly_c_module_p (global_header_)) + scopes = scm_cons (global_header_, scopes); + + if (ly_c_module_p (score_lines_[i].header_)) + scopes = scm_cons (score_lines_[i].header_, scopes); + //end ugh + + SCM s = ly_modules_lookup (scopes, field, SCM_BOOL_F); + if (s != SCM_BOOL_F) title = *unsmob_stencil (scm_call_2 (user_title, - score_lines_[0].paper_->self_scm (), - scm_variable_ref (s))); + bookpaper_->self_scm (), + s)); else title = *unsmob_stencil (scm_call_2 (i == 0 ? book_title : score_title, - score_lines_[0].paper_->self_scm (), - scopes)); + bookpaper_->self_scm (), + scopes)); if (!title.is_empty ()) title.align_to (Y_AXIS, UP); @@ -144,14 +154,22 @@ Paper_book::title (int i) void Paper_book::classic_output (String outname) { - int count = score_lines_.size (); Paper_outputter *out = get_paper_outputter (outname); - Output_def * p = score_lines_.top ().paper_; + Output_def * p = bookpaper_; while (p && p->parent_) p = p->parent_; + + // ugh code dup + SCM scopes = SCM_EOL; + if (ly_c_module_p (global_header_)) + scopes = scm_cons (global_header_, scopes); + + if (ly_c_module_p (score_lines_[0].header_)) + scopes = scm_cons (score_lines_[0].header_, scopes); + //end ugh - out->output_header (p, scopes (count - 1), 0, true); + out->output_header (p, global_header_, 0, true); SCM top_lines = score_lines_.top ().lines_; Paper_line *first = unsmob_paper_line (scm_vector_ref (top_lines, @@ -200,8 +218,11 @@ Paper_book::init () } } - Output_def *paper = score_lines_[0].paper_; - SCM scopes = this->scopes (0); + Output_def *paper = bookpaper_; + + SCM scopes = SCM_EOL; + if (ly_c_module_p (global_header_)) + scopes = scm_cons (global_header_, scopes); SCM make_tagline = paper->c_variable ("make-tagline"); tagline_ = scm_call_2 (make_tagline, paper->self_scm (), scopes); @@ -243,7 +264,8 @@ Paper_book::pages () { init (); Page::page_count_ = 0; - Output_def *paper = score_lines_[0].paper_; + + Output_def *paper = bookpaper_; Page *page = new Page (paper, 1); Real text_height = page->text_height (); @@ -347,31 +369,13 @@ LY_DEFINE (ly_ragged_page_breaks, "ly:ragged-page-breaks", Score_lines::Score_lines () { lines_ = SCM_EOL; - global_header_ = SCM_EOL; header_ = SCM_EOL; - paper_ = 0; } void Score_lines::gc_mark () { scm_gc_mark (lines_); - scm_gc_mark (global_header_); scm_gc_mark (header_); - if (paper_) - scm_gc_mark (paper_->self_scm ()); } - -SCM -Score_lines::scopes () -{ - SCM scopes = SCM_EOL; - if (header_) - scopes = scm_cons (header_, scopes); - if (SCM_MODULEP(global_header_) - && global_header_ != header_) - scopes = scm_cons (global_header_, scopes); - - return scopes; -} diff --git a/lily/paper-line.cc b/lily/paper-line.cc index d92a32370c..b4dbf3b7a1 100644 --- a/lily/paper-line.cc +++ b/lily/paper-line.cc @@ -16,6 +16,7 @@ Paper_line::Paper_line (Offset o, SCM stencils, int penalty, bool is_title) { is_title_ = is_title; + number_ = 0; penalty_ = penalty; smobify_self (); @@ -57,6 +58,7 @@ Paper_line::print_smob (SCM smob, SCM port, scm_print_state*) Paper_line *p = (Paper_line*) ly_cdr (smob); scm_puts ("#<", port); scm_puts (classname (p), port); + scm_puts (" ", port); scm_puts (to_string (p->number_).to_str0 (), port); if (p->is_title ()) scm_puts (" t", port); diff --git a/lily/paper-outputter.cc b/lily/paper-outputter.cc index 310ce23830..ec1f3f9f8d 100644 --- a/lily/paper-outputter.cc +++ b/lily/paper-outputter.cc @@ -10,7 +10,7 @@ #include #include -#include "book-paper-def.hh" + #include "array.hh" #include "dimensions.hh" #include "font-metric.hh" diff --git a/lily/parser.yy b/lily/parser.yy index 915449be0f..b9439c3e21 100644 --- a/lily/parser.yy +++ b/lily/parser.yy @@ -26,7 +26,7 @@ TODO: #include "book.hh" -#include "book-paper-def.hh" + #include "context-def.hh" #include "dimensions.hh" #include "event.hh" @@ -193,7 +193,6 @@ of the parse stack onto the heap. */ %union { Book *book; - Book_output_def *bookpaper; Output_def *outputdef; SCM scm; String *string; @@ -363,7 +362,7 @@ or %type markup markup_line markup_list markup_list_body full_markup %type book_block book_body -%type book_paper_head book_paper_block book_paper_body +%type book_paper_head book_paper_block book_paper_body %type exclamations questions dots optional_rest %type bass_mod @@ -473,15 +472,17 @@ toplevel_expression: } | output_def { SCM id = SCM_EOL; + Output_def * od = $1; + if ($1->c_variable ("is-paper") == SCM_BOOL_T) id = ly_symbol2scm ("$defaultpaper"); else if ($1->c_variable ("is-midi") == SCM_BOOL_T) id = ly_symbol2scm ("$defaultmidi"); - else if ($1->c_variable ("is-book-paper") == SCM_BOOL_T) + else if ($1->c_variable ("is-bookpaper") == SCM_BOOL_T) id = ly_symbol2scm ("$defaultbookpaper"); - THIS->lexer_->set_identifier (id, $1->self_scm ()); - scm_gc_unprotect_object ($1->self_scm ()); + THIS->lexer_->set_identifier (id, od->self_scm ()); + scm_gc_unprotect_object (od->self_scm ()); } | book_paper_block { THIS->lexer_->set_identifier (ly_symbol2scm ("$defaultbookpaper"), $1->self_scm ()); @@ -620,11 +621,13 @@ context_def_spec_body: book_paper_block: book_paper_body '}' { $$ = $1; + THIS->lexer_->remove_scope (); } ; book_paper_head: BOOKPAPER '{' { $$ = get_bookpaper (THIS); + $$->input_origin_ = THIS->here_input (); THIS->lexer_->add_scope ($$->scope_); } ; @@ -653,7 +656,7 @@ book_body: { $$ = new Book; $$->set_spot (THIS->here_input ()); - $$->bookpaper_ = dynamic_cast (unsmob_book_output_def (THIS->lexer_->lookup_identifier ("$defaultbookpaper"))->clone ()); + $$->bookpaper_ = dynamic_cast (unsmob_output_def (THIS->lexer_->lookup_identifier ("$defaultbookpaper"))->clone ()); scm_gc_unprotect_object ($$->bookpaper_->self_scm ()); } | book_body book_paper_block { @@ -730,6 +733,9 @@ score_body: output_def: music_output_def_body '}' { $$ = $1; + if ($1->parent_) + THIS->lexer_->remove_scope (); + THIS->lexer_->remove_scope (); THIS->lexer_->pop_state (); } @@ -744,6 +750,8 @@ music_output_def_head: | PAPER { Output_def* p = get_paper (THIS); + if (p->parent_) + THIS->lexer_->add_scope (p->parent_->scope_); THIS->lexer_->add_scope (p->scope_); $$ = p; @@ -754,7 +762,7 @@ music_output_def_head: music_output_def_body: music_output_def_head '{' { $$ = $1; - $$->input_origin_. set_spot (THIS->here_input ()); + $$->input_origin_.set_spot (THIS->here_input ()); THIS->lexer_->push_initial_state (); } | music_output_def_head '{' MUSIC_OUTPUT_DEF_IDENTIFIER { diff --git a/lily/score.cc b/lily/score.cc index aa66207b9d..fad7635d4f 100644 --- a/lily/score.cc +++ b/lily/score.cc @@ -9,7 +9,7 @@ #include #include "book.hh" -#include "book-paper-def.hh" + #include "cpu-timer.hh" #include "global-context.hh" #include "ly-module.hh" @@ -88,7 +88,7 @@ Score::Score (Score const &s) defs_.push (s.defs_[i]->clone ()); header_ = ly_make_anonymous_module (false); - if (is_module (s.header_)) + if (ly_c_module_p (s.header_)) ly_import_module (header_, s.header_); } @@ -160,12 +160,29 @@ default_rendering (SCM music, SCM outdef, SCM book_outputdef, SCM header, SCM outname) { - Book_output_def *bpd = unsmob_book_output_def (book_outputdef); - if (bpd && unsmob_output_def (outdef)) - /* FIXME: memory leak */ - outdef = bpd->scale_paper (unsmob_output_def (outdef))->self_scm (); + SCM scaled_def = outdef; + SCM scaled_bookdef = book_outputdef; + + Output_def *bpd = unsmob_output_def (book_outputdef); + + /* + ugh. + */ + if (bpd->c_variable ("is-bookpaper") == SCM_BOOL_T) + { + Real scale = ly_scm2double (bpd->c_variable ("outputscale")); + + Output_def * def = scale_output_def (unsmob_output_def (outdef), scale); + scaled_def = def->self_scm (); + + scaled_bookdef = scale_output_def (bpd, scale)->self_scm (); + unsmob_output_def (scaled_def)->parent_ = unsmob_output_def (scaled_bookdef); + + scm_gc_unprotect_object (scaled_bookdef); + scm_gc_unprotect_object (scaled_def); + } - SCM context = ly_run_translator (music, outdef); + SCM context = ly_run_translator (music, scaled_def); if (Global_context *g = dynamic_cast (unsmob_context (context))) @@ -175,10 +192,10 @@ default_rendering (SCM music, SCM outdef, if (systems != SCM_UNDEFINED) { Paper_book *paper_book = new Paper_book (); - Paper_score *ps = dynamic_cast (output); + paper_book->bookpaper_ = unsmob_output_def (scaled_bookdef); + Score_lines sc; - sc.paper_ = ps->paper_; sc.lines_ = systems; sc.header_ = header; @@ -189,43 +206,59 @@ default_rendering (SCM music, SCM outdef, } delete output; } + + scm_remember_upto_here_1 (scaled_def); + scm_remember_upto_here_1 (scaled_bookdef); } - + +/* + PAPERBOOK should be scaled already. + */ SCM Score::book_rendering (String outname, - Book_output_def* paperbook, - Output_def *default_def, - Output_def **paper) + Output_def *paperbook, + Output_def *default_def) { + SCM scaled_bookdef = SCM_EOL; + Real scale = 1.0; + + if (paperbook && paperbook->c_variable ("is-bookpaper") == SCM_BOOL_T) + { + scale = ly_scm2double (paperbook->c_variable ("outputscale")); + } + SCM out = scm_makfrom0str (outname.to_str0 ()); SCM systems = SCM_EOL; int outdef_count = defs_.size (); for (int i = 0; !i || i < outdef_count; i++) { Output_def *def = outdef_count ? defs_[i] : default_def; - if (Output_def * pd = dynamic_cast (def)) + SCM scaled= SCM_EOL; + if (def->c_variable ("is-paper") == SCM_BOOL_T) { - def = paperbook->scale_paper (pd); + def = scale_output_def (def, scale); + def->parent_ = paperbook; + scaled = def->self_scm (); + scm_gc_unprotect_object (scaled); } if (!(no_paper_global_b && dynamic_cast (def))) { SCM context = ly_run_translator (music_, def->self_scm ()); - if (Global_context *g = dynamic_cast - (unsmob_context (context))) + if (dynamic_cast (unsmob_context (context))) { SCM s = ly_format_output (context, out); if (s != SCM_UNDEFINED) { systems = s; - /* Ugh. */ - Music_output *output = g->get_output (); - if (Paper_score *ps = dynamic_cast (output)) - *paper = ps->paper_; } } } + + scm_remember_upto_here_1 (scaled); } + + scm_remember_upto_here_1 (scaled_bookdef); return systems; } diff --git a/ly/book-paper-defaults.ly b/ly/book-paper-defaults.ly index 6ba340e714..b4e81fcae3 100644 --- a/ly/book-paper-defaults.ly +++ b/ly/book-paper-defaults.ly @@ -1,74 +1,50 @@ \version "2.3.2" \bookpaper { -#(define-public is-bookpaper #t) - -#(define-public (book-title paper scopes) - "Generate book title from header strings." - - (define (get sym) - (let ((x (ly:modules-lookup scopes sym))) - (if (and x (not (unspecified? x))) x ""))) - - (let ((props (page-properties paper))) + unit = #(ly:unit) + mm = 1.0 + in = 25.4 + pt = #(/ in 72.27) + cm = #(* 10 mm) + + inputencoding = #"TeX" - (interpret-markup - paper props - (markup - #:column - (#:override '(baseline-skip . 4) - #:column - (#:fill-line - (#:normalsize (get 'dedication)) - #:fill-line - (#:huge #:bigger #:bigger #:bigger #:bigger #:bold (get 'title)) - #:override '(baseline-skip . 3) - #:column - (#:fill-line - (#:large #:bigger #:bigger #:bold (get 'subtitle)) - #:fill-line (#:bigger #:bigger #:bold (get 'subsubtitle))) - #:override '(baseline-skip . 5) - #:column ("") - #:override '(baseline-skip . 2.5) - #:column - (#:fill-line - (#:bigger (get 'poet) #:large #:bigger #:caps (get 'composer)) - #:fill-line (#:bigger (get 'texttranslator) #:bigger (get 'opus)) - #:fill-line - (#:bigger (get 'meter) #:bigger (get 'arranger)) - "" - #:fill-line (#:large #:bigger (get 'instrument)) - " " - #:fill-line (#:large #:bigger #:caps (get 'piece) "")))))))) + % + % 20pt staff, 5 pt = 1.75 mm + % -#(define-public (user-title paper markup) - "Generate book title from header markup." - (if (markup? markup) - (let ((props (page-properties paper)) - (baseline-skip (chain-assoc-get 'baseline-skip props 2)) ) - (stack-lines DOWN 0 BASELINE-SKIP - (list (interpret-markup paper props markup)))))) + outputscale = #1.7573 + + #(define-public score-title default-score-title) + #(define-public user-title default-user-title) + #(define-public book-title default-book-title) -#(define-public (score-title paper scopes) - "Generate score title from header strings." - - (define (get sym) - (let ((x (ly:modules-lookup scopes sym))) - (if (and x (not (unspecified? x))) x ""))) - - (let ((props (page-properties paper))) + % + % ugh. hard coded? + % - (interpret-markup - paper props - (markup - #:column - (#:override '(baseline-skip . 4) - #:column - (#:fill-line - ("" (get 'opus)) - #:fill-line (#:large #:bigger #:caps (get 'piece) ""))))))) + #(paper-set-staff-size (* 20.0 pt)) papersize = "a4" + #(define font-defaults + '((font-encoding . fetaMusic))) + + #(define text-font-defaults + '((font-encoding . latin1) + (baseline-skip . 2) + (word-space . 0.6))) + + #(define page-breaking ly:ragged-page-breaks) + %%#(define page-breaking ly:optimal-page-breaks) + + #(define page-to-stencil ly:page-header-lines-footer-stencil) + + #(define make-header plain-header) + #(define make-footer plain-footer) + %%#(define make-footer empty-markup) + #(define make-tagline TAGLINE-or-tagline-from-header) + #(define make-copyright copyright-from-header) + } diff --git a/ly/declarations-init.ly b/ly/declarations-init.ly index 6dfa049e5d..1e47fb9e65 100644 --- a/ly/declarations-init.ly +++ b/ly/declarations-init.ly @@ -48,65 +48,29 @@ melismaEnd = #(make-span-event 'ManualMelismaEvent STOP) % ugh \include "midi-init.ly" +\include "book-paper-defaults.ly" -% Do units first; must be done before any units are specified. \paper { - unit = #(ly:unit) - mm = 1.0 - in = 25.4 + mm = #(ly:output-def-lookup $defaultbookpaper 'mm) + unit = #(ly:output-def-lookup $defaultbookpaper 'unit) + + in = #(* 25.4 mm) pt = #(/ in 72.27) cm = #(* 10 mm) - - inputencoding = #"TeX" - raggedright = ##f - raggedlast = ##f - packed = ##f - #(define $is-paper #t) - - #(define font-defaults - '((font-encoding . fetaMusic))) - - #(define text-font-defaults - '((font-encoding . latin1) - (baseline-skip . 2) - (word-space . 0.6))) - - #(define page-breaking ly:ragged-page-breaks) - %%#(define page-breaking ly:optimal-page-breaks) - - #(define page-to-stencil ly:page-header-lines-footer-stencil) - - #(define make-header plain-header) - #(define make-footer plain-footer) - %%#(define make-footer empty-markup) - #(define make-tagline TAGLINE-or-tagline-from-header) - #(define make-copyright copyright-from-header) - \include "engraver-init.ly" } -% -% 20pt staff, 5 pt = 1.75 mm -% - -#(define-public $defaultbookpaper (ly:make-bookpaper 1.7573)) - -\include "book-paper-defaults.ly" #(set-default-paper-size "a4") -%{ - -; note: -; you can add fonts manually in the paper block by issuing -#(set! fonts (append ...myfonts... fonts)) +%{ -for the format of myfonts, see font.scm +%% these would supercede defaults in \bookpaper. +% let's comment this out for now. -%} paperEleven = \paper { #(paper-set-staff-size (* 11.0 pt)) @@ -138,6 +102,8 @@ paperTwentysix = \paper { \paper { \paperTwenty } +%} + partCombineListener = \paper { \context { \Voice diff --git a/ly/engraver-init.ly b/ly/engraver-init.ly index 41e483d9ab..77a781b010 100644 --- a/ly/engraver-init.ly +++ b/ly/engraver-init.ly @@ -8,10 +8,6 @@ \grobdescriptions #all-grob-descriptions } -% -% setup for Request->Element conversion. Guru-only -% - \context { \type "Engraver_group_engraver" \name Staff @@ -48,6 +44,7 @@ verticalExtent = ##f localKeySignature = #'() createSpacing = ##t + % explicitly set instrument, so we don't get % weird effects when doing instrument names for % piano staves diff --git a/scm/lily.scm b/scm/lily.scm index 6e6605703e..0c29b3b5a5 100644 --- a/scm/lily.scm +++ b/scm/lily.scm @@ -119,18 +119,6 @@ (define-public default-toplevel-score-handler print-score-as-book) -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;;; Unassorted utility functions. - - -;; modules -(define-public (ly:modules-lookup modules sym) - "DOCME." - (let ((v (module-variable (car modules) sym))) - (if (and v (variable-bound? v) (variable-ref v)) - (variable-ref v) - (if (module? (cdr modules)) (ly:modules-lookup (cdr modules) sym))))) - ;;;;;;;;;;;;;;;; ; alist @@ -471,6 +459,7 @@ L1 is copied, L2 not. "define-grobs.scm" "define-grob-interfaces.scm" "page-layout.scm" + "paper.scm" ; last: diff --git a/scm/output-tex.scm b/scm/output-tex.scm index 899f05ba85..461165da0e 100644 --- a/scm/output-tex.scm +++ b/scm/output-tex.scm @@ -76,12 +76,13 @@ (number->string (exact->inexact (ly:bookpaper-outputscale bookpaper)))) (tex-string-def "lilypondpapersize" 'papersize - (eval 'papersize (ly:bookpaper-def-scope bookpaper))) + (eval 'papersize (ly:output-def-scope bookpaper))) + (apply string-append (map (lambda (x) (font-load-command bookpaper x)) (ly:bookpaper-fonts bookpaper) - ))) - ) + )))) + (define (unknown) "%\n\\unknown\n") diff --git a/scm/page-layout.scm b/scm/page-layout.scm index aa1f847dc0..999c094748 100644 --- a/scm/page-layout.scm +++ b/scm/page-layout.scm @@ -213,3 +213,72 @@ ;; TODO: if solution is bad return no breaks and revert to ;; ragged bottom (list->vector breaks))) + + + +;;;;;;;;;;;;;;;;;; +; titling. +(define-public (default-book-title paper scopes) + "Generate book title from header strings." + + (define (get sym) + (let ((x (ly:modules-lookup scopes sym))) + (if (and x (not (unspecified? x))) x ""))) + + (let ((props (page-properties paper))) + + (interpret-markup + paper props + (markup + #:column + (#:override '(baseline-skip . 4) + #:column + (#:fill-line + (#:normalsize (get 'dedication)) + #:fill-line + (#:huge #:bigger #:bigger #:bigger #:bigger #:bold (get 'title)) + #:override '(baseline-skip . 3) + #:column + (#:fill-line + (#:large #:bigger #:bigger #:bold (get 'subtitle)) + #:fill-line (#:bigger #:bigger #:bold (get 'subsubtitle))) + #:override '(baseline-skip . 5) + #:column ("") + #:override '(baseline-skip . 2.5) + #:column + (#:fill-line + (#:bigger (get 'poet) #:large #:bigger #:caps (get 'composer)) + #:fill-line (#:bigger (get 'texttranslator) #:bigger (get 'opus)) + #:fill-line + (#:bigger (get 'meter) #:bigger (get 'arranger)) + "" + #:fill-line (#:large #:bigger (get 'instrument)) + " " + #:fill-line (#:large #:bigger #:caps (get 'piece) "")))))))) + +(define-public (default-user-title paper markup) + "Generate book title from header markup." + (if (markup? markup) + (let ((props (page-properties paper)) + (baseline-skip (chain-assoc-get 'baseline-skip props 2)) ) + (stack-lines DOWN 0 BASELINE-SKIP + (list (interpret-markup paper props markup)))))) + +(define-public (default-score-title paper scopes) + "Generate score title from header strings." + + (define (get sym) + (let ((x (ly:modules-lookup scopes sym))) + (if (and x (not (unspecified? x))) x ""))) + + (let ((props (page-properties paper))) + + (interpret-markup + paper props + (markup + #:column + (#:override '(baseline-skip . 4) + #:column + (#:fill-line + ("" (get 'opus)) + #:fill-line (#:large #:bigger #:caps (get 'piece) ""))))))) diff --git a/scm/paper.scm b/scm/paper.scm index 41fa80f54c..163d836245 100644 --- a/scm/paper.scm +++ b/scm/paper.scm @@ -11,13 +11,13 @@ (ss (/ sz 4)) (pt (eval 'pt m)) (mm (eval 'mm m))) - + + (module-define! m 'outputscale ss) (module-define! m 'fonts (make-cmr-tree (/ sz (* 20 pt)))) (module-define! m 'staffheight sz) (module-define! m 'staff-space ss) (module-define! m 'staffspace ss) - ;; !! synchronize with feta-params.mf (module-define! m 'linethickness (+ (* 0.3 pt) (* 0.04 ss))) (module-define! m 'ledgerlinethickness (+ (* 0.5 pt) (/ ss 10))) @@ -34,19 +34,23 @@ (define-public (set-global-staff-size sz) "Set the default staff size, where SZ is thought to be in PT." (let* ((old-mod (current-module)) - (pap (eval '$defaultpaper old-mod)) - (is-paper? (module-defined? old-mod '$defaultpaper)) - + (pap (eval '$defaultbookpaper old-mod)) + (in-paper? (or (module-defined? old-mod 'is-bookpaper) + (module-defined? old-mod 'is-paper))) - ;; Huh? Why is it necessary to clone object? + ; maybe not necessary. + ; but let's be paranoid. Maybe someone still refers to the + ; old one. (new-paper (ly:output-def-clone pap)) + (new-scope (ly:output-def-scope new-paper))) - (if (not is-paper?) + + (if in-paper? (ly:warn "Not in toplevel scope")) (set-current-module new-scope) (paper-set-staff-size (* sz (eval 'pt new-scope))) (set-current-module old-mod) - (module-define! old-mod '$defaultpaper new-paper))) + (module-define! old-mod '$defaultbookpaper new-paper))) (define paper-alist '(("a6" . (cons (* 105 mm) (* 148.95 mm))) @@ -75,11 +79,11 @@ (define (internal-set-paper-size module name) (let* ((entry (assoc name paper-alist)) - (is-paper? (module-defined? module '$is-paper)) + (is-bookpaper? (module-defined? module 'is-bookpaper)) (mm (eval 'mm module))) (cond - ((not is-paper?) + ((not is-bookpaper?) (ly:warning "This is not a \\paper {} object:") (display module)) ((pair? entry) @@ -94,28 +98,33 @@ )) (define-public (set-default-paper-size name) - (internal-set-paper-size (ly:output-def-scope (eval '$defaultpaper (current-module))) + (internal-set-paper-size (ly:output-def-scope (eval '$defaultbookpaper (current-module))) name)) (define-public (set-paper-size name) - (if (module-defined? (current-module) '$is-paper) + (if (module-defined? (current-module) 'is-paper) (internal-set-paper-size (current-module) name) ;;; TODO: should raise (generic) exception with throw, and catch ;;; that in parse-scm.cc (ly:warn "Must use #(set-paper-size .. ) within \\paper { ... }"))) -(define-public (scale-paper pap bookpap) +(define-public (scale-paper pap scale) (let* - ((scale (ly:bookpaper-outputscale bookpap)) - (new-pap (ly:output-def-clone pap)) + ((new-pap (ly:output-def-clone pap)) (dim-vars (ly:output-def-lookup pap 'dimension-variables)) (scope (ly:output-def-scope new-pap))) (for-each (lambda (v) - (module-define! scope v - (/ (ly:output-def-lookup pap v) scale))) + (define val (ly:output-def-lookup pap v)) + (if (number? val) + (module-define! scope v + (/ val scale)) + + ;; spurious warnings, eg. for hsize, vsize. +; (ly:warn (format "not a number, ~S = ~S " v val)) + )) dim-vars) -- 2.39.2