X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fscore-engraver.cc;h=b361d03fc15770783150b03c11b446932054c8ca;hb=21a1e3b8267fd76ff261ed9f01e833d5d04703e7;hp=5f39102e276c38366a44efbf9bcc1fa7cd5f9b0f;hpb=0119396bf047bbc0a6debd06f48e6d18573e2303;p=lilypond.git diff --git a/lily/score-engraver.cc b/lily/score-engraver.cc index 5f39102e27..b361d03fc1 100644 --- a/lily/score-engraver.cc +++ b/lily/score-engraver.cc @@ -1,294 +1,207 @@ /* - score-engraver.cc -- implement Score_engraver + This file is part of LilyPond, the GNU music typesetter. - source file of the GNU LilyPond music typesetter + Copyright (C) 1997--2014 Han-Wen Nienhuys - (c) 1997--2001 Han-Wen Nienhuys -*/ + LilyPond is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + LilyPond is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -#include "debug.hh" + You should have received a copy of the GNU General Public License + along with LilyPond. If not, see . +*/ -#include "line-of-score.hh" -#include "item.hh" #include "score-engraver.hh" -#include "paper-score.hh" -#include "paper-column.hh" -#include "command-request.hh" -#include "paper-def.hh" -#include "axis-group-interface.hh" -#include "translator-def.hh" +#include "all-font-metrics.hh" +#include "axis-group-interface.hh" +#include "context-def.hh" +#include "dispatcher.hh" +#include "global-context.hh" +#include "international.hh" +#include "main.hh" +#include "open-type-font.hh" +#include "output-def.hh" +#include "paper-column-engraver.hh" +#include "paper-column.hh" +#include "paper-score.hh" +#include "system.hh" +#include "warn.hh" -Score_engraver::Score_engraver() +Score_engraver::Score_engraver () { - scoreline_l_ =0; - command_column_l_ =0; - musical_column_l_ =0; - breaks_i_ =0; - pscore_p_ = 0; + system_ = 0; + pscore_ = 0; } void -Score_engraver::make_columns (Moment w) +Score_engraver::derived_mark () const { - /* - ugh. - */ - if (!command_column_l_ - || *unsmob_moment (command_column_l_->get_grob_property ("when")) != w) - { - set_columns (new Paper_column (get_property (ly_symbol2scm ("NonMusicalPaperColumn"))), - new Paper_column (get_property (ly_symbol2scm ("PaperColumn")))); - - command_column_l_->set_grob_property ("when", w.smobbed_copy()); - musical_column_l_->set_grob_property ("when", w.smobbed_copy()); - command_column_l_->set_grob_property ("breakable", SCM_BOOL_T); - - Grob_info i1(command_column_l_, 0), i2 (musical_column_l_,0); - - i1.origin_trans_l_ = this; - i2.origin_trans_l_ = this; - announce_grob (i1); - announce_grob (i2); - } + if (pscore_) + scm_gc_mark (pscore_->self_scm ()); + Engraver_group::derived_mark (); } +IMPLEMENT_LISTENER (Score_engraver, prepare); void -Score_engraver::prepare (Moment w) +Score_engraver::prepare (SCM) { - Global_translator::prepare (w); - make_columns (w); - - post_move_processing(); + precomputed_recurse_over_translators (context (), START_TRANSLATION_TIMESTEP, DOWN); } +IMPLEMENT_LISTENER (Score_engraver, finish); void -Score_engraver::finish() +Score_engraver::finish (SCM) { - if ((breaks_i_%8)) - progress_indication ("[" + to_str ( breaks_i_) + "]"); - - check_removal(); - removal_processing(); + recurse_over_translators (context (), &Translator::finalize, + &Translator_group::finalize, + UP); } +#define MUSIC_FONT "emmentaler-20" + /* use start/finish? - */ +*/ void Score_engraver::initialize () { - unsmob_translator_def (definition_)->apply_property_operations (this); - - assert (dynamic_cast (output_def_l_)); - assert (!daddy_trans_l_); - pscore_p_ = new Paper_score; - pscore_p_->paper_l_ = dynamic_cast(output_def_l_); - - SCM props = get_property (ly_symbol2scm ("LineOfScore")); - - pscore_p_->typeset_line (new Line_of_score (props)); - - make_columns (Moment (0)); - scoreline_l_ = pscore_p_->line_l_; + Font_metric *fm = all_fonts_global->find_otf (MUSIC_FONT); + if (!fm) + { + error (_f ("cannot find `%s'", MUSIC_FONT ".otf") + + "\n" + + _ ("Music font has not been installed properly.") + + "\n" + + _f ("Search path `%s'", global_path.to_string ().c_str ()) + + "\n" + + _ ("Aborting")); + } - scoreline_l_->set_bound(LEFT, command_column_l_); - - command_column_l_->set_grob_property ("breakable", SCM_BOOL_T); + pscore_ = new Paper_score (dynamic_cast (context ()->get_output_def ())); + pscore_->unprotect (); + context ()->set_property ("output", pscore_->self_scm ()); - Engraver_group_engraver::initialize(); -} + SCM props = updated_grob_properties (context (), ly_symbol2scm ("System")); + pscore_->typeset_system (new System (props)); -void -Score_engraver::finalize() -{ - Engraver_group_engraver::finalize(); - scoreline_l_->set_bound(RIGHT,command_column_l_); - command_column_l_->set_grob_property ("breakable", SCM_BOOL_T); - - typeset_all (); + system_ = pscore_->root_system (); + context ()->set_property ("rootSystem", system_->self_scm ()); - set_columns (0,0); + Engraver_group::initialize (); } void -Score_engraver::one_time_step() +Score_engraver::connect_to_context (Context *c) { - process_music(); - announces(); - pre_move_processing(); - check_removal(); -} + Engraver_group::connect_to_context (c); -void -Score_engraver::announce_grob (Grob_info info) -{ - announce_info_arr_.push (info); - pscore_p_->line_l_->typeset_grob (info.elem_l_); + Dispatcher *d = c->get_global_context ()->event_source (); + d->add_listener (GET_LISTENER (one_time_step), ly_symbol2scm ("OneTimeStep")); + d->add_listener (GET_LISTENER (prepare), ly_symbol2scm ("Prepare")); + d->add_listener (GET_LISTENER (finish), ly_symbol2scm ("Finish")); } -/* All elements are propagated to the top upon announcement. If - something was created during one run of - Engraver_group_engraver::do_announces, then - announce_info_arr_.size() will be nonzero again -*/ -/* junkme? Done by Engraver_group_engraver::do_announces ()? +/* + uncovered: + + check_removal always returns false for Score contexts, it has been that way +since I joined the project. There is a reason for this: The typeset score is +stored in the Score_engraver, which in turn is accessed through the +Global_context returned by ly:run-translator. So the score-translator must be +connected to the score-context after run-translator finishes. + +I plan to change this: we should junk run-translator, and instead keep track +of both context and translator in the SCM code, and access the typeset score +directly via the created global-translator. Then it would be possible to +disconnect score-translators at iteration time. -es */ - void -Score_engraver::do_announces() +Score_engraver::disconnect_from_context () { - ////// do - Engraver_group_engraver::do_announces(); - //////while (announce_info_arr_.size()); -} + Dispatcher *d = context ()->get_global_context ()->event_source (); + d->remove_listener (GET_LISTENER (one_time_step), ly_symbol2scm ("OneTimeStep")); + d->remove_listener (GET_LISTENER (prepare), ly_symbol2scm ("Prepare")); + d->remove_listener (GET_LISTENER (finish), ly_symbol2scm ("Finish")); + Engraver_group::disconnect_from_context (); +} void -Score_engraver::typeset_grob (Grob *elem_p) +Score_engraver::finalize () { - if (!elem_p) - programming_error ("Score_engraver: empty elt\n"); - else + Engraver_group::finalize (); - elem_p_arr_.push (elem_p); + typeset_all (); } - +IMPLEMENT_LISTENER (Score_engraver, one_time_step); void -Score_engraver::typeset_all() +Score_engraver::one_time_step (SCM) { - for (int i =0; i < elem_p_arr_.size(); i++) + if (!to_boolean (context ()->get_property ("skipTypesetting"))) { - Grob * elem_p = elem_p_arr_[i]; - - if (Spanner *s = dynamic_cast (elem_p)) - { - /* - do something sensible if spanner not - spanned on 2 items. - */ - Direction d = LEFT; - do { - if (!s->get_bound (d)) - { - s->set_bound(d, command_column_l_); - /* don't warn for empty/suicided spanners, - it makes real warningsinvisible. - maybe should be junked earlier? */ - if (elem_p->immutable_property_alist_ == SCM_EOL) - ; // gdb hook - else - ::warning (_f ("unbound spanner `%s'", s->name ().ch_C ())); - } - } while (flip (&d) != LEFT); - } - else - { - if (!elem_p->parent_l (X_AXIS)) - { - bool br = to_boolean (elem_p->get_grob_property ("breakable")); - Axis_group_interface::add_element (br ? command_column_l_ : musical_column_l_, elem_p); - - } - } - if (!elem_p->parent_l(Y_AXIS)) - Axis_group_interface::add_element (scoreline_l_, elem_p); + precomputed_recurse_over_translators (context (), PROCESS_MUSIC, UP); + Engraver_group::do_announces (); } - elem_p_arr_.clear(); + + precomputed_recurse_over_translators (context (), STOP_TRANSLATION_TIMESTEP, UP); + typeset_all (); } void -Score_engraver::stop_translation_timestep() +Score_engraver::announce_grob (Grob_info info) { - // this generates all items. - Engraver_group_engraver::stop_translation_timestep(); - - typeset_all(); - if (to_boolean (command_column_l_->get_grob_property ("breakable"))) + Engraver_group::announce_grob (info); + if (info.start_end () == START) { - breaks_i_ ++; - if (! (breaks_i_%8)) - progress_indication ("[" + to_str ( breaks_i_) + "]"); + pscore_->root_system ()->typeset_grob (info.grob ()); + elems_.push_back (info.grob ()); } } void -Score_engraver::set_columns (Paper_column *new_command_l, - Paper_column *new_musical_l) +Score_engraver::typeset_all () { - Paper_column * news[] = {new_command_l, new_musical_l}; - Paper_column **current[] = {&command_column_l_, &musical_column_l_}; - - for (int i=00; i< 2; i++) + for (vsize i = 0; i < elems_.size (); i++) { - if (*current[i]) - { - scoreline_l_->add_column ((*current[i])); - } - if (news[i]) - *current[i] = news[i]; - } - - if (new_musical_l) - set_property ("currentMusicalColumn", new_musical_l->self_scm ()); - if (new_command_l) - set_property ("currentCommandColumn", new_command_l->self_scm ()); -} - -Music_output* -Score_engraver::get_output_p () -{ - Music_output * o = pscore_p_; - pscore_p_=0; - return o; -} + Grob *elem = elems_[i]; -bool -Score_engraver::try_music (Music*r) -{ - bool gotcha = Engraver_group_engraver::try_music (r); - - if (!gotcha) - { - if (Break_req* b = dynamic_cast (r)) - { - gotcha = true; - - - SCM pen = command_column_l_->get_grob_property ("penalty"); - Real total_penalty = gh_number_p (pen) - ? gh_scm2double(pen) - : 0.0; - - SCM rpen = b->get_mus_property ("penalty"); - if (gh_number_p (rpen)) - total_penalty += gh_scm2double (rpen); - - if (total_penalty > 10000.0) // ugh. arbitrary. - forbid_breaks (); - - command_column_l_->set_grob_property ("penalty", - gh_double2scm (total_penalty)); - } + if (!elem->get_parent (Y_AXIS)) + Axis_group_interface::add_element (system_, elem); } - return gotcha; -} - -/* - TODO: use property Score.breakForbidden = #t - */ - -void -Score_engraver::forbid_breaks () -{ - /* - result is junked. - */ - command_column_l_->remove_grob_property ("breakable"); -} - -ADD_THIS_TRANSLATOR(Score_engraver); - - + elems_.clear (); +} + +ADD_TRANSLATOR_GROUP (Score_engraver, + /* doc */ + "The top-level engraver. Takes care of generating" + " columns and the complete system (i.e.," + " @code{System}).\n" + "\n" + "This engraver decides whether a column is breakable." + " The default is that a column is always breakable." + " However, every @code{Bar_engraver} that does not have" + " a bar line at a certain point sets @code{forbidBreaks}" + " to stop line breaks. In practice, this means that you" + " can make a break point by creating a bar line" + " (assuming that there are no beams or notes that" + " prevent a break point).", + + /* create */ + "System ", + + /* read */ + "currentMusicalColumn " + "currentCommandColumn ", + + /* write */ + "" + );