]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/piano-pedal-engraver.cc
release: 1.3.55
[lilypond.git] / lily / piano-pedal-engraver.cc
index 6d0327ddc3f6d906773808c2762aafa03f533b13..e51fff1c6eacfec6da71b43f38e32e4790e2c82a 100644 (file)
@@ -4,7 +4,6 @@
   source file of the GNU LilyPond music typesetter
   
   (c) 2000 Jan Nieuwenhuizen <janneke@gnu.org>
-  
  */
 
 #include "engraver.hh"
 #include "stem.hh"
 #include "side-position-interface.hh"
 #include "staff-symbol-referencer.hh"
-
+#include "text-item.hh"
+#include "sustain-pedal.hh"
 
 /*
-  TODO:
-    sostenuto
-    una-chorda / tre-corde
- */
+   TODO:
+     * it would be really cool if an engraver could be initialised with a
+       string, ie:
 
+          Piano_pedal_engraver::"sostenuto"
+          Piano_pedal_engraver::"sustain"
+          Piano_pedal_engraver::"una-chorda"
+
+ */
 
 /*
-  Urg.
-  This is almost text
-  Problem is:
-    * we have no kerning
-    * symbols are at wrong place in font
+  Would it? The semantics are unclear, and real benefits are muddy
+  too.  --hwn
 */
 
-class Sustain_pedal : public Item
-{
-public:
-  VIRTUAL_COPY_CONS (Score_element);
 
-protected:
-  virtual Molecule do_brew_molecule () const;
-  virtual void after_line_breaking ();
-};
-
-void
-Sustain_pedal::after_line_breaking ()
-{
-  Side_position_interface i (this);
-  Direction d =  i.get_direction ();
-  i.set_direction (d);
-}
-
-Molecule
-Sustain_pedal::do_brew_molecule () const
-{
-  Molecule mol;
-  SCM glyph = get_elt_property ("glyph");
-  if (glyph == SCM_UNDEFINED)
-    return mol;
-  String text = ly_scm2string (glyph);
-
-  for (int i = 0; i < text.length_i (); i++)
-    {
-      // leuke koor dump door tiepo, snapnie helemaal:
-      //String idx = ("pedal-") + text[i];
-      // urg, Byte* ??
-      // braak: waarom vindt String het zo moeilijk om
-      // String + char te doen?
-      //String idx = "pedal-" + String (&text.byte_C ()[i], 1);
-      String idx = String ("pedal-") + String (&text.byte_C ()[i], 1);
-      Molecule m = lookup_l ()->afm_find (idx);
-      if (m.empty_b ())
-       continue;
-      Real kern = 0;
-      if (i)
-       {
-         SCM s = scm_eval (gh_list (ly_symbol2scm ("pedal-kerning"),
-                                    ly_str02scm (String (&text.byte_C ()[i - 1], 1).ch_C ()),
-                                    ly_str02scm (String (&text.byte_C ()[i], 1).ch_C ()),
-                                    SCM_UNDEFINED));
-         if (gh_number_p (s))
-           {
-             Staff_symbol_referencer_interface st (this);
-             Real staff_space = st.staff_space ();
-             kern = gh_scm2double (s) * staff_space;
-           }
-       }
-      mol.add_at_edge (X_AXIS, RIGHT, m, kern);
-    }
-    
-  return mol;
-}
 
 /**
-   engrave Piano pedals
+   engrave Piano pedals symbols.
  */
 class Piano_pedal_engraver : public Engraver
 {
 public:
   VIRTUAL_COPY_CONS (Translator);
   Piano_pedal_engraver ();
-
+  ~Piano_pedal_engraver ();
 protected:
+  virtual void do_creation_processing ();
   virtual bool do_try_music (Music*);
   virtual void do_process_music ();
   virtual void do_pre_move_processing ();
@@ -110,19 +55,49 @@ protected:
   virtual void acknowledge_element (Score_element_info);
 
 private:
-  Span_req* sustain_start_req_l_;
-  Drul_array<Span_req*> sustain_req_l_drul_;
-  Sustain_pedal* sustain_p_;
+  struct Pedal_info
+  {
+    char const * name_;
+    Span_req* start_req_l_;
+    Drul_array<Span_req*> req_l_drul_;
+    Item* item_p_;
+  };
+
+
+  Pedal_info *info_list_;
 };
 
-ADD_THIS_TRANSLATOR(Piano_pedal_engraver);
+ADD_THIS_TRANSLATOR (Piano_pedal_engraver);
 
 Piano_pedal_engraver::Piano_pedal_engraver ()
 {
-  sustain_p_ = 0;
-  sustain_req_l_drul_[START] = 0;
-  sustain_req_l_drul_[STOP] = 0;
-  sustain_start_req_l_ = 0;
+  info_list_ = 0;
+}
+void
+Piano_pedal_engraver::do_creation_processing()
+{
+  info_list_ = new Pedal_info[4];
+  Pedal_info *p = info_list_;
+
+
+  char * names [] = { "Sostenuto", "Sustain", "UnaChorda", 0  };
+  char **np = names ;
+  do
+    {
+      p->name_ = *np;
+      p->item_p_ = 0;
+      p->req_l_drul_[START] = 0;
+      p->req_l_drul_[STOP] = 0;
+      p->start_req_l_ = 0;
+
+      p++;
+    }
+  while (*(np ++));
+}
+
+Piano_pedal_engraver::~Piano_pedal_engraver()
+{
+  delete[] info_list_;
 }
 
 /*
@@ -130,22 +105,25 @@ Piano_pedal_engraver::Piano_pedal_engraver ()
   I'm a script
  */
 void
-Piano_pedal_engraver::acknowledge_element (Score_element_info i)
+Piano_pedal_engraver::acknowledge_element (Score_element_info info)
 {
-  if (sustain_p_)
+  for (Pedal_info*p = info_list_; p->name_; p ++)
     {
-      if (Note_head* n = dynamic_cast<Note_head*> (i.elem_l_))
+      if (p->item_p_)
        {
-         Side_position_interface st (sustain_p_);
-         st.add_support (n);
-         if (st.get_axis( ) == X_AXIS
-             && !sustain_p_->parent_l (Y_AXIS))
-           sustain_p_->set_parent (n, Y_AXIS);
-       }
-      if (Stem* s = dynamic_cast<Stem*> (i.elem_l_))
-       {
-         Side_position_interface st (sustain_p_);
-         st.add_support (s);
+         if (Note_head* n = dynamic_cast<Note_head*> (info.elem_l_))
+           {
+             Side_position_interface st (p->item_p_);
+             st.add_support (n);
+             if (st.get_axis( ) == X_AXIS
+                 && !p->item_p_->parent_l (Y_AXIS))
+               p->item_p_->set_parent (n, Y_AXIS);
+           }
+         if (Stem* s = dynamic_cast<Stem*> (info.elem_l_))
+           {
+             Side_position_interface st (p->item_p_);
+             st.add_support (s);
+           }
        }
     }
 }
@@ -155,10 +133,13 @@ Piano_pedal_engraver::do_try_music (Music *m)
 {
   if (Span_req * s = dynamic_cast<Span_req*>(m))
     {
-      if (s->span_type_str_ == "sustain")
+      for (Pedal_info*p = info_list_; p->name_; p ++)
        {
-         sustain_req_l_drul_[s->span_dir_] = s;
-         return true;
+         if (s->span_type_str_ == p->name_)
+           {
+             p->req_l_drul_[s->span_dir_] = s;
+             return true;
+           }
        }
     }
   return false;
@@ -167,80 +148,108 @@ Piano_pedal_engraver::do_try_music (Music *m)
 void
 Piano_pedal_engraver::do_process_music ()
 {
-  SCM s = SCM_UNDEFINED;
-  if (sustain_req_l_drul_[STOP] && sustain_req_l_drul_[START])
+  for (Pedal_info*p = info_list_; p->name_; p ++)
     {
-      if (!sustain_start_req_l_)
+      SCM s = SCM_UNDEFINED;
+      if (p->req_l_drul_[STOP] && p->req_l_drul_[START])
        {
-         sustain_req_l_drul_[STOP]->warning (_ ("can't find start of piano_pedal"));
+         if (!p->start_req_l_)
+           {
+             p->req_l_drul_[STOP]->warning (_f ("can't find start of piano pedal: %s",  p->name_ ));
+           }
+         else
+           {
+             s = get_property ("stopStart" + String (p->name_ ));
+           }
+         p->start_req_l_ = p->req_l_drul_[START];
        }
-      else
+      else if (p->req_l_drul_[STOP])
        {
-         s = get_property ("stopStartSustain");
-         if (!gh_string_p (s))
-           s = ly_str02scm ("*Ped.");
+         if (!p->start_req_l_)
+           {
+             p->req_l_drul_[STOP]->warning (_f ("can't find start of piano pedal: %s", p->name_ ));
+           }
+         else
+           {
+             s = get_property ("stop" + String (p->name_ ));
+           }
+         p->start_req_l_ = 0;
        }
-      sustain_start_req_l_ = sustain_req_l_drul_[START];
-    }
-  else if (sustain_req_l_drul_[STOP])
-    {
-      if (!sustain_start_req_l_)
+      else if (p->req_l_drul_[START])
        {
-         sustain_req_l_drul_[STOP]->warning (_ ("can't find start of piano_pedal"));
+         p->start_req_l_ = p->req_l_drul_[START];
+         s = get_property ("start" + String (p->name_ ));
        }
-      else
+
+      if (s != SCM_UNDEFINED)
        {
-         s = get_property ("stopSustain");
-         if (!gh_string_p (s))
-           s = ly_str02scm ("*");
+         if (p->name_ == String ("Sustain"))
+           {
+             p->item_p_ = new Sustain_pedal (SCM_EOL);
+             p->item_p_->set_elt_property ("text", s);
+           }
+         else
+           {
+             p->item_p_ = new Text_item (SCM_EOL);
+             p->item_p_->set_elt_property ("text", s);
+             // guh
+             p->item_p_->set_elt_property ("style", ly_str02scm ("italic"));
+           }
+
+         Side_position_interface si (p->item_p_);
+         si.set_axis (Y_AXIS);
+
+         // todo: init with basic props.
+         p->item_p_->set_elt_property ("no-spacing-rods"  , SCM_BOOL_T);
+         p->item_p_->set_elt_property ("self-alignment-X", gh_int2scm (0));
+         p->item_p_->add_offset_callback (Side_position_interface::aligned_on_self, X_AXIS);
+         p->item_p_->add_offset_callback (Side_position_interface::centered_on_parent, X_AXIS);
+         announce_element (Score_element_info (p->item_p_,
+                                               p->req_l_drul_[START]
+                                               ? p->req_l_drul_[START]
+                                               : p->req_l_drul_[STOP]));
        }
-      sustain_start_req_l_ = 0;
-    }
-  else if (sustain_req_l_drul_[START])
-    {
-      sustain_start_req_l_ = sustain_req_l_drul_[START];
-      s = get_property ("startSustain");
-      if (!gh_string_p (s))
-       s = ly_str02scm ("Ped.");
-    }
-  if (s != SCM_UNDEFINED)
-    {
-      sustain_p_ = new Sustain_pedal;
-      sustain_p_->set_elt_property ("glyph", s);
-
-
-      Side_position_interface si (sustain_p_);
-      si.set_axis (Y_AXIS);
-
-      /* Hmm,
-        If set to empty, it can't be centred
-        Howto centre non-fat text?
-        sustain_p_->set_empty (X_AXIS);
-      */
-      sustain_p_->set_elt_property ("self-alignment-X", gh_int2scm (0));
-      sustain_p_->add_offset_callback (Side_position_interface::aligned_on_self, X_AXIS);
-      sustain_p_->add_offset_callback (Side_position_interface::centered_on_parent, X_AXIS);
-      announce_element (Score_element_info (sustain_p_,
-                                           sustain_req_l_drul_[START]
-                                           ? sustain_req_l_drul_[START]
-                                           : sustain_req_l_drul_[STOP]));
     }
 }
 
 void
 Piano_pedal_engraver::do_pre_move_processing ()
 {
-  if (sustain_p_)
+  Item * sustain = 0;
+  for (Pedal_info*p = info_list_; p->name_; p ++)
     {
-      side_position (sustain_p_).add_staff_support ();
-      typeset_element (sustain_p_);
+      if (p->name_ == String ("Sustain"))
+       sustain = p->item_p_;
+    }
+
+  for (Pedal_info*p = info_list_; p->name_; p ++)
+    {
+      if (p->item_p_)
+       {
+         Side_position_interface (p->item_p_).add_staff_support ();
+         /*
+           Hmm.
+         */
+         if (p->name_ != String ("Sustain"))
+           {
+             if (sustain)
+               {
+                 Side_position_interface st (p->item_p_);
+                 st.add_support (sustain);
+               }
+           }
+         typeset_element (p->item_p_);
+       }
+      p->item_p_ = 0;
     }
-  sustain_p_ = 0;
 }
 
 void
 Piano_pedal_engraver::do_post_move_processing ()
 {
-  sustain_req_l_drul_[STOP] = 0;
-  sustain_req_l_drul_[START] = 0;
+  for (Pedal_info*p = info_list_; p->name_; p ++)
+    {
+      p->req_l_drul_[STOP] = 0;
+      p->req_l_drul_[START] = 0;
+    }
 }