X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fdynamic-engraver.cc;h=273aa105688c435fa9221f1b7b6643d7f96cb2fc;hb=b542997680bb2d95c3a03a77468b67e04d30685f;hp=dff3e7259325bfbbb768d40d0e4fafe8d564660f;hpb=a16fa3d5e278abdbcdd3a02e0074b0ed038ff4a2;p=lilypond.git diff --git a/lily/dynamic-engraver.cc b/lily/dynamic-engraver.cc index dff3e72593..273aa10568 100644 --- a/lily/dynamic-engraver.cc +++ b/lily/dynamic-engraver.cc @@ -24,32 +24,37 @@ #include "directional-element-interface.hh" #include "staff-symbol-referencer.hh" #include "translator-group.hh" +#include "axis-group-interface.hh" /* TODO: - * fix vertical placement of orphaned items - * fix padding + * direction of text-dynamic-request if not equalt to direction + of line-spanner + + * FIXME: this has gotten a bit too hairy. */ class Dynamic_line_spanner : public Spanner { public: - Dynamic_line_spanner (); + Dynamic_line_spanner (SCM); VIRTUAL_COPY_CONS(Score_element); - void add_column (Item*); - Direction get_default_dir () const; + void add_column (Note_column*); + void add_element (Score_element*); }; -Dynamic_line_spanner::Dynamic_line_spanner () +Dynamic_line_spanner::Dynamic_line_spanner (SCM s) + : Spanner (s) { - set_elt_property ("transparent", SCM_BOOL_T); - side_position (this).set_axis (Y_AXIS); + Side_position_interface (this).set_axis (Y_AXIS); + Axis_group_interface (this).set_interface (); + Axis_group_interface (this).set_axes (X_AXIS, Y_AXIS); } void -Dynamic_line_spanner::add_column (Item* n) +Dynamic_line_spanner::add_column (Note_column* n) { if (!get_bound (LEFT)) set_bound (LEFT, n); @@ -59,10 +64,12 @@ Dynamic_line_spanner::add_column (Item* n) add_dependency (n); } -Direction -Dynamic_line_spanner::get_default_dir () const + +void +Dynamic_line_spanner::add_element (Score_element* e) { - return DOWN; + e->set_parent (this, Y_AXIS); + Axis_group_interface (this).add_element (e); } /** @@ -79,9 +86,10 @@ class Dynamic_engraver : public Engraver Drul_array span_req_l_drul_; Dynamic_line_spanner* line_spanner_; + Dynamic_line_spanner* finished_line_spanner_; Moment last_request_mom_; - Note_column* pending_column_; + Array pending_column_arr_; Link_array pending_element_arr_; void typeset_all (); @@ -99,7 +107,6 @@ protected: virtual void do_process_music (); virtual void do_pre_move_processing (); virtual void do_post_move_processing (); - virtual void typeset_element (Score_element*); }; ADD_THIS_TRANSLATOR (Dynamic_engraver); @@ -107,7 +114,7 @@ ADD_THIS_TRANSLATOR (Dynamic_engraver); void Dynamic_engraver::announce_element (Score_element_info i) { - group (i.elem_l_, "interfaces").add_thing (ly_symbol2scm ("dynamic")); + Group_interface (i.elem_l_, "interfaces").add_thing (ly_symbol2scm ("dynamic")); Engraver::announce_element (i); } @@ -118,9 +125,9 @@ Dynamic_engraver::Dynamic_engraver () text_p_ = 0; finished_cresc_p_ = 0; line_spanner_ = 0; + finished_line_spanner_ = 0; span_start_req_l_ = 0; cresc_p_ =0; - pending_column_ = 0; text_req_l_ = 0; span_req_l_drul_[START] = 0; @@ -133,12 +140,6 @@ Dynamic_engraver::do_post_move_processing () text_req_l_ = 0; span_req_l_drul_[START] = 0; span_req_l_drul_[STOP] = 0; - - /* ugr; we must attach the Dynamic_line_spanner to something - to be sure that the linebreaker will not be confused - */ - // if (line_spanner_) - // line_spanner_->add_column (LEFT, get_staff_info ().command_pcol_l ()); } bool @@ -167,14 +168,14 @@ Dynamic_engraver::do_try_music (Music * m) void Dynamic_engraver::do_process_music () { - if ((span_req_l_drul_[START] || text_req_l_) + if ((span_req_l_drul_[START] || span_req_l_drul_[STOP] || text_req_l_) && !line_spanner_ && pending_element_arr_.size ()) { - line_spanner_ = new Dynamic_line_spanner; - assert (pending_column_); - line_spanner_->add_column (pending_column_); - side_position (line_spanner_).set_axis (Y_AXIS); + line_spanner_ = new Dynamic_line_spanner (get_property ("basicDynamicLineSpannerProperties")); + for (int i = 0; i < pending_column_arr_.size (); i++) + line_spanner_->add_column (pending_column_arr_[i]); + pending_column_arr_.clear (); announce_element (Score_element_info (line_spanner_, text_req_l_ ? text_req_l_ : span_req_l_drul_[START])); @@ -184,30 +185,91 @@ Dynamic_engraver::do_process_music () if (line_spanner_ && pending_element_arr_.size ()) { for (int i = 0; i < pending_element_arr_.size (); i++) - pending_element_arr_[i]->set_parent (line_spanner_, Y_AXIS); + line_spanner_->add_element (pending_element_arr_[i]); pending_element_arr_.clear (); } - if (span_req_l_drul_[START] || text_req_l_) - last_request_mom_ = now_mom (); + /* + TODO: This should be optionised: + * break when group of dynamic requests ends + * break now (only if no cresc. in progress) + * continue through piece */ + if (span_req_l_drul_[START] || span_req_l_drul_[STOP] || text_req_l_) + { + last_request_mom_ = now_mom (); + } else - pending_element_arr_.clear (); + { + /* + 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 (now_mom () > last_request_mom_ && !span_start_req_l_) + { + for (int i = 0; i < pending_element_arr_.size (); i++) + { + Score_element* e = pending_element_arr_[i]; + Side_position_interface (e).set_axis (Y_AXIS); + Side_position_interface (e).add_staff_support (); + + /* + UGH UGH + */ + Direction d = directional_element (e).get (); + if (!d) + { + SCM s = get_property ("dynamicDirection"); + if (!isdir_b (s)) + s = get_property ("verticalDirection"); + if (isdir_b (s)) + d = to_dir (s); + directional_element (e).set (d); + } + + SCM s = get_property ("dynamicPadding"); + if (gh_number_p (s)) + e->set_elt_property ("padding", s); + s = get_property ("dynamicMinimumSpace"); + if (gh_number_p (s)) + e->set_elt_property ("minimum-space", s); + } + pending_element_arr_.clear (); + if (line_spanner_) + { + for (int i = 0; i < pending_column_arr_.size (); i++) + line_spanner_->add_column (pending_column_arr_[i]); + pending_column_arr_.clear (); + finished_line_spanner_ = line_spanner_; + line_spanner_ = 0; + } + } + } - if (text_req_l_) { String loud = text_req_l_->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_ = new Text_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 (text_p_).set (d); pending_element_arr_.push (text_p_); - text_p_->set_elt_property ("self-alignment-Y", gh_int2scm (0)); - text_p_->dim_cache_[Y_AXIS]->off_callbacks_.push - (Side_position_interface::aligned_on_self); + + text_p_->add_offset_callback (Side_position_interface::aligned_on_self, + Y_AXIS); announce_element (Score_element_info (text_p_, text_req_l_)); } @@ -221,7 +283,7 @@ Dynamic_engraver::do_process_music () else { assert (!finished_cresc_p_); - cresc_p_->set_bound(RIGHT, get_staff_info ().musical_pcol_l ()); + cresc_p_->set_bound (RIGHT, get_staff_info ().musical_pcol_l ()); finished_cresc_p_ = cresc_p_; cresc_p_ = 0; span_start_req_l_ = 0; @@ -241,7 +303,7 @@ Dynamic_engraver::do_process_music () else { span_start_req_l_ = span_req_l_drul_[START]; - cresc_p_ = new Crescendo; + cresc_p_ = new Crescendo (get_property ("basicCrescendoProperties")); cresc_p_->set_elt_property ("grow-direction", gh_int2scm ((span_req_l_drul_[START]->span_type_str_ == "crescendo") @@ -256,6 +318,11 @@ Dynamic_engraver::do_process_music () } s = get_property (span_req_l_drul_[START]->span_type_str_ + "Spanner"); + + + /* + TODO: Use symbols. + */ if (gh_string_p (s)) //&& ly_scm2string (s) != "hairpin") { cresc_p_->set_elt_property ("spanner", s); @@ -263,7 +330,7 @@ Dynamic_engraver::do_process_music () + "Spanner", SCM_UNDEFINED); } - cresc_p_->set_bound(LEFT, get_staff_info ().musical_pcol_l ()); + cresc_p_->set_bound (LEFT, get_staff_info ().musical_pcol_l ()); /* @@ -292,8 +359,8 @@ Dynamic_engraver::do_process_music () } pending_element_arr_.push (cresc_p_); cresc_p_->set_elt_property ("self-alignment-Y", gh_int2scm (0)); - cresc_p_->dim_cache_[Y_AXIS]->off_callbacks_.push - (Side_position_interface::aligned_on_self); + cresc_p_->add_offset_callback + (Side_position_interface::aligned_on_self, Y_AXIS); announce_element (Score_element_info (cresc_p_, span_req_l_drul_[START])); } } @@ -305,7 +372,6 @@ Dynamic_engraver::do_pre_move_processing () typeset_all (); } - void Dynamic_engraver::do_removal_processing () { @@ -318,18 +384,12 @@ Dynamic_engraver::do_removal_processing () typeset_all (); if (line_spanner_) { + Side_position_interface (line_spanner_).add_staff_support (); typeset_element (line_spanner_); line_spanner_ = 0; } } -void -Dynamic_engraver::typeset_element (Score_element* e) -{ - side_position (e).add_staff_support (); - Engraver::typeset_element (e); -} - void Dynamic_engraver::typeset_all () { @@ -344,16 +404,11 @@ Dynamic_engraver::typeset_all () typeset_element (text_p_); text_p_ = 0; } - - /* - TODO: This should be optionised: - * break when group of dynamic requests ends - * break now - * continue through piece */ - if (line_spanner_ && last_request_mom_ < now_mom ()) + if (finished_line_spanner_) { - typeset_element (line_spanner_); - line_spanner_ = 0; + Side_position_interface (finished_line_spanner_).add_staff_support (); + typeset_element (finished_line_spanner_); + finished_line_spanner_ = 0; } } @@ -364,12 +419,12 @@ Dynamic_engraver::acknowledge_element (Score_element_info i) { if (line_spanner_) { - side_position (line_spanner_).add_support (n); + Side_position_interface (line_spanner_).add_support (n); line_spanner_->add_column (n); } else { - pending_column_ = n; + pending_column_arr_.push (n); } } }