X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fpiano-pedal-engraver.cc;h=77283f3bce6442ec8bcaa617e1b5cd8b50cd12fe;hb=402045837e7134cdf90d1fcf31768c62227a4936;hp=666cda769e3ed5842da8d0428b15f60bab8ca075;hpb=cf33d3709d3b5028fa9c208aa490ce066960ad5c;p=lilypond.git diff --git a/lily/piano-pedal-engraver.cc b/lily/piano-pedal-engraver.cc index 666cda769e..77283f3bce 100644 --- a/lily/piano-pedal-engraver.cc +++ b/lily/piano-pedal-engraver.cc @@ -3,14 +3,14 @@ source file of the GNU LilyPond music typesetter - (c) 2000--2002 Jan Nieuwenhuizen + (c) 2000--2004 Jan Nieuwenhuizen Chris Jackson - extended to support bracketed pedals. */ #include "engraver.hh" -#include "musical-request.hh" +#include "event.hh" #include "grob.hh" #include "item.hh" #include "lily-guile.hh" @@ -21,22 +21,45 @@ #include "translator-group.hh" #include "directional-element-interface.hh" #include "note-column.hh" +#include "warn.hh" + +/* + Urgh. This engraver is too complex. rewrite. --hwn + +*/ struct Pedal_info { char const * name_; - Span_req* start_req_l_; - Drul_array req_l_drul_; - Item* item_p_; - Spanner* bracket_p_; // A single portion of a pedal bracket - Spanner* finished_bracket_p_; + + /* + Event for currently running pedal. + */ + Music* current_bracket_ev_; + + /* + Event for currently starting pedal, (necessary? + + 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 + Spanner* finished_bracket_; /* This grob contains all the pedals of the same type on the same staff */ Spanner* line_spanner_; Spanner* finished_line_spanner_; - Span_req* current_bracket_req_; }; @@ -50,9 +73,8 @@ protected: virtual void finalize (); virtual bool try_music (Music*); virtual void stop_translation_timestep (); - virtual void start_translation_timestep (); virtual void acknowledge_grob (Grob_info); - virtual void process_acknowledged_grobs (); + virtual void process_music (); private: @@ -61,23 +83,12 @@ private: /* Record a stack of the current pedal spanners, so if more than one pedal occurs simultaneously then extra space can be added between them. - - - Why 4, why not 3. Why not 3423 ? ---hwn. */ - Spanner *previous_p_ [4]; - - int spanner_count_; - - /* - Left and right flare widths of a \___/, as specified by the grob - property edge-widen. - */ - Drul_array edge_width_drul_; + Link_array previous_; - void create_text_grobs (Pedal_info *p, SCM pedaltype); - void create_bracket_grobs (Pedal_info *p, SCM pedaltype); + void create_text_grobs (Pedal_info *p, bool); + void create_bracket_grobs (Pedal_info *p, bool); void typeset_all (); }; @@ -90,28 +101,26 @@ Piano_pedal_engraver::Piano_pedal_engraver () void Piano_pedal_engraver::initialize () { - info_list_ = new Pedal_info[4]; - Pedal_info *p = info_list_; + previous_.clear (); - spanner_count_ = 0; - for (int i = 0; i < 3; ++i) - previous_p_[i] = 0; + char * names [] = { "Sostenuto", "Sustain", "UnaCorda", 0 }; + info_list_ = new Pedal_info[sizeof (names)/ sizeof (const char*)]; + Pedal_info *p = info_list_; - char * names [] = { "Sostenuto", "Sustain", "UnaCorda", 0 }; char **np = names ; do { p->name_ = *np; - p->item_p_ = 0; - p->bracket_p_ = 0; - p->finished_bracket_p_ = 0; + p->item_ = 0; + p->bracket_ = 0; + p->finished_bracket_ = 0; p->line_spanner_ = 0; p->finished_line_spanner_ = 0; - p->current_bracket_req_ = 0; - p->req_l_drul_[START] = 0; - p->req_l_drul_[STOP] = 0; - p->start_req_l_ = 0; + p->current_bracket_ev_ = 0; + p->event_drul_[START] = 0; + p->event_drul_[STOP] = 0; + p->start_ev_ = 0; p++; } @@ -132,17 +141,17 @@ Piano_pedal_engraver::acknowledge_grob (Grob_info info) { for (Pedal_info*p = info_list_; p && p->name_; p ++) { - if (Note_column::has_interface (info.grob_l_)) + if (Note_column::has_interface (info.grob_)) { if (p->line_spanner_) { - Side_position_interface::add_support (p->line_spanner_, info.grob_l_); - - add_bound_item (p->line_spanner_,info.grob_l_); + Side_position_interface::add_support (p->line_spanner_, info.grob_); + add_bound_item (p->line_spanner_,info.grob_); } - if (p->bracket_p_) - add_bound_item (p->bracket_p_,info.grob_l_); - + if (p->bracket_) + add_bound_item (p->bracket_,info.grob_); + if (p->finished_bracket_) + add_bound_item (p->finished_bracket_,info.grob_); } } } @@ -150,23 +159,16 @@ Piano_pedal_engraver::acknowledge_grob (Grob_info info) bool Piano_pedal_engraver::try_music (Music *m) { - if (Span_req * s = dynamic_cast (m)) + if (m->is_mus_type ("pedal-event")) { for (Pedal_info*p = info_list_; p->name_; p ++) { - if (ly_scm2string (s->get_mus_property ("span-type")) == "abort") - { - p->req_l_drul_[START] = 0; - p->req_l_drul_[STOP] = 0; - - if (p->bracket_p_) - p->bracket_p_->suicide (); /* as in dynamic-engraver.cc */ - p->bracket_p_ = 0; - } - if (scm_equal_p (s->get_mus_property ("span-type"), - ly_str02scm (p->name_))==SCM_BOOL_T) + String nm = p->name_ + String ("Event"); + if (gh_equal_p (m->get_mus_property ("name") , + gh_symbol2scm (nm.to_str0()))) { - p->req_l_drul_[s->get_span_dir ()] = s; + Direction d = to_dir (m->get_mus_property ("span-direction")); + p->event_drul_[d] = m; return true; } } @@ -175,208 +177,258 @@ Piano_pedal_engraver::try_music (Music *m) } void -Piano_pedal_engraver::process_acknowledged_grobs () +Piano_pedal_engraver::process_music () { for (Pedal_info*p = info_list_; p && p->name_; p ++) { - if (p->req_l_drul_[STOP] || p->req_l_drul_[START]) + if (p->event_drul_[STOP] || p->event_drul_[START]) { if (!p->line_spanner_) { String name = String (p->name_) + "PedalLineSpanner"; - p->line_spanner_ = new Spanner (get_property (name.ch_C ())); - Side_position_interface::set_axis (p->line_spanner_, Y_AXIS); - Music * rq = (p->req_l_drul_[START] ? p->req_l_drul_[START] : p->req_l_drul_[STOP]); + 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 */ - SCM type = ly_cdr (scm_assoc (ly_symbol2scm ("pedal-type"), - get_property ( (String (p->name_) + "Pedal").ch_C ()))); - if (type == ly_symbol2scm ("text") || // Ped. *Ped. * - type == ly_symbol2scm ("mixed") ) // Ped. _____/\____| + + /* + ugh, code dup, should read grob to create from other + property. + + 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_p_) - create_text_grobs (p, type); + if (! p->item_) + create_text_grobs (p, mixed); } - if (type == ly_symbol2scm ("bracket") || // |_________/\____| - type == ly_symbol2scm ("mixed") ) + if (style == ly_symbol2scm ("bracket") || + mixed) { - create_bracket_grobs (p, type); + create_bracket_grobs (p, mixed); } } } } - void -Piano_pedal_engraver::create_text_grobs (Pedal_info *p, SCM pedaltype) +Piano_pedal_engraver::create_text_grobs (Pedal_info *p, bool mixed) { - SCM b; SCM s = SCM_EOL; - SCM strings = get_property ( ("pedal" + String (p->name_) + "Strings").ch_C ()); + SCM strings = get_property ( ("pedal" + String (p->name_) + "Strings").to_str0 ()); - if (scm_ilength (strings) >= 3) + if (scm_ilength (strings) < 3) { - if (p->req_l_drul_[STOP] && p->req_l_drul_[START]) + Music * m = p->event_drul_[START]; + if (!m) m = p->event_drul_ [STOP]; + + String msg = _ ("Need 3 strings for piano pedals. No pedal made. "); + if (m) + m->origin()->warning (msg); + else + warning (msg); + + return ; + } + + if (p->event_drul_[STOP] && p->event_drul_[START]) + { + if (!mixed) { - if (pedaltype == ly_symbol2scm ("text")) + if (!p->start_ev_) { - if (!p->start_req_l_) - { - p->req_l_drul_[STOP]->origin ()->warning (_f ("can't find start of piano pedal: `%s'", p->name_)); - } - else - { - s = ly_cadr (strings); - } - p->start_req_l_ = p->req_l_drul_[START]; + p->event_drul_[STOP]->origin ()->warning (_f ("can't find start of piano pedal: `%s'", p->name_)); } - } - else if (p->req_l_drul_[STOP]) - { - if (pedaltype == ly_symbol2scm ("text")) + else { - if (!p->start_req_l_) - { - p->req_l_drul_[STOP]->origin ()->warning (_f ("can't find start of piano pedal: `%s'", p->name_)); - } - else - { - s = ly_caddr (strings); - spanner_count_ --; - } - p->start_req_l_ = 0; + s = ly_cadr (strings); } + p->start_ev_ = p->event_drul_[START]; } - else if (p->req_l_drul_[START]) + } + else if (p->event_drul_[STOP]) + { + if (!mixed) { - p->start_req_l_ = p->req_l_drul_[START]; - s = ly_car (strings); - if (pedaltype == ly_symbol2scm ("text")) + if (!p->start_ev_) { - spanner_count_ ++; - previous_p_[spanner_count_] = p->line_spanner_; - if (spanner_count_ > 1) - // add extra space below the previous already-occuring pedal - Side_position_interface::add_support (p->line_spanner_, - previous_p_[spanner_count_ - 1]); + p->event_drul_[STOP]->origin ()->warning (_f ("can't find start of piano pedal: `%s'", p->name_)); } + else + { + s = ly_caddr (strings); + if (previous_.size ()) + previous_.pop(); + } + p->start_ev_ = 0; } - - if (gh_string_p (s)) - { - String propname = String (p->name_) + "Pedal"; - b = get_property (propname.ch_C ()); - p->item_p_ = new Item (b); - p->item_p_->set_grob_property ("text", s); - Axis_group_interface::add_element (p->line_spanner_, p->item_p_); - - announce_grob (p->item_p_, - (p->req_l_drul_[START] - ? p->req_l_drul_[START] - : p->req_l_drul_[STOP])->self_scm ()); - - } - if (pedaltype == ly_symbol2scm ("text")) + } + else if (p->event_drul_[START]) + { + p->start_ev_ = p->event_drul_[START]; + s = ly_car (strings); + if (!mixed) { - p->req_l_drul_[START] = 0; - p->req_l_drul_[STOP] = 0; + /* + Code dup?! see below. + */ + if (previous_.size ()) + // add extra space below the previous already-occuring pedal + Side_position_interface::add_support (p->line_spanner_, + previous_.top ()); + previous_.push ( p->line_spanner_); } } + + if (gh_string_p (s)) + { + String propname = String (p->name_) + "Pedal"; + + p->item_ = make_item (propname.to_str0 ()); + p->item_->set_grob_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; + p->event_drul_[STOP] = 0; + } } void -Piano_pedal_engraver::create_bracket_grobs (Pedal_info *p, SCM pedaltype) +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_); + p->event_drul_[STOP]->origin ()->warning (msg); + p->event_drul_[STOP] = 0; + } - if (p->req_l_drul_[STOP]) + if (p->event_drul_[STOP]) { - if (!p->start_req_l_) + if (!p->event_drul_[START]) { - p->req_l_drul_[STOP]->origin ()->warning (_f ("can't find start of piano pedal: `%s'", p->name_)); + if (previous_.size()) + previous_.pop(); } - else if (!p->req_l_drul_[START]) - spanner_count_ -- ; - - assert (!p->finished_bracket_p_ && p->bracket_p_); + + assert (!p->finished_bracket_); Grob *cmc = unsmob_grob (get_property ("currentMusicalColumn")); - p->bracket_p_->set_bound (RIGHT, cmc); + + if (!p->bracket_->get_bound (RIGHT)) + p->bracket_->set_bound (RIGHT, cmc); /* - Set properties so that the molecule-creating function will + Set properties so that the stencil-creating function will know whether the right edge should be flared ___/ */ - SCM eleft = ly_car (p->bracket_p_->get_grob_property ("edge-widen")); - SCM eright = (p->req_l_drul_[START] ? edge_width_drul_[RIGHT] : gh_double2scm (0)); - p->bracket_p_->set_grob_property ("edge-widen", gh_cons (eleft, eright)); - - p->finished_bracket_p_ = p->bracket_p_; - p->bracket_p_ = 0; - p->current_bracket_req_ = 0; - p->start_req_l_ = p->req_l_drul_[START]; + + if (!p->event_drul_[START]) + { + SCM flare = p->bracket_->get_grob_property ("bracket-flare"); + p->bracket_->set_grob_property ("bracket-flare", scm_cons (gh_car (flare), + gh_double2scm (0))); + } + + p->finished_bracket_ = p->bracket_; + p->bracket_ = 0; + p->current_bracket_ev_ = 0; } - if (p->req_l_drul_[START]) + if (p->event_drul_[START]) { - p->start_req_l_ = p->req_l_drul_[START]; - p->current_bracket_req_ = p->req_l_drul_[START]; + p->start_ev_ = p->event_drul_[START]; + p->current_bracket_ev_ = p->event_drul_[START]; - p->bracket_p_ = new Spanner (get_property ("PianoPedalBracket")); + p->bracket_ = make_spanner ("PianoPedalBracket"); /* - Set properties so that the molecule-creating function will + Set properties so that the stencil-creating function will know whether the left edge should be flared \___ */ - SCM ew = p->bracket_p_->get_grob_property ("edge-widen"); - edge_width_drul_[LEFT] = ly_car (ew); - edge_width_drul_[RIGHT] = ly_cdr (ew); - - SCM eleft = ( (bool) p->req_l_drul_[STOP] ? - edge_width_drul_[LEFT] : - gh_double2scm (0)); - SCM eright = gh_double2scm (0); - p->bracket_p_->set_grob_property ("edge-widen", gh_cons (eleft, eright)); + if (!p->finished_bracket_) + { + SCM flare = p->bracket_->get_grob_property ("bracket-flare"); + p->bracket_->set_grob_property ("bracket-flare", scm_cons (gh_double2scm (0),gh_cdr (flare))); + } + /* Set this property for 'mixed style' pedals, Ped._______/\ , - so the molecule 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. */ - - p->bracket_p_->set_grob_property ("text-start", - pedaltype == ly_symbol2scm ("mixed") ? - gh_bool2scm ( (bool) ! p->req_l_drul_[STOP]) : - gh_bool2scm (false)); + + if (mixed) + { + /* + Mixed style: Store a pointer to the preceding text for use in + calculating the length of the line + + + TODO: + + WTF is pedal-text not the bound of the object? --hwn + */ + if (p->item_) + p->bracket_->set_grob_property ("pedal-text", p->item_->self_scm ()); + } + /* - Mixed style: Store a pointer to the preceding text for use in - calculating the length of the line - */ - if (p->item_p_) - p->bracket_p_->set_grob_property ("pedal-text", p->item_p_->self_scm ()); - - p->bracket_p_->set_bound (LEFT, unsmob_grob (get_property ("currentMusicalColumn"))); - Axis_group_interface::add_element (p->line_spanner_, p->bracket_p_); + We do not use currentMusicalColumn for the left span-point. + If the column as accidentals (eg on a different stave), the + currentMusicalColumn is too wide, making the bracket too big. + + TODO: - add_bound_item (p->line_spanner_, p->bracket_p_->get_bound (LEFT)); - announce_grob (p->bracket_p_, p->req_l_drul_[START]->self_scm ()); + Hmm. What do we do when there are no notes when the spanner starts? - if (!p->req_l_drul_[STOP]) + TODO: + + 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]) { - spanner_count_ ++; - previous_p_[spanner_count_] = p->line_spanner_; - if (spanner_count_ > 1) + /* + code dup. --hwn. + // position new pedal spanner below the current one - Side_position_interface::add_support (p->line_spanner_, previous_p_[spanner_count_ - 1]); + */ + if (previous_.size()) + Side_position_interface::add_support (p->line_spanner_, previous_.top()); + + previous_.push (p->line_spanner_); } } - p->req_l_drul_[START] = 0; - p->req_l_drul_[STOP] = 0; + p->event_drul_[START] = 0; + p->event_drul_[STOP] = 0; } void @@ -396,14 +448,15 @@ Piano_pedal_engraver::finalize () p->finished_line_spanner_ = p->line_spanner_; typeset_all (); } - if (p->bracket_p_ - && !p->bracket_p_->live()) - p->bracket_p_ = 0; - if (p->bracket_p_) + if (p->bracket_ + && !p->bracket_->live()) + p->bracket_ = 0; + + if (p->bracket_) { - p->current_bracket_req_->origin ()->warning (_ ("unterminated pedal bracket")); - p->bracket_p_->suicide (); - p->bracket_p_ = 0; + p->current_bracket_ev_->origin ()->warning (_ ("unterminated pedal bracket")); + p->bracket_->suicide (); + p->bracket_ = 0; } } } @@ -414,7 +467,7 @@ Piano_pedal_engraver::stop_translation_timestep () { for (Pedal_info*p = info_list_; p && p->name_; p ++) { - if (!p->bracket_p_) + if (!p->bracket_) { p->finished_line_spanner_ = p->line_spanner_; p->line_spanner_ = 0; @@ -422,6 +475,12 @@ Piano_pedal_engraver::stop_translation_timestep () } typeset_all (); + + for (Pedal_info*p = info_list_; p->name_; p ++) + { + p->event_drul_[STOP] = 0; + p->event_drul_[START] = 0; + } } @@ -437,46 +496,42 @@ Piano_pedal_engraver::typeset_all () if (p->finished_line_spanner_ && !p->finished_line_spanner_->live ()) p->finished_line_spanner_ = 0; - if (p->finished_bracket_p_ - && !p->finished_bracket_p_->live()) - p->finished_bracket_p_ = 0; + if (p->finished_bracket_ + && !p->finished_bracket_->live()) + p->finished_bracket_ = 0; if (p->name_ == String ("Sustain")) - sustain = p->item_p_; + sustain = p->item_; - if (p->item_p_) + if (p->item_) { /* Hmm. */ - if (p->name_ != String ("Sustain")) + if (p->name_ != String ("Sustain") && sustain) { - if (sustain) - { - Side_position_interface::add_support (p->item_p_,sustain); - } + Side_position_interface::add_support (p->item_,sustain); } - typeset_grob (p->item_p_); - p->item_p_ = 0; + typeset_grob (p->item_); + p->item_ = 0; } - if (p->finished_bracket_p_) + if (p->finished_bracket_) { - Grob * l = p->finished_bracket_p_->get_bound (LEFT); - Grob * r = p->finished_bracket_p_->get_bound (RIGHT); + Grob * r = p->finished_bracket_->get_bound (RIGHT); if (!r) { - p->finished_bracket_p_->set_bound (RIGHT, unsmob_grob (get_property ("currentMusicalColumn"))); + p->finished_bracket_->set_bound (RIGHT, unsmob_grob (get_property ("currentMusicalColumn"))); } - typeset_grob (p->finished_bracket_p_); - p->finished_bracket_p_ =0; + typeset_grob (p->finished_bracket_); + + p->finished_bracket_ =0; } if (p->finished_line_spanner_) { - Side_position_interface::add_staff_support (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) @@ -496,18 +551,10 @@ Piano_pedal_engraver::typeset_all () } } -void -Piano_pedal_engraver::start_translation_timestep () -{ - for (Pedal_info*p = info_list_; p->name_; p ++) - { - p->req_l_drul_[STOP] = 0; - p->req_l_drul_[START] = 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", +/* reads */ "pedalSostenutoStrings pedalSustainStrings pedalUnaCordaStrings pedalSostenutoStyle pedalSustainStyle pedalUnaCordaStyle", /* write */ "");