X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Ftuplet-engraver.cc;h=8ace269d131fbbc0782b35f709f97aca740ed9a1;hb=498d0148b2c2611a8d96549527a3c14fa6e9de04;hp=b8f85eb870dfef0668728e58597190d19fbea66b;hpb=f6e3a77381e8eb67aa01195ec3945bd978f86aa8;p=lilypond.git diff --git a/lily/tuplet-engraver.cc b/lily/tuplet-engraver.cc index b8f85eb870..8ace269d13 100644 --- a/lily/tuplet-engraver.cc +++ b/lily/tuplet-engraver.cc @@ -1,30 +1,61 @@ /* - auto-plet-engraver.cc -- implement Auto_plet_engraver + plet-engraver.cc -- implement Tuplet_engraver source file of the GNU LilyPond music typesetter - (c) 1998--1999 Han-Wen Nienhuys + (c) 1998--2002 Han-Wen Nienhuys */ -#include "tuplet-engraver.hh" + #include "command-request.hh" -#include "tuplet-spanner.hh" +#include "tuplet-bracket.hh" #include "note-column.hh" #include "time-scaled-music.hh" #include "beam.hh" #include "music-list.hh" +#include "engraver.hh" +#include "spanner.hh" + +class Tuplet_engraver : public Engraver +{ +public: + TRANSLATOR_DECLARATIONS(Tuplet_engraver); + +protected: + Link_array time_scaled_music_arr_; + /// when does the scaled music stop? Array order is synced with time_scaled_music_arr_ + Array stop_moments_; + /// when does the current spanner stop? Array order is synced with time_scaled_music_arr_ + Array span_stop_moments_; + + /// The spanners. Array order is synced with time_scaled_music_arr_ + Link_array started_span_p_arr_; + + virtual void finalize (); + virtual void acknowledge_grob (Grob_info); + virtual bool try_music (Music*r); + virtual void start_translation_timestep (); + virtual void create_grobs (); +}; bool -Tuplet_engraver::do_try_music (Music *r) +Tuplet_engraver::try_music (Music *r) { if (Time_scaled_music * c = dynamic_cast (r)) { - Music *el = c->element_l (); + Music *el = c->element (); if (!dynamic_cast (el)) { time_scaled_music_arr_.push (c); - stop_moments_.push (now_mom () + c->length_mom ()); + Rational m = now_mom ().main_part_ + c->length_mom ().main_part_; + stop_moments_.push (m); + + SCM s = get_property ("tupletSpannerDuration"); + if (unsmob_moment (s)) + m = m number_str_ = to_str (time_scaled_music_arr_[i]->den_i_); - glep->set_elt_property("tuplet-visibility", - gh_int2scm (visibility)); - if (dir != 0) - glep->set_elt_property("dir-forced", gh_int2scm (dir)); - announce_element (Score_element_info (glep, time_scaled_music_arr_ [i])); + if (i < started_span_p_arr_.size () && started_span_p_arr_[i]) + continue; + + Spanner* glep = new Spanner (get_property ("TupletBracket")); + + if (i >= started_span_p_arr_.size ()) + started_span_p_arr_.push (glep); + else + started_span_p_arr_[i] = glep; + + + SCM proc = get_property ("tupletNumberFormatFunction"); + if (gh_procedure_p (proc)) + { + SCM t = gh_apply (proc, scm_list_n (time_scaled_music_arr_[i]->self_scm (), SCM_UNDEFINED)); + glep->set_grob_property ("text", t); + } + + announce_grob(glep, time_scaled_music_arr_ [i]->self_scm()); } } void -Tuplet_engraver::acknowledge_element (Score_element_info i) +Tuplet_engraver::acknowledge_grob (Grob_info i) { - bool grace= (i.elem_l_->get_elt_property ("grace") != SCM_UNDEFINED); - SCM wg = get_property ("weAreGraceContext",0); - bool wgb = to_boolean (wg); - if (grace != wgb) - return; - - if (Note_column *nc = dynamic_cast (i.elem_l_)) + if (Note_column::has_interface (i.grob_l_)) { for (int j =0; j add_column (nc); - } - else if (Beam *b = dynamic_cast (i.elem_l_)) - { - for (int j = 0; j < started_span_p_arr_.size (); j++) - started_span_p_arr_[j]->add_beam (b); + if (started_span_p_arr_[j]) + Tuplet_bracket::add_column (started_span_p_arr_[j], dynamic_cast (i.grob_l_)); } } void -Tuplet_engraver::do_post_move_processing () +Tuplet_engraver::start_translation_timestep () { Moment now = now_mom (); - for (int i= started_span_p_arr_.size (); i--; ) + + Moment tsd; + SCM s = get_property ("tupletSpannerDuration"); + if (unsmob_moment (s)) + tsd = unsmob_moment (s)->main_part_; + + for (int i= started_span_p_arr_.size (); i--;) { - if (now >= stop_moments_[i]) + if (now.main_part_ >= span_stop_moments_[i]) + { + if (started_span_p_arr_[i]) + { + typeset_grob (started_span_p_arr_[i]); + started_span_p_arr_[i] =0; + } + + if (tsd.to_bool ()) + span_stop_moments_[i] += tsd.main_part_; + } + + if (now.main_part_ >= stop_moments_[i]) { - typeset_element (started_span_p_arr_[i]); started_span_p_arr_.del (i); - stop_moments_.del(i); - time_scaled_music_arr_.del(i); + stop_moments_.del (i); + span_stop_moments_.del (i); + time_scaled_music_arr_.del (i); } } } void -Tuplet_engraver::do_removal_processing () +Tuplet_engraver::finalize () { for (int i=0; i < started_span_p_arr_.size (); i++) { - typeset_element (started_span_p_arr_[i]); + if (started_span_p_arr_[i]) + typeset_grob (started_span_p_arr_[i]); } } -ADD_THIS_TRANSLATOR(Tuplet_engraver); +Tuplet_engraver::Tuplet_engraver(){} + +ENTER_DESCRIPTION(Tuplet_engraver, +/* descr */ "Catch Time_scaled_music and generate appropriate bracket ", +/* creats*/ "TupletBracket", +/* acks */ "note-column-interface", +/* reads */ "tupletNumberFormatFunction tupletSpannerDuration tupletInvisible", +/* write */ "");