]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/piano-pedal-engraver.cc
Release: bump Welcome versions.
[lilypond.git] / lily / piano-pedal-engraver.cc
index 14bfb4e3199adae68b594ca3f2f2cafa3ec35e54..2a2d2aa8ec5b417081fb09f8f1a31ba8e7de9f19 100644 (file)
-/*   
-  piano-pedal-engraver.cc --  implement Piano_pedal_engraver
-  
-  source file of the GNU LilyPond music typesetter
-  
- (c) 2000--2002 Jan Nieuwenhuizen <janneke@gnu.org>
-  
+/*
+  This file is part of LilyPond, the GNU music typesetter.
+
+  Copyright (C) 2000--2015 Jan Nieuwenhuizen <janneke@gnu.org>,
+                 Erik Sandberg <mandolaerik@gmail.com>
+
   Chris Jackson <chris@fluffhouse.org.uk> - extended to support
   bracketed pedals.
+
+  LilyPond is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation, either version 3 of the License, or
+  (at your option) any later version.
+
+  LilyPond is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "engraver.hh"
-#include "musical-request.hh"
-#include "grob.hh"
-#include "item.hh"
+
+#include "axis-group-interface.hh"
+#include "context.hh"
+#include "directional-element-interface.hh"
+#include "international.hh"
 #include "lily-guile.hh"
+#include "note-column.hh"
 #include "side-position-interface.hh"
 #include "staff-symbol-referencer.hh"
+#include "stream-event.hh"
+#include "string-convert.hh"
+#include "warn.hh"
+#include "spanner.hh"
 #include "item.hh"
-#include "axis-group-interface.hh"
-#include "translator-group.hh"
-#include "directional-element-interface.hh"
-#include "note-column.hh"
+
+#include "translator.icc"
+
+#include <string.h>
+
+/*
+  TODO:
+
+  * Junk hardcoded sustain/sostenuto/una_corda distinction;
+    Softcode using (list (sustain-event SustainPedal PianoPedalBracket) ... )
+
+  * Try to use same engraver for dynamics.
+*/
+
+/* Ugh: This declaration is duplicated in piano-pedal-performer */
+enum Pedal_type
+{
+  SOSTENUTO,
+  SUSTAIN,
+  UNA_CORDA,
+  NUM_PEDAL_TYPES
+};
+
+/*
+  Static precalculated data (symbols and strings) for the different
+  pedal types
+*/
+struct Pedal_type_info
+{
+  string base_name_;
+  SCM event_class_sym_;
+  SCM style_sym_;
+  SCM strings_sym_;
+
+  const char *pedal_c_str_;
+
+  Pedal_type_info ()
+  {
+    event_class_sym_ = SCM_EOL;
+    style_sym_ = SCM_EOL;
+    strings_sym_ = SCM_EOL;
+    pedal_c_str_ = 0;
+  }
+  void protect ()
+  {
+    scm_gc_protect_object (event_class_sym_);
+    scm_gc_protect_object (style_sym_);
+    scm_gc_protect_object (strings_sym_);
+  }
+};
 
 struct Pedal_info
 {
-  char const * name_;
-  Span_req* start_req_l_;
-  Drul_array<Span_req*> req_l_drul_;
-  Item* item_p_;
-  Spanner* bracket_p_;     // A single portion of a pedal bracket
-  Spanner* finished_bracket_p_;
+  const Pedal_type_info *type_;
 
   /*
-    This grob contains all the pedals of the same type on the same staff
-   */
-  Spanner* line_spanner_;
-  Spanner* finished_line_spanner_;
-  Span_req* current_bracket_req_;
+    Event for currently running pedal.
+  */
+  Stream_event *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.
+  */
+  Stream_event *start_ev_;
+
+  /*
+    Events that were found in this timestep.
+  */
+  Drul_array<Stream_event *> event_drul_;
+  Item *item_;
+  Spanner *bracket_; // A single portion of a pedal bracket
+  Spanner *finished_bracket_;
 };
 
+static Pedal_type_info pedal_types_[NUM_PEDAL_TYPES];
 
 class Piano_pedal_engraver : public Engraver
 {
 public:
   TRANSLATOR_DECLARATIONS (Piano_pedal_engraver);
-  ~Piano_pedal_engraver ();
+
 protected:
   virtual void initialize ();
   virtual void finalize ();
-  virtual bool try_music (Music*);
-  virtual void stop_translation_timestep ();
-  virtual void start_translation_timestep ();
-  virtual void acknowledge_grob (Grob_info);
-  virtual void process_acknowledged_grobs ();
+  void listen_sustain (Stream_event *);
+  void listen_una_corda (Stream_event *);
+  void listen_sostenuto (Stream_event *);
+  void stop_translation_timestep ();
+  void process_music ();
 
 private:
+  Pedal_info info_list_[NUM_PEDAL_TYPES + 1];
 
-  Pedal_info *info_list_;
+  void create_text_grobs (Pedal_info *p, bool);
+  void create_bracket_grobs (Pedal_info *p, bool);
+  void typeset_all (Pedal_info *p);
+};
 
-  /*
-    Record a stack of the current pedal spanners, so if more than one pedal
-    occurs simultaneously then extra space can be added between them.
+static void
+init_pedal_types ()
+{
+  const char *names [NUM_PEDAL_TYPES];
+  names[SOSTENUTO] = "Sostenuto";
+  names[SUSTAIN] = "Sustain";
+  names[UNA_CORDA] = "UnaCorda";
 
+  for (int i = 0; i < NUM_PEDAL_TYPES; i++)
+    {
+      const char *name = names[i];
+      /* FooBar */
+      string base_name = name;
+      /* foo-bar */
+      string base_ident = "";
+      int prev_pos = 0;
+      int cur_pos;
+      for (cur_pos = 1; name[cur_pos]; cur_pos++)
+        if (isupper (name[cur_pos]))
+          {
+            base_ident = base_ident + String_convert::to_lower (string (name, prev_pos, cur_pos - prev_pos)) + "-";
+            prev_pos = cur_pos;
+          }
+      base_ident += String_convert::to_lower (string (name, prev_pos, cur_pos - prev_pos));
 
-    Why 4, why not 3. Why not 3423 ?  ---hwn.
-  */
-  
-  Spanner *previous_p_ [4];
-  
-  int spanner_count_;
+      /*
+        be careful, as we don't want to loose references to the _sym_ members.
+       */
+      Pedal_type_info info;
+      info.event_class_sym_ = scm_from_ascii_symbol ((base_ident + "-event").c_str ());
+      info.style_sym_ = scm_from_ascii_symbol (("pedal" + base_name + "Style").c_str ());
+      info.strings_sym_ = scm_from_ascii_symbol (("pedal" + base_name + "Strings").c_str ());
 
-  /*
-    Left and right flare widths of a \___/, as specified by the grob
-    property edge-widen.
-   */
-  Drul_array<SCM> edge_width_drul_;
-  
-  void create_text_grobs (Pedal_info *p, SCM pedaltype);
-  void create_bracket_grobs (Pedal_info *p, SCM pedaltype);
-  void typeset_all ();
-};
+      info.base_name_ = name;
+      info.pedal_c_str_ = strdup ((base_name + "Pedal").c_str ());
+
+      info.protect ();
+
+      pedal_types_[i] = info;
+    }
+}
 
+ADD_SCM_INIT_FUNC (Piano_pedal_engraver_init_pedal_types_, init_pedal_types);
 
-Piano_pedal_engraver::Piano_pedal_engraver ()
+Piano_pedal_engraver::Piano_pedal_engraver (Context *c)
+  : Engraver (c)
 {
-  info_list_ = 0;
 }
 
 void
 Piano_pedal_engraver::initialize ()
 {
-  info_list_ = new Pedal_info[4];
-  Pedal_info *p = info_list_;
-
-  spanner_count_ = 0;
-  for (int i = 0; i < 3; ++i)
-    previous_p_[i] = 0; 
-
-
-  char * names [] = { "Sostenuto", "Sustain", "UnaCorda", 0  };
-  char **np = names ;
-  do
+  for (int i = 0; i < NUM_PEDAL_TYPES; i++)
     {
-      p->name_ = *np;
-      p->item_p_ = 0;
-      p->bracket_p_ = 0;
-      p->finished_bracket_p_ = 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_l_ = 0;
-
-      p++;
+      Pedal_type_info *s = &pedal_types_[i];
+      Pedal_info *info = &info_list_[i];
+
+      info->type_ = s;
+      info->item_ = 0;
+      info->bracket_ = 0;
+      info->finished_bracket_ = 0;
+      info->current_bracket_ev_ = 0;
+      info->event_drul_[START] = 0;
+      info->event_drul_[STOP] = 0;
+      info->start_ev_ = 0;
     }
-  while (* (np ++));
+  info_list_[NUM_PEDAL_TYPES].type_ = 0;
 }
 
-Piano_pedal_engraver::~Piano_pedal_engraver ()
+void
+Piano_pedal_engraver::listen_sostenuto (Stream_event *ev)
 {
-  delete[] info_list_;
+  Direction d = to_dir (ev->get_property ("span-direction"));
+  ASSIGN_EVENT_ONCE (info_list_[SOSTENUTO].event_drul_[d], ev);
 }
 
-/*
-   Urg: Code dup
-   I'm a script
-  */
 void
-Piano_pedal_engraver::acknowledge_grob (Grob_info info)
+Piano_pedal_engraver::listen_sustain (Stream_event *ev)
 {
-  for (Pedal_info*p = info_list_; p && p->name_; p ++)
-    {
-      if (Note_column::has_interface (info.grob_l_))
-       {
-         if (p->line_spanner_)
-           {
-             Side_position_interface::add_support (p->line_spanner_, info.grob_l_);
-             
-             add_bound_item (p->line_spanner_,info.grob_l_);
-           }     
-         if (p->bracket_p_)
-           add_bound_item (p->bracket_p_,info.grob_l_);                  
-         
-       }
-    }
+  Direction d = to_dir (ev->get_property ("span-direction"));
+  ASSIGN_EVENT_ONCE (info_list_[SUSTAIN].event_drul_[d], ev);
 }
 
-bool
-Piano_pedal_engraver::try_music (Music *m)
+void
+Piano_pedal_engraver::listen_una_corda (Stream_event *ev)
 {
-  if (Span_req * s = dynamic_cast<Span_req*> (m))
-    {
-      for (Pedal_info*p = info_list_; p->name_; p ++)
-       {
-         if (ly_scm2string (s->get_mus_property ("span-type")) == "abort")
-           {
-             p->req_l_drul_[START] = 0;
-             p->req_l_drul_[STOP] = 0;
-             
-             if (p->bracket_p_)
-               p->bracket_p_->suicide (); /* as in dynamic-engraver.cc */
-             p->bracket_p_ = 0;
-           }  
-         if (scm_equal_p (s->get_mus_property ("span-type"),
-                          ly_str02scm (p->name_))==SCM_BOOL_T)
-           {
-             p->req_l_drul_[s->get_span_dir ()] = s;
-             return true;
-           }
-       }
-    }
-  return false;
+  Direction d = to_dir (ev->get_property ("span-direction"));
+  ASSIGN_EVENT_ONCE (info_list_[UNA_CORDA].event_drul_[d], ev);
 }
 
 void
-Piano_pedal_engraver::process_acknowledged_grobs ()
+Piano_pedal_engraver::process_music ()
 {
-  for (Pedal_info*p = info_list_; p && p->name_; p ++)
+  for (Pedal_info *p = info_list_; p->type_; p++)
     {
-      if (p->req_l_drul_[STOP] || p->req_l_drul_[START])
-       {
-         if (!p->line_spanner_)
-           {
-             String name  = String (p->name_) + "PedalLineSpanner";
-             p->line_spanner_ = new Spanner (get_property (name.ch_C ()));
-             Side_position_interface::set_axis (p->line_spanner_, Y_AXIS);
-             Music * rq = (p->req_l_drul_[START]  ?  p->req_l_drul_[START]  :  p->req_l_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").ch_C ())));
-         if (type == ly_symbol2scm ("text") ||      // Ped.     *Ped.  *
-             type == ly_symbol2scm ("mixed")  )    // Ped. _____/\____|
-           {
-             if (! p->item_p_)
-               create_text_grobs (p, type);
-           }
-         if (type == ly_symbol2scm ("bracket") ||   // |_________/\____|
-             type == ly_symbol2scm ("mixed")  )
-          {
-            create_bracket_grobs (p, type);
-          }
-       }
+      if (p->event_drul_[STOP] || p->event_drul_[START])
+        {
+          /* Choose the appropriate grobs to add to the line spanner
+             These can be text items or text-spanners
+          */
+
+          /*
+            ugh, code dup, should read grob to create from other
+            property.
+
+            bracket: |_________/\____|
+            text:    Ped.     *Ped.  *
+            mixed:   Ped. _____/\____|
+          */
+
+          SCM style = get_property (p->type_->style_sym_);
+
+          bool mixed = scm_is_eq (style, ly_symbol2scm ("mixed"));
+          bool bracket = (mixed
+                          || scm_is_eq (style, ly_symbol2scm ("bracket")));
+          bool text = (mixed
+                       || scm_is_eq (style, ly_symbol2scm ("text")));
+
+          if (text && !p->item_)
+            create_text_grobs (p, mixed);
+          if (bracket)
+            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 b;
   SCM s = SCM_EOL;
-  SCM strings = get_property ( ("pedal" + String (p->name_) + "Strings").ch_C ());
+  SCM strings = get_property (p->type_->strings_sym_);
 
-  if (scm_ilength (strings) >= 3)
+  if (scm_ilength (strings) < 3)
     {
-      if (p->req_l_drul_[STOP] && p->req_l_drul_[START]) 
-       {
-         if (pedaltype == ly_symbol2scm ("text")) 
-           {
-             if (!p->start_req_l_)
-               {
-                 p->req_l_drul_[STOP]->origin ()->warning (_f ("can't find start of piano pedal: `%s'",  p->name_));
-               }
-             else
-               {
-                 s = ly_cadr (strings);
-               }
-             p->start_req_l_ = p->req_l_drul_[START];
-           }
-       }
-      else if (p->req_l_drul_[STOP])
-       { 
-         if (pedaltype == ly_symbol2scm ("text"))
-           {
-             if (!p->start_req_l_)
-               {
-                 p->req_l_drul_[STOP]->origin ()->warning (_f ("can't find start of piano pedal: `%s'", p->name_));
-               }
-             else
-               {
-                 s = ly_caddr (strings);
-                 spanner_count_ --;
-               }
-             p->start_req_l_ = 0;
-           }
-       }
-      else if (p->req_l_drul_[START])
-       {
-         p->start_req_l_ = p->req_l_drul_[START];
-         s = ly_car (strings);
-         if (pedaltype == ly_symbol2scm ("text"))
-           {
-             spanner_count_ ++;
-             previous_p_[spanner_count_] = p->line_spanner_;
-             if (spanner_count_ > 1)
-               // add extra space below the previous already-occuring pedal
-               Side_position_interface::add_support (p->line_spanner_,
-                                                    previous_p_[spanner_count_ - 1]);
-           }
-       }
-      
-      if (gh_string_p (s))
-       {
-         String propname = String (p->name_) + "Pedal";
-         b = get_property (propname.ch_C ());
-         p->item_p_ = new Item (b);
-         p->item_p_->set_grob_property ("text", s);
-         Axis_group_interface::add_element (p->line_spanner_, p->item_p_);
-         
-         announce_grob (p->item_p_,
-                        (p->req_l_drul_[START]
-                        ? p->req_l_drul_[START]
-                        : p->req_l_drul_[STOP])->self_scm ());
-         
-       }
-      if (pedaltype == ly_symbol2scm ("text")) 
-       {
-         p->req_l_drul_[START] = 0;
-         p->req_l_drul_[STOP] = 0;
-       }
+      Stream_event *m = p->event_drul_[START];
+      if (!m) m = p->event_drul_ [STOP];
+
+      string msg = _f ("expect 3 strings for piano pedals, found: %ld",
+                       scm_ilength (strings));
+      if (m)
+        m->origin ()->warning (msg);
+      else
+        warning (msg);
+
+      return;
+    }
+
+  if (p->event_drul_[STOP] && p->event_drul_[START])
+    {
+      if (!mixed)
+        {
+          if (!p->start_ev_)
+            p->event_drul_[STOP]->origin ()->warning (_f ("cannot find start of piano pedal: `%s'", p->type_->base_name_.c_str ()));
+          else
+            s = scm_cadr (strings);
+          p->start_ev_ = p->event_drul_[START];
+        }
+    }
+  else if (p->event_drul_[STOP])
+    {
+      if (!mixed)
+        {
+          if (!p->start_ev_)
+            p->event_drul_[STOP]->origin ()->warning (_f ("cannot find start of piano pedal: `%s'", p->type_->base_name_.c_str ()));
+          else
+            s = scm_caddr (strings);
+          p->start_ev_ = 0;
+        }
+    }
+  else if (p->event_drul_[START])
+    {
+      p->start_ev_ = p->event_drul_[START];
+      s = scm_car (strings);
+    }
+
+  if (scm_is_string (s))
+    {
+      const char *propname = p->type_->pedal_c_str_;
+
+      p->item_ = make_item (propname, (p->event_drul_[START]
+                                       ? p->event_drul_[START]
+                                       : p->event_drul_[STOP])->self_scm ());
+
+      p->item_->set_property ("text", s);
+    }
+
+  if (!mixed)
+    {
+      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->req_l_drul_[STOP])
+  if (!p->bracket_ && p->event_drul_[STOP])
     {
-      if (!p->start_req_l_)
-       {
-         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])
-       spanner_count_ -- ;
+      string msg = _f ("cannot find start of piano pedal bracket: `%s'", p->type_->base_name_.c_str ());
+      p->event_drul_[STOP]->origin ()->warning (msg);
+      p->event_drul_[STOP] = 0;
+    }
 
-      assert (!p->finished_bracket_p_ && p->bracket_p_);
+  if (p->event_drul_[STOP])
+    {
+      assert (!p->finished_bracket_);
 
-      Grob *cmc = unsmob_grob (get_property ("currentMusicalColumn"));
-      p->bracket_p_->set_bound (RIGHT, cmc);
+      Grob *cmc = unsmob<Grob> (get_property ("currentMusicalColumn"));
+      p->bracket_->set_bound (RIGHT, cmc);
 
       /*
-       Set properties so that the molecule-creating function will
-       know whether the right edge should be flared ___/
-       */
-      SCM eleft = ly_car (p->bracket_p_->get_grob_property ("edge-widen"));
-      SCM eright = (p->req_l_drul_[START]  ? edge_width_drul_[RIGHT] : gh_double2scm (0));
-      p->bracket_p_->set_grob_property ("edge-widen", gh_cons (eleft, eright));
-      
-      p->finished_bracket_p_ = p->bracket_p_;
-      p->bracket_p_ = 0;
-      p->current_bracket_req_ = 0;
-      p->start_req_l_ = p->req_l_drul_[START];
+        Set properties so that the stencil-creating function will
+        know whether the right edge should be flared ___/
+      */
+
+      if (!p->event_drul_[START])
+        {
+          SCM flare = p->bracket_->get_property ("bracket-flare");
+          if (scm_is_pair (flare))
+            p->bracket_->set_property ("bracket-flare", scm_cons (scm_car (flare),
+                                                                  scm_from_double (0)));
+        }
+
+      p->finished_bracket_ = p->bracket_;
+      p->bracket_ = 0;
+
+      announce_end_grob (p->finished_bracket_, p->event_drul_[STOP]->self_scm ());
+
+      p->current_bracket_ev_ = 0;
     }
 
-  if (p->req_l_drul_[START])
+  if (p->event_drul_[START])
     {
-      p->start_req_l_ = 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_p_  = new Spanner (get_property ("PianoPedalBracket"));
+      p->bracket_ = make_spanner ("PianoPedalBracket", p->event_drul_[START]->self_scm ());
 
       /*
-       Set properties so that the molecule-creating function will
-       know whether the left edge should be flared \___
+        Set properties so that the stencil-creating function will
+        know whether the left edge should be flared \___
       */
 
-      SCM ew = p->bracket_p_->get_grob_property ("edge-widen");
-      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_p_->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_p_->set_grob_property ("text-start", 
-                                      pedaltype == ly_symbol2scm ("mixed") ? 
-                                      gh_bool2scm ( (bool) ! p->req_l_drul_[STOP]) :
-                                      gh_bool2scm (false));
+      if (!p->finished_bracket_)
+        {
+          SCM flare = p->bracket_->get_property ("bracket-flare");
+          p->bracket_->set_property ("bracket-flare", scm_cons (scm_from_double (0), scm_cdr (flare)));
+        }
 
-      /*
-       Mixed style: Store a pointer to the preceding text for use in
-       calculating the length of the line 
+      /* Set this property for 'mixed style' pedals,    Ped._______/\ ,
+         so the stencil function will shorten the ____ line by the length of the Ped. text.
       */
-      if (p->item_p_)
-       p->bracket_p_->set_grob_property ("pedal-text", p->item_p_->self_scm ());
-      
-      p->bracket_p_->set_bound (LEFT, unsmob_grob (get_property ("currentMusicalColumn")));
-      Axis_group_interface::add_element (p->line_spanner_, p->bracket_p_);           
-
-      add_bound_item (p->line_spanner_, p->bracket_p_->get_bound (LEFT));
-      announce_grob (p->bracket_p_, p->req_l_drul_[START]->self_scm ());
-
-      if (!p->req_l_drul_[STOP])
-       {
-         spanner_count_ ++;
-         previous_p_[spanner_count_] = p->line_spanner_;       
-
-         if (spanner_count_ > 1) 
-           // position new pedal spanner below the current one
-           Side_position_interface::add_support (p->line_spanner_, previous_p_[spanner_count_ - 1]);
-       }
+
+      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_object ("pedal-text", p->item_->self_scm ());
+        }
     }
 
-  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::finalize ()
-{  
-  for (Pedal_info*p = info_list_; p && p->name_; p ++)
+{
+  for (Pedal_info *p = info_list_; p->type_; p++)
     {
-      /*
-       suicide?
-       */
-      if (p->line_spanner_
-         && p->line_spanner_->immutable_property_alist_ == SCM_EOL)
-       p->line_spanner_ = 0;
-      
-      if (p->line_spanner_)
-       {
-         p->finished_line_spanner_ = p->line_spanner_;
-         typeset_all ();
-       }
-      if (p->bracket_p_
-         && p->bracket_p_->immutable_property_alist_ == SCM_EOL)
-       p->bracket_p_ = 0;
-      if (p->bracket_p_)
-       {
-         p->current_bracket_req_->origin ()->warning (_ ("unterminated pedal bracket"));
-         p->bracket_p_->suicide ();
-         p->bracket_p_ = 0;
-       }
+      if (p->bracket_
+          && !p->bracket_->is_live ())
+        p->bracket_ = 0;
+
+      if (p->bracket_)
+        {
+          SCM cc = get_property ("currentCommandColumn");
+          Item *c = unsmob<Item> (cc);
+          p->bracket_->set_bound (RIGHT, c);
+
+          p->finished_bracket_ = p->bracket_;
+          p->bracket_ = 0;
+          typeset_all (p);
+        }
+
     }
 }
 
-  
 void
 Piano_pedal_engraver::stop_translation_timestep ()
 {
-  for (Pedal_info*p = info_list_; p && p->name_; p ++)
+  for (Pedal_info *p = info_list_; p->type_; p++)
     {
-      if (!p->bracket_p_)
-       {
-         p->finished_line_spanner_ = p->line_spanner_;
-         p->line_spanner_ = 0;
-       }
+
+      typeset_all (p);
+      if (p->bracket_ && !p->bracket_->get_bound (LEFT))
+        {
+          Grob *cmc = unsmob<Grob> (get_property ("currentMusicalColumn"));
+          p->bracket_->set_bound (LEFT, cmc);
+        }
     }
-  
-  typeset_all ();
-}
 
+  for (Pedal_info *p = info_list_; p->type_; p++)
+    {
+      p->event_drul_[STOP] = 0;
+      p->event_drul_[START] = 0;
+    }
+}
 
 void
-Piano_pedal_engraver::typeset_all ()
+Piano_pedal_engraver::typeset_all (Pedal_info *p)
 {
-  Item * sustain = 0;
-  for (Pedal_info*p = info_list_; p->name_; p ++)
+  /*
+    Handle suicide.
+  */
+  if (p->finished_bracket_
+      && !p->finished_bracket_->is_live ())
+    p->finished_bracket_ = 0;
+
+  if (p->item_)
+    p->item_ = 0;
+
+  if (p->finished_bracket_)
     {
-      /*
-       Handle suicide. 
-       */
-      if (p->finished_line_spanner_
-         && p->finished_line_spanner_->immutable_property_alist_ == SCM_EOL)
-       p->finished_line_spanner_ = 0;
-      if (p->finished_bracket_p_
-         && p->finished_bracket_p_->immutable_property_alist_ == SCM_EOL)
-       p->finished_bracket_p_ = 0;
-
-
-      if (p->name_ == String ("Sustain"))
-       sustain = p->item_p_;
-
-      if (p->item_p_)
-       {
-         /*
-           Hmm.
-         */
-         if (p->name_ != String ("Sustain"))
-           {
-             if (sustain)
-               {
-                 Side_position_interface::add_support (p->item_p_,sustain);
-               }
-           }
-         typeset_grob (p->item_p_);
-         p->item_p_ = 0;
-       }
-      
-      if (p->finished_bracket_p_)
-       {
-         Grob * l = p->finished_bracket_p_->get_bound (LEFT);
-         Grob * r = p->finished_bracket_p_->get_bound (RIGHT);      
-         if (!r)
-           {
-             p->finished_bracket_p_->set_bound (RIGHT, unsmob_grob (get_property ("currentMusicalColumn")));
-           }
-
-         typeset_grob (p->finished_bracket_p_);
-         p->finished_bracket_p_ =0;
-       }
-
-      if (p->finished_line_spanner_)
-       {
-         Side_position_interface::add_staff_support (p->finished_line_spanner_);
-         Grob * l = p->finished_line_spanner_->get_bound (LEFT);
-         Grob * r = p->finished_line_spanner_->get_bound (RIGHT);      
-         if (!r && l)
-           p->finished_line_spanner_->set_bound (RIGHT, l);
-         else if (!l && r)
-           p->finished_line_spanner_->set_bound (LEFT, r);
-         else if (!r && !l)
-           {
-             Grob * cc = unsmob_grob (get_property ("currentMusicalColumn"));
-             Item * ci = dynamic_cast<Item*> (cc);
-             p->finished_line_spanner_->set_bound (RIGHT, ci);
-             p->finished_line_spanner_->set_bound (LEFT, ci);    
-           }
-         typeset_grob (p->finished_line_spanner_);
-         p->finished_line_spanner_ = 0;
-       }
+      Grob *r = p->finished_bracket_->get_bound (RIGHT);
+      if (!r)
+        p->finished_bracket_->set_bound (RIGHT, unsmob<Grob> (get_property ("currentMusicalColumn")));
+
+      p->finished_bracket_ = 0;
     }
 }
 
 void
-Piano_pedal_engraver::start_translation_timestep ()
+Piano_pedal_engraver::boot ()
 {
-  for (Pedal_info*p = info_list_; p->name_; p ++)
-    {
-      p->req_l_drul_[STOP] = 0;
-      p->req_l_drul_[START] = 0;
-    }
+  ADD_LISTENER (Piano_pedal_engraver, sostenuto);
+  ADD_LISTENER (Piano_pedal_engraver, sustain);
+  ADD_LISTENER (Piano_pedal_engraver, una_corda);
 }
-ENTER_DESCRIPTION (Piano_pedal_engraver,
-/* descr */       "Engrave piano pedal symbols and brackets.",
-/* creats*/       "SostenutoPedal SustainPedal UnaCordaPedal SostenutoPedalLineSpanner SustainPedalLineSpanner UnaCordaPedalLineSpanner",
-/* acks  */       "note-column-interface",
-/* reads */       "pedalSostenutoStrings pedalSustainStrings pedalUnaCordaStrings",
-/* write */       "");
+
+ADD_TRANSLATOR (Piano_pedal_engraver,
+                /* doc */
+                "Engrave piano pedal symbols and brackets.",
+
+                /* create */
+                "PianoPedalBracket "
+                "SostenutoPedal "
+                "SustainPedal "
+                "UnaCordaPedal ",
+
+                /* read */
+                "currentCommandColumn "
+                "pedalSostenutoStrings "
+                "pedalSostenutoStyle "
+                "pedalSustainStrings "
+                "pedalSustainStyle "
+                "pedalUnaCordaStrings "
+                "pedalUnaCordaStyle ",
+
+                /* write */
+                ""
+               );