-/*
- 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--2005 Han-Wen Nienhuys <hanwen@cs.uu.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"
+
+struct Tuplet_description
+{
+ Music *music_;
+ Rational stop_;
+ Rational span_stop_;
+ Spanner *spanner_;
+ Tuplet_description ()
+ {
+ music_ = 0;
+ spanner_ = 0;
+ }
+};
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_music ();
- virtual void do_post_move_processing ();
+ Array<Tuplet_description> 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<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.stop_ = now_mom ().main_part_ + music->get_length ().main_part_;
+ d.span_stop_ = d.stop_;
SCM s = get_property ("tupletSpannerDuration");
- if (unsmob_moment(s))
- m = m <? (now_mom () + *unsmob_moment (s));
-
- span_stop_moments_.push (m);
+ if (unsmob_moment (s))
+ d.span_stop_ = d.span_stop_ <? (now_mom () + *unsmob_moment (s)).main_part_;
+
+ tuplets_.push (d);
}
return true;
}
}
void
-Tuplet_engraver::do_process_music ()
+Tuplet_engraver::process_music ()
{
- SCM v = get_property ("tupletInvisible");
- if (to_boolean (v))
- return;
-
- for (int i= 0; i < time_scaled_music_arr_.size (); i++)
+ for (int i = 0; i < tuplets_.size (); i++)
{
- if (i < started_span_p_arr_.size () && started_span_p_arr_[i])
+ if (tuplets_[i].spanner_)
continue;
- Tuplet_spanner* glep = new Tuplet_spanner (get_property ("basicTupletSpannerProperties"));
- 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()));
-
- announce_element (Score_element_info (glep, time_scaled_music_arr_ [i]));
+ 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");
- 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_))
+ if (Note_column::has_interface (i.grob_))
{
- 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].spanner_)
+ Tuplet_bracket::add_column (tuplets_[j].spanner_,
+ dynamic_cast<Item *> (i.grob_));
}
}
void
-Tuplet_engraver::do_post_move_processing ()
+Tuplet_engraver::start_translation_timestep ()
{
Moment now = now_mom ();
Moment tsd;
SCM s = get_property ("tupletSpannerDuration");
if (unsmob_moment (s))
- tsd = *unsmob_moment (s);
+ tsd = unsmob_moment (s)->main_part_;
- for (int i= started_span_p_arr_.size (); i--; )
+ for (int i = tuplets_.size (); i--;)
{
- if (now >= span_stop_moments_[i])
+ if (now.main_part_ >= tuplets_[i].span_stop_)
{
- if (started_span_p_arr_[i])
+ if (Spanner *sp = tuplets_[i].spanner_)
{
- typeset_element (started_span_p_arr_[i]);
- started_span_p_arr_[i] =0;
+ if (!sp->get_bound (RIGHT))
+ sp->set_bound (RIGHT, sp->get_bound (LEFT));
+
+ tuplets_[i].spanner_ = 0;
}
-
- if (tsd)
- span_stop_moments_[i] += tsd;
+
+ if (tsd.to_bool ())
+ tuplets_[i].span_stop_ += tsd.main_part_;
}
- if (now >= stop_moments_[i])
+ if (now.main_part_ >= tuplets_[i].stop_)
{
- started_span_p_arr_.del (i);
- stop_moments_.del(i);
- span_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++)
- {
- if (started_span_p_arr_[i])
- typeset_element (started_span_p_arr_[i]);
- }
}
-ADD_THIS_TRANSLATOR(Tuplet_engraver);
-
-
+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 */ "");