]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/translator.cc
*** empty log message ***
[lilypond.git] / lily / translator.cc
index 4229f61600d44e91af80452eecef916a53e22ce4..d55fe15729b9677b7f07d138b26c8d66fe836c25 100644 (file)
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+  (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
 */
 
-
 #include "translator.hh"
-#include "debug.hh"
+
+#include "warn.hh"
 #include "translator-group.hh"
-#include "dictionary-iter.hh"
+#include "context-def.hh"
+#include "global-context.hh"
+
+#include "translator.icc"
+#include "ly-smobs.icc"
 
 Translator::~Translator ()
 {
 }
 
-Translator::Translator ()
+void
+Translator::init ()
 {
-  status = ORPHAN;
-  daddy_trans_l_ = 0;
-  output_def_l_ = 0;
+  must_be_last_ = false;
+  self_scm_ = SCM_EOL;
+  daddy_context_ = 0;
+  smobify_self ();
 }
 
-Translator::Translator (Translator const &s)
-  : Input (s)
+void
+Translator::process_music ()
 {
-  status = ORPHAN;
-  daddy_trans_l_ =0;
-  output_def_l_ = s.output_def_l_;
-  properties_dict_ = s.properties_dict_;
-  type_str_ = s.type_str_;
 }
 
-bool
-Translator::is_alias_b (String s) const
+void
+Translator::process_acknowledged ()
+{
+}
+
+Translator::Translator ()
+{
+  init ();
+}
+
+Translator::Translator (Translator const &src)
 {
-  return s == type_str_;
+  init ();
+  must_be_last_ = src.must_be_last_;
 }
 
 bool
-Translator::do_try_request (Request *)
+Translator::try_music (Music *)
 {
   return false;
 }
-                           
 
 Moment
-Translator::now_moment () const
+Translator::now_mom () const
 {
-  return daddy_trans_l_->now_moment ();
+  return daddy_context_->now_mom ();
 }
 
-
-void
-Translator::add_processing ()
+Output_def *
+Translator::get_output_def () const
 {
-  if (status > ORPHAN)
-    return;
-  
-  do_add_processing ();
-  status = VIRGIN;
+  return daddy_context_->get_output_def ();
 }
 
-void
-Translator::do_add_processing ()
+Translator_group *
+Translator::get_daddy_translator () const
 {
+  return daddy_context_->implementation ();
 }
 
-void
-Translator::print () const
+SCM
+Translator::internal_get_property (SCM sym) const
 {
-#ifndef NPRINT
-  DOUT << name () << " {";
-  if (name () != type_str_)
-    DOUT << "type = " << type_str_;
-  for (Dictionary_iter<Scalar> i (properties_dict_); i.ok (); i++)
-    {
-      DOUT << i.key () << "=" << i.val () <<"\n";
-    }
-  do_print ();
-  DOUT << "}\n";
-#endif
+  return daddy_context_->internal_get_property (sym);
 }
 
 void
-Translator::do_print () const
+Translator::stop_translation_timestep ()
 {
 }
 
-IMPLEMENT_IS_TYPE_B(Translator);
+/*
+  this function has 2 properties
 
+  - It is called before try_music ()
 
+  - It is called before any user information enters the translators.
+  (i.e. any \property or event is not processed yet.)
+*/
 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::initialize ()
 {
-  if (status >= MOVE_INITED)
-    return;
-
-  creation_processing ();
-  do_post_move_processing ();
-  status = MOVE_INITED;
 }
 
 void
-Translator::removal_processing ()
+Translator::finalize ()
 {
-  if (status == ORPHAN)
-    return;
-  creation_processing ();
-  do_removal_processing ();
-  // elegancy ...
-  // status = ORPHAN;
 }
 
+/*
+  SMOBS
+*/
+SCM
+Translator::mark_smob (SCM sm)
+{
+  Translator *me = (Translator *) SCM_CELL_WORD_1 (sm);
+  me->derived_mark ();
+  return SCM_EOL;
+}
 
-bool
-Translator::try_request (Request * r)
+Global_context *
+Translator::get_global_context () const
 {
-  if (status < MOVE_INITED)
-    post_move_processing ();
+  return daddy_context_->get_global_context ();
+}
 
-  return do_try_request (r);
+Score_context *
+Translator::get_score_context () const
+{
+  return daddy_context_->get_score_context ();
 }
 
-void
-Translator::process_requests ()
+IMPLEMENT_SMOBS (Translator);
+IMPLEMENT_DEFAULT_EQUAL_P (Translator);
+IMPLEMENT_TYPE_P (Translator, "ly:translator?");
+
+bool
+Translator::must_be_last () const
 {
-  if (status < PROCESSED_REQS)
-    post_move_processing ();
-  else if (status >= PROCESSED_REQS)
-    return; 
-  
-  status = PROCESSED_REQS;
-  do_process_requests ();
+  return must_be_last_;
 }
 
 void
-Translator::pre_move_processing ()
+Translator::derived_mark () const
 {
-  do_pre_move_processing ();
-  status = CREATION_INITED;
 }
 
-Scalar
-Translator::get_property (String id)
+int
+Translator::print_smob (SCM s, SCM port, scm_print_state *)
 {
-  if (properties_dict_.elt_b (id))
-    {
-      return properties_dict_[id];
-    }
-  
-  if (daddy_trans_l_)
-    return daddy_trans_l_->get_property (id);
-
-  return "";
+  Translator *me = (Translator *) SCM_CELL_WORD_1 (s);
+  scm_puts ("#<Translator ", port);
+  scm_puts (me->class_name (), port);
+  scm_puts (" >", port);
+  return 1;
 }
 
 void
-Translator::set_property (String id, Scalar val)
+add_acknowledger (Engraver_void_function_engraver_grob_info ptr,
+                 char const *func_name,
+                 Array<Acknowledge_information> *ack_array)
 {
-  properties_dict_[id] = val;
-}
+  Acknowledge_information inf;
+  inf.function_ = ptr;
+
+  std::string interface_name (func_name);
 
+  interface_name = replace_all (interface_name, '_', '-');
+  interface_name += "-interface";
 
-Music_output_def *
-Translator::output_def_l () const
+  inf.symbol_ = scm_gc_protect_object (ly_symbol2scm (interface_name.c_str ()));
+  ack_array->push (inf);
+}
+
+Engraver_void_function_engraver_grob_info
+generic_get_acknowledger (SCM sym, Array<Acknowledge_information> const *ack_array)
 {
-  return output_def_l_;
+  for (int i = 0; i < ack_array->size (); i++)
+    {
+      if (ack_array->elem (i).symbol_ == sym)
+       return ack_array->elem (i).function_;
+    }
+  return 0;
 }
+
+ADD_TRANSLATOR (Translator,
+               "Base class. Unused",
+               "",
+               "",
+               "",
+               "");