X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fpiano-pedal-engraver.cc;h=95cc99d30e8d059e8041dbda7c53463a44f7be8b;hb=28976d28a04cfb9abe97af7214d7dce11f732604;hp=b26d280600057a5530f7aa5ac19b5deaad846452;hpb=304b5f3aa7eee7b0ff8d4ba7526a1410735f6e74;p=lilypond.git diff --git a/lily/piano-pedal-engraver.cc b/lily/piano-pedal-engraver.cc index b26d280600..95cc99d30e 100644 --- a/lily/piano-pedal-engraver.cc +++ b/lily/piano-pedal-engraver.cc @@ -1,12 +1,12 @@ /* - piano-pedal-engraver.cc -- implement Piano_pedal_engraver + piano-pedal-engraver.cc -- implement Piano_pedal_engraver - source file of the GNU LilyPond music typesetter + source file of the GNU LilyPond music typesetter - (c) 2000--2004 Jan Nieuwenhuizen + (c) 2000--2004 Jan Nieuwenhuizen - Chris Jackson - extended to support - bracketed pedals. + Chris Jackson - extended to support + bracketed pedals. */ #include "engraver.hh" @@ -26,7 +26,6 @@ /* Urgh. This engraver is too complex. rewrite. --hwn - */ struct Pedal_info @@ -43,14 +42,14 @@ struct Pedal_info distinct from current_bracket_ev_, since current_bracket_ev_ only necessary for brackets, not for text style. - */ + */ Music* start_ev_; /* Events that were found in this timestep. - */ + */ Drul_array event_drul_; Item* item_; Spanner* bracket_; // A single portion of a pedal bracket @@ -58,7 +57,7 @@ struct Pedal_info /* This grob contains all the pedals of the same type on the same staff - */ + */ Spanner* line_spanner_; Spanner* finished_line_spanner_; }; @@ -87,10 +86,11 @@ private: */ Link_array previous_; + void del_linespanner (Spanner*); void create_text_grobs (Pedal_info *p, bool); void create_bracket_grobs (Pedal_info *p, bool); - void typeset_all (); + void typeset_all (Pedal_info*p); }; @@ -102,8 +102,6 @@ Piano_pedal_engraver::Piano_pedal_engraver () void Piano_pedal_engraver::initialize () { - previous_.clear (); - char * names [] = { "Sostenuto", "Sustain", "UnaCorda", 0 }; info_list_ = new Pedal_info[sizeof (names)/ sizeof (const char*)]; @@ -134,9 +132,9 @@ Piano_pedal_engraver::~Piano_pedal_engraver () } /* - Urg: Code dup - I'm a script - */ + Urg: Code dup + I'm a script +*/ void Piano_pedal_engraver::acknowledge_grob (Grob_info info) { @@ -160,13 +158,13 @@ Piano_pedal_engraver::acknowledge_grob (Grob_info info) bool Piano_pedal_engraver::try_music (Music *m) { - if (m->is_mus_type ("pedal-event")) + if (m->is_mus_type ("pedal-event")) { for (Pedal_info*p = info_list_; p->name_; p ++) { String nm = p->name_ + String ("Event"); - if (gh_equal_p (m->get_property ("name") , - gh_symbol2scm (nm.to_str0()))) + if (is_equal (m->get_property ("name") , + scm_str2symbol(nm.to_str0()))) { Direction d = to_dir (m->get_property ("span-direction")); p->event_drul_[d] = m; @@ -190,37 +188,38 @@ Piano_pedal_engraver::process_music () p->line_spanner_ = make_spanner (name.to_str0 ()); Music * rq = (p->event_drul_[START] ? p->event_drul_[START] : p->event_drul_[STOP]); + + announce_grob (p->line_spanner_, rq->self_scm ()); } /* Choose the appropriate grobs to add to the line spanner - These can be text items or text-spanners + These can be text items or text-spanners */ /* ugh, code dup, should read grob to create from other property. - bracket: |_________/\____| - text: Ped. *Ped. * - mixed: Ped. _____/\____| - */ + bracket: |_________/\____| + text: Ped. *Ped. * + mixed: Ped. _____/\____| + */ String prop = String ("pedal") + p->name_ + "Style"; SCM style = get_property (prop.to_str0 ()); + bool mixed = style == ly_symbol2scm ("mixed"); - if (style == ly_symbol2scm ("text") || - mixed) - { - if (! p->item_) - create_text_grobs (p, mixed); - } - if (style == ly_symbol2scm ("bracket") || - mixed) - { - create_bracket_grobs (p, mixed); - } + bool bracket = (mixed + || style == ly_symbol2scm ("bracket")); + bool text = (style == ly_symbol2scm ("text") + || mixed); + + if (text && !p->item_) + create_text_grobs (p, mixed); + if (bracket) + create_bracket_grobs (p, mixed); } } } @@ -271,8 +270,6 @@ Piano_pedal_engraver::create_text_grobs (Pedal_info *p, bool mixed) else { s = ly_caddr (strings); - if (previous_.size ()) - previous_.pop (); } p->start_ev_ = 0; } @@ -290,11 +287,11 @@ Piano_pedal_engraver::create_text_grobs (Pedal_info *p, bool mixed) // add extra space below the previous already-occuring pedal Side_position_interface::add_support (p->line_spanner_, previous_.top ()); - previous_.push ( p->line_spanner_); + previous_.push (p->line_spanner_); } } - if (gh_string_p (s)) + if (is_string (s)) { String propname = String (p->name_) + "Pedal"; @@ -315,6 +312,7 @@ Piano_pedal_engraver::create_text_grobs (Pedal_info *p, bool mixed) } } + void Piano_pedal_engraver::create_bracket_grobs (Pedal_info *p, bool mixed) { @@ -327,12 +325,6 @@ Piano_pedal_engraver::create_bracket_grobs (Pedal_info *p, bool mixed) if (p->event_drul_[STOP]) { - if (!p->event_drul_[START]) - { - if (previous_.size ()) - previous_.pop (); - } - assert (!p->finished_bracket_); Grob *cmc = unsmob_grob (get_property ("currentMusicalColumn")); @@ -343,13 +335,13 @@ Piano_pedal_engraver::create_bracket_grobs (Pedal_info *p, bool mixed) /* Set properties so that the stencil-creating function will know whether the right edge should be flared ___/ - */ + */ if (!p->event_drul_[START]) { SCM flare = p->bracket_->get_property ("bracket-flare"); - p->bracket_->set_property ("bracket-flare", scm_cons (gh_car (flare), - gh_double2scm (0))); + p->bracket_->set_property ("bracket-flare", scm_cons (ly_car (flare), + scm_make_real (0))); } p->finished_bracket_ = p->bracket_; @@ -372,12 +364,12 @@ Piano_pedal_engraver::create_bracket_grobs (Pedal_info *p, bool mixed) if (!p->finished_bracket_) { SCM flare = p->bracket_->get_property ("bracket-flare"); - p->bracket_->set_property ("bracket-flare", scm_cons (gh_double2scm (0),gh_cdr (flare))); + p->bracket_->set_property ("bracket-flare", scm_cons (scm_make_real (0),ly_cdr (flare))); } /* Set this property for 'mixed style' pedals, Ped._______/\ , - so the stencil function will shorten the ____ line by the length of the Ped. text. + so the stencil function will shorten the ____ line by the length of the Ped. text. */ if (mixed) @@ -409,7 +401,7 @@ Piano_pedal_engraver::create_bracket_grobs (Pedal_info *p, bool mixed) what about the right span point? - */ + */ Axis_group_interface::add_element (p->line_spanner_, p->bracket_); announce_grob (p->bracket_, p->event_drul_[START]->self_scm ()); @@ -420,7 +412,7 @@ Piano_pedal_engraver::create_bracket_grobs (Pedal_info *p, bool mixed) code dup. --hwn. // position new pedal spanner below the current one - */ + */ if (previous_.size ()) Side_position_interface::add_support (p->line_spanner_, previous_.top ()); @@ -439,30 +431,48 @@ Piano_pedal_engraver::finalize () { /* suicide? - */ + */ if (p->line_spanner_ && !p->line_spanner_->live ()) p->line_spanner_ = 0; - if (p->line_spanner_) - { - p->finished_line_spanner_ = p->line_spanner_; - typeset_all (); - } if (p->bracket_ && !p->bracket_->live ()) p->bracket_ = 0; if (p->bracket_) { - p->current_bracket_ev_->origin ()->warning (_ ("unterminated pedal bracket")); - p->bracket_->suicide (); + SCM cc = get_property ("currentCommandColumn"); + Item *c = unsmob_item (cc); + if (p->line_spanner_) + { + p->line_spanner_->set_bound (RIGHT, c); + } + p->bracket_ ->set_bound (RIGHT, c); + + p->finished_bracket_ = p->bracket_; p->bracket_ = 0; + p->finished_line_spanner_ = p->line_spanner_; + p->line_spanner_ = 0; + typeset_all (p); + } + + if (p->line_spanner_) + { + p->finished_line_spanner_ = p->line_spanner_; + typeset_all (p); } } } - +void +Piano_pedal_engraver::del_linespanner (Spanner *g) +{ + int idx = previous_.find_index (g); + if (idx >= 0) + previous_.del (idx); +} + void Piano_pedal_engraver::stop_translation_timestep () { @@ -472,10 +482,12 @@ Piano_pedal_engraver::stop_translation_timestep () { p->finished_line_spanner_ = p->line_spanner_; p->line_spanner_ = 0; + del_linespanner (p->finished_line_spanner_); } + + typeset_all (p); } - typeset_all (); for (Pedal_info*p = info_list_; p->name_; p ++) { @@ -486,76 +498,65 @@ Piano_pedal_engraver::stop_translation_timestep () void -Piano_pedal_engraver::typeset_all () +Piano_pedal_engraver::typeset_all (Pedal_info * p) { - Item * sustain = 0; - for (Pedal_info*p = info_list_; p->name_; p ++) - { - /* - Handle suicide. - */ - if (p->finished_line_spanner_ - && !p->finished_line_spanner_->live ()) - p->finished_line_spanner_ = 0; - if (p->finished_bracket_ - && !p->finished_bracket_->live ()) - p->finished_bracket_ = 0; - + /* + Handle suicide. + */ + if (p->finished_line_spanner_ + && !p->finished_line_spanner_->live ()) + p->finished_line_spanner_ = 0; + if (p->finished_bracket_ + && !p->finished_bracket_->live ()) + p->finished_bracket_ = 0; - if (p->name_ == String ("Sustain")) - sustain = p->item_; - if (p->item_) - { - /* - Hmm. - */ - if (p->name_ != String ("Sustain") && sustain) - { - Side_position_interface::add_support (p->item_,sustain); - } - typeset_grob (p->item_); - p->item_ = 0; - } + if (p->item_) + { + typeset_grob (p->item_); + p->item_ = 0; + } - if (p->finished_bracket_) + if (p->finished_bracket_) + { + Grob * r = p->finished_bracket_->get_bound (RIGHT); + if (!r) { - Grob * r = p->finished_bracket_->get_bound (RIGHT); - if (!r) - { - p->finished_bracket_->set_bound (RIGHT, unsmob_grob (get_property ("currentMusicalColumn"))); - } + p->finished_bracket_->set_bound (RIGHT, unsmob_grob (get_property ("currentMusicalColumn"))); + } - typeset_grob (p->finished_bracket_); + typeset_grob (p->finished_bracket_); - p->finished_bracket_ =0; - } + p->finished_bracket_ =0; + } - if (p->finished_line_spanner_) + if (p->finished_line_spanner_) + { + Grob * l = p->finished_line_spanner_->get_bound (LEFT); + Grob * r = p->finished_line_spanner_->get_bound (RIGHT); + if (!r && l) + p->finished_line_spanner_->set_bound (RIGHT, l); + else if (!l && r) + p->finished_line_spanner_->set_bound (LEFT, r); + else if (!r && !l) { - Grob * l = p->finished_line_spanner_->get_bound (LEFT); - Grob * r = p->finished_line_spanner_->get_bound (RIGHT); - if (!r && l) - p->finished_line_spanner_->set_bound (RIGHT, l); - else if (!l && r) - p->finished_line_spanner_->set_bound (LEFT, r); - else if (!r && !l) - { - Grob * cc = unsmob_grob (get_property ("currentMusicalColumn")); - Item * ci = dynamic_cast (cc); - p->finished_line_spanner_->set_bound (RIGHT, ci); - p->finished_line_spanner_->set_bound (LEFT, ci); - } - typeset_grob (p->finished_line_spanner_); - p->finished_line_spanner_ = 0; + Grob * cc = unsmob_grob (get_property ("currentMusicalColumn")); + Item * ci = dynamic_cast (cc); + p->finished_line_spanner_->set_bound (RIGHT, ci); + p->finished_line_spanner_->set_bound (LEFT, ci); } + typeset_grob (p->finished_line_spanner_); + p->finished_line_spanner_ = 0; } } ENTER_DESCRIPTION (Piano_pedal_engraver, -/* descr */ "Engrave piano pedal symbols and brackets.", -/* creats*/ "SostenutoPedal SustainPedal UnaCordaPedal SostenutoPedalLineSpanner SustainPedalLineSpanner UnaCordaPedalLineSpanner", -/* accepts */ "pedal-event", -/* acks */ "note-column-interface", -/* reads */ "pedalSostenutoStrings pedalSustainStrings pedalUnaCordaStrings pedalSostenutoStyle pedalSustainStyle pedalUnaCordaStyle", -/* write */ ""); + /* descr */ "Engrave piano pedal symbols and brackets.", + /* creats*/ "SostenutoPedal SustainPedal UnaCordaPedal SostenutoPedalLineSpanner SustainPedalLineSpanner UnaCordaPedalLineSpanner", + /* accepts */ "pedal-event", + /* acks */ "note-column-interface", + /* reads */ "currentCommandColumn " + "pedalSostenutoStrings pedalSustainStrings " + "pedalUnaCordaStrings pedalSostenutoStyle " + "pedalSustainStyle pedalUnaCordaStyle", + /* write */ "");