X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;ds=sidebyside;f=lily%2Fpercent-repeat-engraver.cc;h=521972ec315be8464af520c65dbfe8e3790062a2;hb=60b8cc51f7c8f3b908c497cc444ed3d5da5cb94b;hp=0082971d9b4b62dd934b6bc6f7da102175039e05;hpb=4995fea559cd5399b4f462de546a15195d76f4c3;p=lilypond.git diff --git a/lily/percent-repeat-engraver.cc b/lily/percent-repeat-engraver.cc index 0082971d9b..521972ec31 100644 --- a/lily/percent-repeat-engraver.cc +++ b/lily/percent-repeat-engraver.cc @@ -1,45 +1,38 @@ -/* - new-chord-tremolo-engraver.cc -- implement Chord_tremolo_engraver - +/* + new-chord-tremolo-engraver.cc -- implement Chord_tremolo_engraver + source file of the GNU LilyPond music typesetter - - (c) 2000--2001 Han-Wen Nienhuys - - */ -#include "engraver.hh" + (c) 2000--2005 Han-Wen Nienhuys +*/ + #include "repeated-music.hh" -#include "engraver-group-engraver.hh" -#include "global-translator.hh" +#include "global-context.hh" #include "warn.hh" #include "misc.hh" #include "spanner.hh" #include "item.hh" #include "percent-repeat-iterator.hh" -#include "bar.hh" - +#include "bar-line.hh" #include "score-engraver.hh" -#include "translator-group.hh" /** - This acknowledges repeated music with "percent" style. It typesets - a % sign. + This acknowledges repeated music with "percent" style. It typesets + a % sign. - TODO: + TODO: - - BEAT case: Create items for single beat repeats, i.e. c4 / / / + - BEAT case: Create items for single beat repeats, i.e. c4 / / / - - DOUBLE_MEASURE case: attach a % to an appropriate barline. - + - DOUBLE_MEASURE case: attach a % to an appropriate barline. */ class Percent_repeat_engraver : public Engraver { void typeset_perc (); public: - VIRTUAL_COPY_CONS (Translator); - Percent_repeat_engraver (); + TRANSLATOR_DECLARATIONS (Percent_repeat_engraver); protected: - Repeated_music * repeat_; + Music *repeat_; /// moment (global time) where beam started. Moment start_mom_; @@ -50,89 +43,78 @@ protected: Moment next_moment_; Moment body_length_; - enum { - UNKNOWN, - BEAT, - MEASURE, - DOUBLE_MEASURE, - } repeat_sign_type_ ; - - Item * beat_slash_; - Item * double_percent_; - Spanner * perc_p_; - Spanner * finished_perc_p_; - Item * stem_tremolo_; + enum + { + UNKNOWN, + MEASURE, + DOUBLE_MEASURE, + } + repeat_sign_type_; + + Item *double_percent_; + Spanner *perc_; + Spanner *finished_perc_; protected: virtual void finalize (); - virtual bool try_music (Music*); - virtual void stop_translation_timestep (); - virtual void start_translation_timestep (); - virtual void process_music (); + virtual bool try_music (Music *); + void stop_translation_timestep (); + void start_translation_timestep (); + void process_music (); }; Percent_repeat_engraver::Percent_repeat_engraver () { - perc_p_ = finished_perc_p_ = 0; - repeat_ =0; - stem_tremolo_ = 0; + perc_ = 0; + finished_perc_ = 0; + repeat_ = 0; - beat_slash_ = 0; double_percent_ = 0; } bool -Percent_repeat_engraver::try_music (Music * m) +Percent_repeat_engraver::try_music (Music *m) { - Repeated_music * rp = dynamic_cast (m); - if (rp - && rp->get_mus_property ("iterator-ctor") - == Percent_repeat_iterator::constructor_cxx_function + if (m->is_mus_type ("repeated-music") + && m->get_property ("iterator-ctor") + == Percent_repeat_iterator::constructor_proc && !repeat_) { - body_length_ = rp->body_length_mom (); - int count = rp->repeat_count (); - + body_length_ = Repeated_music::body_get_length (m); + int count = Repeated_music::repeat_count (m); + Moment now = now_mom (); start_mom_ = now; stop_mom_ = start_mom_ + Moment (count) * body_length_; next_moment_ = start_mom_ + body_length_; - SCM m = get_property ("measureLength"); - Moment meas_len; - if (unsmob_moment (m)) - meas_len = *unsmob_moment (m); - - if (body_length_ < meas_len && - meas_len.main_part_.mod_rat (body_length_.main_part_) == Moment (0,0)) - repeat_sign_type_ = BEAT; - else if (meas_len == body_length_) + Moment meas_len (robust_scm2moment (get_property ("measureLength"), Moment (1))); + if (meas_len == body_length_) repeat_sign_type_ = MEASURE; - else if (Moment (2)* meas_len == body_length_) - { - repeat_sign_type_ = DOUBLE_MEASURE; - next_moment_ += meas_len ; - } + else if (Moment (2) * meas_len == body_length_) + repeat_sign_type_ = DOUBLE_MEASURE; else { - warning (_ ("Don't know how to handle a percent repeat of this length.")); + warning (_f ("can't handle a percent repeat of length: %s", + body_length_.to_string ())); return false; } - repeat_ = rp; + repeat_ = m; - - Global_translator *global_l =0; - Translator *t = this; - do + Global_context *global = get_global_context (); + for (int i = 1; i < count; i++) { - t = t->daddy_trans_l_ ; - global_l = dynamic_cast (t); + Moment m = next_moment_ + Moment (i) * body_length_; + global->add_moment_to_process (m); + + /* bars between % too. */ + if (repeat_sign_type_ == DOUBLE_MEASURE) + global->add_moment_to_process (m - meas_len); } - while (!global_l); - for (int i = 0; i < count; i++) - global_l->add_moment_to_process (now + Moment (1+i) * body_length_); - + if (repeat_sign_type_ == DOUBLE_MEASURE) + next_moment_ += meas_len; + return true; } @@ -144,40 +126,25 @@ Percent_repeat_engraver::process_music () { if (repeat_ && now_mom () == next_moment_) { - if (repeat_sign_type_ == BEAT) - { - beat_slash_ = new Item (get_property ("RepeatSlash")); - announce_grob (beat_slash_, repeat_); - } - else if (repeat_sign_type_ == MEASURE) + if (repeat_sign_type_ == MEASURE) { - finished_perc_p_ = perc_p_; + finished_perc_ = perc_; typeset_perc (); - perc_p_ = new Spanner (get_property ("PercentRepeat")); - SCM col =get_property ("currentCommandColumn"); - perc_p_->set_bound (LEFT, unsmob_grob (col)); - announce_grob (perc_p_, repeat_); + perc_ = make_spanner ("PercentRepeat", repeat_->self_scm ()); + SCM col = get_property ("currentCommandColumn"); + perc_->set_bound (LEFT, unsmob_grob (col)); } else if (repeat_sign_type_ == DOUBLE_MEASURE) - { - double_percent_ = new Item (get_property ("DoublePercentRepeat")); - announce_grob (double_percent_, repeat_); - - /* - forbid breaks on a % line. Should forbid all breaks, really. - */ - Score_engraver * e = 0; - Translator * t = daddy_grav_l (); - for (; !e && t; t = t->daddy_trans_l_) - { - e = dynamic_cast (t); - } - - if (!e) - programming_error ("No score engraver!"); - else - e->forbid_breaks (); // guh. Use properties! + double_percent_ = make_item ("DoublePercentRepeat", repeat_->self_scm ()); + + /* + forbid breaks on a % line. Should forbid all breaks, really. + + Ugh. Why can't this be regular communication between + contexts? + */ + get_score_engraver ()->forbid_breaks (); } next_moment_ = next_moment_ + body_length_; } @@ -187,63 +154,53 @@ void Percent_repeat_engraver::finalize () { typeset_perc (); - if (perc_p_) + if (perc_) { - repeat_->origin ()->warning (_ ("unterminated chord tremolo")); - perc_p_->suicide (); + repeat_->origin ()->warning (_ ("unterminated percent repeat")); + perc_->suicide (); } } void Percent_repeat_engraver::typeset_perc () { - if (finished_perc_p_) + if (finished_perc_) { - SCM col =get_property ("currentCommandColumn"); - finished_perc_p_->set_bound (RIGHT, unsmob_grob (col)); - typeset_grob (finished_perc_p_); - finished_perc_p_ = 0; + SCM col = get_property ("currentCommandColumn"); + finished_perc_->set_bound (RIGHT, unsmob_grob (col)); + finished_perc_ = 0; } - if (beat_slash_) - { - typeset_grob (beat_slash_); - beat_slash_ = 0; - } - - if (double_percent_) - { - typeset_grob (double_percent_); - double_percent_ = 0; - } + double_percent_ = 0; } - - - void Percent_repeat_engraver::start_translation_timestep () { if (stop_mom_ == now_mom ()) { - if (perc_p_) + if (perc_) { - finished_perc_p_ = perc_p_; + finished_perc_ = perc_; typeset_perc (); } repeat_ = 0; - perc_p_ = 0; + perc_ = 0; repeat_sign_type_ = UNKNOWN; } } - void Percent_repeat_engraver::stop_translation_timestep () { typeset_perc (); } -ADD_THIS_TRANSLATOR (Percent_repeat_engraver); - +#include "translator.icc" +ADD_TRANSLATOR (Percent_repeat_engraver, + /* doc */ "Make whole bar and double bar repeats.", + /* create */ "PercentRepeat DoublePercentRepeat", + /* accept */ "repeated-music", + /* read */ "measureLength currentCommandColumn", + /* write */ "");