X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;ds=sidebyside;f=lily%2Ftuplet-engraver.cc;h=9acf07106b601525e6a388cfc0fa85bbbb9390b2;hb=32f10f1e5741ddadbae0ed5d4bd3008a22fb6fb9;hp=9441b7144a9b580c59d4a04a928538ca72c96f3a;hpb=2fd5f86de0500ecd9a3f47a2540c3b304f835ef4;p=lilypond.git diff --git a/lily/tuplet-engraver.cc b/lily/tuplet-engraver.cc index 9441b7144a..9acf07106b 100644 --- a/lily/tuplet-engraver.cc +++ b/lily/tuplet-engraver.cc @@ -1,32 +1,62 @@ -/* - auto-plet-engraver.cc -- implement Auto_plet_engraver - +/* + tuplet-engraver.cc -- implement Tuplet_engraver + source file of the GNU LilyPond music typesetter - - (c) 1998--1999 Han-Wen Nienhuys - - */ - -#include "tuplet-engraver.hh" -#include "command-request.hh" -#include "tuplet-spanner.hh" + + (c) 1998--2005 Han-Wen Nienhuys +*/ + +#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" + +struct Tuplet_description +{ + Music *music_; + Rational stop_; + Rational span_stop_; + Spanner *spanner_; + Tuplet_description () + { + music_ = 0; + spanner_ = 0; + } +}; + +class Tuplet_engraver : public Engraver +{ +public: + TRANSLATOR_DECLARATIONS (Tuplet_engraver); -ADD_THIS_TRANSLATOR (Tuplet_engraver); +protected: + Array tuplets_; + + virtual void acknowledge_grob (Grob_info); + virtual bool try_music (Music *r); + virtual void start_translation_timestep (); + virtual void process_music (); +}; bool -Tuplet_engraver::do_try_music (Music *r) +Tuplet_engraver::try_music (Music *music) { - if (Time_scaled_music * c = dynamic_cast (r)) + if (music->is_mus_type ("time-scaled-music")) { - Music *el = c->element_l (); - if (!dynamic_cast (el)) + Music *el = unsmob_music (music->get_property ("element")); + if (el && !el->is_mus_type ("event-chord")) { - time_scaled_music_arr_.push (c); - stop_moments_.push (now_mom () + c->length_mom ()); + Tuplet_description d; + d.music_ = music; + d.stop_ = now_mom ().main_part_ + music->get_length ().main_part_; + d.span_stop_ = d.stop_; + + SCM s = get_property ("tupletSpannerDuration"); + if (unsmob_moment (s)) + d.span_stop_ = d.span_stop_ set_elt_property ("text", - ly_str02scm (to_str (time_scaled_music_arr_[i]->den_i_).ch_C())); - - 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 (tuplets_[i].spanner_) + continue; + + Spanner *spanner = make_spanner ("TupletBracket", + tuplets_[i].music_->self_scm ()); + tuplets_[i].spanner_ = spanner; + + SCM proc = get_property ("tupletNumberFormatFunction"); + if (ly_c_procedure_p (proc)) + { + SCM t = scm_apply_0 (proc, scm_list_1 (tuplets_[i].music_->self_scm ())); + spanner->set_property ("text", t); + } } } void -Tuplet_engraver::acknowledge_element (Score_element_info i) +Tuplet_engraver::acknowledge_grob (Grob_info i) { - bool grace= to_boolean (i.elem_l_->get_elt_property ("grace")); - SCM wg = get_property ("weAreGraceContext",0); - bool wgb = to_boolean (wg); - if (grace != wgb) - return; - - if (Note_column *nc = dynamic_cast (i.elem_l_)) - { - for (int j =0; j add_column (nc); - } - else if (Beam *b = dynamic_cast (i.elem_l_)) + if (Note_column::has_interface (i.grob_)) { - for (int j = 0; j < started_span_p_arr_.size (); j++) - started_span_p_arr_[j]->add_beam (b); + for (int j = 0; j < tuplets_.size (); j++) + if (tuplets_[j].spanner_) + Tuplet_bracket::add_column (tuplets_[j].spanner_, + dynamic_cast (i.grob_)); } } 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 = tuplets_.size (); i--;) { - if (now >= stop_moments_[i]) + if (now.main_part_ >= tuplets_[i].span_stop_) + { + if (Spanner *sp = tuplets_[i].spanner_) + { + if (!sp->get_bound (RIGHT)) + sp->set_bound (RIGHT, sp->get_bound (LEFT)); + + tuplets_[i].spanner_ = 0; + } + + if (tsd.to_bool ()) + tuplets_[i].span_stop_ += tsd.main_part_; + } + + if (now.main_part_ >= tuplets_[i].stop_) { - typeset_element (started_span_p_arr_[i]); - started_span_p_arr_.del (i); - stop_moments_.del(i); - time_scaled_music_arr_.del(i); + tuplets_.del (i); } } } -void -Tuplet_engraver::do_removal_processing () +Tuplet_engraver::Tuplet_engraver () { - for (int i=0; i < started_span_p_arr_.size (); i++) - { - typeset_element (started_span_p_arr_[i]); - } } +ADD_TRANSLATOR (Tuplet_engraver, + /* descr */ "Catch Time_scaled_music and generate appropriate bracket ", + /* creats*/ "TupletBracket", + /* accepts */ "time-scaled-music", + /* acks */ "note-column-interface", + /* reads */ "tupletNumberFormatFunction tupletSpannerDuration", + /* write */ "");