-/*
- plet-engraver.cc -- implement Tuplet_engraver
-
+/*
+ tuplet-engraver.cc -- implement Tuplet_engraver
+
source file of the GNU LilyPond music typesetter
-
- (c) 1998--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
-
- */
+ (c) 1998--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
+*/
-#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"
+
+#include "translator.icc"
+
+struct Tuplet_description
+{
+ Music *music_;
+ Rational stop_;
+ Rational span_stop_;
+ Rational length_;
+ Spanner *bracket_;
+ Spanner *number_;
+ Tuplet_description ()
+ {
+ music_ = 0;
+ bracket_ = 0;
+ number_ = 0;
+ }
+ static int compare (Tuplet_description const &a, Tuplet_description const &b)
+ {
+ return ::compare (a.length_, b.length_);
+ }
+};
class Tuplet_engraver : public Engraver
{
public:
- VIRTUAL_COPY_CONS(Translator);
+ TRANSLATOR_DECLARATIONS (Tuplet_engraver);
protected:
- Link_array<Time_scaled_music> time_scaled_music_arr_;
- /// when does the scaled music stop? Array order is synced with time_scaled_music_arr_
- Array<Moment> stop_moments_;
- /// when does the current spanner stop? Array order is synced with time_scaled_music_arr_
- Array<Moment> span_stop_moments_;
-
- /// The spanners. Array order is synced with time_scaled_music_arr_
- Link_array<Tuplet_spanner> started_span_p_arr_;
-
- virtual void do_removal_processing ();
- virtual void acknowledge_element (Score_element_info);
- virtual bool do_try_music (Music*r);
- virtual void do_process_requests ();
- virtual void do_post_move_processing ();
+ Array<Tuplet_description> tuplets_;
+ Link_array<Spanner> last_tuplets_;
+ DECLARE_ACKNOWLEDGER (note_column);
+ virtual bool try_music (Music *r);
+ virtual void finalize ();
+ void start_translation_timestep ();
+ void process_music ();
};
bool
-Tuplet_engraver::do_try_music (Music *r)
+Tuplet_engraver::try_music (Music *music)
{
- if (Time_scaled_music * c = dynamic_cast<Time_scaled_music *> (r))
+ if (music->is_mus_type ("time-scaled-music"))
{
- Music *el = c->element_l ();
- if (!dynamic_cast<Request_chord*> (el))
+ Music *el = unsmob_music (music->get_property ("element"));
+ if (el && !el->is_mus_type ("event-chord"))
{
- time_scaled_music_arr_.push (c);
- Moment m = now_mom () + c->length_mom ();
- stop_moments_.push (m);
+ Tuplet_description d;
+ d.music_ = music;
+ d.length_ = music->get_length ().main_part_;
+ d.stop_ = now_mom ().main_part_ + d.length_;
+ d.span_stop_ = d.stop_;
SCM s = get_property ("tupletSpannerDuration");
- if (SMOB_IS_TYPE_B(Moment, s))
- m = m <? (now_mom () + *SMOB_TO_TYPE(Moment,s));
-
- span_stop_moments_.push (m);
+ if (unsmob_moment (s))
+ d.span_stop_ = min (d.span_stop_, (now_mom () + *unsmob_moment (s)).main_part_);
+
+ tuplets_.push (d);
}
return true;
}
}
void
-Tuplet_engraver::do_process_requests ()
+Tuplet_engraver::process_music ()
{
- SCM v = get_property ("tupletInvisible");
- if (to_boolean (v))
+ if (!tuplets_.size ())
return;
- for (int i= 0; i < time_scaled_music_arr_.size (); i++)
+ tuplets_.sort (&Tuplet_description::compare);
+ for (int i = 0; i < tuplets_.size (); i++)
{
- if (i < started_span_p_arr_.size () && started_span_p_arr_[i])
+ if (tuplets_[i].bracket_)
continue;
- Tuplet_spanner* glep = new Tuplet_spanner;
- if (i >= started_span_p_arr_.size ())
- started_span_p_arr_.push (glep);
- else
- started_span_p_arr_[i] = glep;
-
- glep->set_elt_property ("text",
- ly_str02scm (to_str (time_scaled_music_arr_[i]->den_i_).ch_C()));
+ tuplets_[i].bracket_ = make_spanner ("TupletBracket",
+ tuplets_[i].music_->self_scm ());
+ tuplets_[i].number_ = make_spanner ("TupletNumber",
+ tuplets_[i].music_->self_scm ());
+ tuplets_[i].number_->set_object ("bracket", tuplets_[i].bracket_->self_scm ());
+ tuplets_[i].bracket_->set_object ("tuplet-number", tuplets_[i].number_->self_scm ());
- announce_element (Score_element_info (glep, time_scaled_music_arr_ [i]));
+ if (i > 0 && tuplets_[i - 1].bracket_)
+ Tuplet_bracket::add_tuplet_bracket (tuplets_[i].bracket_, tuplets_[i - 1].bracket_);
+
+ if (i < tuplets_.size () - 1 && tuplets_[i + 1].bracket_)
+ Tuplet_bracket::add_tuplet_bracket (tuplets_[i + 1].bracket_, tuplets_[i].bracket_);
+
+ SCM proc = get_property ("tupletNumberFormatFunction");
+ if (ly_is_procedure (proc))
+ {
+ SCM t = scm_apply_0 (proc, scm_list_1 (tuplets_[i].music_->self_scm ()));
+ tuplets_[i].number_->set_property ("text", t);
+ }
}
}
void
-Tuplet_engraver::acknowledge_element (Score_element_info i)
+Tuplet_engraver::acknowledge_note_column (Grob_info inf)
{
- bool grace= to_boolean (i.elem_l_->get_elt_property ("grace"));
- SCM wg = get_property ("weAreGraceContext");
- bool wgb = to_boolean (wg);
- if (grace != wgb)
- return;
-
- if (Note_column *nc = dynamic_cast<Note_column *> (i.elem_l_))
- {
- for (int j =0; j <started_span_p_arr_.size (); j++)
- if (started_span_p_arr_[j])
- started_span_p_arr_[j]->add_column (nc);
- }
- else if (Beam *b = dynamic_cast<Beam *> (i.elem_l_))
- {
- for (int j = 0; j < started_span_p_arr_.size (); j++)
- if (started_span_p_arr_[j])
- started_span_p_arr_[j]->add_beam (b);
- }
+ for (int j = 0; j < tuplets_.size (); j++)
+ if (tuplets_[j].bracket_)
+ {
+ Item *i = dynamic_cast<Item *> (inf.grob ());
+ Tuplet_bracket::add_column (tuplets_[j].bracket_, i);
+ add_bound_item (tuplets_[j].number_, i);
+ }
}
void
-Tuplet_engraver::do_post_move_processing ()
+Tuplet_engraver::start_translation_timestep ()
{
Moment now = now_mom ();
- Moment tsd;
- SCM s = get_property ("tupletSpannerDuration");
- if (SMOB_IS_TYPE_B(Moment, s))
- tsd = *SMOB_TO_TYPE(Moment,s);
+ last_tuplets_.clear ();
+ if (tuplets_.is_empty ())
+ return;
+
+ Moment tsdmom = robust_scm2moment (get_property ("tupletSpannerDuration"), Moment (0));
+ bool full_length = to_boolean (get_property ("tupletFullLength"));
- for (int i= started_span_p_arr_.size (); i--; )
+ for (int i = tuplets_.size (); i--;)
{
- if (now >= span_stop_moments_[i])
+ Rational tsd = tsdmom.main_part_;
+
+ if (now.main_part_ >= tuplets_[i].span_stop_)
{
- if (started_span_p_arr_[i])
+ if (tuplets_[i].bracket_)
{
- typeset_element (started_span_p_arr_[i]);
- started_span_p_arr_[i] =0;
+ if (full_length)
+ {
+ Item *col = unsmob_item (get_property ("currentMusicalColumn"));
+
+ tuplets_[i].bracket_->set_bound (RIGHT, col);
+ tuplets_[i].number_->set_bound (RIGHT, col);
+ }
+ else if (!tuplets_[i].bracket_->get_bound (RIGHT))
+ {
+ tuplets_[i].bracket_->set_bound (RIGHT,
+ tuplets_[i].bracket_->get_bound (LEFT));
+ tuplets_[i].number_->set_bound (RIGHT,
+ tuplets_[i].bracket_->get_bound (LEFT));
+ }
+ last_tuplets_.push (tuplets_[i].bracket_);
+ last_tuplets_.push (tuplets_[i].number_);
+
+ tuplets_[i].bracket_ = 0;
+ tuplets_[i].number_ = 0;
}
-
+
if (tsd)
- span_stop_moments_[i] += tsd;
+ tuplets_[i].span_stop_ += tsd;
}
- if (now >= stop_moments_[i])
- {
- started_span_p_arr_.del (i);
- stop_moments_.del(i);
- span_stop_moments_.del (i);
- time_scaled_music_arr_.del(i);
- }
+ if (now.main_part_ >= tuplets_[i].stop_)
+ tuplets_.del (i);
}
}
void
-Tuplet_engraver::do_removal_processing ()
+Tuplet_engraver::finalize ()
{
- for (int i=0; i < started_span_p_arr_.size (); i++)
+ if (to_boolean (get_property ("tupletFullLength")))
{
- if (started_span_p_arr_[i])
- typeset_element (started_span_p_arr_[i]);
- }
+ for (int i = 0; i < last_tuplets_.size (); i++)
+ {
+ Item *col = unsmob_item (get_property ("currentCommandColumn"));
+ last_tuplets_[i]->set_bound (RIGHT, col);
+ }
+ }
}
-ADD_THIS_TRANSLATOR(Tuplet_engraver);
-
+Tuplet_engraver::Tuplet_engraver ()
+{
+}
+ADD_ACKNOWLEDGER (Tuplet_engraver, note_column);
+ADD_TRANSLATOR (Tuplet_engraver,
+ /* doc */ "Catch Time_scaled_music and generate appropriate bracket ",
+ /* create */ "TupletBracket TupletNumber",
+ /* accept */ "time-scaled-music",
+ /* read */ "tupletNumberFormatFunction tupletSpannerDuration tupletFullLength",
+ /* write */ "");