X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fdynamic-engraver.cc;h=a2da4e1b2b32db16712b4286b72c20f3e1cd8544;hb=105fd7580334c8f42838ac62504c5f290f3428c5;hp=b02b5aeff7576bf4acdfe185b1a8bfb1b7827c87;hpb=2fd5f86de0500ecd9a3f47a2540c3b304f835ef4;p=lilypond.git diff --git a/lily/dynamic-engraver.cc b/lily/dynamic-engraver.cc index b02b5aeff7..a2da4e1b2b 100644 --- a/lily/dynamic-engraver.cc +++ b/lily/dynamic-engraver.cc @@ -1,213 +1,289 @@ /* - dynamic-reg.cc -- implement Dynamic_engraver + dynamic-engraver.cc -- implement Dynamic_engraver source file of the GNU LilyPond music typesetter - (c) 1997--1999 Han-Wen Nienhuys + (c) 1997--2000 Han-Wen Nienhuys */ - #include "debug.hh" +#include "dimensions.hh" #include "crescendo.hh" #include "musical-request.hh" -#include "lookup.hh" -#include "paper-def.hh" #include "paper-column.hh" -#include "staff-symbol.hh" #include "note-column.hh" -#include "text-item.hh" +#include "item.hh" #include "side-position-interface.hh" #include "engraver.hh" -#include "stem.hh" -#include "note-head.hh" +#include "group-interface.hh" +#include "directional-element-interface.hh" +#include "translator-group.hh" +#include "axis-group-interface.hh" + + +/* + TODO: + + * direction of text-dynamic-request if not equal to direction of + line-spanner +*/ /** print text & hairpin dynamics. */ class Dynamic_engraver : public Engraver { - Text_item * text_p_; - Crescendo * to_end_cresc_p_; - Crescendo * cresc_p_; + Item * text_p_; + Spanner * finished_cresc_p_; + Spanner * cresc_p_; + + Text_script_req* text_req_l_; + + Span_req * current_cresc_req_; + Drul_array accepted_spanreqs_drul_; + + Spanner* line_spanner_; + Spanner* finished_line_spanner_; + + Link_array pending_column_arr_; + Link_array pending_element_arr_; + + void typeset_all (); - Span_req * cresc_req_l_; - Array dynamic_req_l_arr_; - void typeset_all (); public: VIRTUAL_COPY_CONS(Translator); - Dynamic_engraver(); + Dynamic_engraver (); protected: virtual void do_removal_processing (); virtual void acknowledge_element (Score_element_info); virtual bool do_try_music (Music *req_l); - virtual void do_process_requests(); - virtual void do_pre_move_processing(); - virtual void do_post_move_processing(); + virtual void do_process_music (); + virtual void do_pre_move_processing (); + virtual void do_post_move_processing (); }; ADD_THIS_TRANSLATOR (Dynamic_engraver); -Dynamic_engraver::Dynamic_engraver() -{ - do_post_move_processing(); - text_p_ =0; - - to_end_cresc_p_ = cresc_p_ = 0; - cresc_req_l_ = 0; +Dynamic_engraver::Dynamic_engraver () +{ + text_p_ = 0; + finished_cresc_p_ = 0; + line_spanner_ = 0; + finished_line_spanner_ = 0; + current_cresc_req_ = 0; + cresc_p_ =0; + + text_req_l_ = 0; + accepted_spanreqs_drul_[START] = 0; + accepted_spanreqs_drul_[STOP] = 0; } void -Dynamic_engraver::do_post_move_processing() +Dynamic_engraver::do_post_move_processing () { - dynamic_req_l_arr_.clear(); + text_req_l_ = 0; + accepted_spanreqs_drul_[START] = 0; + accepted_spanreqs_drul_[STOP] = 0; } bool Dynamic_engraver::do_try_music (Music * m) { - Request * r = dynamic_cast (m); - - if(Text_script_req * d = dynamic_cast (r)) + if (Text_script_req* d = dynamic_cast (m)) { - if (d->style_str_ != "dynamic") - return false; + if (d->style_str_ == "dynamic") + { + text_req_l_ = d; + return true; + } } - else if (Span_req * s = dynamic_cast (r)) + else if (Span_req* s = dynamic_cast (m)) { - if (s-> span_type_str_ != "crescendo" - && s->span_type_str_ != "decrescendo") - return false; + if ((s->span_type_str_ == "crescendo" + || s->span_type_str_ == "decrescendo")) + { + accepted_spanreqs_drul_[s->span_dir_] = s; + return true; + } } - else - return false; - - for (int i=0; i < dynamic_req_l_arr_.size (); i++) - if (r->equal_b (dynamic_req_l_arr_[i])) - return true; - - dynamic_req_l_arr_.push (r); - return true; + return false; } - void -Dynamic_engraver::do_process_requests() +Dynamic_engraver::do_process_music () { - Crescendo* new_cresc_p=0; + if (accepted_spanreqs_drul_[START] || accepted_spanreqs_drul_[STOP] || text_req_l_) + + { + if (!line_spanner_) + { + line_spanner_ = new Spanner (get_property ("basicDynamicLineSpannerProperties")); + + Side_position::set_axis (line_spanner_, Y_AXIS); + Axis_group_interface::set_interface (line_spanner_); + Axis_group_interface::set_axes (line_spanner_, Y_AXIS, Y_AXIS); + announce_element (line_spanner_, + text_req_l_ ? text_req_l_ : accepted_spanreqs_drul_[START]); - for (int i=0; i < dynamic_req_l_arr_.size(); i++) + } + } + + /* + finish side position alignment if the (de)cresc ends here, and + there are no new dynamics. + + */ + else if (accepted_spanreqs_drul_[STOP] + && !accepted_spanreqs_drul_[START] && !text_req_l_) + { + finished_line_spanner_ = line_spanner_; + line_spanner_ = 0; + } + + /* + todo: resurrect dynamic{direction, padding,minimumspace} + */ + /* + During a (de)crescendo, pending request will not be cleared, + and a line-spanner will always be created, as \< \! are already + two requests. + + Maybe always creating a line-spanner for a (de)crescendo (see + below) is not a good idea: + + a\< b\p \!c + + the \p will be centred on the line-spanner, and thus clash + with the hairpin. When axis-group code is in place, the \p + should move below the hairpin, which is probably better? + + Urg, but line-spanner must always have at least same duration + as (de)crecsendo, b.o. line-breaking. + */ + + + + /* + maybe we should leave dynamic texts to the text-engraver and + simply acknowledge them? + */ + if (text_req_l_) + { + String loud = text_req_l_->text_str_; + + text_p_ = new Item (get_property ("basicDynamicTextProperties")); + text_p_->set_elt_property ("text", ly_str02scm (loud.ch_C ())); + if (Direction d=text_req_l_->get_direction ()) + Directional_element_interface::set (line_spanner_, d); + + Axis_group_interface::add_element (line_spanner_, text_p_); + + text_p_->add_offset_callback (Side_position::aligned_on_self, + Y_AXIS); + announce_element (text_p_, text_req_l_); + } + + if (accepted_spanreqs_drul_[STOP]) { - if (Text_script_req *absd = - dynamic_cast ( dynamic_req_l_arr_[i])) + if (!cresc_p_) { - if (text_p_) - { - dynamic_req_l_arr_[i]->warning (_("Got a dynamic already. Continuing dazed and confused.")); - continue; - } - - String loud = absd->text_str_; - - text_p_ = new Text_item; - text_p_->set_elt_property ("text", - ly_str02scm (loud.ch_C())); - text_p_->set_elt_property ("style", gh_str02scm ("dynamic")); - text_p_->set_elt_property ("script-priority", - gh_int2scm (100)); - text_p_->set_elt_property ("staff-support", SCM_BOOL_T); + accepted_spanreqs_drul_[STOP]->origin ()->warning + (_ ("can't find start of (de)crescendo")); + } + else + { + assert (!finished_cresc_p_); + Score_element* cc = unsmob_element (get_property ("currentMusicalColumn")); - Side_position_interface (text_p_).set_axis (Y_AXIS); + cresc_p_->set_bound (RIGHT, cc); - - if (absd->get_direction ()) + finished_cresc_p_ = cresc_p_; + cresc_p_ = 0; + current_cresc_req_ = 0; + } + } + + if (accepted_spanreqs_drul_[START]) + { + if (current_cresc_req_) + { + accepted_spanreqs_drul_[START]->origin ()->warning + (current_cresc_req_->span_dir_ == 1 + ? _ ("already have a crescendo") + : _ ("already have a decrescendo")); + } + else + { + current_cresc_req_ = accepted_spanreqs_drul_[START]; + cresc_p_ = new Spanner (get_property ("basicCrescendoProperties")); + Crescendo::set_interface (cresc_p_); + cresc_p_->set_elt_property + ("grow-direction", + gh_int2scm ((accepted_spanreqs_drul_[START]->span_type_str_ == "crescendo") + ? BIGGER : SMALLER)); + + SCM s = get_property ((accepted_spanreqs_drul_[START]->span_type_str_ + "Text").ch_C()); + if (gh_string_p (s)) { - text_p_->set_elt_property ("direction", gh_int2scm (absd->get_direction ())); + cresc_p_->set_elt_property ("start-text", s); + daddy_trans_l_->set_property (accepted_spanreqs_drul_[START]->span_type_str_ + + "Text", SCM_UNDEFINED); } + s = get_property ((accepted_spanreqs_drul_[START]->span_type_str_ + "Spanner").ch_C()); + /* - UGH UGH + TODO: Use symbols. */ - SCM prop = get_property ("dynamicDirection", 0); - if (!isdir_b (prop)) + if (gh_string_p (s)) //&& ly_scm2string (s) != "hairpin") { - prop = get_property ("verticalDirection", 0); + cresc_p_->set_elt_property ("spanner", s); + daddy_trans_l_->set_property (accepted_spanreqs_drul_[START]->span_type_str_ + + "Spanner", SCM_UNDEFINED); } - if (isdir_b (prop) && to_dir (prop)) - text_p_->set_elt_property ("direction", prop); + Score_element *cc = unsmob_element (get_property ("currentMusicalColumn")); + cresc_p_->set_bound (LEFT, cc); - prop = get_property ("dynamicPadding", 0); - if (gh_number_p(prop)) - { - text_p_->set_elt_property ("padding", prop); - } - announce_element (Score_element_info (text_p_, absd)); - } - else if (Span_req *span_l - = dynamic_cast (dynamic_req_l_arr_[i])) - { - if (span_l->span_dir_ == STOP) - { - if (!cresc_p_) - { - span_l->warning (_ ("Can't find (de)crescendo to end")); - } - else - { - assert (!to_end_cresc_p_); - to_end_cresc_p_ =cresc_p_; - - cresc_p_ = 0; - } - } - else if (span_l->span_dir_ == START) - { - cresc_req_l_ = span_l; - assert (!new_cresc_p); - new_cresc_p = new Crescendo; - new_cresc_p - ->set_elt_property ("grow-direction", - gh_int2scm ((span_l->span_type_str_ == "crescendo") ? BIGGER : SMALLER)); - - new_cresc_p->set_elt_property ("staff-support", SCM_BOOL_T); + /* + We know how wide the text is, if we can be sure that the + text already has relevant pointers into the paperdef, + and it has its font-size property set. - Side_position_interface (new_cresc_p).set_axis (Y_AXIS); - announce_element (Score_element_info (new_cresc_p, span_l)); - } - } - } + Since font-size may be set by a context higher up, we + can not be sure of the size. - if (new_cresc_p) - { - if (cresc_p_) - { - ::warning (_ ("Too many crescendi here")); + We shouldn't try to do this stuff here, the Item should + do it when the score is finished. We could maybe + set a callback to have the Item do the alignment if + it is not a special symbol, like Crescendo. + */ - typeset_element (cresc_p_); - - cresc_p_ = 0; - } - - cresc_p_ = new_cresc_p; - cresc_p_->set_bounds(LEFT,get_staff_info().musical_pcol_l ()); + + if (text_p_) + { + index_set_cell (cresc_p_->get_elt_property ("dynamic-drul"), + LEFT, text_p_->self_scm ()); + if (finished_cresc_p_) + index_set_cell (finished_cresc_p_->get_elt_property ("dynamic-drul"), + RIGHT, text_p_->self_scm ()); + } - if (text_p_) - { - index_set_cell (cresc_p_->get_elt_property ("dynamic-drul"), - LEFT, SCM_BOOL_T); - if (to_end_cresc_p_) - index_set_cell (to_end_cresc_p_->get_elt_property ("dynamic-drul"), - RIGHT, SCM_BOOL_T); + Axis_group_interface::add_element (line_spanner_, cresc_p_); + cresc_p_->set_elt_property ("self-alignment-Y", gh_int2scm (0)); + cresc_p_->add_offset_callback + (Side_position::aligned_on_self, Y_AXIS); + announce_element (cresc_p_, accepted_spanreqs_drul_[START]); } } } void -Dynamic_engraver::do_pre_move_processing() +Dynamic_engraver::do_pre_move_processing () { typeset_all (); } @@ -215,51 +291,52 @@ Dynamic_engraver::do_pre_move_processing() void Dynamic_engraver::do_removal_processing () { + typeset_all (); + if (line_spanner_) + { + finished_line_spanner_ = line_spanner_; + typeset_all (); + } + if (cresc_p_) { - typeset_element (cresc_p_ ); - cresc_req_l_->warning (_ ("unended crescendo")); - cresc_p_ =0; + current_cresc_req_->origin ()->warning (_ ("unterminated (de)crescendo")); + cresc_p_->suicide (); } - typeset_all (); } - void Dynamic_engraver::typeset_all () { - if (to_end_cresc_p_) + if (finished_cresc_p_) { - to_end_cresc_p_->set_bounds(RIGHT,get_staff_info().musical_pcol_l ()); - typeset_element (to_end_cresc_p_); - - to_end_cresc_p_ =0; - + typeset_element (finished_cresc_p_); + finished_cresc_p_ =0; } if (text_p_) { typeset_element (text_p_); - text_p_ =0; + text_p_ = 0; + } + if (finished_line_spanner_) + { + Side_position::add_staff_support (finished_line_spanner_); + extend_spanner_over_elements (finished_line_spanner_); + typeset_element (finished_line_spanner_); + finished_line_spanner_ = 0; } } - void Dynamic_engraver::acknowledge_element (Score_element_info i) { - if (dynamic_cast (i.elem_l_) - || dynamic_cast (i.elem_l_) - ) + if (Note_column::has_interface (i.elem_l_)) { - if (text_p_) - Side_position_interface (text_p_).add_support (i.elem_l_); - - if (to_end_cresc_p_) - Side_position_interface (to_end_cresc_p_).add_support (i.elem_l_); - - if (cresc_p_) - Side_position_interface(cresc_p_).add_support (i.elem_l_); + if (line_spanner_) + { + Side_position::add_support (line_spanner_,i.elem_l_); + add_bound_item (line_spanner_,dynamic_cast(i.elem_l_)); + } } } -