X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fpiano-pedal-engraver.cc;h=829b9c12bab698c03cfa9238d81e2f984e6ee35f;hb=7e7a2bf8bde2353decd68a9c4ac7a68d815e8185;hp=b26d280600057a5530f7aa5ac19b5deaad846452;hpb=304b5f3aa7eee7b0ff8d4ba7526a1410735f6e74;p=lilypond.git diff --git a/lily/piano-pedal-engraver.cc b/lily/piano-pedal-engraver.cc index b26d280600..829b9c12ba 100644 --- a/lily/piano-pedal-engraver.cc +++ b/lily/piano-pedal-engraver.cc @@ -1,32 +1,26 @@ /* - 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" -#include "event.hh" -#include "grob.hh" -#include "item.hh" #include "lily-guile.hh" #include "side-position-interface.hh" #include "staff-symbol-referencer.hh" -#include "item.hh" #include "axis-group-interface.hh" #include "context.hh" - #include "directional-element-interface.hh" #include "note-column.hh" #include "warn.hh" /* Urgh. This engraver is too complex. rewrite. --hwn - */ struct Pedal_info @@ -43,14 +37,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 +52,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 +81,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 +97,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 +127,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 +153,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 (ly_c_equal_p (m->get_property ("name") , + scm_str2symbol(nm.to_str0()))) { Direction d = to_dir (m->get_property ("span-direction")); p->event_drul_[d] = m; @@ -187,40 +180,40 @@ Piano_pedal_engraver::process_music () if (!p->line_spanner_) { String name = String (p->name_) + "PedalLineSpanner"; - 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 ()); + p->line_spanner_ = make_spanner (name.to_str0 (), 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); } } } @@ -255,7 +248,7 @@ Piano_pedal_engraver::create_text_grobs (Pedal_info *p, bool mixed) } else { - s = ly_cadr (strings); + s = scm_cadr (strings); } p->start_ev_ = p->event_drul_[START]; } @@ -270,9 +263,7 @@ Piano_pedal_engraver::create_text_grobs (Pedal_info *p, bool mixed) } else { - s = ly_caddr (strings); - if (previous_.size ()) - previous_.pop (); + s = scm_caddr (strings); } p->start_ev_ = 0; } @@ -280,7 +271,7 @@ Piano_pedal_engraver::create_text_grobs (Pedal_info *p, bool mixed) else if (p->event_drul_[START]) { p->start_ev_ = p->event_drul_[START]; - s = ly_car (strings); + s = scm_car (strings); if (!mixed) { /* @@ -290,24 +281,22 @@ 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 (scm_is_string (s)) { String propname = String (p->name_) + "Pedal"; - p->item_ = make_item (propname.to_str0 ()); + p->item_ = make_item (propname.to_str0 (), (p->event_drul_[START] + ? p->event_drul_[START] + : p->event_drul_[STOP])->self_scm ()); + p->item_->set_property ("text", s); Axis_group_interface::add_element (p->line_spanner_, p->item_); - - announce_grob (p->item_, - (p->event_drul_[START] - ? p->event_drul_[START] - : p->event_drul_[STOP])->self_scm ()); } - + if (!mixed) { p->event_drul_[START] = 0; @@ -315,24 +304,19 @@ Piano_pedal_engraver::create_text_grobs (Pedal_info *p, bool mixed) } } + void Piano_pedal_engraver::create_bracket_grobs (Pedal_info *p, bool mixed) { if (!p->bracket_ && p->event_drul_[STOP]) { - String msg =_f ("can't find start of piano pedal bracket: `%s'", p->name_); + String msg = _f ("can't find start of piano pedal bracket: `%s'", p->name_); p->event_drul_[STOP]->origin ()->warning (msg); p->event_drul_[STOP] = 0; } 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 +327,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 (scm_car (flare), + scm_make_real (0))); } p->finished_bracket_ = p->bracket_; @@ -362,7 +346,7 @@ Piano_pedal_engraver::create_bracket_grobs (Pedal_info *p, bool mixed) p->start_ev_ = p->event_drul_[START]; p->current_bracket_ev_ = p->event_drul_[START]; - p->bracket_ = make_spanner ("PianoPedalBracket"); + p->bracket_ = make_spanner ("PianoPedalBracket", p->event_drul_[START]->self_scm ()); /* Set properties so that the stencil-creating function will @@ -372,12 +356,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),scm_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,9 +393,8 @@ 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 ()); if (!p->event_drul_[STOP]) { @@ -420,7 +403,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 +422,48 @@ Piano_pedal_engraver::finalize () { /* suicide? - */ + */ if (p->line_spanner_ - && !p->line_spanner_->live ()) + && !p->line_spanner_->is_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_->is_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 +473,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 +489,62 @@ 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_->is_live ()) + p->finished_line_spanner_ = 0; + if (p->finished_bracket_ + && !p->finished_bracket_->is_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_) + { + 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"))); - } - - typeset_grob (p->finished_bracket_); - - p->finished_bracket_ =0; + p->finished_bracket_->set_bound (RIGHT, unsmob_grob (get_property ("currentMusicalColumn"))); } - if (p->finished_line_spanner_) + p->finished_bracket_ = 0; + } + + 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); } + + 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 */ ""); +ADD_TRANSLATOR (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 */ "currentCommandColumn " + "pedalSostenutoStrings pedalSustainStrings " + "pedalUnaCordaStrings pedalSostenutoStyle " + "pedalSustainStyle pedalUnaCordaStyle", + /* write */ "");