From: fred Date: Tue, 26 Mar 2002 22:14:46 +0000 (+0000) Subject: lilypond-1.1.54 X-Git-Tag: release/1.5.59~2306 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=5577c97f5c1c1a0b0b44ea2cf42c9ac3f946c941;p=lilypond.git lilypond-1.1.54 --- 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/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/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 {