From 6ddd5b9373861e63801b29b336580621ca4b9ef1 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Mon, 11 Jul 2005 12:51:13 +0000 Subject: [PATCH] (LY_DEFINE): ly:parser-output-name: new function. (LY_DEFINE): change name ly:parser-define -> ly:parser-define! --- ChangeLog | 4 ++ lily/book-scheme.cc | 35 +++++++++++++- lily/book.cc | 14 ++++-- lily/default-actions.cc | 96 -------------------------------------- lily/include/book.hh | 4 +- lily/include/ly-module.hh | 2 +- lily/lily-parser-scheme.cc | 14 +++++- lily/output-def.cc | 2 +- lily/paper-book-scheme.cc | 2 +- lily/paper-book.cc | 16 +++---- lily/score-scheme.cc | 52 +++++++++++++++++++++ lily/score.cc | 12 ++--- ly/declarations-init.ly | 2 +- ly/init.ly | 4 +- python/convertrules.py | 10 +++- scm/framework-eps.scm | 2 +- scm/lily-library.scm | 45 ++++++++++++++++-- scm/safe-lily.scm | 2 - scripts/lilypond-book.py | 4 +- 19 files changed, 187 insertions(+), 135 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6e730da368..8ccf916294 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2005-07-11 Han-Wen Nienhuys + * lily/lily-parser-scheme.cc (LY_DEFINE): ly:parser-output-name: + new function. + (LY_DEFINE): change name ly:parser-define -> ly:parser-define! + * scm/framework-*.scm: use port arguments throughout. * lily/include/lily-guile.hh: rename ly_c_X_p -> ly_is_X diff --git a/lily/book-scheme.cc b/lily/book-scheme.cc index 5c86770e3f..c3b30bd8e7 100644 --- a/lily/book-scheme.cc +++ b/lily/book-scheme.cc @@ -7,8 +7,10 @@ */ #include "book.hh" + #include "output-def.hh" #include "score.hh" +#include "paper-book.hh" #include "ly-module.hh" LY_DEFINE (ly_make_book, "ly:make-book", @@ -23,7 +25,7 @@ LY_DEFINE (ly_make_book, "ly:make-book", Book *book = new Book; book->paper_ = odef; - if (ly_c_module_p (header)) + if (ly_is_module (header)) book->header_ = header; book->scores_ = scm_append (scm_list_2 (scores, book->scores_)); @@ -32,3 +34,34 @@ LY_DEFINE (ly_make_book, "ly:make-book", scm_gc_unprotect_object (x); return x; } + +LY_DEFINE (ly_parser_print_book, "ly:book-process", + 3, 0, 0, (SCM book_smob, + SCM default_paper, + SCM default_layout, + SCM basename), + "Print book.") +{ + Book *book = unsmob_book (book_smob); + + SCM_ASSERT_TYPE (book, book_smob, SCM_ARG1, __FUNCTION__, "Book"); + SCM_ASSERT_TYPE (unsmob_output_def (default_paper), + default_layout, SCM_ARG2, __FUNCTION__, "\\paper block"); + SCM_ASSERT_TYPE (unsmob_output_def (default_layout), + default_layout, SCM_ARG3, __FUNCTION__, "\\layout block"); + SCM_ASSERT_TYPE (scm_is_string (basename), basename, SCM_ARG4, __FUNCTION__, "string"); + + String base = ly_scm2string (basename); + Paper_book *pb = book->process (base, + unsmob_output_def (default_paper), + unsmob_output_def (default_layout) + ); + if (pb) + { + pb->output (base); + scm_gc_unprotect_object (pb->self_scm ()); + } + + return SCM_UNSPECIFIED; +} + diff --git a/lily/book.cc b/lily/book.cc index 724ab9cc13..59c9c206af 100644 --- a/lily/book.cc +++ b/lily/book.cc @@ -77,16 +77,20 @@ Book::add_score (SCM s) /* This function does not dump the output; outname is required eg. for dumping header fields. */ Paper_book * -Book::process (String outname, Output_def *default_def) +Book::process (String outname, + Output_def *default_paper, + Output_def *default_layout) { for (SCM s = scores_; s != SCM_EOL; s = scm_cdr (s)) if (Score *score = unsmob_score (scm_car (s))) if (score->error_found_) return 0; + Output_def *paper = paper_ ? default_paper : paper_; + Paper_book *paper_book = new Paper_book (); - Real scale = scm_to_double (paper_->c_variable ("outputscale")); - Output_def *scaled_bookdef = scale_output_def (paper_, scale); + Real scale = scm_to_double (paper->c_variable ("outputscale")); + Output_def *scaled_bookdef = scale_output_def (paper, scale); Object_key *key = new Lilypond_general_key (0, user_key_, 0); SCM scm_key = key->self_scm (); @@ -104,7 +108,7 @@ Book::process (String outname, Output_def *default_def) if (Score *score = unsmob_score (scm_car (s))) { SCM outputs = score - ->book_rendering (paper_book->paper_, default_def, key); + ->book_rendering (paper_book->paper_, default_layout, key); while (scm_is_pair (outputs)) { @@ -122,7 +126,7 @@ Book::process (String outname, Output_def *default_def) else if (Paper_score *pscore = dynamic_cast (output)) { SCM systems = pscore->get_paper_systems (); - if (ly_c_module_p (score->header_)) + if (ly_is_module (score->header_)) paper_book->add_score (score->header_); paper_book->add_score (systems); } diff --git a/lily/default-actions.cc b/lily/default-actions.cc index 34f7c62224..ef7f931191 100644 --- a/lily/default-actions.cc +++ b/lily/default-actions.cc @@ -8,99 +8,3 @@ */ -#include "lily-parser.hh" -#include "lily-lexer.hh" -#include "lilypond-key.hh" -#include "book.hh" -#include "paper-book.hh" -#include "score.hh" -#include "file-name.hh" -#include "output-def.hh" - - - - -/* TODO: move this to Scheme? Why take the parser arg, and all the back - & forth between scm and c++? */ -LY_DEFINE (ly_parser_print_score, "ly:parser-print-score", - 2, 0, 0, - (SCM parser_smob, SCM score_smob), - "Print score, i.e., the classic way.") -{ - Lily_parser *parser = unsmob_lily_parser (parser_smob); - Score *score = unsmob_score (score_smob); - - Object_key *key = new Lilypond_general_key (0, score->user_key_, 0); - - if (score->error_found_) - return SCM_UNSPECIFIED; - - SCM_ASSERT_TYPE (parser, parser_smob, SCM_ARG1, __FUNCTION__, "parser"); - SCM_ASSERT_TYPE (score, score_smob, SCM_ARG2, __FUNCTION__, "score"); - - SCM header = ly_c_module_p (score->header_) - ? score->header_ - : parser->lexer_->lookup_identifier ("$globalheader"); - - File_name outname (parser->output_basename_); - int *c = &parser->book_count_; - if (*c) - outname.base_ += "-" + to_string (*c); - (*c)++; - - SCM os = scm_makfrom0str (outname.to_string ().to_str0 ()); - 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 ()); - - if (score->defs_.is_empty ()) - { - Output_def *layout = get_layout (parser); - default_rendering (score->get_music (), - layout->self_scm (), - paper, - header, os, key->self_scm ()); - - scm_gc_unprotect_object (layout->self_scm ()); - } - - scm_gc_unprotect_object (paper); - scm_gc_unprotect_object (key->self_scm ()); - return SCM_UNSPECIFIED; -} - - -LY_DEFINE (ly_parser_print_book, "ly:parser-print-book", - 2, 0, 0, (SCM parser_smob, SCM book_smob), - "Print book.") -{ - Lily_parser *parser = unsmob_lily_parser (parser_smob); - Book *book = unsmob_book (book_smob); - Output_def *bp = unsmob_output_def (parser->lexer_->lookup_identifier ("$defaultpaper")); - - SCM_ASSERT_TYPE (parser, parser_smob, SCM_ARG1, __FUNCTION__, "Lilypond parser"); - SCM_ASSERT_TYPE (book, book_smob, SCM_ARG2, __FUNCTION__, "Book"); - - /* ugh. changing argument.*/ - book->paper_ = bp; - - File_name outname (parser->output_basename_); - int *c = &parser->book_count_; - if (*c) - outname.base_ += "-" + to_string (*c); - (*c)++; - - Output_def *layout = get_layout (parser); - Paper_book *pb = book->process (outname.to_string (), layout); - - if (pb) - { - pb->output (outname.to_string ()); - scm_gc_unprotect_object (pb->self_scm ()); - } - - scm_gc_unprotect_object (layout->self_scm ()); - return SCM_UNSPECIFIED; -} - diff --git a/lily/include/book.hh b/lily/include/book.hh index 88b9207c3e..44c764703d 100644 --- a/lily/include/book.hh +++ b/lily/include/book.hh @@ -27,7 +27,9 @@ public: Book (); void add_score (SCM); - Paper_book *process (String, Output_def *); + Paper_book *process (String, + Output_def *def_paper, + Output_def *def_layout); void set_keys (); }; diff --git a/lily/include/ly-module.hh b/lily/include/ly-module.hh index 5237160576..96d2e1fccf 100644 --- a/lily/include/ly-module.hh +++ b/lily/include/ly-module.hh @@ -17,7 +17,7 @@ SCM ly_module_lookup (SCM module, 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 ly_c_module_p (SCM x) { return SCM_MODULEP (x); } +inline bool ly_is_module (SCM x) { return SCM_MODULEP (x); } void ly_clear_anonymous_modules (); SCM ly_use_module (SCM mod, SCM used); diff --git a/lily/lily-parser-scheme.cc b/lily/lily-parser-scheme.cc index 006e556027..27cf5e5e5c 100644 --- a/lily/lily-parser-scheme.cc +++ b/lily/lily-parser-scheme.cc @@ -155,7 +155,7 @@ LY_DEFINE (ly_clone_parser, "ly:clone-parser", return scm_gc_unprotect_object (clone->self_scm ()); } -LY_DEFINE (ly_parser_define, "ly:parser-define", +LY_DEFINE (ly_parser_define, "ly:parser-define!", 3, 0, 0, (SCM parser_smob, SCM symbol, SCM val), "Bind SYMBOL to VAL in PARSER_SMOB's module.") { @@ -216,3 +216,15 @@ LY_DEFINE (ly_parser_set_note_names, "ly:parser-set-note-names", return SCM_UNSPECIFIED; } + + +LY_DEFINE (ly_parser_output_name, "ly:parser-output-name", + 1, 0, 0, (SCM parser), + "Return the base name of the output file.") +{ + Lily_parser *p = unsmob_lily_parser (parser); + SCM_ASSERT_TYPE (p, parser, SCM_ARG1, __FUNCTION__, "Lilypond parser"); + + return scm_from_locale_string (p->output_basename_.to_str0 ()); +} + diff --git a/lily/output-def.cc b/lily/output-def.cc index e08816a7b8..0010d69b4f 100644 --- a/lily/output-def.cc +++ b/lily/output-def.cc @@ -40,7 +40,7 @@ Output_def::Output_def (Output_def const &s) input_origin_ = s.input_origin_; scope_ = ly_make_anonymous_module (false); - if (ly_c_module_p (s.scope_)) + if (ly_is_module (s.scope_)) ly_module_copy (scope_, s.scope_); } diff --git a/lily/paper-book-scheme.cc b/lily/paper-book-scheme.cc index 8b5d6c866e..69b7dc02ee 100644 --- a/lily/paper-book-scheme.cc +++ b/lily/paper-book-scheme.cc @@ -25,7 +25,7 @@ LY_DEFINE (ly_paper_book_scopes, "ly:paper-book-scopes", SCM_ASSERT_TYPE (pb, book, SCM_ARG1, __FUNCTION__, "Paper_book"); SCM scopes = SCM_EOL; - if (ly_c_module_p (pb->header_)) + if (ly_is_module (pb->header_)) scopes = scm_cons (pb->header_, scopes); return scopes; diff --git a/lily/paper-book.cc b/lily/paper-book.cc index 97be3c094a..e1fadabd32 100644 --- a/lily/paper-book.cc +++ b/lily/paper-book.cc @@ -89,7 +89,7 @@ Paper_book::output (String outname) pages (); SCM scopes = SCM_EOL; - if (ly_c_module_p (header_)) + if (ly_is_module (header_)) scopes = scm_cons (header_, scopes); String mod_nm = "scm framework-" + output_backend_global; @@ -126,10 +126,10 @@ Paper_book::classic_output (String outname) systems (); SCM scopes = SCM_EOL; - if (ly_c_module_p (header_)) + if (ly_is_module (header_)) scopes = scm_cons (header_, scopes); - if (ly_c_module_p (header_0_)) + if (ly_is_module (header_0_)) scopes = scm_cons (header_0_, scopes); String format = output_backend_global; @@ -156,7 +156,7 @@ Paper_book::book_title () Stencil title; SCM scopes = SCM_EOL; - if (ly_c_module_p (header_)) + if (ly_is_module (header_)) scopes = scm_cons (header_, scopes); SCM tit = SCM_EOL; @@ -182,10 +182,10 @@ Paper_book::score_title (SCM header) Stencil title; SCM scopes = SCM_EOL; - if (ly_c_module_p (header_)) + if (ly_is_module (header_)) scopes = scm_cons (header_, scopes); - if (ly_c_module_p (header)) + if (ly_is_module (header)) scopes = scm_cons (header, scopes); SCM tit = SCM_EOL; @@ -206,7 +206,7 @@ Paper_book::score_title (SCM header) void set_system_penalty (Paper_system *ps, SCM header) { - if (ly_c_module_p (header)) + if (ly_is_module (header)) { SCM force = ly_module_lookup (header, ly_symbol2scm ("breakbefore")); if (SCM_VARIABLEP (force) @@ -259,7 +259,7 @@ Paper_book::systems () SCM header = SCM_EOL; for (SCM s = scm_reverse (scores_); s != SCM_EOL; s = scm_cdr (s)) { - if (ly_c_module_p (scm_car (s))) + if (ly_is_module (scm_car (s))) { header = scm_car (s); if (header_0_ == SCM_EOL) diff --git a/lily/score-scheme.cc b/lily/score-scheme.cc index 19bac6c48a..ddd97e3a0d 100644 --- a/lily/score-scheme.cc +++ b/lily/score-scheme.cc @@ -7,9 +7,12 @@ */ #include "score.hh" + #include "music.hh" #include "output-def.hh" #include "global-context.hh" +#include "lilypond-key.hh" + LY_DEFINE (ly_make_score, "ly:make-score", 1, 0, 0, @@ -69,3 +72,52 @@ LY_DEFINE (ly_score_embedded_format, "ly:score-embedded-format", scm_remember_upto_here_1 (prot); return output; } + +LY_DEFINE (ly_score_process, "ly:score-process", + 2, 0, 0, + (SCM score_smob, + SCM default_header, + SCM default_paper, + SCM default_layout, + SCM basename), + "Print score, i.e., the classic way.") +{ + Score *score = unsmob_score (score_smob); + + SCM_ASSERT_TYPE (score, score_smob, SCM_ARG1, __FUNCTION__, "score"); + + SCM_ASSERT_TYPE (ly_is_module (default_header), + default_header, SCM_ARG2, __FUNCTION__, "module"); + SCM_ASSERT_TYPE (unsmob_output_def (default_paper), + default_header, SCM_ARG3, __FUNCTION__, "\\paper block"); + SCM_ASSERT_TYPE (unsmob_output_def (default_layout), + default_header, SCM_ARG4, __FUNCTION__, "\\layout block"); + SCM_ASSERT_TYPE (scm_is_string (basename), + default_header, SCM_ARG5, __FUNCTION__, "basename"); + + Object_key *key = new Lilypond_general_key (0, score->user_key_, 0); + + if (score->error_found_) + return SCM_UNSPECIFIED; + + SCM header = ly_is_module (score->header_) + ? score->header_ + : default_header; + + for (int i = 0; i < score->defs_.size (); i++) + default_rendering (score->get_music (), score->defs_[i]->self_scm (), + default_paper, header, basename, key->self_scm ()); + + if (score->defs_.is_empty ()) + { + default_rendering (score->get_music (), + default_layout, + default_paper, + header, basename, key->self_scm ()); + } + + scm_gc_unprotect_object (key->self_scm ()); + return SCM_UNSPECIFIED; +} + + diff --git a/lily/score.cc b/lily/score.cc index 6d86607e68..032c4be496 100644 --- a/lily/score.cc +++ b/lily/score.cc @@ -15,17 +15,17 @@ #include "global-context.hh" #include "lily-parser.hh" #include "lilypond-key.hh" -#include "ly-smobs.icc" #include "main.hh" -#include "music-iterator.hh" #include "music.hh" #include "output-def.hh" -#include "output-def.hh" #include "paper-book.hh" #include "paper-score.hh" -#include "scm-hash.hh" #include "warn.hh" + +#include "music.hh" +#include "ly-smobs.icc" + Score::Score () : Input () { @@ -84,7 +84,7 @@ Score::Score (Score const &s) scm_gc_unprotect_object (copy->self_scm ()); } header_ = ly_make_anonymous_module (false); - if (ly_c_module_p (s.header_)) + if (ly_is_module (s.header_)) ly_module_copy (header_, s.header_); texts_ = s.texts_; @@ -130,7 +130,7 @@ default_rendering (SCM music, SCM outdef, paper_book->header_ = header; paper_book->paper_ = unsmob_output_def (scaled_bookdef); - if (ly_c_module_p (header)) + if (ly_is_module (header)) paper_book->add_score (header); SCM systems = pscore->get_paper_systems (); diff --git a/ly/declarations-init.ly b/ly/declarations-init.ly index 3c73227be1..9366ea7400 100644 --- a/ly/declarations-init.ly +++ b/ly/declarations-init.ly @@ -116,7 +116,7 @@ setDefaultDurationToQuarter = { c4 } %% MAKE-HASH-TABLE in GUILE 1.6 takes mandatory size parameter. #(define musicQuotes (make-hash-table 29)) -#(define toplevel-book-handler ly:parser-print-book) +#(define toplevel-book-handler print-book-with-defaults) #(define toplevel-music-handler collect-music-for-book) #(define toplevel-score-handler collect-scores-for-book) #(define toplevel-text-handler collect-scores-for-book) diff --git a/ly/init.ly b/ly/init.ly index 6a7e513c7e..29694bb3d8 100644 --- a/ly/init.ly +++ b/ly/init.ly @@ -34,6 +34,6 @@ (version-not-seen-message input-file-name)) #(if (pair? toplevel-scores) - (ly:parser-print-book parser + (toplevel-book-handler + parser (apply ly:make-book $defaultpaper $globalheader toplevel-scores))) - diff --git a/python/convertrules.py b/python/convertrules.py index 84f5fd3ea6..94dd62a711 100644 --- a/python/convertrules.py +++ b/python/convertrules.py @@ -2504,12 +2504,18 @@ conversions.append (((2, 6, 0), conv, 'dummy rule for 2.6')) + def conv (str): return re.sub('ly:get-default-font', 'ly:grob-default-font', str) conversions.append (((2, 7, 0), conv, - - 'ly:get-default-font -> ly:grob-default-font')) + 'ly:get-default-font -> ly:grob-default-font')) + +def conv (str): + return re.sub('ly:parser-define', 'ly:parser-define!', str) + +conversions.append (((2, 7, 0), conv, + 'ly:parser-define -> ly:parser-define!')) ################################################################ diff --git a/scm/framework-eps.scm b/scm/framework-eps.scm index b0212a8e69..29d4df46b2 100644 --- a/scm/framework-eps.scm +++ b/scm/framework-eps.scm @@ -60,7 +60,7 @@ (display (format "@image{~a-~a}\n" basename (1+ c)) texi-system-port)) (iota (length stencils))) - (display "@c eof - 'eof' is a Makefile marker; don not remove. " texi-system-port) + (display "@c eof - 'eof' is a Makefile marker; do not remove. " texi-system-port) (display "% eof - 'eof' is Makefile marker; do not remove. " tex-system-port) (dump-infinite-stack-EPS stencils)) diff --git a/scm/lily-library.scm b/scm/lily-library.scm index b9e326cae7..f14f3d7b42 100644 --- a/scm/lily-library.scm +++ b/scm/lily-library.scm @@ -72,16 +72,53 @@ (set! music (func music parser))) toplevel-music-functions) -; (display-scheme-music music) (ly:make-score music)) - (define-public (collect-music-for-book parser music) (collect-scores-for-book parser (scorify-music music parser))) - + +(define-public (print-book-with-defaults parser book) + (let* + ((paper (ly:parser-lookup parser '$defaultpaper)) + (layout (ly:parser-lookup parser '$defaultlayout)) + (count (ly:parser-lookup parser 'book-count)) + (base (ly:parser-output-name parser))) + + (if (not (integer? count)) + (set! count 0)) + + (if (> count 0) + (set! (base (format #f "~a-~a" count)))) + + (ly:parser-define! book-count (1+ count)) + + + (ly:book-process book paper layout base) + )) + +(define-public (print-score-with-defaults parser score) + (let* + ((paper (ly:parser-lookup parser '$defaultpaper)) + (layout (ly:parser-lookup parser '$defaultlayout)) + (layout (ly:parser-lookup parser '$globalheader)) + (count (ly:parser-lookup parser 'book-count))i + (base (ly:parser-output-name parser))) + + (if (not (integer? count)) + (set! count 0)) + + (if (> count 0) + (set! (base (format #f "~a-~a" count)))) + + (ly:parser-define! book-count (1+ count)) + + + (ly:score-process score header paper layout base) + )) + ;;;;;;;;;;;;;;;; -; alist +;; alist (define-public assoc-get ly:assoc-get) (define-public (uniqued-alist alist acc) diff --git a/scm/safe-lily.scm b/scm/safe-lily.scm index 0e0fb0d9cf..2f1e7dec53 100644 --- a/scm/safe-lily.scm +++ b/scm/safe-lily.scm @@ -108,8 +108,6 @@ ly:output-def-lookup ly:parse-string ly:parser-parse-string - ly:parser-print-book - ly:parser-print-score ly:pitch-alteration ly:pitch-diff ly:pitch-notename diff --git a/scripts/lilypond-book.py b/scripts/lilypond-book.py index 692790bf3c..9ca2640b05 100644 --- a/scripts/lilypond-book.py +++ b/scripts/lilypond-book.py @@ -551,9 +551,9 @@ output = { PREAMBLE_LY = r'''%%%% Generated by %(program_name)s %%%% Options: [%(option_string)s] -#(set! toplevel-score-handler ly:parser-print-score) +#(set! toplevel-score-handler print-score-with-defaults) #(set! toplevel-music-handler (lambda (p m) - (ly:parser-print-score + (print-score-with-defaults p (scorify-music m p)))) #(ly:set-option (quote no-point-and-click)) -- 2.39.5