From: Glen Prideaux Date: Tue, 6 Jul 1999 08:08:10 +0000 (+0200) Subject: patch::: 1.1.53.gp1 X-Git-Tag: release/1.1.54~4 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=f37c48ec2664d22a8be0693b8073fbc66ae91856;p=lilypond.git patch::: 1.1.53.gp1 pl 53.gp1 - added Hyphen-engraver, Hyphen-spanner ************ --- diff --git a/Documentation/tex/refman.yo b/Documentation/tex/refman.yo index 8f0285e287..a6d9cce778 100644 --- a/Documentation/tex/refman.yo +++ b/Documentation/tex/refman.yo @@ -883,6 +883,21 @@ mudela(verbatim)(\score{ foo1 __ bar2. __ _4 baz1 __ } > }) +If you want to have hyphens centred between syllables (rather than attached +to the end of the first syllable) you can use the special code(--) lyric as +separate word between syllables. This will result in a hyphen whose length +varies depending on the space between syllables, and centred between the +syllables. For example: +mudela(verbatim)(\score{ + < \notes \transpose c'' {c d e c | c d e c | e f g'2 | + e'4 f g'2 \bar "|."; } + \context Lyrics \lyrics { + DOEXPAND(Fr\)`e4 -- re Ja -- que DOEXPAND(Fr\)`e -- re Ja -- que + Dor -- mez vous?2 Dor4 -- mez vous?2 } + > +}) + + sect(Time) diff --git a/NEWS b/NEWS index 25c143f79d..c805f1b72c 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,6 @@ - +pl 53.gp1 + - added Hyphen-engraver, Hyphen-spanner +************ pl 52.jcn3 - bf: mi2mu: midi without key - try at grace-performer-group; breaks MIDI output even when no \grace diff --git a/VERSION b/VERSION index d06e719920..75b3a1cff1 100644 --- a/VERSION +++ b/VERSION @@ -2,7 +2,7 @@ PACKAGE_NAME=LilyPond MAJOR_VERSION=1 MINOR_VERSION=1 PATCH_LEVEL=53 -MY_PATCH_LEVEL= +MY_PATCH_LEVEL=gp1 # use the above to send patches: MY_PATCH_LEVEL is always empty for a # released version. diff --git a/input/test/hyphen.ly b/input/test/hyphen.ly new file mode 100644 index 0000000000..149b02d9b4 --- /dev/null +++ b/input/test/hyphen.ly @@ -0,0 +1,11 @@ +\score{ + < + \context Staff \notes { c' () c' () c' c' } + \context Lyrics \context LyricVoice \lyrics { bla -- alb xxx -- yyy } + > +} + +\version "1.0.21"; + + + diff --git a/lily/hyphen-engraver.cc b/lily/hyphen-engraver.cc new file mode 100644 index 0000000000..013c9620b6 --- /dev/null +++ b/lily/hyphen-engraver.cc @@ -0,0 +1,121 @@ +/* + hyphen-engraver.cc -- implement Hyphen_engraver + + (c) 1999 Glen Prideaux +*/ + +#include "proto.hh" +#include "musical-request.hh" +#include "hyphen-engraver.hh" +#include "hyphen-spanner.hh" +#include "score-column.hh" +#include "text-item.hh" +#include "extender-engraver.hh" + +ADD_THIS_TRANSLATOR (Hyphen_engraver); + +Hyphen_engraver::Hyphen_engraver () +{ + hyphen_spanner_p_ = 0; + req_l_ = 0; +} + +void +Hyphen_engraver::acknowledge_element (Score_element_info i) +{ + if (Text_item* t = dynamic_cast (i.elem_l_)) + { + Rhythmic_req * rh = dynamic_cast (i.req_l_); + if (!rh) + return; + + now_lyrics_.push (Text_lyric_tuple (t, rh, now_mom () + rh->length_mom ())); + /* + UGH. What do we do in case of multiple alternatives? + */ + if (hyphen_spanner_p_ + && !hyphen_spanner_p_->spanned_drul_[RIGHT] + ) + { + hyphen_spanner_p_->set_textitem (RIGHT, t); + } + } +} + + +bool +Hyphen_engraver::do_try_music (Music* r) +{ + if (Hyphen_req* p = dynamic_cast (r)) + { + if (req_l_) + return false; + + req_l_ = p; + return true; + } + return false; +} + +void +Hyphen_engraver::do_removal_processing () +{ + if (hyphen_spanner_p_) + { + req_l_->warning (_ ("unterminated hyphen")); + hyphen_spanner_p_->set_bounds(RIGHT, get_staff_info ().command_pcol_l ()); + } +} + +void +Hyphen_engraver::do_process_requests () +{ + Array stopped_texts; + Moment now = now_mom (); + + stopped_texts.clear (); + while (past_lyrics_pq_.size () + && past_lyrics_pq_.front ().end_ == now) + stopped_texts.push (past_lyrics_pq_.get ()); + + if (req_l_) + { + if (!stopped_texts.size ()) + { + req_l_->warning ("Nothing to connect hyphen to on the left. Ignoring hyphen request"); + return; + } + + hyphen_spanner_p_ = new Hyphen_spanner; + hyphen_spanner_p_->set_textitem (LEFT, stopped_texts[0].text_l_); + announce_element (Score_element_info (hyphen_spanner_p_, req_l_)); + } +} + + +void +Hyphen_engraver::do_pre_move_processing () +{ + for (int i=0; i < now_lyrics_.size (); i++) + { + past_lyrics_pq_.insert (now_lyrics_[i]); + } + now_lyrics_.clear (); + + if (hyphen_spanner_p_) + { + typeset_element (hyphen_spanner_p_); + hyphen_spanner_p_ = 0; + } +} +void +Hyphen_engraver::do_post_move_processing () +{ + Moment now = now_mom (); + while (past_lyrics_pq_.size () && past_lyrics_pq_.front ().end_ < now) + past_lyrics_pq_.delmin (); + + req_l_ =0; +} + + diff --git a/lily/hyphen-spanner.cc b/lily/hyphen-spanner.cc new file mode 100644 index 0000000000..8636dbb756 --- /dev/null +++ b/lily/hyphen-spanner.cc @@ -0,0 +1,96 @@ +/* + hyphen-spanner.cc -- implement Hyphen_spanner + + source file of the GNU LilyPond music typesetter + + (c) 1999 Glen Prideaux + + (adapted from extender-spanner) +*/ + +/* + TODO: too complicated implementation. Why the dx_drul?. + */ + +#include +#include "box.hh" +#include "debug.hh" +#include "lookup.hh" +#include "molecule.hh" +#include "p-col.hh" +#include "paper-def.hh" +#include "hyphen-spanner.hh" + +Hyphen_spanner::Hyphen_spanner () + : Directional_spanner () +{ + dx_f_drul_[LEFT] = dx_f_drul_[RIGHT] = 0.0; +} + +// UGH - is this even used? +Offset +Hyphen_spanner::center () const +{ + Real dx = extent (X_AXIS).length (); + + return Offset (dx / 2, 0); +} + +Molecule* +Hyphen_spanner::do_brew_molecule_p () const +{ + Molecule* mol_p = new Molecule; + + Real w = extent (X_AXIS).length (); + + w += (dx_f_drul_[RIGHT] - dx_f_drul_[LEFT]); + + Real th = paper_l ()->get_realvar (hyphen_thickness_scm_sym); + Real h = paper_l ()->get_realvar (hyphen_height_scm_sym); + + // UGH. First try: just make the hyphen take 1/3 of the available space + // for length, use a geometric mean of the available space and some minimum + Real l = paper_l ()->get_realvar (hyphen_minimum_length_scm_sym); + if(l < w) + l = sqrt(l*w); + Molecule a = lookup_l ()->filledbox ( Box (Interval ((w-l)/2,(w+l)/2), Interval (h,h+th))); + a.translate (Offset (dx_f_drul_[LEFT], 0)); + + mol_p->add_molecule (a); + + return mol_p; +} + +Interval +Hyphen_spanner::do_height () const +{ + return Interval (0,0); +} + +void +Hyphen_spanner::do_post_processing () +{ + // UGH + Real nw_f = paper_l ()->note_width () * 0.8; + + Direction d = LEFT; + do + { + Item* t = spanned_drul_[d] + ? spanned_drul_[d] : spanned_drul_[(Direction)-d]; + if (d == LEFT) + dx_f_drul_[d] += t->extent (X_AXIS).length (); + else + dx_f_drul_[d] -= d * nw_f / 2; + } + while (flip(&d) != LEFT); +} + + +void +Hyphen_spanner::set_textitem (Direction d, Item* textitem_l) +{ + set_bounds (d, textitem_l); + add_dependency (textitem_l); +} + diff --git a/lily/include/hyphen-engraver.hh b/lily/include/hyphen-engraver.hh new file mode 100644 index 0000000000..6ab2eb59bc --- /dev/null +++ b/lily/include/hyphen-engraver.hh @@ -0,0 +1,53 @@ +/* + hyphen-engraver.hh -- declare Hyphen_engraver + + source file of the GNU LilyPond music typesetter + + (c) 1999 Glen Prideaux +*/ + +#ifndef HYPHEN_ENGRAVER_HH +#define HYPHEN_ENGRAVER_HH + +#include "engraver.hh" +#include "drul-array.hh" +#include "hyphen-spanner.hh" +#include "pqueue.hh" +#include "extender-engraver.hh" + + +/** + Generate an centred hyphen. Should make a Hyphen_spanner that typesets + a nice centred hyphen of varying length depending on the gap between syllables. + + We remember all Text_items that come across, and store their + termination times. When we get a request, we create the spanner, and + attach the left point to the finished lyrics, and the right point to + any lyrics we receive by then. +*/ +class Hyphen_engraver : public Engraver +{ + PQueue past_lyrics_pq_; + Array now_lyrics_; + Array stopped_lyrics_; + + Hyphen_req* req_l_; + Hyphen_spanner* hyphen_spanner_p_; + + +public: + Hyphen_engraver (); + VIRTUAL_COPY_CONS (Translator); + +protected: + virtual void acknowledge_element (Score_element_info); + virtual void do_removal_processing(); + virtual void do_process_requests(); + virtual bool do_try_music (Music*); + virtual void do_pre_move_processing(); + virtual void do_post_move_processing (); +private: + +}; + +#endif // HYPHEN_ENGRAVER_HH diff --git a/lily/include/hyphen-spanner.hh b/lily/include/hyphen-spanner.hh new file mode 100644 index 0000000000..e1316252c9 --- /dev/null +++ b/lily/include/hyphen-spanner.hh @@ -0,0 +1,40 @@ +/* + hyphen-spanner.hh -- part of GNU LilyPond + + (c) 1999 Glen Prideaux +*/ + +#ifndef HYPHEN_SPANNER_HH +#define HYPHEN_SPANNER_HH + +#include "directional-spanner.hh" + +/** + centred hyphen + + A centred hyphen is a simple line between lyrics used to + divide syllables. + + The length of the hyphen line should stretch based on the + size of the gap between syllables. + */ +class Hyphen_spanner : public Directional_spanner +{ +public: +Hyphen_spanner (); + Offset center () const; + void set_textitem (Direction, Item*); + +protected: + virtual Molecule* do_brew_molecule_p () const; + Interval do_height () const; + + void do_post_processing (); + + VIRTUAL_COPY_CONS (Score_element); + + Drul_array dx_f_drul_; +}; + +#endif // HYPHEN_SPANNER_HH + diff --git a/lily/include/lily-proto.hh b/lily/include/lily-proto.hh index e78946882c..029309d854 100644 --- a/lily/include/lily-proto.hh +++ b/lily/include/lily-proto.hh @@ -62,6 +62,7 @@ struct Change_iterator; struct Change_translator; struct Chord; struct Chord_name_engraver; +struct CHyphen_req; struct Clef_change_req; struct Clef_item; struct Clef_engraver; diff --git a/lily/include/ly-symbols.hh b/lily/include/ly-symbols.hh index 4383fc8eea..be99f08c74 100644 --- a/lily/include/ly-symbols.hh +++ b/lily/include/ly-symbols.hh @@ -36,6 +36,9 @@ DECLARE_LY_SYMBOL(extra_space); DECLARE_LY_SYMBOL(dir_forced); DECLARE_LY_SYMBOL(dir_list); DECLARE_LY_SYMBOL(extender_height); +DECLARE_LY_SYMBOL(hyphen_thickness); +DECLARE_LY_SYMBOL(hyphen_height); +DECLARE_LY_SYMBOL(hyphen_minimum_length); DECLARE_LY_SYMBOL(filledbox); DECLARE_LY_SYMBOL(fontsize); DECLARE_LY_SYMBOL(grace); diff --git a/lily/include/musical-request.hh b/lily/include/musical-request.hh index 2c220138a9..88d5f6fbce 100644 --- a/lily/include/musical-request.hh +++ b/lily/include/musical-request.hh @@ -145,4 +145,10 @@ public: VIRTUAL_COPY_CONS(Music); }; +/// a centred hyphen +class Hyphen_req : public Request { +public: + VIRTUAL_COPY_CONS(Music); +}; + #endif // MUSICALREQUESTS_HH diff --git a/lily/lexer.ll b/lily/lexer.ll index e9a0c10371..8c340af25c 100644 --- a/lily/lexer.ll +++ b/lily/lexer.ll @@ -93,7 +93,7 @@ NOTECOMMAND \\{A}+ LYRICS ({AA}|{TEX})[^0-9 \t\n\f]* ESCAPED [nt\\'"] EXTENDER __ - +HYPHEN -- %% @@ -267,6 +267,8 @@ EXTENDER __ String s (YYText ()); if (s == "__") return yylval.i = EXTENDER; + if (s == "--") + return yylval.i = HYPHEN; int i = 0; while ((i=s.index_i ("_")) != -1) // change word binding "_" to " " *(s.ch_l () + i) = ' '; diff --git a/lily/parser.yy b/lily/parser.yy index cb4f0a942b..51a26d08d7 100644 --- a/lily/parser.yy +++ b/lily/parser.yy @@ -143,6 +143,7 @@ yylex (YYSTYPE *s, void * v_l) %token CADENZA %token CHORDMODIFIERS %token CHORDS +%token HYPHEN %token CLEF %token CM_T %token CONSISTS @@ -252,6 +253,7 @@ yylex (YYSTYPE *s, void * v_l) %type post_request %type command_req verbose_command_req %type extender_req +%type hyphen_req %type string %type score_block score_body %type shape_array @@ -904,6 +906,9 @@ abbrev_command_req: extender_req { $$ = $1; } + | hyphen_req { + $$ = $1; + } | '|' { $$ = new Barcheck_req; } @@ -1158,6 +1163,14 @@ extender_req: } ; +hyphen_req: + HYPHEN { + if (!THIS->lexer_p_->lyric_state_b ()) + THIS->parser_error (_ ("have to be in Lyric mode for lyrics")); + $$ = new Hyphen_req; + } + ; + close_request: close_request_parens { $$ = $1; diff --git a/ly/engraver.ly b/ly/engraver.ly index 10adf06a55..f340a29c9a 100644 --- a/ly/engraver.ly +++ b/ly/engraver.ly @@ -190,6 +190,7 @@ StaffGroupContext= \translator { \consists "Separating_line_group_engraver"; \consists "Lyric_engraver"; \consists "Extender_engraver"; + \consists "Hyphen_engraver"; } \translator { diff --git a/ly/params.ly b/ly/params.ly index a41d3c2c1a..8706ac12fc 100644 --- a/ly/params.ly +++ b/ly/params.ly @@ -153,6 +153,10 @@ rulethickness = \staffline; extender_height = 0.8*\staffline; +hyphen_thickness = 0.05*\font_normal; +hyphen_height = 0.2*\font_normal; +hyphen_minimum_length = 0.25*\font_normal; + % Multi-measure rests mmrest_x_minimum = 2.0*\staffheight;