X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fdynamic-engraver.cc;h=0593606bb6f852073fdf838253e1537b44bc14cd;hb=9b34d4afef6dd3f50c8f9cec1e613eb44f8c7913;hp=b0670d523631731b106123a0a309bcd77a9b1227;hpb=b1aa7f76f1ad7606699fc797161a583df7367013;p=lilypond.git diff --git a/lily/dynamic-engraver.cc b/lily/dynamic-engraver.cc index b0670d5236..0593606bb6 100644 --- a/lily/dynamic-engraver.cc +++ b/lily/dynamic-engraver.cc @@ -1,269 +1,360 @@ /* - 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 "dynamic-engraver.hh" #include "musical-request.hh" -#include "lookup.hh" -#include "paper-def.hh" -#include "score-column.hh" -#include "staff-symbol.hh" +#include "paper-column.hh" #include "note-column.hh" -#include "g-text-item.hh" -#include "g-staff-side.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 { - G_text_item * text_p_; - G_staff_side_item * staff_side_p_; - G_staff_side_spanner * ss_span_p_; - G_staff_side_spanner * to_end_ss_span_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_; - Crescendo * to_end_cresc_p_; - Crescendo * cresc_p_; - Span_req * cresc_req_l_; - Array dynamic_req_l_arr_; - void typeset_all (); + 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() +Dynamic_engraver::Dynamic_engraver () { - do_post_move_processing(); - text_p_ =0; - staff_side_p_ =0; - to_end_cresc_p_ = cresc_p_ = 0; - ss_span_p_ = to_end_ss_span_p_=0; - cresc_req_l_ = 0; + 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; - G_staff_side_spanner * new_sss_p =0; - for (int i=0; i < dynamic_req_l_arr_.size(); i++) + if (accepted_spanreqs_drul_[START] || accepted_spanreqs_drul_[STOP] || text_req_l_) + { - if (Text_script_req *absd = - dynamic_cast ( dynamic_req_l_arr_[i])) + if (!line_spanner_) { - if (text_p_) - { - dynamic_req_l_arr_[i]->warning (_("Got a dynamic already. Continuing dazed and confused")); - continue; - } - - String loud = absd->text_str_; + line_spanner_ = new Spanner (get_property ("basicDynamicLineSpannerProperties")); - text_p_ = new G_text_item; - text_p_->text_str_ = loud; // ugh - Scalar prop = get_property ("dynamicStyle", 0); + 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]); - text_p_->style_str_ = prop.length_i () ? prop : "dynamic"; + } + } - staff_side_p_ = new G_staff_side_item; - staff_side_p_->set_elt_property (script_priority_scm_sym, - gh_int2scm (100)); - - staff_side_p_->set_victim (text_p_); - staff_side_p_->axis_ = Y_AXIS; - + /* + TODO: should finish and create new spanner if vertical dyn-direction is changed. + */ + else if (!accepted_spanreqs_drul_[START] && !text_req_l_) + { + finished_line_spanner_ = line_spanner_; + line_spanner_ = 0; + } - prop = get_property ("dynamicDir", 0); - if (prop.isnum_b ()) - { - staff_side_p_->dir_ = (Direction) (int) prop; - } + /* + 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. + */ + + + 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); - announce_element (Score_element_info (text_p_, absd)); - announce_element (Score_element_info (staff_side_p_, absd)); + 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 (!cresc_p_) + { + accepted_spanreqs_drul_[STOP]->origin ()->warning + (_ ("can't find start of (de)crescendo")); } - else if (Span_req *span_l - = dynamic_cast (dynamic_req_l_arr_[i])) + else { - 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_; - to_end_ss_span_p_ = ss_span_p_ ; - - cresc_p_ = 0; - ss_span_p_ =0; - Scalar prop = get_property ("dynamicDir", 0); - if (prop.isnum_b ()) - { - to_end_ss_span_p_->dir_ = (Direction) (int) prop; - } - - } - } - else if (span_l->span_dir_ == START) - { - cresc_req_l_ = span_l; - assert (!new_cresc_p); - new_cresc_p = new Crescendo; - new_cresc_p->grow_dir_ = (span_l->span_type_str_ == "crescendo") ? BIGGER : SMALLER; - announce_element (Score_element_info (new_cresc_p, span_l)); - - new_sss_p = new G_staff_side_spanner; - new_sss_p->set_victim (new_cresc_p); - new_sss_p->axis_ = Y_AXIS; - announce_element (Score_element_info (new_sss_p, span_l)); - } + assert (!finished_cresc_p_); + Score_element* cc = unsmob_element (get_property ("currentMusicalColumn")); + + cresc_p_->set_bound (RIGHT, cc); + + finished_cresc_p_ = cresc_p_; + cresc_p_ = 0; + current_cresc_req_ = 0; } } - if (new_cresc_p) + if (accepted_spanreqs_drul_[START]) { - if (cresc_p_) + if (current_cresc_req_) { - ::warning (_ ("Too many crescendi here")); - typeset_element (cresc_p_); - typeset_element (ss_span_p_); - cresc_p_ = 0; - ss_span_p_ =0; + accepted_spanreqs_drul_[START]->origin ()->warning + (current_cresc_req_->span_dir_ == 1 + ? _ ("already have a crescendo") + : _ ("already have a decrescendo")); } - - cresc_p_ = new_cresc_p; - ss_span_p_ = new_sss_p; - cresc_p_->set_bounds(LEFT,get_staff_info().musical_pcol_l ()); - ss_span_p_->set_bounds (LEFT,get_staff_info().musical_pcol_l ()); - if (text_p_) + else { - cresc_p_->dyn_b_drul_[LEFT] = true; - if (to_end_cresc_p_) - to_end_cresc_p_->dyn_b_drul_[RIGHT] = true; + 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)) + { + 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()); + + + /* + TODO: Use symbols. + */ + if (gh_string_p (s)) //&& ly_scm2string (s) != "hairpin") + { + cresc_p_->set_elt_property ("spanner", s); + daddy_trans_l_->set_property (accepted_spanreqs_drul_[START]->span_type_str_ + + "Spanner", SCM_UNDEFINED); + } + + Score_element *cc = unsmob_element (get_property ("currentMusicalColumn")); + cresc_p_->set_bound (LEFT, cc); + + + /* + 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. + + Since font-size may be set by a context higher up, we + can not be sure of the size. + + + 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. + */ + + + 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 ()); + } + + 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 (); } - - -ADD_THIS_TRANSLATOR(Dynamic_engraver); - void Dynamic_engraver::do_removal_processing () { + typeset_all (); + +#if 0 if (cresc_p_) { typeset_element (cresc_p_ ); - typeset_element (ss_span_p_); - ss_span_p_ =0; - cresc_req_l_->warning (_ ("unended crescendo")); - cresc_p_ =0; + finished_cresc_p_ = cresc_p_; + + current_cresc_req_->origin ()->warning (_ ("unterminated (de)crescendo")); + } + if (line_spanner_) + { + finished_line_spanner_ = line_spanner_; } typeset_all (); +#else + if (cresc_p_) + { + current_cresc_req_->origin ()->warning (_ ("unterminated (de)crescendo")); + cresc_p_->suicide (); + } + if (line_spanner_) + { + line_spanner_->suicide (); + } +#endif } - 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 ()); - to_end_ss_span_p_->set_bounds(RIGHT,get_staff_info().musical_pcol_l ()); - typeset_element (to_end_cresc_p_); - typeset_element (to_end_ss_span_p_); - to_end_cresc_p_ =0; - to_end_ss_span_p_ =0; + typeset_element (finished_cresc_p_); + finished_cresc_p_ =0; } if (text_p_) { typeset_element (text_p_); - typeset_element (staff_side_p_); - text_p_ =0; - staff_side_p_ =0; + text_p_ = 0; + } + if (finished_line_spanner_) + { + Side_position::add_staff_support (finished_line_spanner_); +#if 0 + if (!finished_line_spanner_->get_bound (LEFT)) + { + Score_element * cmc + = unsmob_element (get_property ("currentMusicalColumn")); + finished_line_spanner_->set_bound (LEFT, cmc); + } + if (!finished_line_spanner_->get_bound (RIGHT)) + finished_line_spanner_->set_bound (RIGHT, + finished_line_spanner_->get_bound (LEFT)); + +#endif + 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 (staff_side_p_) - staff_side_p_->add_support (i.elem_l_); - - if (to_end_ss_span_p_) - to_end_ss_span_p_->add_support (i.elem_l_); - - if (ss_span_p_) - ss_span_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_)); + } } }