]> git.donarmstrong.com Git - lilypond.git/commitdiff
patch::: 1.1.53.gp1
authorGlen Prideaux <glenprideaux@iname.com>
Tue, 6 Jul 1999 08:08:10 +0000 (10:08 +0200)
committerGlen Prideaux <glenprideaux@iname.com>
Tue, 6 Jul 1999 08:08:10 +0000 (10:08 +0200)
pl 53.gp1
- added Hyphen-engraver, Hyphen-spanner
************

15 files changed:
Documentation/tex/refman.yo
NEWS
VERSION
input/test/hyphen.ly [new file with mode: 0644]
lily/hyphen-engraver.cc [new file with mode: 0644]
lily/hyphen-spanner.cc [new file with mode: 0644]
lily/include/hyphen-engraver.hh [new file with mode: 0644]
lily/include/hyphen-spanner.hh [new file with mode: 0644]
lily/include/lily-proto.hh
lily/include/ly-symbols.hh
lily/include/musical-request.hh
lily/lexer.ll
lily/parser.yy
ly/engraver.ly
ly/params.ly

index 8f0285e287776cfb17a10681a41718519731874e..a6d9cce7788d119e90d265ee20c3c6c2cda7acf8 100644 (file)
@@ -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 25c143f79ddfbac018430f9f00bfdb18f5ed2bb5..c805f1b72c84161db912fa664ee31337f3fafa51 100644 (file)
--- 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 d06e719920e11c8791d0ab98eebc50f8bc2f6572..75b3a1cff1ef22d3b0bd7b3dcba4392720b0bee0 100644 (file)
--- 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 (file)
index 0000000..149b02d
--- /dev/null
@@ -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 (file)
index 0000000..013c962
--- /dev/null
@@ -0,0 +1,121 @@
+/*
+  hyphen-engraver.cc -- implement Hyphen_engraver
+
+  (c) 1999 Glen Prideaux <glenprideaux@iname.com>
+*/
+
+#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<Text_item*> (i.elem_l_))
+    {
+      Rhythmic_req * rh = dynamic_cast<Rhythmic_req*>  (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 <Hyphen_req *> (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<Text_lyric_tuple> 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 (file)
index 0000000..8636dbb
--- /dev/null
@@ -0,0 +1,96 @@
+/*
+  hyphen-spanner.cc -- implement Hyphen_spanner
+
+  source file of the GNU LilyPond music typesetter
+
+  (c) 1999 Glen Prideaux <glenprideaux@iname.com>
+
+  (adapted from extender-spanner)
+*/
+
+/*
+  TODO: too complicated implementation.  Why the dx_drul?.
+ */
+
+#include <math.h>
+#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 (file)
index 0000000..6ab2eb5
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+  hyphen-engraver.hh -- declare Hyphen_engraver
+
+  source file of the GNU LilyPond music typesetter
+
+  (c) 1999 Glen Prideaux <glenprideaux@iname.com>
+*/
+
+#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<Text_lyric_tuple> past_lyrics_pq_;
+  Array<Text_lyric_tuple> now_lyrics_;
+  Array<Text_lyric_tuple> 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 (file)
index 0000000..e131625
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+  hyphen-spanner.hh -- part of GNU LilyPond
+
+  (c) 1999 Glen Prideaux <glenprideaux@iname.com>
+*/
+
+#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<Real> dx_f_drul_;
+};
+
+#endif // HYPHEN_SPANNER_HH
+
index e78946882cf2773c1f6ed5fcc9f5a38407ffde48..029309d854956c6465e27389d1112ea1830fc17a 100644 (file)
@@ -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;
index 4383fc8eea03d8f0bd0b0e4c50678e0be9710583..be99f08c74e625c27c3e5fa85f28e43dd8db8747 100644 (file)
@@ -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);
index 2c220138a9c384e636d31e17a40f1ee6e5612191..88d5f6fbcee88c9fd5c97df69c36a7a470ff8370 100644 (file)
@@ -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
index e9a0c10371b4a4058317ea1056693b3e0dee2d5c..8c340af25c94a23ec9ccfd29339a1e0d57d9e851 100644 (file)
@@ -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) = ' ';
index cb4f0a942b2e8346b5ded595649fb48eca6d5a43..51a26d08d785249fd0444977dc5bdc9c884710ac 100644 (file)
@@ -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 <request>        post_request 
 %type <request> command_req verbose_command_req
 %type <request>        extender_req
+%type <request> hyphen_req
 %type <string> string
 %type <score>  score_block score_body
 %type <intarr> 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;
index 10adf06a5534ae50e9142c99f189aad57f36295d..f340a29c9a47625ffed043e2242fc0b6843111be 100644 (file)
@@ -190,6 +190,7 @@ StaffGroupContext= \translator {
        \consists "Separating_line_group_engraver";
        \consists "Lyric_engraver";
        \consists "Extender_engraver";
+       \consists "Hyphen_engraver";
 }
 
 \translator {
index a41d3c2c1a856b31ae976f947eb8f9254781a703..8706ac12fc82c9f8d4441031aa48dbd450185e4c 100644 (file)
@@ -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;