From 58285d9a44003dc28d5183daa5c1ae71249440e5 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sat, 10 Apr 2004 01:17:30 +0000 Subject: [PATCH] * lily/input-file-results.cc (do_one_file): Remove Paper_book hack. * lily/score.cc (book_rendering): New method. (default_rendering): Create Paper_book helper locally, dump output. * lily/my-lily-lexer.cc (the_key_tab): Add book. * lily/parser.yy: Handle \book. * lily/include/book.hh: * lily/book.cc: New file. --- ChangeLog | 15 +++++ lily/book.cc | 97 +++++++++++++++++++++++++++ lily/include/book.hh | 32 +++++++++ lily/include/context-def.hh | 25 +++---- lily/include/input-file-results.hh | 1 + lily/include/lily-proto.hh | 1 + lily/include/main.hh | 2 - lily/include/music-output-def.hh | 10 +-- lily/include/score.hh | 12 ++-- lily/input-file-results.cc | 16 +---- lily/my-lily-lexer.cc | 1 + lily/paper-book.cc | 8 +-- lily/parser.yy | 104 +++++++++++++++++++---------- lily/score.cc | 47 +++++++++---- 14 files changed, 280 insertions(+), 91 deletions(-) create mode 100644 lily/book.cc create mode 100644 lily/include/book.hh diff --git a/ChangeLog b/ChangeLog index da67305e42..862940022c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2004-04-10 Jan Nieuwenhuizen + + * lily/input-file-results.cc (do_one_file): Remove Paper_book hack. + + * lily/score.cc (book_rendering): New method. + (default_rendering): Create Paper_book helper locally, dump + output. + + * lily/my-lily-lexer.cc (the_key_tab): Add book. + + * lily/parser.yy: Handle \book. + + * lily/include/book.hh: + * lily/book.cc: New file. + 2004-04-10 Han-Wen Nienhuys * lily/text-item.cc (interpret_string): new file, select font with diff --git a/lily/book.cc b/lily/book.cc new file mode 100644 index 0000000000..f539374cbf --- /dev/null +++ b/lily/book.cc @@ -0,0 +1,97 @@ +/* + book.cc -- implement Book + + source file of the GNU LilyPond music typesetter + + (c) 1997--2004 Han-Wen Nienhuys +*/ + +#include + +#include "ly-smobs.icc" + +#include "book.hh" +#include "global-context.hh" +#include "ly-module.hh" +#include "input-file-results.hh" +#include "main.hh" +#include "music-iterator.hh" +#include "music-output-def.hh" +#include "music-output.hh" +#include "music.hh" +#include "paper-book.hh" +#include "paper-def.hh" +#include "score.hh" +#include "warn.hh" + +Book::Book () + : Input () +{ + header_ = SCM_EOL; + smobify_self (); +} + +#if 0 +Book::Book (Book const &src) + : Input (src) +{ + header_ = SCM_EOL; + smobify_self (); + + int score_count = src.scores_.size (); + for (int i = 0; i < score_count; i++) + scores_.push (src.scores_[i]->clone ()); + +#if 0 + header_ = ly_make_anonymous_module (); + if (is_module (src.header_)) + ly_import_module (header_, src.header_); +#endif +} +#endif + +Book::~Book () +{ +} + +IMPLEMENT_SMOBS (Book); +IMPLEMENT_DEFAULT_EQUAL_P (Book); + +SCM +Book::mark_smob (SCM s) +{ + Book *book = (Book*) SCM_CELL_WORD_1 (s); + int score_count = book->scores_.size (); + for (int i = 0; i < score_count; i++) + scm_gc_mark (book->scores_[i]->self_scm ()); + return book->header_; +} + +int +Book::print_smob (SCM, SCM p, scm_print_state*) +{ + scm_puts ("#", p); + return 1; +} + +void +Book::process (String outname, Music_output_def *default_def, SCM header) +{ + Paper_book *paper_book = new Paper_book (); + int score_count = scores_.size (); + for (int i = 0; i < score_count; i++) + { + Paper_def *paper = 0; + SCM systems = scores_[i]->book_rendering (outname, default_def, &paper); + if (systems != SCM_UNDEFINED) + { + if (paper) + paper_book->papers_.push (paper); + paper_book->scores_.push (systems); + paper_book->global_headers_.push (global_input_file->header_); + paper_book->headers_.push (scores_[i]->header_); + } + } + paper_book->output (outname); + scm_gc_unprotect_object (paper_book->self_scm ()); +} diff --git a/lily/include/book.hh b/lily/include/book.hh new file mode 100644 index 0000000000..7ffeec5888 --- /dev/null +++ b/lily/include/book.hh @@ -0,0 +1,32 @@ +/* + book.hh -- declare Book + + source file of the GNU LilyPond music typesetter + + (c) 1997--2004 Han-Wen Nienhuys +*/ + +#ifndef BOOK_HH +#define BOOK_HH + +#include "input.hh" +#include "lily-proto.hh" + +#include "parray.hh" +#include "smobs.hh" + +class Book : public Input +{ + DECLARE_SMOBS (Book, foo); + +public: + SCM header_; + Link_array scores_; + + Book (); + Book (Book const&); + void process (String outname, Music_output_def*, SCM header); +}; +DECLARE_UNSMOB (Book,book); + +#endif /* BOOK_HH */ diff --git a/lily/include/context-def.hh b/lily/include/context-def.hh index 3760c044a6..01484666a6 100644 --- a/lily/include/context-def.hh +++ b/lily/include/context-def.hh @@ -7,8 +7,8 @@ */ -#ifndef TRANSLATOR_DEF_HH -#define TRANSLATOR_DEF_HH +#ifndef CONTEXT_DEF_HH +#define CONTEXT_DEF_HH #include "lily-proto.hh" #include "smobs.hh" @@ -36,27 +36,28 @@ public: void add_context_mod (SCM); SCM default_child_context_name (); SCM get_context_name () const; - SCM get_accepted (SCM) const; - SCM get_property_ops () const { return property_ops_; } + SCM get_accepted (SCM) const; + SCM get_property_ops () const { return property_ops_; } SCM get_translator_names (SCM) const; void set_acceptor (SCM accepts, bool add); - Link_array path_to_acceptable_context (SCM type_string, Music_output_def* odef) const; + Link_array path_to_acceptable_context (SCM type_string, + Music_output_def*) const; Context * instantiate (SCM extra_ops); SCM to_alist () const; - static SCM make_scm () ; + static SCM make_scm (); + + SCM clone_scm () const; + void apply_default_property_operations (Context*); - SCM clone_scm ()const; - void apply_default_property_operations (Context *); private: - DECLARE_SMOBS (Context_def,foo); + DECLARE_SMOBS (Context_def, foo); Context_def (); Context_def (Context_def const&); }; -DECLARE_UNSMOB(Context_def,context_def); - +DECLARE_UNSMOB (Context_def, context_def); -#endif /* TRANSLATOR_DEF_HH */ +#endif /* CONTEXT_DEF_HH */ diff --git a/lily/include/input-file-results.hh b/lily/include/input-file-results.hh index 08d7192417..610ff422a6 100644 --- a/lily/include/input-file-results.hh +++ b/lily/include/input-file-results.hh @@ -23,6 +23,7 @@ public: Array target_strings_; Protected_scm header_; + int book_count_; int score_count_; void do_deps (String); diff --git a/lily/include/lily-proto.hh b/lily/include/lily-proto.hh index b8181cdf58..0e1dc356c1 100644 --- a/lily/include/lily-proto.hh +++ b/lily/include/lily-proto.hh @@ -36,6 +36,7 @@ class Bar_req_collect_engraver; class Beaming_info_list; class Bezier; class Bezier_bow; +class Book; class Break_algorithm; class Change_iterator; class Change_translator; diff --git a/lily/include/main.hh b/lily/include/main.hh index b923465bd1..5465c3cfd9 100644 --- a/lily/include/main.hh +++ b/lily/include/main.hh @@ -45,6 +45,4 @@ extern int exit_status_global; extern File_path global_path; extern int score_count_global; -extern Paper_book *paper_book; - #endif /* MAIN_HH */ diff --git a/lily/include/music-output-def.hh b/lily/include/music-output-def.hh index fd32745452..4bde0d6e8d 100644 --- a/lily/include/music-output-def.hh +++ b/lily/include/music-output-def.hh @@ -6,9 +6,8 @@ (c) 1997--2004 Han-Wen Nienhuys */ - -#ifndef Music_output_DEF_HH -#define Music_output_DEF_HH +#ifndef MUSIC_OUTPUT_DEF_HH +#define MUSIC_OUTPUT_DEF_HH #include "string.hh" #include "lily-proto.hh" @@ -44,5 +43,6 @@ public: DECLARE_SMOBS (Music_output_def,); }; -DECLARE_UNSMOB(Music_output_def,music_output_def); -#endif // Music_output_DEF_HH +DECLARE_UNSMOB (Music_output_def, music_output_def); + +#endif /* MUSIC_OUTPUT_DEF_HH */ diff --git a/lily/include/score.hh b/lily/include/score.hh index 38e4b3aaf5..2c9858948e 100644 --- a/lily/include/score.hh +++ b/lily/include/score.hh @@ -9,14 +9,17 @@ #ifndef SCORE_HH #define SCORE_HH -#include "input.hh" #include "lily-proto.hh" +#include "input.hh" #include "parray.hh" #include "smobs.hh" +#include "virtual-methods.hh" class Score : public Input { + DECLARE_SMOBS (Score, foo); + public: Link_array defs_; SCM music_; @@ -24,13 +27,12 @@ public: Score (); Score (Score const&); - DECLARE_SMOBS (Score,foo); + SCM book_rendering (String, Music_output_def*, Paper_def**); }; -DECLARE_UNSMOB (Score,score); - +DECLARE_UNSMOB (Score, score); SCM ly_run_translator (SCM, SCM); SCM ly_render_output (SCM, SCM); -void default_rendering (SCM,SCM,SCM,SCM); +void default_rendering (SCM, SCM, SCM, SCM); #endif /* SCORE_HH */ diff --git a/lily/input-file-results.cc b/lily/input-file-results.cc index bd45322c03..d29420140f 100644 --- a/lily/input-file-results.cc +++ b/lily/input-file-results.cc @@ -32,8 +32,6 @@ #include "scm-hash.hh" #include "ly-module.hh" -#include "paper-book.hh" - bool store_locations_global_b; /* @@ -127,18 +125,17 @@ Input_file_results::~Input_file_results () ly_clear_anonymous_modules (); } - - Input_file_results* global_input_file; -Input_file_results::Input_file_results (String init, String in_file, String out_file) +Input_file_results::Input_file_results (String init, + String in_file, String out_file) { header_ = ly_make_anonymous_module (); global_input_file = this; + book_count_ = 0; score_count_ = 0; sources_.set_path (&global_path); - progress_indication (_f ("Now processing `%s'", in_file.to_str0 ())); progress_indication ("\n"); @@ -150,7 +147,6 @@ Input_file_results::Input_file_results (String init, String in_file, String out_ exit_status_global = 1; failed_files.push (in_file); } - do_deps (out_file); } @@ -225,11 +221,5 @@ do_one_file (char const *file) return; } - paper_book = new Paper_book ();; Input_file_results inp_file (init, in_file, out_file); - if (output_format_global == PAGE_LAYOUT) - paper_book->output (out_file); - - scm_gc_unprotect_object (paper_book->self_scm ()); - paper_book = 0; } diff --git a/lily/my-lily-lexer.cc b/lily/my-lily-lexer.cc index 9cd0942a1e..6a4016e35c 100644 --- a/lily/my-lily-lexer.cc +++ b/lily/my-lily-lexer.cc @@ -38,6 +38,7 @@ static Keyword_ent the_key_tab[] = { {"appoggiatura", APPOGGIATURA}, {"autochange", AUTOCHANGE}, {"bar", BAR}, + {"book", BOOK}, {"breathe", BREATHE}, {"change", CHANGE}, {"chords", CHORDS}, diff --git a/lily/paper-book.cc b/lily/paper-book.cc index c552f51d33..1a844ab7e6 100644 --- a/lily/paper-book.cc +++ b/lily/paper-book.cc @@ -190,10 +190,6 @@ Page::text_height () /****************************************************************/ -/* Current global paper book. Gives default_rendering access from - input-file-results. */ -Paper_book *paper_book; - Paper_book::Paper_book () { copyright_ = SCM_EOL; @@ -288,8 +284,8 @@ Stencil* Paper_book::title (int i) { SCM user_title = ly_scheme_function ("user-title"); - SCM book_title = ly_scheme_function ("book-title"); - SCM score_title = ly_scheme_function ("score-title"); + SCM book_title = ly_scheme_function ("book-title"); + SCM score_title = ly_scheme_function ("score-title"); SCM field = (i == 0 ? ly_symbol2scm ("bookTitle") : ly_symbol2scm ("scoreTitle")); diff --git a/lily/parser.yy b/lily/parser.yy index 528c4549fe..aaad718b35 100644 --- a/lily/parser.yy +++ b/lily/parser.yy @@ -25,30 +25,31 @@ TODO: #include -#include "scm-option.hh" +#include "book.hh" #include "context-def.hh" -#include "lily-guile.hh" -#include "misc.hh" -#include "my-lily-lexer.hh" -#include "paper-def.hh" -#include "midi-def.hh" -#include "main.hh" -#include "file-path.hh" -#include "warn.hh" #include "dimensions.hh" -#include "my-lily-parser.hh" -#include "score.hh" +#include "event.hh" +#include "file-path.hh" #include "input-file-results.hh" +#include "input-smob.hh" #include "input.hh" +#include "lily-guile.hh" #include "lilypond-input-version.hh" -#include "scm-hash.hh" #include "ly-module.hh" -#include "music-sequence.hh" -#include "input-smob.hh" -#include "event.hh" -#include "text-item.hh" +#include "main.hh" +#include "midi-def.hh" +#include "misc.hh" #include "music-list.hh" +#include "music-sequence.hh" +#include "my-lily-lexer.hh" +#include "my-lily-parser.hh" #include "paper-book.hh" +#include "paper-def.hh" +#include "scm-hash.hh" +#include "scm-option.hh" +#include "score.hh" +#include "text-item.hh" +#include "warn.hh" #define MY_MAKE_MUSIC(x) make_music_by_name (ly_symbol2scm (x)) @@ -107,16 +108,11 @@ make_simple_markup (SCM encoding, SCM a) { SCM simple = ly_scheme_function ("simple-markup"); if (is_symbol (encoding)) - { return scm_list_3 (ly_scheme_function ("encoded-simple-markup"), encoding, a); - } else - return scm_list_2 (simple, a); - - return markup; + return scm_list_2 (simple, a); } - bool is_duration (int t) { @@ -177,12 +173,13 @@ of the parse stack onto the heap. */ %union { + Book *book; + Music_output_def *outputdef; + SCM scm; String *string; - Music *music; - Score *score; - Music_output_def *outputdef; - SCM scm; - int i; + Music *music; + Score *score; + int i; } %{ @@ -248,6 +245,7 @@ or %token APPLYOUTPUT %token AUTOCHANGE %token BAR +%token BOOK %token BREATHE %token CHANGE %token CHORDMODIFIERS @@ -315,6 +313,7 @@ or %token CHORD_BASS CHORD_COLON CHORD_MINUS CHORD_CARET CHORD_SLASH %token FIGURE_SPACE +%type book_block book_body %type exclamations questions dots optional_rest %type bass_mod %type grace_head @@ -427,23 +426,37 @@ toplevel_expression: } | add_quote { } + | book_block { + Book *book = $1; + SCM header = THIS->input_file_->header_.to_SCM (); + Path outname = split_path (THIS->output_basename_); + int *c = &THIS->input_file_->book_count_; + if (*c) + outname.base += "-" + to_string (*c); + (*c)++; + Music_output_def *dp = unsmob_music_output_def + (THIS->lexer_->lookup_identifier ("$defaultpaper")); + book->process (outname.to_string (), + dp ? dp->clone () : new Paper_def, header); + scm_gc_unprotect_object (book->self_scm ()); + } | score_block { Score *sc = $1; - - SCM head = is_module (sc->header_) ? sc->header_ : THIS->input_file_->header_.to_SCM (); + SCM head = is_module (sc->header_) ? sc->header_ + : THIS->input_file_->header_.to_SCM (); Path p = split_path (THIS->output_basename_); int *c = &THIS->input_file_->score_count_; if (*c) - { p.base += "-" + to_string (*c); - } (*c)++; SCM outname = scm_makfrom0str (p.to_string ().to_str0()); for (int i = 0; i < sc->defs_.size (); i++) - default_rendering (sc->music_, sc->defs_[i]->self_scm (), head, outname); + default_rendering (sc->music_, + sc->defs_[i]->self_scm (), head, + outname); if (sc->defs_.is_empty ()) { @@ -592,9 +605,29 @@ context_def_spec_body: } ; -/* - SCORE -*/ +book_block: + BOOK { + THIS->push_spot (); + } + /*cont*/ '{' book_body '}' { + THIS->pop_spot (); + $$ = $4; + } + ; + +book_body: + { + $$ = new Book; + $$->set_spot (THIS->here_input ()); + } + | book_body score_block { + $$->scores_.push ($2); + scm_gc_unprotect_object ($2->self_scm ()); + } + | book_body error { + } + ; + score_block: SCORE { THIS->push_spot (); @@ -602,7 +635,6 @@ score_block: /*cont*/ '{' score_body '}' { THIS->pop_spot (); $$ = $4; - } ; diff --git a/lily/score.cc b/lily/score.cc index 81f8576f0b..e81210c996 100644 --- a/lily/score.cc +++ b/lily/score.cc @@ -35,32 +35,24 @@ Score::Score () { header_ = SCM_EOL; music_ = SCM_EOL; - smobify_self (); } Score::~Score () { - } - - - IMPLEMENT_SMOBS (Score); IMPLEMENT_DEFAULT_EQUAL_P (Score); - SCM Score::mark_smob (SCM s) { - Score * sc = (Score*) SCM_CELL_WORD_1 (s); - + Score *sc = (Score*) SCM_CELL_WORD_1 (s); if (sc->header_) scm_gc_mark (sc->header_); for (int i = sc->defs_.size (); i--;) scm_gc_mark (sc->defs_[i]->self_scm ()); - return sc->music_; } @@ -83,7 +75,10 @@ Score::Score (Score const &s) : Input (s) { music_ = SCM_EOL; + + // FIXME: SCM_EOL? header_ = 0; + smobify_self (); Music * m =unsmob_music (s.music_); @@ -175,15 +170,43 @@ default_rendering (SCM music, SCM outdef, SCM header, SCM outname) Music_output *output = g->get_output (); if (systems != SCM_UNDEFINED) { + Paper_book *paper_book = new Paper_book (); Paper_score *ps = dynamic_cast (output); - paper_book->papers_.push (ps->paper_); paper_book->scores_.push (systems); paper_book->global_headers_.push (global_input_file->header_); paper_book->headers_.push (header); - if (output_format_global != PAGE_LAYOUT) - paper_book->classic_output (ly_scm2string (outname)); + paper_book->classic_output (ly_scm2string (outname)); + scm_gc_unprotect_object (paper_book->self_scm ()); } delete output; } } + +SCM +Score::book_rendering (String outname, Music_output_def *default_def, + Paper_def **paper) +{ + 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++) + { + Music_output_def *def = outdef_count ? defs_[i] : default_def; + SCM context = ly_run_translator (music_, def->self_scm ()); + if (Global_context *g = 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_; + } + } + } + return systems; +} -- 2.39.2