]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/translator.cc
Run grand-replace (issue 3765)
[lilypond.git] / lily / translator.cc
index dc70c155ce97058e9491a598360ceb7f3d19012c..116f2849ac702e33bb6e892dd6d8774f36e26c4b 100644 (file)
@@ -1,9 +1,20 @@
 /*
-  translator.cc -- implement Translator
+  This file is part of LilyPond, the GNU music typesetter.
 
-  source file of the GNU LilyPond music typesetter
+  Copyright (C) 1997--2014 Han-Wen Nienhuys <hanwen@xs4all.nl>
 
-  (c) 1997--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
+  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 "translator.hh"
@@ -25,7 +36,6 @@ Translator::~Translator ()
 void
 Translator::init ()
 {
-  must_be_last_ = false;
   self_scm_ = SCM_EOL;
   daddy_context_ = 0;
   smobify_self ();
@@ -48,8 +58,8 @@ Translator::Translator ()
 
 Translator::Translator (Translator const &src)
 {
+  (void) src;
   init ();
-  must_be_last_ = src.must_be_last_;
 }
 
 Moment
@@ -110,51 +120,19 @@ Translator::finalize ()
 void
 Translator::connect_to_context (Context *c)
 {
-  for (translator_listener_record *r = get_listener_list (); r; r=r->next_)
-    c->events_below ()->add_listener (r->get_listener_ (this), r->event_class_);
+  for (translator_listener_record *r = get_listener_list (); r; r = r->next_)
+    c->events_below ()->add_listener (r->get_listener_ (this, r->event_class_),
+                                      r->event_class_);
 }
 
 void
 Translator::disconnect_from_context (Context *c)
 {
-  for (translator_listener_record *r = get_listener_list (); r; r=r->next_)
-    c->events_below ()->remove_listener (r->get_listener_ (this), r->event_class_);
-}
-
-static SCM listened_event_class_table;
-void
-ensure_listened_hash ()
-{
-  if (!listened_event_class_table)
-    listened_event_class_table = scm_permanent_object (scm_c_make_hash_table (61));
+  for (translator_listener_record *r = get_listener_list (); r; r = r->next_)
+    c->events_below ()->remove_listener (r->get_listener_ (this, r->event_class_),
+                                         r->event_class_);
 }
 
-
-LY_DEFINE (ly_get_listened_event_classes, "ly:get-listened-event-classes",
-          0, 0, 0, (),
-          "Return a list of all event classes that some translator listens"
-          " to.")
-{
-  ensure_listened_hash ();
-  return ly_hash_table_keys (listened_event_class_table);
-}
-
-LY_DEFINE (ly_is_listened_event_class, "ly:is-listened-event-class",
-          1, 0, 0, (SCM sym),
-          "Is @var{sym} a listened event class?")
-{
-  ensure_listened_hash ();
-  return scm_hashq_ref (listened_event_class_table, sym, SCM_BOOL_F);
-}
-
-void
-add_listened_event_class (SCM sym)
-{
-  ensure_listened_hash ();
-  scm_hashq_set_x (listened_event_class_table, sym, SCM_BOOL_T);
-}
-
-
 /*
   internally called once, statically, for each translator
   listener. Connects the name of an event class with a procedure that
@@ -165,18 +143,20 @@ add_listened_event_class (SCM sym)
  */
 void
 Translator::add_translator_listener (translator_listener_record **listener_list,
-                                    translator_listener_record *r,
-                                    Listener (*get_listener) (void *), 
-                                    const char *ev_class)
+                                     translator_listener_record *r,
+                                     Listener (*get_listener) (void *, SCM),
+                                     const char *ev_class)
 {
   /* ev_class is the C++ identifier name. Convert to scm symbol */
   string name = string (ev_class);
   name = replace_all (&name, '_', '-');
   name += "-event";
-  
-  SCM class_sym = scm_str2symbol (name.c_str ());
-  
-  add_listened_event_class (class_sym);
+
+  // we make the symbol permanent in order not to have to bother about
+  // the static translator_listener_record chains while garbage
+  // collecting.
+
+  SCM class_sym = scm_permanent_object (scm_from_locale_symbol (name.c_str ()));
 
   r->event_class_ = class_sym;
   r->get_listener_ = get_listener;
@@ -189,34 +169,34 @@ Translator::add_translator_listener (translator_listener_record **listener_list,
 */
 SCM
 Translator::static_translator_description (const char *grobs,
-                                          const char *desc,
-                                          translator_listener_record *listener_list,
-                                          const char *read, 
-                                          const char *write) const
+                                           const char *desc,
+                                           translator_listener_record *listener_list,
+                                           const char *read,
+                                           const char *write) const
 {
-  SCM static_properties = SCM_EOL;                                     
-
-  static_properties = scm_acons (ly_symbol2scm ("grobs-created"),      
-                                parse_symbol_list (grobs), static_properties);
-  
-  static_properties = scm_acons (ly_symbol2scm ("description"),        
-                                scm_from_locale_string (desc), static_properties); 
-  
+  SCM static_properties = SCM_EOL;
+
+  static_properties = scm_acons (ly_symbol2scm ("grobs-created"),
+                                 parse_symbol_list (grobs), static_properties);
+
+  static_properties = scm_acons (ly_symbol2scm ("description"),
+                                 scm_from_locale_string (desc), static_properties);
+
   SCM list = SCM_EOL;
   for (; listener_list; listener_list = listener_list->next_)
     list = scm_cons (listener_list->event_class_, list);
   static_properties = scm_acons (ly_symbol2scm ("events-accepted"),
-                                list, static_properties);
-  
-  static_properties = scm_acons (ly_symbol2scm ("properties-read"),    
-                                parse_symbol_list (read), static_properties); 
-  
-  static_properties = scm_acons (ly_symbol2scm ("properties-written"), 
-                                parse_symbol_list (write), static_properties); 
-  
-  return static_properties;                                            
+                                 list, static_properties);
+
+  static_properties = scm_acons (ly_symbol2scm ("properties-read"),
+                                 parse_symbol_list (read), static_properties);
+
+  static_properties = scm_acons (ly_symbol2scm ("properties-written"),
+                                 parse_symbol_list (write), static_properties);
+
+  return static_properties;
 }
-  
+
 /*
   SMOBS
 */
@@ -247,7 +227,7 @@ IMPLEMENT_TYPE_P (Translator, "ly:translator?");
 bool
 Translator::must_be_last () const
 {
-  return must_be_last_;
+  return false;
 }
 
 void
@@ -267,8 +247,8 @@ Translator::print_smob (SCM s, SCM port, scm_print_state *)
 
 void
 add_acknowledger (Engraver_void_function_engraver_grob_info ptr,
-                 char const *func_name,
-                 vector<Acknowledge_information> *ack_array)
+                  char const *func_name,
+                  vector<Acknowledge_information> *ack_array)
 {
   Acknowledge_information inf;
   inf.function_ = ptr;
@@ -291,12 +271,11 @@ generic_get_acknowledger (SCM sym, vector<Acknowledge_information> const *ack_ar
   for (vsize i = 0; i < ack_array->size (); i++)
     {
       if (ack_array->at (i).symbol_ == sym)
-       return ack_array->at (i).function_;
+        return ack_array->at (i).function_;
     }
   return 0;
 }
 
-
 Moment
 get_event_length (Stream_event *e)
 {
@@ -311,7 +290,7 @@ Moment
 get_event_length (Stream_event *e, Moment now)
 {
   Moment len = get_event_length (e);
-  
+
   if (now.grace_part_)
     {
       len.grace_part_ = len.main_part_;
@@ -328,15 +307,15 @@ get_event_length (Stream_event *e, Moment now)
 bool
 internal_event_assignment (Stream_event **old_ev, Stream_event *new_ev, const char *function)
 {
-  if (*old_ev &&
-      !to_boolean (scm_equal_p ((*old_ev)->self_scm (), 
-                              new_ev->self_scm ())))
+  if (*old_ev
+      && !to_boolean (scm_equal_p ((*old_ev)->self_scm (),
+                                   new_ev->self_scm ())))
     {
       /* extract event class from function name */
       string ev_class = function;
 
       /* This assertion fails if EVENT_ASSIGNMENT was called outside a
-        translator listener. Don't do that. */
+         translator listener. Don't do that. */
       const char *prefix = "listen_";
       assert (0 == ev_class.find (prefix));
 
@@ -356,15 +335,15 @@ internal_event_assignment (Stream_event **old_ev, Stream_event *new_ev, const ch
 }
 
 ADD_TRANSLATOR (Translator,
-               /* doc */
-               "Base class.  Not instantiated.",
+                /* doc */
+                "Base class.  Not instantiated.",
 
-               /* create */
-               "",
+                /* create */
+                "",
 
-               /* read */
-               "",
+                /* read */
+                "",
 
-               /* write */
-               ""
-               );
+                /* write */
+                ""
+               );