]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/piano-pedal-engraver.cc
Web-ja: update introduction
[lilypond.git] / lily / piano-pedal-engraver.cc
index d708ddfcc644de4e1b2193455c37ffb983e0ed8b..2a2d2aa8ec5b417081fb09f8f1a31ba8e7de9f19 100644 (file)
@@ -1,7 +1,7 @@
 /*
   This file is part of LilyPond, the GNU music typesetter.
 
-  Copyright (C) 2000--2010 Jan Nieuwenhuizen <janneke@gnu.org>,
+  Copyright (C) 2000--2015 Jan Nieuwenhuizen <janneke@gnu.org>,
                  Erik Sandberg <mandolaerik@gmail.com>
 
   Chris Jackson <chris@fluffhouse.org.uk> - extended to support
     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 {
+enum Pedal_type
+{
   SOSTENUTO,
   SUSTAIN,
   UNA_CORDA,
@@ -69,7 +69,7 @@ struct Pedal_type_info
   SCM event_class_sym_;
   SCM style_sym_;
   SCM strings_sym_;
-  
+
   const char *pedal_c_str_;
 
   Pedal_type_info ()
@@ -123,10 +123,9 @@ public:
 protected:
   virtual void initialize ();
   virtual void finalize ();
-  DECLARE_TRANSLATOR_LISTENER (sustain);
-  DECLARE_TRANSLATOR_LISTENER (una_corda);
-  DECLARE_TRANSLATOR_LISTENER (sostenuto);
-  DECLARE_ACKNOWLEDGER (note_column);
+  void listen_sustain (Stream_event *);
+  void listen_una_corda (Stream_event *);
+  void listen_sostenuto (Stream_event *);
   void stop_translation_timestep ();
   void process_music ();
 
@@ -138,7 +137,6 @@ private:
   void typeset_all (Pedal_info *p);
 };
 
-
 static void
 init_pedal_types ()
 {
@@ -154,36 +152,37 @@ init_pedal_types ()
       string base_name = name;
       /* foo-bar */
       string base_ident = "";
-      int prev_pos=0;
+      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;
-         }
+        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));
 
       /*
-       be careful, as we don't want to loose references to the _sym_ members.
+        be careful, as we don't want to loose references to the _sym_ members.
        */
       Pedal_type_info info;
-      info.event_class_sym_ = scm_str2symbol ((base_ident + "-event").c_str ());
-      info.style_sym_ = scm_str2symbol (("pedal" + base_name + "Style").c_str ());
-      info.strings_sym_ = scm_str2symbol (("pedal" + base_name + "Strings").c_str ());
-      
+      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 ());
+
       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)
 {
 }
 
@@ -207,24 +206,6 @@ Piano_pedal_engraver::initialize ()
   info_list_[NUM_PEDAL_TYPES].type_ = 0;
 }
 
-
-/*
-  Urg: Code dup
-  I'm a script
-*/
-void
-Piano_pedal_engraver::acknowledge_note_column (Grob_info info)
-{
-  for (Pedal_info *p = info_list_; p->type_; p++)
-    {
-      if (p->bracket_)
-       add_bound_item (p->bracket_, info.grob ());
-      if (p->finished_bracket_)
-       add_bound_item (p->finished_bracket_, info.grob ());
-    }
-}
-
-IMPLEMENT_TRANSLATOR_LISTENER (Piano_pedal_engraver, sostenuto);
 void
 Piano_pedal_engraver::listen_sostenuto (Stream_event *ev)
 {
@@ -232,7 +213,6 @@ Piano_pedal_engraver::listen_sostenuto (Stream_event *ev)
   ASSIGN_EVENT_ONCE (info_list_[SOSTENUTO].event_drul_[d], ev);
 }
 
-IMPLEMENT_TRANSLATOR_LISTENER (Piano_pedal_engraver, sustain);
 void
 Piano_pedal_engraver::listen_sustain (Stream_event *ev)
 {
@@ -240,7 +220,6 @@ Piano_pedal_engraver::listen_sustain (Stream_event *ev)
   ASSIGN_EVENT_ONCE (info_list_[SUSTAIN].event_drul_[d], ev);
 }
 
-IMPLEMENT_TRANSLATOR_LISTENER (Piano_pedal_engraver, una_corda);
 void
 Piano_pedal_engraver::listen_una_corda (Stream_event *ev)
 {
@@ -254,33 +233,33 @@ Piano_pedal_engraver::process_music ()
   for (Pedal_info *p = info_list_; p->type_; p++)
     {
       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 = internal_get_property (p->type_->style_sym_);
-
-         bool mixed = style == ly_symbol2scm ("mixed");
-         bool bracket = (mixed
-                         || style == ly_symbol2scm ("bracket"));
-         bool text = (style == ly_symbol2scm ("text")
-                      || mixed);
-
-         if (text && !p->item_)
-           create_text_grobs (p, mixed);
-         if (bracket)
-           create_bracket_grobs (p, mixed);
-       }
+        {
+          /* 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);
+        }
     }
 }
 
@@ -288,7 +267,7 @@ void
 Piano_pedal_engraver::create_text_grobs (Pedal_info *p, bool mixed)
 {
   SCM s = SCM_EOL;
-  SCM strings = internal_get_property (p->type_->strings_sym_);
+  SCM strings = get_property (p->type_->strings_sym_);
 
   if (scm_ilength (strings) < 3)
     {
@@ -296,11 +275,11 @@ Piano_pedal_engraver::create_text_grobs (Pedal_info *p, bool mixed)
       if (!m) m = p->event_drul_ [STOP];
 
       string msg = _f ("expect 3 strings for piano pedals, found: %ld",
-                      scm_ilength (strings));
+                       scm_ilength (strings));
       if (m)
-       m->origin ()->warning (msg);
+        m->origin ()->warning (msg);
       else
-       warning (msg);
+        warning (msg);
 
       return;
     }
@@ -308,38 +287,38 @@ Piano_pedal_engraver::create_text_grobs (Pedal_info *p, bool mixed)
   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];
-       }
+        {
+          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;
-       }
+        {
+          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->event_drul_[START]
+                                       : p->event_drul_[STOP])->self_scm ());
 
       p->item_->set_property ("text", s);
     }
@@ -365,29 +344,27 @@ Piano_pedal_engraver::create_bracket_grobs (Pedal_info *p, bool mixed)
     {
       assert (!p->finished_bracket_);
 
-      Grob *cmc = unsmob_grob (get_property ("currentMusicalColumn"));
-
-      if (!p->bracket_->get_bound (RIGHT))
-       p->bracket_->set_bound (RIGHT, cmc);
+      Grob *cmc = unsmob<Grob> (get_property ("currentMusicalColumn"));
+      p->bracket_->set_bound (RIGHT, cmc);
 
       /*
-       Set properties so that the stencil-creating function will
-       know whether the right edge should be flared ___/
+        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)));
-       }
+        {
+          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;
     }
 
@@ -399,34 +376,34 @@ Piano_pedal_engraver::create_bracket_grobs (Pedal_info *p, bool mixed)
       p->bracket_ = make_spanner ("PianoPedalBracket", p->event_drul_[START]->self_scm ());
 
       /*
-       Set properties so that the stencil-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 \___
       */
 
       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)));
-       }
+        {
+          SCM flare = p->bracket_->get_property ("bracket-flare");
+          p->bracket_->set_property ("bracket-flare", scm_cons (scm_from_double (0), scm_cdr (flare)));
+        }
 
       /* Set this property for 'mixed style' pedals,    Ped._______/\ ,
-        so the stencil function will shorten the ____ line by the length of the Ped. text.
+         so the stencil function will shorten the ____ line by the length of the Ped. text.
       */
 
       if (mixed)
-       {
-         /*
-           Mixed style: Store a pointer to the preceding text for use in
-           calculating the length of the line
+        {
+          /*
+            Mixed style: Store a pointer to the preceding text for use in
+            calculating the length of the line
 
 
-           TODO:
+            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 ());
-       }
+            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->event_drul_[START] = 0;
@@ -439,19 +416,19 @@ Piano_pedal_engraver::finalize ()
   for (Pedal_info *p = info_list_; p->type_; p++)
     {
       if (p->bracket_
-         && !p->bracket_->is_live ())
-       p->bracket_ = 0;
+          && !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);
+        {
+          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);
-       }
+          p->finished_bracket_ = p->bracket_;
+          p->bracket_ = 0;
+          typeset_all (p);
+        }
 
     }
 }
@@ -461,15 +438,13 @@ Piano_pedal_engraver::stop_translation_timestep ()
 {
   for (Pedal_info *p = info_list_; p->type_; p++)
     {
-      
+
       typeset_all (p);
       if (p->bracket_ && !p->bracket_->get_bound (LEFT))
-       {
-         Grob *cmc = unsmob_grob (get_property ("currentMusicalColumn"));
-
-         if (!p->bracket_->get_bound (LEFT))
-           p->bracket_->set_bound (LEFT, cmc);
-       }
+        {
+          Grob *cmc = unsmob<Grob> (get_property ("currentMusicalColumn"));
+          p->bracket_->set_bound (LEFT, cmc);
+        }
     }
 
   for (Pedal_info *p = info_list_; p->type_; p++)
@@ -496,33 +471,39 @@ Piano_pedal_engraver::typeset_all (Pedal_info *p)
     {
       Grob *r = p->finished_bracket_->get_bound (RIGHT);
       if (!r)
-       p->finished_bracket_->set_bound (RIGHT, unsmob_grob (get_property ("currentMusicalColumn")));
+        p->finished_bracket_->set_bound (RIGHT, unsmob<Grob> (get_property ("currentMusicalColumn")));
 
       p->finished_bracket_ = 0;
     }
 }
 
-ADD_ACKNOWLEDGER (Piano_pedal_engraver, note_column);
+void
+Piano_pedal_engraver::boot ()
+{
+  ADD_LISTENER (Piano_pedal_engraver, sostenuto);
+  ADD_LISTENER (Piano_pedal_engraver, sustain);
+  ADD_LISTENER (Piano_pedal_engraver, una_corda);
+}
 
 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 */
-               ""
-               );
+                /* doc */
+                "Engrave piano pedal symbols and brackets.",
+
+                /* create */
+                "PianoPedalBracket "
+                "SostenutoPedal "
+                "SustainPedal "
+                "UnaCordaPedal ",
+
+                /* read */
+                "currentCommandColumn "
+                "pedalSostenutoStrings "
+                "pedalSostenutoStyle "
+                "pedalSustainStrings "
+                "pedalSustainStyle "
+                "pedalUnaCordaStrings "
+                "pedalUnaCordaStyle ",
+
+                /* write */
+                ""
+               );