From 7b0f8be2de9c5c4bc2c2e0afb69853d49a38ed3b Mon Sep 17 00:00:00 2001 From: hanwen Date: Wed, 23 Jul 2003 18:03:58 +0000 Subject: [PATCH] * lily/text-spanner.cc (brew_molecule): use bracket-flare iso. edge-widen. * lily/piano-pedal-engraver.cc (process_music): change from process_acknowledged () * lily/piano-pedal-bracket.cc: new file. Change setup_pedal_bracket in after_line_breaking callback. Thoroughly cleaned up. * lily/text-spanner.cc (setup_pedal_bracket): cleanup. --- ChangeLog | 12 ++ lily/include/line-spanner.hh | 3 +- lily/line-spanner.cc | 60 +++++--- lily/piano-pedal-bracket.cc | 99 +++++++++++++ lily/piano-pedal-engraver.cc | 264 ++++++++++++++++++----------------- lily/sustain-pedal.cc | 3 +- lily/text-spanner.cc | 139 ++---------------- ly/engraver-init.ly | 4 + scm/define-grob-properties.scm | 5 - scm/define-grobs.scm | 10 +- scm/define-translator-properties.scm | 5 + 11 files changed, 312 insertions(+), 292 deletions(-) create mode 100644 lily/piano-pedal-bracket.cc diff --git a/ChangeLog b/ChangeLog index 8a80194651..f2cb2f9b00 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,17 @@ 2003-07-23 Han-Wen Nienhuys + * lily/text-spanner.cc (brew_molecule): use bracket-flare + iso. edge-widen. + + * lily/piano-pedal-engraver.cc (process_music): change from + process_acknowledged () + + * lily/piano-pedal-bracket.cc: new file. Change + setup_pedal_bracket in after_line_breaking callback. Thoroughly + cleaned up. + + * lily/text-spanner.cc (setup_pedal_bracket): cleanup. + * input/regression/tuplets.ly (texidoc): rename file. * po/fr.po: update diff --git a/lily/include/line-spanner.hh b/lily/include/line-spanner.hh index a784b02bb2..a3d32d7c62 100644 --- a/lily/include/line-spanner.hh +++ b/lily/include/line-spanner.hh @@ -17,7 +17,8 @@ class Line_spanner public: DECLARE_SCHEME_CALLBACK (brew_molecule, (SCM)); DECLARE_SCHEME_CALLBACK(after_line_breaking, (SCM)); - static Molecule line_molecule (Grob* me, Real thick, Real dx, Real dy); + static Molecule line_molecule (Grob* me, Real thick, + Offset f, Offset t); static bool has_interface (Grob*); private: diff --git a/lily/line-spanner.cc b/lily/line-spanner.cc index aa137fa38c..a1a58b5e7c 100644 --- a/lily/line-spanner.cc +++ b/lily/line-spanner.cc @@ -19,6 +19,18 @@ #include +/* + TODO: convert all Molecule functions to taking arguments of the form + + Offset FROM, Offset TO. + + + TODO: + + Introduce line-interface that allows dots/dashes/etc. to be set as + grob-properties. Make arbitrary paths. + + */ /* slightishly clumsy interface? @@ -121,28 +133,32 @@ Line_spanner::after_line_breaking (SCM g) Molecule -Line_spanner::line_molecule (Grob *me, Real thick, Real dx, Real dy) +Line_spanner::line_molecule (Grob *me, Real thick, + Offset from, + Offset to) { + Offset dz = to -from ; Molecule mol; SCM type = me->get_grob_property ("style"); if (gh_symbol_p (type) && (type == ly_symbol2scm ("line") || type == ly_symbol2scm ("dashed-line") || type == ly_symbol2scm ("dotted-line") - || (type == ly_symbol2scm ("trill") && dy != 0))) + || type == ly_symbol2scm ("zigzag") + || (type == ly_symbol2scm ("trill") && dz[Y_AXIS] != 0))) { - Box b (Interval (-0.5* thick + (0 ? dx)), - Interval (- 0.5* thick + (0? dy))); - mol = Molecule (b, line_atom (me, thick, dx, dy)); - } - else if (gh_symbol_p (type) - && type == ly_symbol2scm ("zigzag")) - { - // TODO: - Box b (Interval (-0.5* thick + (0 ? dx)), - Interval (- 0.5* thick + (0? dy))); - mol = Molecule (b, zigzag_atom (me, thick, dx, dy)); - + Box b; + b.add_point (Offset (0,0)); + b.add_point (dz); + b[X_AXIS].widen (thick/2); + b[Y_AXIS].widen (thick/2); + + SCM atom = (type == ly_symbol2scm ("zigzag")) + ? zigzag_atom (me, thick, dz[X_AXIS], dz[Y_AXIS]) + : line_atom (me, thick, dz[X_AXIS], dz[Y_AXIS]); + + mol = Molecule (b, atom); + mol.translate (from); } else if (gh_symbol_p (type) && type == ly_symbol2scm ("trill")) @@ -160,15 +176,18 @@ Line_spanner::line_molecule (Grob *me, Real thick, Real dx, Real dy) mol.add_at_edge (X_AXIS, RIGHT, m, 0,0); while (m.extent (X_AXIS).length () && mol.extent (X_AXIS).length () - + m.extent (X_AXIS).length () < dx); + + m.extent (X_AXIS).length () < dz[X_AXIS]); /* FIXME: should center element on x/y */ mol.translate_axis (m.extent (X_AXIS).length () / 2, X_AXIS); mol.translate_axis (-(mol.extent (Y_AXIS)[DOWN] - + mol.extent (Y_AXIS).length ())/2, Y_AXIS); + + mol.extent (Y_AXIS).length ())/2, Y_AXIS); + + mol.translate (from); } + return mol; } @@ -280,8 +299,7 @@ Line_spanner::brew_molecule (SCM smob) dz = (dz.length () - 2*gap) *dir; - Molecule l (line_molecule (me, thick, dz[X_AXIS], - dz[Y_AXIS])); + Molecule l (line_molecule (me, thick, Offset(0, 0), dz)); l.translate (dir * gap + p1 - Offset (me->relative_coordinate (commonx, X_AXIS), @@ -316,9 +334,9 @@ Line_spanner::brew_molecule (SCM smob) ofxy = dxy * (off/dxy.length ()); dxy -= 2*ofxy; - Molecule line = line_molecule (me, thick, dxy[X_AXIS], dxy[Y_AXIS]); - line.translate_axis (bound[LEFT]->extent (bound[LEFT], - X_AXIS).length ()/2, X_AXIS); + Molecule line = line_molecule (me, thick, Offset (0,0),dxy); + + line.translate_axis (bound[LEFT]->extent (bound[LEFT], X_AXIS).length ()/2, X_AXIS); line.translate (ofxy - my_off + his_off); return line.smobbed_copy (); } diff --git a/lily/piano-pedal-bracket.cc b/lily/piano-pedal-bracket.cc new file mode 100644 index 0000000000..1289dd9057 --- /dev/null +++ b/lily/piano-pedal-bracket.cc @@ -0,0 +1,99 @@ +/* + piano-pedal-bracket.cc -- implement Piano_pedal_bracket + +source file of the GNU LilyPond music typesetter + +(c) 2003 Han-Wen Nienhuys + +based on smouldering remains by + + Chris Jackson + + +*/ +/* + Piano pedal brackets are a special case of a text spanner. + Pedal up-down (restart) indicated by the angled right and left edges + of consecutive pedals touching exactly to form an __/\__ + +*/ + + +/* + TODO: this should be moved somewhere else (?). + + Perhaps make separate function for pedal-bracket. + */ +#include "molecule.hh" +#include "spanner.hh" +#include "item.hh" +#include "paper-def.hh" + +struct Piano_pedal_bracket +{ + DECLARE_SCHEME_CALLBACK(after_line_breaking,(SCM)); + static bool has_interface (Grob*); +}; + +ADD_INTERFACE (Piano_pedal_bracket,"piano-pedal-bracket-interface", + "", + "pedal-text"); + +MAKE_SCHEME_CALLBACK(Piano_pedal_bracket,after_line_breaking,1); +SCM +Piano_pedal_bracket::after_line_breaking (SCM smob) +{ + Spanner *me = dynamic_cast (unsmob_grob (smob)); + + Drul_array broken; + Drul_array height(0,0), shorten(0,0); + + SCM eh = me->get_grob_property ("edge-height"); + SCM sp = me->get_grob_property ("shorten-pair"); + + Direction d = LEFT; + + do + { + Item *b = me->get_bound (d); + broken[d] = b->break_status_dir () != CENTER; + + if (!broken[d] && (ly_number_pair_p (eh))) + height[d] += gh_scm2double (index_get_cell (eh, d)); + if (ly_number_pair_p (sp)) + shorten[d] += gh_scm2double (index_get_cell (sp, d)); + } + while (flip (&d) != LEFT); + + /* For 'Mixed' style pedals, i.e. a bracket preceded by text: Ped._____| + need to shorten by the extent of the text grob + + + Urg. - why not hang bracket between text items? --hwn + */ + if (Grob *textbit = unsmob_grob (me->get_grob_property("pedal-text"))) + { + height[LEFT] = 0; + SCM pa = me->get_grob_property ("if-text-padding"); // UGH. + Real padding =0.; + if (gh_number_p (pa)) + padding = gh_scm2double (pa); + + shorten[LEFT] += padding + textbit->extent (textbit, X_AXIS)[RIGHT]; + } + + if (broken[LEFT]) + { + shorten[LEFT] -= me->get_broken_left_end_align () ; + } + + // Also shorten so that it ends just before the spanned note. + Grob *rb = me->get_bound (RIGHT); + shorten[RIGHT] += rb->extent (rb, X_AXIS)[RIGHT]; + + me->set_grob_property ("edge-height", ly_interval2scm (height)); + me->set_grob_property ("shorten-pair", ly_interval2scm (shorten)); + + return SCM_UNSPECIFIED; +} + diff --git a/lily/piano-pedal-engraver.cc b/lily/piano-pedal-engraver.cc index 5781110d76..67a877306e 100644 --- a/lily/piano-pedal-engraver.cc +++ b/lily/piano-pedal-engraver.cc @@ -26,8 +26,25 @@ struct Pedal_info { char const * name_; - Music* start_req_; - Drul_array req_l_drul_; + + /* + 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_; @@ -37,7 +54,6 @@ struct Pedal_info */ Spanner* line_spanner_; Spanner* finished_line_spanner_; - Music* current_bracket_req_; }; @@ -53,7 +69,7 @@ protected: 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: @@ -66,19 +82,10 @@ private: Link_array previous_; - int spanner_count_; - - /* - Left and right flare widths of a \___/, as specified by the grob - property edge-widen. - UGR. No GC protection. - - */ - Drul_array edge_width_drul_; - 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 (); }; @@ -91,13 +98,14 @@ Piano_pedal_engraver::Piano_pedal_engraver () void Piano_pedal_engraver::initialize () { - info_list_ = new Pedal_info[4]; - Pedal_info *p = info_list_; - spanner_count_ = 0; previous_.clear (); char * names [] = { "Sostenuto", "Sustain", "UnaCorda", 0 }; + + info_list_ = new Pedal_info[sizeof (names)/ sizeof (const char*)]; + Pedal_info *p = info_list_; + char **np = names ; do { @@ -107,10 +115,10 @@ Piano_pedal_engraver::initialize () 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_ = 0; + p->current_bracket_ev_ = 0; + p->event_drul_[START] = 0; + p->event_drul_[STOP] = 0; + p->start_ev_ = 0; p++; } @@ -153,13 +161,13 @@ Piano_pedal_engraver::try_music (Music *m) { for (Pedal_info*p = info_list_; p->name_; p ++) { - p->req_l_drul_[START] = 0; - p->req_l_drul_[STOP] = 0; + p->event_drul_[START] = 0; + p->event_drul_[STOP] = 0; - if (p->bracket_) - p->bracket_->suicide (); /* as in dynamic-engraver.cc */ - p->bracket_ = 0; - } + if (p->bracket_) + p->bracket_->suicide (); + p->bracket_ = 0; + } } else if (m->is_mus_type ("pedal-event")) { @@ -170,7 +178,7 @@ Piano_pedal_engraver::try_music (Music *m) gh_symbol2scm (nm.to_str0()))) { Direction d = to_dir (m->get_mus_property ("span-direction")); - p->req_l_drul_[d] = m; + p->event_drul_[d] = m; return true; } } @@ -179,11 +187,11 @@ 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_) { @@ -191,41 +199,52 @@ Piano_pedal_engraver::process_acknowledged_grobs () p->line_spanner_ = new Spanner (get_property (name.to_str0 ())); - Music * rq = (p->req_l_drul_[START] ? p->req_l_drul_[START] : p->req_l_drul_[STOP]); + 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").to_str0 ()))); - 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_) - create_text_grobs (p, type); + 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 s = SCM_EOL; SCM strings = get_property ( ("pedal" + String (p->name_) + "Strings").to_str0 ()); if (scm_ilength (strings) < 3) { - Music * m = p->req_l_drul_[START]; - if (!m) m = p->req_l_drul_ [STOP]; + 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) @@ -235,49 +254,45 @@ Piano_pedal_engraver::create_text_grobs (Pedal_info *p, SCM pedaltype) return ; } - - if (p->req_l_drul_[STOP] && p->req_l_drul_[START]) + if (p->event_drul_[STOP] && p->event_drul_[START]) { - if (pedaltype == ly_symbol2scm ("text")) + if (!mixed) { - if (!p->start_req_) + if (!p->start_ev_) { - p->req_l_drul_[STOP]->origin ()->warning (_f ("can't find start of piano pedal: `%s'", p->name_)); + p->event_drul_[STOP]->origin ()->warning (_f ("can't find start of piano pedal: `%s'", p->name_)); } else { s = ly_cadr (strings); } - p->start_req_ = p->req_l_drul_[START]; + p->start_ev_ = p->event_drul_[START]; } } - else if (p->req_l_drul_[STOP]) + else if (p->event_drul_[STOP]) { - if (pedaltype == ly_symbol2scm ("text")) + if (!mixed) { - if (!p->start_req_) + if (!p->start_ev_) { - p->req_l_drul_[STOP]->origin ()->warning (_f ("can't find start of piano pedal: `%s'", p->name_)); + p->event_drul_[STOP]->origin ()->warning (_f ("can't find start of piano pedal: `%s'", p->name_)); } else { s = ly_caddr (strings); - spanner_count_ --; if (previous_.size ()) previous_.pop(); } - p->start_req_ = 0; + p->start_ev_ = 0; } } - else if (p->req_l_drul_[START]) + else if (p->event_drul_[START]) { - p->start_req_ = p->req_l_drul_[START]; + p->start_ev_ = p->event_drul_[START]; s = ly_car (strings); - if (pedaltype == ly_symbol2scm ("text")) + if (!mixed) { - spanner_count_ ++; - /* Code dup?! see below. */ @@ -299,37 +314,37 @@ Piano_pedal_engraver::create_text_grobs (Pedal_info *p, SCM pedaltype) Axis_group_interface::add_element (p->line_spanner_, p->item_); announce_grob (p->item_, - (p->req_l_drul_[START] - ? p->req_l_drul_[START] - : p->req_l_drul_[STOP])->self_scm ()); - + (p->event_drul_[START] + ? p->event_drul_[START] + : p->event_drul_[STOP])->self_scm ()); } - if (pedaltype == ly_symbol2scm ("text")) + if (!mixed) { - p->req_l_drul_[START] = 0; - p->req_l_drul_[STOP] = 0; + 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_) - { - p->req_l_drul_[STOP]->origin ()->warning (_f ("can't find start of piano pedal: `%s'", p->name_)); - } - else if (!p->req_l_drul_[START]) + if (!p->event_drul_[START]) { - spanner_count_ -- ; if (previous_.size()) previous_.pop(); } - assert (!p->finished_bracket_ && p->bracket_); + assert (!p->finished_bracket_); Grob *cmc = unsmob_grob (get_property ("currentMusicalColumn")); p->bracket_->set_bound (RIGHT, cmc); @@ -338,20 +353,23 @@ Piano_pedal_engraver::create_bracket_grobs (Pedal_info *p, SCM pedaltype) Set properties so that the molecule-creating function will know whether the right edge should be flared ___/ */ - SCM eleft = ly_car (p->bracket_->get_grob_property ("edge-widen")); - SCM eright = (p->req_l_drul_[START] ? edge_width_drul_[RIGHT] : gh_double2scm (0)); - p->bracket_->set_grob_property ("edge-widen", gh_cons (eleft, eright)); - + + 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_req_ = 0; - p->start_req_ = p->req_l_drul_[START]; + p->current_bracket_ev_ = 0; } - if (p->req_l_drul_[START]) + if (p->event_drul_[START]) { - p->start_req_ = 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_ = new Spanner (get_property ("PianoPedalBracket")); @@ -360,63 +378,55 @@ Piano_pedal_engraver::create_bracket_grobs (Pedal_info *p, SCM pedaltype) know whether the left edge should be flared \___ */ - SCM ew = p->bracket_->get_grob_property ("edge-widen"); - - /* - WTF is this doing here? - - This must go to the backend. + 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))); + } - --HWN. - */ - 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_->set_grob_property ("edge-widen", gh_cons (eleft, eright)); /* Set this property for 'mixed style' pedals, Ped._______/\ , so the molecule function will shorten the ____ line by the length of the Ped. text. */ - p->bracket_->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->bracket_->set_grob_property ("pedal-text", p->item_->self_scm ()); - p->bracket_->set_bound (LEFT, unsmob_grob (get_property ("currentMusicalColumn"))); Axis_group_interface::add_element (p->line_spanner_, p->bracket_); add_bound_item (p->line_spanner_, p->bracket_->get_bound (LEFT)); - announce_grob (p->bracket_, p->req_l_drul_[START]->self_scm ()); + announce_grob (p->bracket_, p->event_drul_[START]->self_scm ()); - if (!p->req_l_drul_[STOP]) + if (!p->event_drul_[STOP]) { /* - code dup. - */ - spanner_count_ ++; - if (previous_.size()) + code dup. --hwn. + // position new pedal spanner below the current one + */ + 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 @@ -439,9 +449,10 @@ Piano_pedal_engraver::finalize () if (p->bracket_ && !p->bracket_->live()) p->bracket_ = 0; + if (p->bracket_) { - p->current_bracket_req_->origin ()->warning (_ ("unterminated pedal bracket")); + p->current_bracket_ev_->origin ()->warning (_ ("unterminated pedal bracket")); p->bracket_->suicide (); p->bracket_ = 0; } @@ -540,14 +551,15 @@ 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; + p->event_drul_[STOP] = 0; + p->event_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 abort-event", -/* acks */ "note-column-interface", -/* reads */ "pedalSostenutoStrings pedalSustainStrings pedalUnaCordaStrings", +/* acks */ "note-column-interface", +/* reads */ "pedalSostenutoStrings pedalSustainStrings pedalUnaCordaStrings pedalSostenutoStyle pedalSustainStyle pedalUnaCordaStyle", /* write */ ""); diff --git a/lily/sustain-pedal.cc b/lily/sustain-pedal.cc index 91d4d6366d..4973d87870 100644 --- a/lily/sustain-pedal.cc +++ b/lily/sustain-pedal.cc @@ -23,7 +23,7 @@ Properties: - glyph -- text string (TODO: make one large glyph of the Ped symbol, removes need for member_brew_molecule ()) + glyph -- text string (TODO: make one large glyph of the Ped symbol, removes need for member_brew_molecule ()) */ @@ -44,6 +44,7 @@ Sustain_pedal::brew_molecule (SCM smob) SCM glyph = e->get_grob_property ("text"); if (!gh_string_p (glyph)) return mol.smobbed_copy (); + String text = ly_scm2string (glyph); for (int i = 0; i < text.length (); i++) diff --git a/lily/text-spanner.cc b/lily/text-spanner.cc index 5161d1bf2a..913c53aab5 100644 --- a/lily/text-spanner.cc +++ b/lily/text-spanner.cc @@ -1,10 +1,11 @@ /* - text-spanner.cc -- implement Text_spanner source file of the GNU LilyPond music typesetter (c) 2000--2003 Jan Nieuwenhuizen + + Revised over good by Han-Wen. */ #include "molecule.hh" @@ -38,11 +39,6 @@ Text_spanner::brew_molecule (SCM smob) Grob *me= unsmob_grob (smob); Spanner *spanner = dynamic_cast (me); - if (spanner->internal_has_interface (ly_symbol2scm ("piano-pedal-interface"))) - { - setup_pedal_bracket(spanner); - } - /* Ugh, must be same as Hairpin::brew_molecule. */ Real padding = 0.0; SCM itp= me->get_grob_property ("if-text-padding"); @@ -106,7 +102,7 @@ Text_spanner::brew_molecule (SCM smob) shorten[LEFT] = 0; shorten[RIGHT] = 0; - SCM ew = me->get_grob_property ("edge-flare"); + SCM ew = me->get_grob_property ("bracket-flare"); SCM s = me->get_grob_property ("shorten-pair"); if (gh_pair_p (s)) { @@ -143,7 +139,8 @@ Text_spanner::brew_molecule (SCM smob) Real dy = gh_scm2double (index_get_cell (s, d)) * - dir; if (dy) - edge_line[d] = Line_spanner::line_molecule (me, thick, dx, dy); + edge_line[d] = Line_spanner::line_molecule (me, thick, Offset(0,0), + Offset (dx, dy)); } while (flip (&d) != LEFT); } @@ -163,8 +160,8 @@ Text_spanner::brew_molecule (SCM smob) while (flip (&d) != LEFT); Molecule l =Line_spanner::line_molecule (me, thick, - span_points.length (), 0); - l.translate_axis (span_points[LEFT], X_AXIS); + Offset (span_points[LEFT], 0), + Offset (span_points[RIGHT], 0)); m.add_molecule (l); m.translate_axis (- me->relative_coordinate (common, X_AXIS), X_AXIS); @@ -174,127 +171,7 @@ Text_spanner::brew_molecule (SCM smob) -/* - Piano pedal brackets are a special case of a text spanner. - Pedal up-down (restart) indicated by the angled right and left edges - of consecutive pedals touching exactly to form an __/\__ - Chris Jackson -*/ -/* - TODO: this should be moved somewhere else (?). - - Perhaps make separate function for pedal-bracket. - */ -/* - UGH UGH UGH . - - This is broken broken. - - All the tweak props should be unnecessary. - - This should not be linked with Text_spanner. - */ - -void -Text_spanner::setup_pedal_bracket(Spanner *me) -{ - - Real thick = me->get_paper ()->get_var ("linethickness"); - SCM st = me->get_grob_property ("thickness"); - if (gh_number_p (st)) - { - thick *= gh_scm2double (st); - } - - Drul_array broken; - Drul_array height, width, shorten, r; - - SCM pa = me->get_grob_property ("if-text-padding"); - SCM eh = me->get_grob_property ("edge-height"); - SCM sp = me->get_grob_property ("shorten-pair"); - - Direction d = LEFT; - Interval e; - Real padding = 0; - - if (gh_number_p (pa)) - padding = gh_scm2double (pa); - - do - { - Item *b = me->get_bound (d); - - e = b->extent (b, X_AXIS); - if (!e.empty_b ()) - r[d] = d * (e[-d] + padding); - - broken[d] = b->break_status_dir () != CENTER; - width[d] = 0; - height[d] = 0; - shorten[d] = 0; - if (!broken[d] && (ly_number_pair_p (eh))) - height[d] += gh_scm2double (index_get_cell (eh, d)); - if (ly_number_pair_p (sp)) - shorten[d] += gh_scm2double (index_get_cell (sp, d)); - } - while (flip (&d) != LEFT); - - Real extra_short = 0; - - // For 'Mixed' style pedals, i.e. a bracket preceded by text: Ped._____| - // need to shorten by the extent of the text grob - if (to_boolean (me->get_grob_property ("text-start"))) - { - height[LEFT] = 0; - extra_short = padding; - if (Grob *textbit = unsmob_grob (me->get_grob_property("pedal-text"))) - { - if (textbit->internal_has_interface(ly_symbol2scm("text-interface"))) - // for plain text, e.g., Sost. Ped. - { - SCM text = textbit->get_grob_property("text"); - if (gh_string_p (text)) { - SCM properties = Font_interface::font_alist_chain (me); - - Molecule mol = Text_item::interpret_new_markup (me->self_scm (), - properties, text); - extra_short += mol.extent(X_AXIS).length() / 2; - } - } - } - shorten[RIGHT] -= thick; - } - - shorten[LEFT] += extra_short ; - - if (broken[LEFT]) - { - shorten[LEFT] -= me->get_broken_left_end_align () ; - shorten[RIGHT] += abs(width[RIGHT]) + thick - r[RIGHT]; - } - - else - { - // Shorten a ____/ on the right so that it will touch an adjoining \___ - shorten[RIGHT] += abs(width[LEFT]) + abs(width[RIGHT]) + thick; - // Also shorten so that it ends just before the spanned note. - shorten[RIGHT] -= (r[LEFT] + r[RIGHT]); - } - - me->set_grob_property ("edge-height", ly_interval2scm (height)); - me->set_grob_property ("shorten-pair", ly_interval2scm (shorten)); -} - - -struct Pianopedal -{ - static bool has_interface (Grob*); -}; -ADD_INTERFACE (Pianopedal,"piano-pedal-interface", - "", - "pedal-type edge-widen edge-height shorten-pair text-start left-widen right-widen pedal-text"); - ADD_INTERFACE (Text_spanner,"text-spanner-interface", "generic text spanner", - "dash-period if-text-padding dash-length edge-height edge-widen edge-text shorten-pair style thickness enclose-bounds width-correct"); + "dash-period if-text-padding dash-length edge-height bracket-flare edge-text shorten-pair style thickness enclose-bounds width-correct"); diff --git a/ly/engraver-init.ly b/ly/engraver-init.ly index 6d589b89db..44a478678f 100644 --- a/ly/engraver-init.ly +++ b/ly/engraver-init.ly @@ -455,14 +455,18 @@ ScoreContext = \translator { verticalAlignmentChildCallback = #Align_interface::alignment_callback pedalSustainStrings = #'("Ped." "*Ped." "*") + pedalSustainStyle = #'text pedalUnaCordaStrings = #'("una corda" "" "tre corde") + pedalUnaCordaStyle = #'text %% These are in ordinary italic font, including the *, %% but they are unlikely to be used, %% as the default pedal-style for SostenutoPedal is 'mixed': %% i.e. Sost. Ped_____________________ pedalSostenutoStrings = #'("Sost. Ped." "*Sost. Ped." "*") + pedalSostenutoStyle = #'mixed + tupletNumberFormatFunction = #denominator-tuplet-formatter subdivideBeams = ##f diff --git a/scm/define-grob-properties.scm b/scm/define-grob-properties.scm index a7f4818082..d16085b396 100644 --- a/scm/define-grob-properties.scm +++ b/scm/define-grob-properties.scm @@ -289,8 +289,6 @@ space to add. For barline, space after a thick line.") (grob-property-description 'right-position number? "position of right part of spanner.") (grob-property-description 'left-padding ly:dimension? "space left of accs.") -(grob-property-description 'left-widen boolean? "Whether the left edge of a piano pedal bracket should be widened by the first element of edge-widen.") - (grob-property-description 'length ly:dimension? "Stem length for unbeamed stems, only for user override.") (grob-property-description 'lengths list? "Stem length given multiplicity of flag. The Nth element of the list gives the stem @@ -360,7 +358,6 @@ provided in @code{input/regression/molecule-hacking.ly}. (grob-property-description 'oriscus boolean? "is this neume an oriscus?.") (grob-property-description 'enclose-bounds boolean? "whether a text spanner should extend to the outer edge of the spanned notes") (grob-property-description 'padding ly:dimension? "add this much extra space between objects that are next to each other.") -(grob-property-description 'pedal-type symbol? "Style of piano pedal: text, bracket or mixed.") (grob-property-description 'pedal-text ly:grob? "Pointer to the text of a mixed-style piano pedal.") (grob-property-description 'penalty number? "Penalty for breaking at this column. 10000 or more means forbid linebreak, -10000 or less @@ -379,7 +376,6 @@ as a real penalty.") (grob-property-description 'ratio number? "Slur parameter. See height-limit.") (grob-property-description 'right-padding ly:dimension? "space right of accs.") (grob-property-description 'right-trim-amount ly:dimension? "shortening of the lyric extender on the right.") -(grob-property-description 'right-widen boolean? "Whether the right edge of a piano pedal bracket should be widened by the second element of edge-widen") (grob-property-description 'script-priority number? "A sorting key that determines in what order a script is within a stack of scripts.") (grob-property-description 'self-alignment-X number-or-grob? "real number: -1 = left aligned, 0 = center, 1 right-aligned in X direction. @@ -439,7 +435,6 @@ the Nth element of the list gives the amount stem shortening of a note with N fl (grob-property-description 'support-head ly:grob? "the note head at one end of the stem.") (grob-property-description 'text markup? "Text markup. See reference manual for more information.") -(grob-property-description 'text-start boolean? "Indicator for whether a piano pedal bracket has leading text, such as Ped.") (grob-property-description 'thick-thickness number? "thickness, measured in stafflinethickness.") (grob-property-description 'thickness number? "thickness, measured in stafflinethickness.") (grob-property-description 'thin-kern number? "space after a hair-line.") diff --git a/scm/define-grobs.scm b/scm/define-grobs.scm index 066d836378..fd13e620bf 100644 --- a/scm/define-grobs.scm +++ b/scm/define-grobs.scm @@ -456,7 +456,6 @@ (gap . 0.0) (padding . 2.0) (thickness . 1.6) - (edge-widen . (0.0 . 0.0)) (edge-height . (0.7 . 0.7)) (shorten-pair . (-0.2 . -0.2)) (before-line-breaking-callback . ,Tuplet_bracket::before_line_breaking) @@ -725,17 +724,18 @@ (PianoPedalBracket ;; an example of a text spanner . ( (molecule-callback . ,Text_spanner::brew_molecule) + (after-line-breaking-callback . ,Piano_pedal_bracket::after_line_breaking) (font-family . roman) (style . line) (if-text-padding . 1.0) (width-correct . 0) (enclose-bounds . #t) (direction . -1) - (edge-widen . (0.5 . 0.5)) + (bracket-flare . (0.5 . 0.5)) (edge-height . (1.0 . 1.0)) (shorten-pair . (0.0 . 0.0)) (thickness . 1.0) - (meta . ((interfaces . (text-spanner-interface piano-pedal-interface spanner-interface)))) + (meta . ((interfaces . (text-spanner-interface piano-pedal-bracket-interface spanner-interface)))) )) (RepeatSlash @@ -891,7 +891,6 @@ (X-offset-callbacks . (,Self_alignment_interface::aligned_on_self)) (no-spacing-rods . #t) (padding . 0.0) ;; padding relative to SostenutoPedalLineSpanner - (pedal-type . mixed) (font-family . roman) (font-shape . italic) (self-alignment-X . 0) @@ -998,7 +997,6 @@ (self-alignment-X . 0) (direction . 1) (padding . 0.0) ;; padding relative to SustainPedalLineSpanner - (pedal-type . text) (X-offset-callbacks . (,Self_alignment_interface::aligned_on_self)) (meta . ((interfaces . (piano-pedal-interface text-spanner-interface text-interface self-alignment-interface font-interface item-interface)))) )) @@ -1155,7 +1153,6 @@ (gap . 2.0) (padding . 0.9) (thickness . 1.6) - (edge-widen . (0.0 . 0.0)) (edge-height . (0.7 . 0.7)) (shorten-pair . (-0.2 . -0.2)) (before-line-breaking-callback . ,Tuplet_bracket::before_line_breaking) @@ -1177,7 +1174,6 @@ (no-spacing-rods . #t) (self-alignment-X . 0) (direction . 1) - (pedal-type . text) (padding . 0.0) ;; padding relative to UnaCordaPedalLineSpanner (X-offset-callbacks . (,Self_alignment_interface::aligned_on_self)) (meta . ((interfaces . (text-interface self-alignment-interface font-interface item-interface )))) diff --git a/scm/define-translator-properties.scm b/scm/define-translator-properties.scm index 6140b1bbd0..a35d9c5ec5 100644 --- a/scm/define-translator-properties.scm +++ b/scm/define-translator-properties.scm @@ -335,6 +335,11 @@ for an 8va spanner. Changing this implies a new text spanner. ") this is done with the pedal.") (translator-property-description 'pedalUnaCordaStrings list? "see pedalSustainStrings.") (translator-property-description 'pedalSostenutoStrings list? "see pedalSustainStrings.") +(translator-property-description 'pedalSustainStyle symbol? "A symbol +that indicates how to print sustain pedals: text, bracket or mixed +(both).") +(translator-property-description 'pedalUnaCordaStyle symbol? "see pedalSustainStyle.") +(translator-property-description 'pedalSostenutoStyle symbol? "see pedalSustainStyle.") (translator-property-description 'phrasingPunctuation string? "A string of characters that are considered -- 2.11.4.GIT