2 tuplet-engraver.cc -- implement Tuplet_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
9 #include "tuplet-bracket.hh"
10 #include "note-column.hh"
12 #include "engraver.hh"
15 #include "translator.icc"
17 struct Tuplet_description
30 class Tuplet_engraver : public Engraver
33 TRANSLATOR_DECLARATIONS (Tuplet_engraver);
36 vector<Tuplet_description> tuplets_;
37 vector<Tuplet_description> stopped_tuplets_;
38 vector<Spanner*> last_tuplets_;
39 DECLARE_ACKNOWLEDGER (note_column);
40 virtual bool try_music (Music *r);
41 virtual void finalize ();
42 void start_translation_timestep ();
43 void process_music ();
47 Tuplet_engraver::try_music (Music *music)
49 if (music->is_mus_type ("tuplet-spanner-event"))
51 Direction dir = to_dir (music->get_property ("span-direction"));
56 tuplets_.push_back (d);
60 stopped_tuplets_.push_back (tuplets_.back ());
69 Tuplet_engraver::process_music ()
71 for (vsize i = 0; i < stopped_tuplets_.size (); i++)
73 bool full_length = to_boolean (get_property ("tupletFullLength"));
74 if (stopped_tuplets_[i].bracket_)
78 Item *col = unsmob_item (get_property ("currentMusicalColumn"));
80 stopped_tuplets_[i].bracket_->set_bound (RIGHT, col);
81 stopped_tuplets_[i].number_->set_bound (RIGHT, col);
83 else if (!stopped_tuplets_[i].bracket_->get_bound (RIGHT))
85 stopped_tuplets_[i].bracket_->set_bound (RIGHT,
86 stopped_tuplets_[i].bracket_->get_bound (LEFT));
87 stopped_tuplets_[i].number_->set_bound (RIGHT,
88 stopped_tuplets_[i].bracket_->get_bound (LEFT));
90 // todo: scrap last_tuplets_, use stopped_tuplets_ only.
91 // clear stopped_tuplets_ at start_translation_timestep
92 last_tuplets_.push_back (tuplets_[i].bracket_);
93 last_tuplets_.push_back (tuplets_[i].number_);
96 stopped_tuplets_.clear ();
98 for (vsize j = tuplets_.size (); j > 0; j--)
100 /* i goes from size-1 downto 0, inclusively */
103 if (tuplets_[i].bracket_)
106 tuplets_[i].bracket_ = make_spanner ("TupletBracket",
107 tuplets_[i].music_->self_scm ());
108 tuplets_[i].number_ = make_spanner ("TupletNumber",
109 tuplets_[i].music_->self_scm ());
110 tuplets_[i].number_->set_object ("bracket", tuplets_[i].bracket_->self_scm ());
111 tuplets_[i].bracket_->set_object ("tuplet-number", tuplets_[i].number_->self_scm ());
113 if (i < tuplets_.size () - 1 && tuplets_[i + 1].bracket_)
114 Tuplet_bracket::add_tuplet_bracket (tuplets_[i].bracket_, tuplets_[i + 1].bracket_);
116 if (i > 0 && tuplets_[i - 1].bracket_)
117 Tuplet_bracket::add_tuplet_bracket (tuplets_[i - 1].bracket_, tuplets_[i].bracket_);
123 Tuplet_engraver::acknowledge_note_column (Grob_info inf)
125 for (vsize j = 0; j < tuplets_.size (); j++)
126 if (tuplets_[j].bracket_)
128 Item *i = dynamic_cast<Item *> (inf.grob ());
129 Tuplet_bracket::add_column (tuplets_[j].bracket_, i);
130 add_bound_item (tuplets_[j].number_, i);
135 Tuplet_engraver::start_translation_timestep ()
137 last_tuplets_.clear ();
141 Tuplet_engraver::finalize ()
143 if (to_boolean (get_property ("tupletFullLength")))
145 for (vsize i = 0; i < last_tuplets_.size (); i++)
147 Item *col = unsmob_item (get_property ("currentCommandColumn"));
148 last_tuplets_[i]->set_bound (RIGHT, col);
153 Tuplet_engraver::Tuplet_engraver ()
157 ADD_ACKNOWLEDGER (Tuplet_engraver, note_column);
158 ADD_TRANSLATOR (Tuplet_engraver,
159 /* doc */ "Catch TupletSpannerEvent and generate appropriate bracket ",
160 /* create */ "TupletBracket TupletNumber ",
161 /* accept */ "tuplet-spanner-event",
162 /* read */ "tupletFullLength ",