From: Jan Nieuwenhuizen Date: Tue, 9 Mar 2004 20:37:44 +0000 (+0000) Subject: * lily/include/music-output.hh (process): Change signature to X-Git-Tag: release/2.1.30~20 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=1b401824fa6fa77ba5ba52cc9b1735a9aa43eb20;p=lilypond.git * lily/include/music-output.hh (process): Change signature to return SCM. * lily/paper-book.cc (classic_output, get_title, get_scopes): New method. * lily/paper-score.cc (process): Return stencils rather than outputting directly. Remove paper-book kludge. Delete grobs. (output): Remove. * lily/include/paper-score.hh (class Paper_score): Remove outputter_. * lily/score-engraver.cc (get_output): Do not reset pscore_. * lily/score.cc (default_rendering) (ly_render_output): Move adding paper-score two levels up. --- diff --git a/ChangeLog b/ChangeLog index e786ed7051..05b08bc7e1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,25 @@ +2004-03-09 Jan Nieuwenhuizen + + * lily/include/music-output.hh (process): Change signature to + return SCM. + + * lily/paper-book.cc (classic_output, get_title, get_scopes): New + method. + + * lily/paper-score.cc (process): Return stencils rather than + outputting directly. Remove paper-book kludge. Delete grobs. + (output): Remove. + + * lily/include/paper-score.hh (class Paper_score): Remove outputter_. + + * lily/score-engraver.cc (get_output): Do not reset pscore_. + + * lily/score.cc (default_rendering) + (ly_render_output): Move adding paper-score two levels up. + + * lily/system.cc (get_line): + * lily/paper-outputter.cc (output_line): Fix `between-system-string'. + 2004-03-09 Han-Wen Nienhuys * scm/font.scm (paper20-font-vector): add more design sizes for @@ -9,11 +31,6 @@ * scm/font.scm (paper20-font-vector): bugfix: use din12, not 10 for 12pt design size. -2004-03-09 Jan Nieuwenhuizen - - * lily/system.cc (get_line): - * lily/paper-outputter.cc (output_line): Fix `between-system-string'. - 2004-03-09 Han-Wen Nienhuys * ly/engraver-init.ly: don't remove slur engraver from DrumVoice. diff --git a/lily/include/lily-proto.hh b/lily/include/lily-proto.hh index 493b5ef46d..017271de13 100644 --- a/lily/include/lily-proto.hh +++ b/lily/include/lily-proto.hh @@ -105,6 +105,7 @@ class Music_output_def; class Music_sequence; class Music_wrapper; class Music_wrapper_iterator; +class Page; class Pitch; class My_lily_lexer; class Note_performer; diff --git a/lily/include/music-output.hh b/lily/include/music-output.hh index d1423852b1..1bee38d812 100644 --- a/lily/include/music-output.hh +++ b/lily/include/music-output.hh @@ -7,26 +7,18 @@ */ -#ifndef Music_output_HH -#define Music_output_HH +#ifndef MUSIC_OUTPUT_HH +#define MUSIC_OUTPUT_HH #include "string.hh" #include "lily-proto.hh" #include "protected-scm.hh" -/** - Output something that was defined in a lilypond file. - */ class Music_output { public: - Protected_scm header_; - - virtual void process (String) {} - virtual ~Music_output (){} - Music_output () - { - } - + virtual SCM process (String) {return SCM_EOL;} + virtual ~Music_output () {} }; -#endif // Music_output_HH + +#endif /* MUSIC_OUTPUT_HH */ diff --git a/lily/include/paper-book.hh b/lily/include/paper-book.hh index 42945d5434..3c2dd05f67 100644 --- a/lily/include/paper-book.hh +++ b/lily/include/paper-book.hh @@ -9,19 +9,25 @@ #ifndef PAPER_BOOK_HH #define PAPER_BOOK_HH -//#define PAGE_LAYOUT 1 +// #define PAGE_LAYOUT 1 +#include "lily-guile.hh" #include "parray.hh" -class Page; +#include "protected-scm.hh" class Paper_book { public: - Link_array paper_scores_; - Paper_book (); + Array headers_; + Link_array papers_; + Array scores_; + Paper_book (); Link_array *get_pages (); - void output (); + SCM get_scopes (int); + Stencil* get_title (int); + void output (String); + void classic_output (String); }; #endif /* PAPER_BOOK_HH */ diff --git a/lily/include/paper-score.hh b/lily/include/paper-score.hh index 6ef31f4796..f6db4de575 100644 --- a/lily/include/paper-score.hh +++ b/lily/include/paper-score.hh @@ -6,9 +6,8 @@ (c) 1996--2004 Han-Wen Nienhuys */ - -#ifndef P_SCORE_HH -#define P_SCORE_HH +#ifndef PAPER_SCORE_HH +#define PAPER_SCORE_HH #include "column-x-positions.hh" #include "parray.hh" @@ -17,48 +16,31 @@ #include "lily-guile.hh" #include "protected-scm.hh" -/** all stuff which goes onto paper. notes, signs, symbols in a score - #Paper_score# contains the items, the columns. - - */ +/* PAPER output */ class Paper_score : public Music_output { - Protected_scm main_smob_; public: Paper_def *paper_; - - /* Vector with lines of stencils. */ - Protected_scm lines_; - Stencil *book_title_; - Stencil *score_title_; - - Paper_outputter *outputter_; System *system_; Paper_score (); - /** - @return index of argument. - */ int find_col_idx (Paper_column const *) const; - - Link_array broken_col_range (Item const*,Item const*) const; + Link_array broken_col_range (Item const*, Item const*) const; void typeset_line (System*); void output (); protected: - /* MAIN ROUTINES */ - virtual void process (String); + virtual SCM process (String); + private: - /// before calc_breaking + Protected_scm score_; + void preprocess (); void calc_idealspacing (); - /// calculate where the lines are to be broken, and use results Array calc_breaking (); - - /// after calc_breaking void postprocess (); Paper_score (Paper_score const &); }; -#endif +#endif /* PAPER_SCORE_HH */ diff --git a/lily/include/performance.hh b/lily/include/performance.hh index 8b29187aab..907b1ec998 100644 --- a/lily/include/performance.hh +++ b/lily/include/performance.hh @@ -12,11 +12,9 @@ #include "cons.hh" #include "music-output.hh" -/** all stuff which goes onto midi. notes, signs, symbols in a score - #Performance# contains the items, the columns. - */ - -class Performance : public Music_output { +/* MIDI output. */ +class Performance : public Music_output +{ public: Performance (); ~Performance (); @@ -27,11 +25,11 @@ public: void output_header_track (Midi_stream& midi_stream_r); void print () const; - void process (String); + SCM process (String); Link_array audio_staffs_; Cons *audio_elem_p_list_; - Midi_def * midi_; + Midi_def *midi_; }; -#endif // PERFORMANCE_HH +#endif /* PERFORMANCE_HH */ diff --git a/lily/include/score.hh b/lily/include/score.hh index 4a03be6932..38e4b3aaf5 100644 --- a/lily/include/score.hh +++ b/lily/include/score.hh @@ -6,7 +6,6 @@ (c) 1997--2004 Han-Wen Nienhuys */ - #ifndef SCORE_HH #define SCORE_HH @@ -26,12 +25,12 @@ public: Score (); Score (Score const&); DECLARE_SMOBS (Score,foo); -private: }; -DECLARE_UNSMOB(Score,score); +DECLARE_UNSMOB (Score,score); SCM ly_run_translator (SCM, SCM); -SCM ly_render_output (SCM, SCM, SCM); +SCM ly_render_output (SCM, SCM); void default_rendering (SCM,SCM,SCM,SCM); -#endif + +#endif /* SCORE_HH */ diff --git a/lily/input-file-results.cc b/lily/input-file-results.cc index a70ed99376..6c446f881d 100644 --- a/lily/input-file-results.cc +++ b/lily/input-file-results.cc @@ -226,16 +226,14 @@ do_one_file (char const *file) return; } - static SCM proc; + static SCM proc; if (!proc) proc = scm_c_eval_string ("dump-gc-protects"); -#ifdef PAGE_LAYOUT Paper_book book; paper_book = &book; -#endif Input_file_results inp_file (init, in_file, out_file); #ifdef PAGE_LAYOUT - book.output (); + book.output (out_file); #endif } diff --git a/lily/paper-book.cc b/lily/paper-book.cc index eaeaf4a27e..0aa137a6b7 100644 --- a/lily/paper-book.cc +++ b/lily/paper-book.cc @@ -8,16 +8,15 @@ #include +#include "input-file-results.hh" +#include "ly-module.hh" #include "main.hh" #include "paper-book.hh" -#include "paper-score.hh" #include "paper-def.hh" -#include "stencil.hh" #include "paper-outputter.hh" +#include "paper-score.hh" +#include "stencil.hh" -// -- this simply adds one Page per \score -// #define ONE_SCORE_PER_PAGE - // WIP -- simplistic page interface // Do we need this at all? SCM, smob? class Page @@ -62,19 +61,12 @@ Page::Page (Paper_def *paper) void Page::output (Paper_outputter *out, bool is_last) { -#if ONE_SCORE_PER_PAGE - int line_count = SCM_VECTOR_LENGTH ((SCM) lines_); - for (int i = 0; i < line_count; i++) - out->output_line (scm_vector_ref (lines_, scm_int2num (i)), - is_last && i == line_count - 1); -#else // TODO: header/footer etc out->output_scheme (scm_list_1 (ly_symbol2scm ("start-page"))); for (SCM s = lines_; gh_pair_p (s); s = ly_cdr (s)) out->output_line (ly_car (s), is_last && gh_pair_p (ly_cdr (s))); out->output_scheme (scm_list_2 (ly_symbol2scm ("stop-page"), gh_bool2scm (is_last))); -#endif } Real @@ -96,16 +88,12 @@ Paper_book::Paper_book () } void -Paper_book::output () +Paper_book::output (String outname) { - Paper_outputter *out = paper_scores_[0]->outputter_; - - Paper_def *paper = paper_scores_[0]->paper_; - out->output_header (paper); - - if (paper_scores_[0]->book_title_) - out->output_expr (paper_scores_[0]->book_title_->get_expr (), - Offset (0, 0)); + Paper_outputter *out = papers_.top ()->get_paper_outputter (outname); + + out->output_metadata (get_scopes (0), papers_.top ()); + out->output_header (papers_.top ()); Link_array *pages = get_pages (); int page_count = pages->size (); @@ -116,6 +104,32 @@ Paper_book::output () progress_indication ("\n"); } +SCM +Paper_book::get_scopes (int i) +{ + SCM scopes = SCM_EOL; + if (headers_[i]) + scopes = scm_cons (headers_[i], scopes); + if (global_input_file->header_ && global_input_file->header_ != headers_[i]) + scopes = scm_cons (global_input_file->header_, scopes); + return scopes; +} + +Stencil* +Paper_book::get_title (int i) +{ + SCM make_title = scm_primitive_eval (ly_symbol2scm ("make-title")); + SCM field = (i == 0 ? ly_symbol2scm ("bookTitle") + : ly_symbol2scm ("scoreTitle")); + + SCM s = ly_modules_lookup (get_scopes (i), field); + if (s != SCM_UNDEFINED && scm_variable_bound_p (s) == SCM_BOOL_T) + return unsmob_stencil (gh_call2 (make_title, + papers_[i]->self_scm (), + scm_variable_ref (s))); + return 0; +} + /* WIP @@ -133,58 +147,51 @@ Link_array* Paper_book::get_pages () { Link_array *pages = new Link_array; - Paper_def *paper = paper_scores_[0]->paper_; - int score_count = paper_scores_.size (); + int score_count = scores_.size (); /* Calculate the full book height. Hmm, can't we cache system heights while making stencils? */ Real book_height = 0; for (int i = 0; i < score_count; i++) { - Paper_score *pscore = paper_scores_[i]; - Stencil *title = (i == 0 ? pscore->book_title_ : pscore->score_title_); + //SCM lines = scores_[i]; + Stencil *title = get_title (i); if (title) book_height += title->extent (Y_AXIS).length (); - int line_count = SCM_VECTOR_LENGTH ((SCM) pscore->lines_); + int line_count = SCM_VECTOR_LENGTH ((SCM) scores_[i]); for (int j = 0; j < line_count; j++) { - SCM line = scm_vector_ref (pscore->lines_, scm_int2num (j)); + SCM line = scm_vector_ref ((SCM) scores_[i], scm_int2num (j)); book_height += ly_scm2offset (ly_car (line))[Y_AXIS]; } } - Page *page = new Page (paper); + Page *page = new Page (papers_.top ()); fprintf (stderr, "book_height: %f\n", book_height); fprintf (stderr, "vsize: %f\n", page->vsize_); fprintf (stderr, "pages: %f\n", book_height / page->text_height ()); -#if ONE_SCORE_PER_PAGE - for (int i = 0; i < score_count; i++) - { - page->lines_ = paper_scores_[i]->lines_; - pages->push (page); - } -#else /* Simplistic page breaking. */ Real text_height = page->text_height (); for (int i = 0; i < score_count; i++) { - Paper_score *pscore = paper_scores_[i]; - Stencil *title = (i == 0 ? pscore->book_title_ : pscore->score_title_); + Stencil *title = get_title (i); + if (title) + book_height += title->extent (Y_AXIS).length (); Real h = 0; if (title) h = title->extent (Y_AXIS).length (); - int line_count = SCM_VECTOR_LENGTH ((SCM) pscore->lines_); + int line_count = SCM_VECTOR_LENGTH ((SCM) scores_[i]); for (int j = 0; j < line_count; j++) { - SCM line = scm_vector_ref (pscore->lines_, scm_int2num (j)); + SCM line = scm_vector_ref ((SCM) scores_[i], scm_int2num (j)); h += ly_scm2offset (ly_car (line))[Y_AXIS]; if (page->height_ + h > text_height) { pages->push (page); - page = new Page (paper); + page = new Page (papers_.top ()); } if (page->height_ + h <= text_height || page->height_ == 0) { @@ -202,8 +209,25 @@ Paper_book::get_pages () } } } -#endif pages->push (page); return pages; } + +void +Paper_book::classic_output (String outname) +{ + Paper_outputter *out = papers_.top ()->get_paper_outputter (outname); + int count = scores_.size (); + + out->output_metadata (get_scopes (count - 1), papers_.top ()); + out->output_header (papers_.top ()); + + int line_count = SCM_VECTOR_LENGTH ((SCM) scores_.top ()); + for (int i = 0; i < line_count; i++) + out->output_line (scm_vector_ref ((SCM) scores_.top (), scm_int2num (i)), + i == line_count - 1); + + out->output_scheme (scm_list_1 (ly_symbol2scm ("end-output"))); + progress_indication ("\n"); +} diff --git a/lily/paper-score.cc b/lily/paper-score.cc index 9202095e17..92f27355f6 100644 --- a/lily/paper-score.cc +++ b/lily/paper-score.cc @@ -18,7 +18,7 @@ #include "paper-column.hh" #include "scm-hash.hh" #include "gourlay-breaking.hh" -#include "paper-outputter.hh" +//#include "paper-outputter.hh" #include "input-file-results.hh" #include "misc.hh" #include "all-font-metrics.hh" @@ -30,12 +30,8 @@ Paper_score::Paper_score () { paper_ = 0; - outputter_ = 0; system_ = 0; - main_smob_ = SCM_EOL; - lines_ = SCM_EOL; - book_title_ = 0; - score_title_ = 0; + score_ = SCM_EOL; } Paper_score::Paper_score (Paper_score const &s) @@ -44,18 +40,16 @@ Paper_score::Paper_score (Paper_score const &s) assert (false); } - void -Paper_score::typeset_line (System *line) +Paper_score::typeset_line (System *system) { if (!system_) - /* ugh. */ - system_ = line; + system_ = system; - main_smob_ = gh_cons (line->self_scm (), main_smob_); - line->pscore_ = this; + score_ = gh_cons (system->self_scm (), score_); + system->pscore_ = this; - scm_gc_unprotect_object (line->self_scm ()); + scm_gc_unprotect_object (system->self_scm ()); } Array @@ -72,8 +66,8 @@ Paper_score::calc_breaking () return sol; } -void -Paper_score::process (String outname) +SCM +Paper_score::process (String) { if (verbose_global_b) progress_indication (_f ("Element count %d (spanners %d) ", @@ -94,65 +88,11 @@ Paper_score::process (String outname) Array breaking = calc_breaking (); system_->break_into_pieces (breaking); - lines_ = system_->get_lines (); - - // FIXME: ... - outputter_ = paper_->get_paper_outputter (outname); - + SCM lines = system_->get_lines (); progress_indication ("\n"); - SCM scopes = SCM_EOL; - if (header_) - scopes = scm_cons (header_, scopes); - if (global_input_file->header_ && global_input_file->header_ != header_) - scopes = scm_cons (global_input_file->header_, scopes); - - outputter_->output_metadata (scopes, paper_); - -#ifdef PAGE_LAYOUT - SCM make_title = scm_primitive_eval (ly_symbol2scm ("make-title")); - SCM b = ly_modules_lookup (scopes, ly_symbol2scm ("bookTitle")); - if (b != SCM_UNDEFINED && scm_variable_bound_p (b) == SCM_BOOL_T) - book_title_ - = unsmob_stencil (gh_call2 (make_title, paper_->self_scm (), - scm_variable_ref (b))); - - SCM s = ly_modules_lookup (scopes, ly_symbol2scm ("scoreTitle")); - if (s != SCM_UNDEFINED && scm_variable_bound_p (s) == SCM_BOOL_T) - score_title_ - = unsmob_stencil (gh_call2 (make_title, paper_->self_scm (), - scm_variable_ref (s))); - -#if 0 - // FIXME: - delete system_; - system_ = 0; -#endif - - /* Ugh: caller (Score) should do this, but does not know our flavor - (paper or midi). */ - paper_book->paper_scores_.push (this); -#else - output (); -#endif -} - -void -Paper_score::output () -{ - outputter_->output_header (paper_); - - int line_count = SCM_VECTOR_LENGTH ((SCM) lines_); - for (int i = 0; i < line_count; i++) - outputter_->output_line (scm_vector_ref (lines_, scm_int2num (i)), - i == line_count - 1); + /* Only keep result stencils in lines_, *title_; delete all grobs. */ + score_ = SCM_EOL; - outputter_->output_scheme (scm_list_1 (ly_symbol2scm ("end-output"))); - progress_indication ("\n"); - -#if 0 - // huh? - delete outputter_; - outputter_ = 0; -#endif + return lines; } diff --git a/lily/performance.cc b/lily/performance.cc index 5ce6da278f..71a84ddb5a 100644 --- a/lily/performance.cc +++ b/lily/performance.cc @@ -146,8 +146,7 @@ Performance::add_element (Audio_element *p) audio_elem_p_list_ = new Killing_cons (p, audio_elem_p_list_); } - -void +SCM Performance::process (String out) { if (out == "-") @@ -165,4 +164,5 @@ Performance::process (String out) output (midi_stream); progress_indication ("\n"); + return SCM_UNDEFINED; } diff --git a/lily/score-context.cc b/lily/score-context.cc index 0ffef5660e..acabbe813f 100644 --- a/lily/score-context.cc +++ b/lily/score-context.cc @@ -35,12 +35,11 @@ Score_context::one_time_step () s->one_time_step (); } - Music_output* Score_context::get_output () { - Translator* t = unsmob_translator (implementation_); - Score_translator * s = dynamic_cast (t); + Translator *t = unsmob_translator (implementation_); + Score_translator *s = dynamic_cast (t); return s->get_output (); } diff --git a/lily/score-engraver.cc b/lily/score-engraver.cc index 5eef0cb6ee..6fd90611cb 100644 --- a/lily/score-engraver.cc +++ b/lily/score-engraver.cc @@ -253,12 +253,11 @@ Score_engraver::set_columns (Paper_column *new_command, Music_output* Score_engraver::get_output () { - Music_output * o = pscore_; - pscore_=0; + Music_output *o = pscore_; + ///FIXME WTF? pscore_ = 0; return o; } - bool Score_engraver::try_music (Music*r) { diff --git a/lily/score.cc b/lily/score.cc index 0f3c924df1..ae9c81f647 100644 --- a/lily/score.cc +++ b/lily/score.cc @@ -22,8 +22,8 @@ #include "main.hh" #include "paper-def.hh" #include "ly-module.hh" - #include "paper-book.hh" +#include "paper-score.hh" /* @@ -146,36 +146,42 @@ LY_DEFINE (ly_run_translator, "ly:run-translator", return scm_gc_unprotect_object (trans->self_scm ()); } - +// FIXME: silly name, score/music is rendered, not the output -- render midi? LY_DEFINE (ly_render_output, "ly:render-output", - 3, 0, 0, (SCM context, SCM header, SCM out_filename), - "Given a Score context in its final state, calculate the output, " - "and dump the result to @var{out-filename}, using " - "@var{header} for the bibliographic information.") + 2, 0, 0, (SCM context, SCM outname), + "Given a Score context in its final state," + "process it and return the (rendered) result.") { - Global_context * gt = dynamic_cast (unsmob_context (context)); - - SCM_ASSERT_TYPE (gt, context, SCM_ARG1, __FUNCTION__, "Global context"); - SCM_ASSERT_TYPE (ly_module_p (header), header, SCM_ARG2, __FUNCTION__, "module"); - SCM_ASSERT_TYPE (gh_string_p (out_filename), out_filename, SCM_ARG3, __FUNCTION__, "output filename"); + Global_context *g = dynamic_cast (unsmob_context (context)); + SCM_ASSERT_TYPE (g, context, SCM_ARG1, __FUNCTION__, "Global context"); + SCM_ASSERT_TYPE (gh_string_p (outname), outname, SCM_ARG2, __FUNCTION__, "output filename"); - Music_output *output = gt->get_output (); - output->header_ = header; + Music_output *output = g->get_output (); progress_indication ("\n"); - output->process (ly_scm2string (out_filename)); - -#ifndef PAGE_LAYOUT - delete output; -#endif - - return SCM_UNDEFINED; + // ugh, midi still wants outname + return output->process (ly_scm2string (outname)); } void -default_rendering (SCM mus, SCM outdef, SCM head, SCM outname) +default_rendering (SCM music, SCM outdef, SCM header, SCM outname) { - SCM context = ly_run_translator (mus, outdef); - - if (unsmob_context (context)) - ly_render_output (context, head, outname); + SCM context = ly_run_translator (music, outdef); + + if (Global_context *g = dynamic_cast + (unsmob_context (context))) + { + SCM systems = ly_render_output (context, outname); + Music_output *output = g->get_output (); + if (systems != SCM_UNDEFINED) + { + paper_book->scores_.push (systems); + paper_book->headers_.push (header); + Paper_score *ps = dynamic_cast (output); + paper_book->papers_.push (ps->paper_); +#ifndef PAGE_LAYOUT + paper_book->classic_output (ly_scm2string (outname)); +#endif + } + delete output; + } }