2 tuplet-engraver.cc -- implement Tuplet_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include "tuplet-bracket.hh"
11 #include "note-column.hh"
12 #include "time-scaled-music.hh"
14 #include "music-list.hh"
15 #include "engraver.hh"
18 struct Tuplet_description
31 class Tuplet_engraver : public Engraver
34 TRANSLATOR_DECLARATIONS (Tuplet_engraver);
37 Array<Tuplet_description> tuplets_;
39 virtual void acknowledge_grob (Grob_info);
40 virtual bool try_music (Music*r);
41 virtual void start_translation_timestep ();
42 virtual void process_music ();
46 Tuplet_engraver::try_music (Music *music)
48 if (music->is_mus_type ("time-scaled-music"))
50 Music *el = unsmob_music (music->get_property ("element"));
51 if (el && !el->is_mus_type ("event-chord"))
55 d.stop_ = now_mom ().main_part_ + music->get_length ().main_part_;
56 d.span_stop_ = d.stop_;
58 SCM s = get_property ("tupletSpannerDuration");
59 if (unsmob_moment (s))
60 d.span_stop_ = d.span_stop_ <? (now_mom () + *unsmob_moment (s)).main_part_;
70 Tuplet_engraver::process_music ()
72 for (int i= 0; i < tuplets_.size (); i++)
74 if (tuplets_[i].spanner_)
77 Spanner* spanner = make_spanner ("TupletBracket",
78 tuplets_[i].music_->self_scm ());
79 tuplets_[i].spanner_ = spanner;
81 SCM proc = get_property ("tupletNumberFormatFunction");
82 if (ly_c_procedure_p (proc))
84 SCM t = scm_apply_0 (proc, scm_list_1 (tuplets_[i].music_->self_scm ()));
85 spanner->set_property ("text", t);
91 Tuplet_engraver::acknowledge_grob (Grob_info i)
93 if (Note_column::has_interface (i.grob_))
95 for (int j =0; j < tuplets_.size (); j++)
96 if (tuplets_[j].spanner_)
97 Tuplet_bracket::add_column (tuplets_[j].spanner_,
98 dynamic_cast<Item*> (i.grob_));
103 Tuplet_engraver::start_translation_timestep ()
105 Moment now = now_mom ();
108 SCM s = get_property ("tupletSpannerDuration");
109 if (unsmob_moment (s))
110 tsd = unsmob_moment (s)->main_part_;
112 for (int i = tuplets_.size (); i--;)
114 if (now.main_part_ >= tuplets_[i].span_stop_)
116 if (Spanner *sp = tuplets_[i].spanner_)
118 if (!sp->get_bound (RIGHT))
119 sp->set_bound (RIGHT, sp->get_bound (LEFT));
121 tuplets_[i].spanner_ = 0;
125 tuplets_[i].span_stop_ += tsd.main_part_;
128 if (now.main_part_ >= tuplets_[i].stop_)
135 Tuplet_engraver::Tuplet_engraver ()
139 ENTER_DESCRIPTION (Tuplet_engraver,
140 /* descr */ "Catch Time_scaled_music and generate appropriate bracket ",
141 /* creats*/ "TupletBracket",
142 /* accepts */ "time-scaled-music",
143 /* acks */ "note-column-interface",
144 /* reads */ "tupletNumberFormatFunction tupletSpannerDuration",