X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fscore-engraver.cc;h=e0bca498f753b81727e5276a3f7615a6f320491d;hb=bfdebcb93bebe820c2d5fd6c1bed5c589536472c;hp=0f01110780f582f50138ee58ddd92a71c207e452;hpb=210397d5e1d8a0b560bac8e683c8be957035b5b4;p=lilypond.git diff --git a/lily/score-engraver.cc b/lily/score-engraver.cc index 0f01110780..e0bca498f7 100644 --- a/lily/score-engraver.cc +++ b/lily/score-engraver.cc @@ -1,88 +1,67 @@ /* - 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--2012 Han-Wen Nienhuys - (c) 1997--2005 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 "score-engraver.hh" -#include "paper-score.hh" -#include "paper-column.hh" -#include "output-def.hh" + +#include "all-font-metrics.hh" #include "axis-group-interface.hh" #include "context-def.hh" -#include "staff-spacing.hh" -#include "note-spacing.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" -/* - TODO: the column creation logic is rather hairy. Revise it. -*/ Score_engraver::Score_engraver () { system_ = 0; - command_column_ = 0; - musical_column_ = 0; - breaks_ = 0; pscore_ = 0; } void -Score_engraver::make_columns () +Score_engraver::derived_mark () const { - /* - ugh. - */ - if (!command_column_) - { - SCM nmp - = updated_grob_properties (context (), - ly_symbol2scm ("NonMusicalPaperColumn")); - - Object_key const *key1 = context ()->get_grob_key ("NonMusicalPaperColumn"); - - SCM pc = updated_grob_properties (context (), - ly_symbol2scm ("PaperColumn")); - Object_key const *key2 = context ()->get_grob_key ("PaperColumn"); - set_columns (new Paper_column (nmp, key1), new Paper_column (pc, key2)); - - Grob_info i1 (this, command_column_); - announce_grob (i1); - - Grob_info i2 (this, musical_column_); - 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 m) +Score_engraver::prepare (SCM) { - /* - TODO: don't make columns when skipTypesetting is true. - */ - make_columns (); - - SCM w = m.smobbed_copy (); - command_column_->set_property ("when", w); - musical_column_->set_property ("when", w); - - recurse_over_translators (context (), &Translator::start_translation_timestep, DOWN); + precomputed_recurse_over_translators (context (), START_TRANSLATION_TIMESTEP, DOWN); } +IMPLEMENT_LISTENER (Score_engraver, finish); void -Score_engraver::finish () +Score_engraver::finish (SCM) { - if ((breaks_ % 8)) - progress_indication ("[" + to_string (breaks_) + "]"); - - recurse_over_translators (context (), &Translator::finalize, UP); + recurse_over_translators (context (), &Translator::finalize, + &Translator_group::finalize, + UP); } #define MUSIC_FONT "emmentaler-20" @@ -97,217 +76,132 @@ Score_engraver::initialize () 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 ().to_str0 ()) - + "\n" - + _ ("Aborting")); + + "\n" + + _ ("Music font has not been installed properly.") + + "\n" + + _f ("Search path `%s'", global_path.to_string ().c_str ()) + + "\n" + + _ ("Aborting")); } - pscore_ = new Paper_score (dynamic_cast (get_output_def ())); + pscore_ = new Paper_score (dynamic_cast (context ()->get_output_def ())); + pscore_->unprotect (); + context ()->set_property ("output", pscore_->self_scm ()); SCM props = updated_grob_properties (context (), ly_symbol2scm ("System")); - Object_key const *sys_key = context ()->get_grob_key ("System"); - pscore_->typeset_system (new System (props, sys_key)); + pscore_->typeset_system (new System (props)); system_ = pscore_->root_system (); - make_columns (); - system_->set_bound (LEFT, command_column_); - command_column_->set_property ("breakable", SCM_BOOL_T); - - Engraver_group_engraver::initialize (); -} - -void -Score_engraver::finalize () -{ - Score_translator::finalize (); + context ()->set_property ("rootSystem", system_->self_scm ()); - Grob *cc - = unsmob_grob (get_property ("currentCommandColumn")); - system_->set_bound (RIGHT, cc); - cc->set_property ("breakable", SCM_BOOL_T); - - typeset_all (); + Engraver_group::initialize (); } void -Score_engraver::one_time_step () +Score_engraver::connect_to_context (Context *c) { - if (!to_boolean (get_property ("skipTypesetting"))) - { - recurse_over_translators (context (), &Engraver::process_music, UP); - Engraver_group_engraver::do_announces (); - } + Engraver_group::connect_to_context (c); - recurse_over_translators (context (), &Translator::stop_translation_timestep, UP); -} - -void -Score_engraver::announce_grob (Grob_info info) -{ - announce_infos_.push (info); - pscore_->root_system ()->typeset_grob (info.grob_); - elems_.push (info.grob_); + 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")); } +/* + 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]; + 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")); - if (dynamic_cast (elem)) - { - if ((!elem->get_parent (X_AXIS) - || !unsmob_grob (elem->get_property ("axis-group-parent-X"))) - && elem != command_column_ - && elem != musical_column_) - { - bool br = to_boolean (elem->get_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 (); + Engraver_group::disconnect_from_context (); } void -Score_engraver::stop_translation_timestep () +Score_engraver::finalize () { - // this generates all items. - Engraver_group_engraver::stop_translation_timestep (); + Engraver_group::finalize (); typeset_all (); - if (to_boolean (command_column_->get_property ("breakable"))) - { - breaks_++; - if (! (breaks_%8)) - progress_indication ("[" + to_string (breaks_) + "]"); - } - - command_column_ = 0; - musical_column_ = 0; } +IMPLEMENT_LISTENER (Score_engraver, one_time_step); 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) - { - context ()->set_property ("currentCommandColumn", new_command->self_scm ()); - } - - if (new_musical) + if (!to_boolean (context ()->get_property ("skipTypesetting"))) { - context ()->set_property ("currentMusicalColumn", new_musical->self_scm ()); + precomputed_recurse_over_translators (context (), PROCESS_MUSIC, UP); + Engraver_group::do_announces (); } - system_->add_column (command_column_); - system_->add_column (musical_column_); -} - -Music_output * -Score_engraver::get_output () -{ - Music_output *o = pscore_; - ///FIXME WTF ? pscore_ = 0; - return o; + precomputed_recurse_over_translators (context (), STOP_TRANSLATION_TIMESTEP, UP); + typeset_all (); } -bool -Score_engraver::try_music (Music *m) +void +Score_engraver::announce_grob (Grob_info info) { - if (Engraver_group_engraver::try_music (m)) - return true; - - if (m->is_mus_type ("break-event")) + Engraver_group::announce_grob (info); + if (info.start_end () == START) { - SCM pen = command_column_->get_property ("penalty"); - Real total_penalty = scm_is_number (pen) ? scm_to_double (pen) : 0.0; - - SCM mpen = m->get_property ("penalty"); - if (scm_is_number (mpen)) - total_penalty += scm_to_double (mpen); - - command_column_->set_property ("penalty", scm_make_real (total_penalty)); - - /* ugh. arbitrary, hardcoded */ - if (total_penalty > 10000.0) - forbid_breaks (); - - SCM page_pen = command_column_->get_property ("page-penalty"); - Real total_pp = scm_is_number (page_pen) ? scm_to_double (page_pen) : 0.0; - SCM mpage_pen = m->get_property ("page-penalty"); - if (scm_is_number (mpage_pen)) - total_pp += scm_to_double (mpage_pen); - - command_column_->set_property ("page-penalty", scm_make_real (total_pp)); - return true; + pscore_->root_system ()->typeset_grob (info.grob ()); + elems_.push_back (info.grob ()); } - return false; -} - -void -Score_engraver::forbid_breaks () -{ - if (command_column_) - command_column_->set_property ("breakable", SCM_EOL); } void -Score_engraver::acknowledge_grob (Grob_info gi) +Score_engraver::typeset_all () { - if (Staff_spacing::has_interface (gi.grob_)) - { - Pointer_group_interface::add_grob (command_column_, - ly_symbol2scm ("spacing-wishes"), - gi.grob_); - } - if (Note_spacing::has_interface (gi.grob_)) + for (vsize i = 0; i < elems_.size (); i++) { - Pointer_group_interface::add_grob (musical_column_, - ly_symbol2scm ("spacing-wishes"), - gi.grob_); - } + Grob *elem = elems_[i]; - if (Axis_group_interface::has_interface (gi.grob_) - && gi.grob_->internal_has_interface (ly_symbol2scm ("vertically-spaceable-interface"))) - { - SCM spaceable = get_property ("verticallySpacedContexts"); - Context *orig = gi.origin_contexts (this)[0]; - - if (scm_memq (ly_symbol2scm (orig->context_name ().to_str0 ()), - spaceable) != SCM_BOOL_F) - { - Pointer_group_interface::add_grob (system_, - ly_symbol2scm ("spaceable-staves"), - gi.grob_); - } + if (!elem->get_parent (Y_AXIS)) + Axis_group_interface::add_element (system_, elem); } + elems_.clear (); } -ADD_TRANSLATOR (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 axis-group-interface", - /* reads */ "currentMusicalColumn currentCommandColumn verticallySpacedContexts", - /* 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 */ + "" + );