]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/translator.cc
release: 1.5.19
[lilypond.git] / lily / translator.cc
index d4a5cb9d2096eda6e51a4720d20c78ff43913d6d..ddac9aae3ccd15599ae0230b31548e996cbf2b7c 100644 (file)
@@ -3,48 +3,65 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c)  1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c)  1997--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
 
+
 #include "translator.hh"
 #include "debug.hh"
 #include "translator-group.hh"
+#include "translator-def.hh"
+
 #include "moment.hh"
+#include "ly-smobs.icc"
+
 
-char const*
-Translator::name() const
+Translator::~Translator ()
 {
-  return classname(this);
 }
 
-Translator::~Translator ()
+void
+Translator::init ()
 {
+  simple_trans_list_ = SCM_EOL;
+  trans_group_list_ = SCM_EOL;
+  properties_scm_ = SCM_EOL;
+  definition_ = SCM_EOL;
+  daddy_trans_l_ =0;
 }
 
 Translator::Translator ()
 {
-  status = ORPHAN;
-  daddy_trans_l_ = 0;
+  init ();
   output_def_l_ = 0;
+  smobify_self ();
+
 }
 
 Translator::Translator (Translator const &s)
   : Input (s)
 {
-  status = ORPHAN;
-  daddy_trans_l_ =0;
+  init ();
   output_def_l_ = s.output_def_l_;
   type_str_ = s.type_str_;
+
+  smobify_self ();
 }
 
 bool
 Translator::is_alias_b (String s) const
 {
-  return s == type_str_;
+  bool b  = s == type_str_;
+
+  for (SCM a = unsmob_translator_def (definition_)->type_aliases_;
+       !b && gh_pair_p (a); a = ly_cdr (a))
+    b = b || s == ly_scm2string (ly_car (a));
+
+  return b;
 }
 
 bool
-Translator::do_try_music (Music *)
+Translator::try_music (Music *)
 {
   return false;
 }
@@ -57,132 +74,140 @@ Translator::now_mom () const
 }
 
 
+
+
+
+
 void
-Translator::add_processing ()
+Translator::removal_processing ()
 {
-  if (status > ORPHAN)
-    return;
-  
-  do_add_processing ();
-  status = VIRGIN;
+  finalize ();
 }
 
+
 void
-Translator::do_add_processing ()
+Translator::announces ()
 {
+  do_announces ();
 }
 
-void
-Translator::print () const
-{
-#ifndef NPRINT
-  DEBUG_OUT << classname (this) << " {";
-  if (classname (this) != type_str_)
-    DEBUG_OUT << "type = " << type_str_;
-  do_print ();
-  DEBUG_OUT << "}\n";
+
+Music_output_def *
+Translator::output_def_l () const
+{
+  return output_def_l_;
+}
+#if 0
+SCM
+Translator::get_property (char const * id) const
+{
+  return daddy_trans_l_->get_property (ly_symbol2scm (id));
+}
 #endif
+
+SCM
+Translator::internal_get_property (SCM sym) const
+{
+  return daddy_trans_l_->internal_get_property (sym);
 }
 
 void
-Translator::do_print () const
+Translator:: stop_translation_timestep ()
 {
 }
 
-
-
-
 void
-Translator::creation_processing ()
+Translator::start_translation_timestep ()
 {
-  if (status >= CREATION_INITED)
-    return ;
-  
-  do_creation_processing ();
-  status = CREATION_INITED;
 }
 
 void
-Translator::post_move_processing ()
+Translator::do_announces ()
 {
-  if (status >= MOVE_INITED)
-    return;
+}
 
-  creation_processing ();
-  do_post_move_processing ();
-  status = MOVE_INITED;
+void
+Translator::initialize ()
+{
 }
 
 void
-Translator::removal_processing ()
+Translator::finalize ()
 {
-  if (status == ORPHAN)
-    return;
-  creation_processing ();
-  do_removal_processing ();
-  // elegancy ...
-  // status = ORPHAN;
 }
 
 
-bool
-Translator::try_music (Music * r)
+/*
+
+  SMOBS
+
+*/
+SCM
+Translator::mark_smob (SCM sm)
 {
-  if (status < MOVE_INITED)
-    post_move_processing ();
+  Translator * me = (Translator*) SCM_CELL_WORD_1 (sm);
+  scm_gc_mark (me->simple_trans_list_);
+  scm_gc_mark (me->trans_group_list_);
+  scm_gc_mark (me->definition_);  
+  scm_gc_mark (me->properties_scm_);  
 
-  return do_try_music (r);
+  return me->properties_scm_;
 }
 
-void
-Translator::process_requests ()
+MAKE_SCHEME_CALLBACK(Translator,name,1);
+SCM
+Translator::name (SCM trans) 
 {
-  if (status < PROCESSED_REQS)
-    post_move_processing ();
-  else if (status >= PROCESSED_REQS)
-    return; 
-  
-  status = PROCESSED_REQS;
-  do_process_requests ();
+  if (unsmob_translator (trans))
+    {
+      char const* nm = classname (unsmob_translator (trans));
+      return ly_str02scm (nm);
+    }
+  return
+    SCM_EOL;
 }
 
-void
-Translator::pre_move_processing ()
+MAKE_SCHEME_CALLBACK(Translator,description,1)
+SCM
+Translator::description (SCM me) 
 {
-  do_pre_move_processing ();
-  status = CREATION_INITED;
+  if (unsmob_translator (me))
+    return unsmob_translator(me)->translator_description ();
+  else
+    {
+      programming_error ("Translator::description ()");  
+      return SCM_EOL;
+    }
 }
 
-
-
-Music_output_def *
-Translator::output_def_l () const
+SCM
+Translator::translator_description () const
 {
-  return output_def_l_;
+  return SCM_EOL;
 }
 
-SCM
-Translator::get_property (String id, Translator_group **where_l) const
+int
+Translator::print_smob (SCM s, SCM port, scm_print_state *)
 {
-  return daddy_trans_l_->get_property (ly_symbol2scm (id.ch_C()), where_l);
+  Translator *sc = (Translator *) ly_cdr (s);
+     
+  scm_puts ("#<Translator ", port);
+  scm_display (name (s), port);
+  scm_display (sc->simple_trans_list_, port);
+  /*
+    don't try to print properties, that is too much hassle.
+   */
+  scm_puts (" >", port);
+  
+  return 1;
 }
 
 SCM
-Translator::get_property (SCM sym,
-                         Translator_group **where_l) const
+Translator::static_translator_description ()const
 {
-  return daddy_trans_l_->get_property (sym, where_l);
+  return SCM_EOL;
 }
 
 
-
-void
-Translator:: do_pre_move_processing(){}
-void
-Translator::do_post_move_processing(){}
-void
-Translator::do_process_requests () {}
-void
-Translator::do_creation_processing() {}
-void
-Translator::do_removal_processing(){}
+IMPLEMENT_SMOBS (Translator);
+IMPLEMENT_DEFAULT_EQUAL_P (Translator);