X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fscore-engraver.cc;h=88ea4af86f34003dd605dad337c56d7e7f1174b1;hb=90e4d7057f3857da049dfda3d130017d4719bd6b;hp=31349ad2cf3b7add88629e247c90d2c84a3e7a3a;hpb=7e72a1e50e94a7f9738d62599de79fe7745f600c;p=lilypond.git diff --git a/lily/score-engraver.cc b/lily/score-engraver.cc index 31349ad2cf..88ea4af86f 100644 --- a/lily/score-engraver.cc +++ b/lily/score-engraver.cc @@ -1,351 +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--2015 Han-Wen Nienhuys - (c) 1997--2004 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. + + You should have received a copy of the GNU General Public License + along with LilyPond. If not, see . */ -#include "all-font-metrics.hh" -#include "afm.hh" -#include "warn.hh" -#include "main.hh" -#include "system.hh" -#include "item.hh" #include "score-engraver.hh" -#include "paper-score.hh" -#include "paper-column.hh" -#include "paper-def.hh" +#include "all-font-metrics.hh" #include "axis-group-interface.hh" #include "context-def.hh" +#include "dispatcher.hh" +#include "global-context.hh" +#include "grob-properties.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" -#include "staff-spacing.hh" -#include "note-spacing.hh" - -/* - TODO: the column creation logic is rather hairy. Revise it. - */ Score_engraver::Score_engraver () { - system_ =0; - command_column_ =0; - musical_column_ =0; - breaks_ =0; + system_ = 0; pscore_ = 0; } void -Score_engraver::make_columns () +Score_engraver::derived_mark () const { - /* - ugh. - */ - if (!command_column_) - { - set_columns (new Paper_column (get_property ("NonMusicalPaperColumn")), - new Paper_column (get_property ("PaperColumn"))); - - command_column_->set_grob_property ("breakable", SCM_BOOL_T); - - - Grob_info i1; - i1.grob_ = command_column_; - i1.origin_trans_ = this; - - announce_grob (i1); - - Grob_info i2; - i2.grob_ = musical_column_; - i2.origin_trans_ = this; - - announce_grob (i2); - } + if (pscore_) + scm_gc_mark (pscore_->self_scm ()); + Engraver_group::derived_mark (); } void -Score_engraver::prepare (Moment w) +Score_engraver::prepare (SCM) { - Global_translator::prepare (w); - - /* - TODO: don't make columns when skipTypesetting is true. - */ - make_columns (); - - command_column_->set_grob_property ("when", now_mom_.smobbed_copy ()); - musical_column_->set_grob_property ("when", now_mom_.smobbed_copy ()); - - - Translator_group::start_translation_timestep(); + precomputed_recurse_over_translators (context (), START_TRANSLATION_TIMESTEP, DOWN); } void -Score_engraver::finish () +Score_engraver::finish (SCM) { - if ((breaks_%8)) - progress_indication ("[" + to_string (breaks_) + "]"); - - check_removal (); - finalize (); + recurse_over_translators + (context (), + Callback0_wrapper::make_smob (), + Callback0_wrapper::make_smob (), + UP); } +#define MUSIC_FONT "emmentaler-20" + /* use start/finish? - */ +*/ void Score_engraver::initialize () { - Font_metric *fm = all_fonts_global->find_afm("feta20"); + Font_metric *fm = all_fonts_global->find_otf (MUSIC_FONT); if (!fm) - error (_f ("can't find `%s'", "feta20.afm") - + "\n" +_ ("Fonts have not been installed properly. Aborting")); - - unsmob_context_def (definition_)->apply_default_property_operations (this); - - assert (dynamic_cast (output_def_)); - assert (!daddy_trans_); - pscore_ = new Paper_score; - pscore_->paper_ = dynamic_cast (output_def_); - - SCM props = get_property ("System"); - - pscore_->typeset_line (new System (props)); - - make_columns (); - system_ = pscore_->system_; - system_->set_bound (LEFT, command_column_); - command_column_->set_grob_property ("breakable", SCM_BOOL_T); - - Engraver_group_engraver::initialize (); -} - + { + 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")); + } -void -Score_engraver::finalize () -{ - Engraver_group_engraver::finalize (); + pscore_ = new Paper_score (dynamic_cast (context ()->get_output_def ())); + pscore_->unprotect (); + context ()->set_property ("output", pscore_->self_scm ()); - Grob * cc - = unsmob_grob (get_property ("currentCommandColumn")); - system_->set_bound (RIGHT, cc); - cc->set_grob_property ("breakable", SCM_BOOL_T); - - typeset_all (); -} + SCM props = Grob_property_info (context (), ly_symbol2scm ("System")).updated (); -void -Score_engraver::one_time_step () -{ - if (!to_boolean (get_property ("skipTypesetting"))) - { - process_music (); - do_announces (); - } - - stop_translation_timestep (); - - apply_finalizations (); - check_removal (); + pscore_->typeset_system (new System (props)); + system_ = pscore_->root_system (); + context ()->set_property ("rootSystem", system_->self_scm ()); - for (int i = announce_infos_.size(); i--;) - { - Grob *g = announce_infos_[i].grob_; - if (!dynamic_cast (g)) // ugh. - { - String msg= "Grob " - + g->name() - + " was created too late!"; - g->programming_error (msg); - } - } - announce_infos_.clear (); + Engraver_group::initialize (); } void -Score_engraver::announce_grob (Grob_info info) +Score_engraver::connect_to_context (Context *c) { - announce_infos_.push (info); - pscore_->system_->typeset_grob (info.grob_); -} + Engraver_group::connect_to_context (c); -void -Score_engraver::typeset_grob (Grob *elem) -{ - if (!elem) - programming_error ("Score_engraver: empty elt\n"); - else - elems_.push (elem); + Dispatcher *d = c->get_global_context ()->event_source (); + d->add_listener (GET_LISTENER (Score_engraver, one_time_step), ly_symbol2scm ("OneTimeStep")); + d->add_listener (GET_LISTENER (Score_engraver, prepare), ly_symbol2scm ("Prepare")); + d->add_listener (GET_LISTENER (Score_engraver, finish), ly_symbol2scm ("Finish")); } +/* + 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::typeset_all () +Score_engraver::disconnect_from_context () { - for (int i =0; i < elems_.size (); i++) - { - Grob * elem = elems_[i]; - - if (Spanner *s = dynamic_cast (elem)) - { - /* - 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_); - /* don't warn for empty/suicided spanners, - it makes real warningsinvisible. - maybe should be junked earlier? */ - if (!elem->live()) - ; // gdb hook - else - elem->warning (_f ("unbound spanner `%s'", s->name ().to_str0 ())); - } - } - while (flip (&d) != LEFT); - - if (dynamic_cast (s->get_parent (Y_AXIS))) - programming_error ("Spanner Y-parent is an item."); - } - else - { - if (!elem->get_parent (X_AXIS)) - { - bool br = to_boolean (elem->get_grob_property ("breakable")); - Axis_group_interface::add_element (br ? command_column_ : musical_column_, elem); - - } - } - if (!elem->get_parent (Y_AXIS)) - Axis_group_interface::add_element (system_, elem); - } - elems_.clear (); + Dispatcher *d = context ()->get_global_context ()->event_source (); + d->remove_listener (GET_LISTENER (Score_engraver, one_time_step), ly_symbol2scm ("OneTimeStep")); + d->remove_listener (GET_LISTENER (Score_engraver, prepare), ly_symbol2scm ("Prepare")); + d->remove_listener (GET_LISTENER (Score_engraver, finish), ly_symbol2scm ("Finish")); + + Engraver_group::disconnect_from_context (); } void -Score_engraver::stop_translation_timestep () +Score_engraver::finalize () { - // this generates all items. - Engraver_group_engraver::stop_translation_timestep (); - - typeset_all (); - if (to_boolean (command_column_->get_grob_property ("breakable"))) - { - breaks_ ++; - if (! (breaks_%8)) - progress_indication ("[" + to_string (breaks_) + "]"); - } - + Engraver_group::finalize (); - system_->add_column (command_column_); - system_->add_column (musical_column_); - - command_column_ = 0; - musical_column_ = 0; + typeset_all (); } void -Score_engraver::set_columns (Paper_column *new_command, - Paper_column *new_musical) +Score_engraver::one_time_step (SCM) { - assert (!command_column_ && !musical_column_); - - command_column_ = new_command; - musical_column_ = new_musical; - if (new_command) + if (!to_boolean (context ()->get_property ("skipTypesetting"))) { - set_property ("currentCommandColumn", new_command->self_scm ()); + precomputed_recurse_over_translators (context (), PROCESS_MUSIC, UP); + Engraver_group::do_announces (); } - - if (new_musical) - { - set_property ("currentMusicalColumn", new_musical->self_scm ()); - } -} -Music_output* -Score_engraver::get_output () -{ - Music_output * o = pscore_; - pscore_=0; - return o; + precomputed_recurse_over_translators (context (), STOP_TRANSLATION_TIMESTEP, UP); + typeset_all (); } -bool -Score_engraver::try_music (Music*r) +void +Score_engraver::announce_grob (Grob_info info, Direction start_end, Context *reroute_context) { - bool gotcha = Engraver_group_engraver::try_music (r); - - if (!gotcha && r->is_mus_type ("break-event")) + Engraver_group::announce_grob (info, start_end, reroute_context); + if (start_end == START) { - gotcha = true; - - SCM pen = command_column_->get_grob_property ("penalty"); - Real total_penalty = gh_number_p (pen) - ? gh_scm2double (pen) - : 0.0; - - SCM rpen = r->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_->set_grob_property ("penalty", - gh_double2scm (total_penalty)); + pscore_->root_system ()->typeset_grob (info.grob ()); + elems_.push_back (info.grob ()); } - return gotcha; } -/* - TODO: use property Score.breakForbidden = #t - */ void -Score_engraver::forbid_breaks () -{ - /* - result is junked. - */ - if (command_column_) - command_column_->set_grob_property ("breakable", SCM_EOL); -} - -void -Score_engraver::acknowledge_grob (Grob_info gi) +Score_engraver::typeset_all () { - if (Staff_spacing::has_interface (gi.grob_)) + for (vsize i = 0; i < elems_.size (); i++) { - Pointer_group_interface::add_grob (command_column_, - ly_symbol2scm ("spacing-wishes"), - gi.grob_); - } - if (Note_spacing::has_interface (gi.grob_)) - { - Pointer_group_interface::add_grob (musical_column_, - ly_symbol2scm ("spacing-wishes"), - gi.grob_); + Grob *elem = elems_[i]; + + if (!elem->get_parent (Y_AXIS)) + Axis_group_interface::add_element (system_, elem); } + elems_.clear (); } - - -ENTER_DESCRIPTION(Score_engraver, -/* descr */ "Top level engraver. Takes care of generating columns and the complete system (ie. System) " -"\n\n " -"This engraver decides whether a column is breakable. The default is " -"that a column is always breakable. However, when every Bar_engraver " -"that does not have a barline at a certain point will call " -"Score_engraver::forbid_breaks to stop linebreaks. In practice, this " -"means that you can make a breakpoint by creating a barline (assuming " -"that there are no beams or notes that prevent a breakpoint.) " -, -/* creats*/ "System PaperColumn NonMusicalPaperColumn", -/* accepts */ "break-event", -/* acks */ "note-spacing-interface staff-spacing-interface", -/* reads */ "currentMusicalColumn currentCommandColumn", -/* write */ ""); +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 */ + "" + );