]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/score-element.cc
patch::: 1.3.96.jcn9
[lilypond.git] / lily / score-element.cc
index f54699f63096e6cdef63e0963dd6117f5607fddc..4a4c59d60da5972de8767809233786472562ac12 100644 (file)
@@ -10,6 +10,7 @@
 #include <string.h>
 #include <math.h>
 
+#include "input-smob.hh"
 #include "libc-extension.hh"
 #include "group-interface.hh"
 #include "misc.hh"
@@ -30,6 +31,8 @@
 #include "side-position-interface.hh"
 #include "item.hh"
 
+#include "ly-smobs.icc"
+
 /*
 TODO:
 
@@ -38,47 +41,63 @@ remove dynamic_cast<Spanner,Item> and put this code into respective
 */
 
 
+#define INFINITY_MSG "Infinity or NaN encountered"
 
 Score_element::Score_element(SCM basicprops)
 {
-  set_extent_callback (molecule_extent, X_AXIS);
-  set_extent_callback (molecule_extent, Y_AXIS);    
+  /*
+    fixme: default should be no callback.
+   */
 
   pscore_l_=0;
   lookup_l_ =0;
   status_i_ = 0;
-  self_scm_ = SCM_EOL;
   original_l_ = 0;
-#ifndef READONLY_PROPS
-  basic_property_list_ = basicprops;
-#endif READONLY_PROPS
-  property_alist_ = basicprops;
-  pointer_alist_ = SCM_EOL;
-  
+  immutable_property_alist_ =  basicprops;
+  mutable_property_alist_ = SCM_EOL;
+
   smobify_self ();
-  set_elt_pointer ("dependencies", SCM_EOL);
-  set_elt_property ("interfaces", SCM_EOL);
+
+  char const*onames[] = {"X-offset-callbacks", "Y-offset-callbacks"};
+  char const*enames[] = {"X-extent-callback", "Y-extent-callback"};
+  
+  for (int a = X_AXIS; a <= Y_AXIS; a++){
+    SCM l = get_elt_property (onames[a]);
+
+    if (scm_ilength (l) >=0)
+      {
+       dim_cache_[a].offset_callbacks_ = l;
+       dim_cache_[a].offsets_left_ = scm_ilength (l);
+      }
+    else
+      {
+       programming_error ("[XY]-offset-callbacks must be a list");
+      }
+
+    SCM cb = get_elt_property (enames[a]);
+
+    /*
+      Should change default to be empty? 
+     */
+    if (!gh_procedure_p (cb) && !gh_pair_p (cb))
+      cb = molecule_extent_proc;
+    
+    dim_cache_[a].dimension_ = cb;
+  }
+
+  SCM meta = get_elt_property ("meta");
+  SCM ifs = scm_assoc (ly_symbol2scm ("interfaces"), meta);
+  
+  set_elt_property ("interfaces",gh_cdr (ifs));
 }
 
 
 Score_element::Score_element (Score_element const&s)
    : dim_cache_ (s.dim_cache_)
 {
-  self_scm_ = SCM_EOL;
   original_l_ =(Score_element*) &s;
-  property_alist_ = s.property_alist_;
-#ifndef READONLY_PROPS
-  basic_property_list_ = s.basic_property_list_;
-  /*
-    TODO: should copy the private part of the list.
-   */
-  SCM y ;
-  for (SCM *sp = &s.property_alist_;  *sp != basic_property_list_; sp = &SCM_CDR(*sp))
-    {
-      *sp = gh_cons (      
-    }
-#endif
-  pointer_alist_ = SCM_EOL;
+  immutable_property_alist_ = s.immutable_property_alist_;
+  mutable_property_alist_ = SCM_EOL;
   
   status_i_ = s.status_i_;
   lookup_l_ = s.lookup_l_;
@@ -89,32 +108,28 @@ Score_element::Score_element (Score_element const&s)
 
 Score_element::~Score_element()
 {
-  // this goes awry when score-elements are copied...
-  // real weird Paper_column::~Paper_column () -> infinity_mom
-  //  unsmobify_self ();
+  /*
+    do nothing scm-ish and no unprotecting here.
+   */
 }
 
 
 SCM
-Score_element::get_elt_pointer (const char *nm) const
+Score_element::get_elt_property (const char *nm) const
 {
-  SCM sym =  ly_symbol2scm (nm);
-  SCM s = scm_assq(sym, pointer_alist_);
-
-  return (s == SCM_BOOL_F) ? SCM_UNDEFINED : gh_cdr (s); 
+  SCM sym = ly_symbol2scm (nm);
+  return get_elt_property (sym);
 }
 
-// should also have one that takes SCM arg. 
 SCM
-Score_element::get_elt_property (String nm) const
+Score_element::get_elt_property (SCM sym) const
 {
-  SCM sym =  ly_symbol2scm (nm.ch_C());
-  SCM s = scm_assq(sym, property_alist_);
-
+  SCM s = scm_sloppy_assq(sym, mutable_property_alist_);
   if (s != SCM_BOOL_F)
-    return gh_cdr (s); 
+    return gh_cdr (s);
 
-  return SCM_UNDEFINED;
+  s = scm_sloppy_assq (sym, immutable_property_alist_);
+  return (s == SCM_BOOL_F) ? SCM_EOL : gh_cdr (s); 
 }
 
 /*
@@ -126,54 +141,62 @@ SCM
 Score_element::remove_elt_property (const char* key)
 {
   SCM val = get_elt_property (key);
-  if (val != SCM_UNDEFINED)
-    set_elt_property (key, SCM_UNDEFINED);
+  if (val != SCM_EOL)
+    set_elt_property (key, SCM_EOL);
   return val;
 }
 
 void
-Score_element::set_elt_property (String k, SCM val)
+Score_element::set_elt_property (const char* k, SCM v)
 {
-  SCM sym = ly_symbol2scm (k.ch_C ());
-#ifndef READONLY_PROPS
-  /*
-    destructive if found in my part of the list.
-   */
-  for (SCM s = property_alist_; s != basic_property_list_; s =gh_cdr (s))
-    {
-      if (gh_caar (s)== sym)
-       {
-         gh_set_cdr_x (gh_car (s), val);
-         return;
-       }
-    }
-/*
-    not found in private list. Override in private list.
-   */
-  
-#endif
-  
-  property_alist_ = gh_cons (gh_cons (sym, val), property_alist_);
+  SCM s = ly_symbol2scm (k);
+  set_elt_property (s, v);
 }
 
+/*
+  Puts the k, v in the immutable_property_alist_, which is convenient for
+  storing variables that are needed during the breaking process. (eg.
+  Line_of_score::rank : int )
+ */
 void
-Score_element::set_elt_pointer (const char* k, SCM v)
+Score_element::set_immutable_elt_property (const char*k, SCM v)
 {
   SCM s = ly_symbol2scm (k);
-  pointer_alist_ = scm_assq_set_x (pointer_alist_, s, v);
+  set_immutable_elt_property (s, v);
+}
+
+void
+Score_element::set_immutable_elt_property (SCM s, SCM v)
+{
+  immutable_property_alist_ = gh_cons (gh_cons (s,v), mutable_property_alist_);
+  mutable_property_alist_ = scm_assq_remove_x (mutable_property_alist_, s);
+}
+void
+Score_element::set_elt_property (SCM s, SCM v)
+{
+  mutable_property_alist_ = scm_assq_set_x (mutable_property_alist_, s, v);
 }
 
 
-Interval
-Score_element::molecule_extent (Score_element const *s, Axis a )
+MAKE_SCHEME_CALLBACK(Score_element,molecule_extent,2);
+SCM
+Score_element::molecule_extent (SCM element_smob, SCM scm_axis)
 {
+  Score_element *s = unsmob_element (element_smob);
+  Axis a = (Axis) gh_scm2int (scm_axis);
+
   Molecule m = s->get_molecule ();
-  return m.extent(a);
+  return ly_interval2scm ( m.extent(a));
 }
 
-Interval
-Score_element::preset_extent (Score_element const *s , Axis a )
+MAKE_SCHEME_CALLBACK(Score_element,preset_extent,2);
+
+SCM
+Score_element::preset_extent (SCM element_smob, SCM scm_axis)
 {
+  Score_element *s = unsmob_element (element_smob);
+  Axis a = (Axis) gh_scm2int (scm_axis);
+
   SCM ext = s->get_elt_property ((a == X_AXIS)
                                 ? "extent-X"
                                 : "extent-Y");
@@ -184,10 +207,10 @@ Score_element::preset_extent (Score_element const *s , Axis a )
       Real r = gh_scm2double (gh_cdr (ext));
       l *= s->paper_l ()->get_var ("staffspace");
       r *= s->paper_l ()->get_var ("staffspace");
-      return Interval (l, r);
+      return ly_interval2scm (Interval (l, r));
     }
   
-  return Interval ();
+  return ly_interval2scm ( Interval ());
 }
 
 
@@ -201,10 +224,13 @@ Score_element::paper_l ()  const
 Lookup const *
 Score_element::lookup_l () const
 {
+  /*
+    URG junkthis, caching is clumsy.
+   */
   if (!lookup_l_)
     {
       Score_element * urg = (Score_element*)this;
-      SCM sz = urg->remove_elt_property ("fontsize");
+      SCM sz = urg->remove_elt_property ("font-size");
       int i = (gh_number_p (sz))
        ? gh_scm2int  (sz)
        : 0;
@@ -215,19 +241,7 @@ Score_element::lookup_l () const
 }
 
 void
-Score_element::add_processing()
-{
-  assert (status_i_ >=0);
-  if (status_i_)
-    return;
-  status_i_ ++;
-
-  do_add_processing();
-}
-
-void
-Score_element::calculate_dependencies (int final, int busy,
-                                      Score_element_method_pointer funcptr)
+Score_element::calculate_dependencies (int final, int busy, SCM funcname)
 {
   assert (status_i_ >=0);
 
@@ -242,24 +256,53 @@ Score_element::calculate_dependencies (int final, int busy,
   
   status_i_= busy;
 
-  for (SCM d=  get_elt_pointer ("dependencies"); gh_pair_p (d); d = gh_cdr (d))
+  for (SCM d=  get_elt_property ("dependencies"); gh_pair_p (d); d = gh_cdr (d))
     {
       unsmob_element (gh_car (d))
-       ->calculate_dependencies (final, busy, funcptr);
+       ->calculate_dependencies (final, busy, funcname);
     }
 
-  (this->*funcptr)();
+  // ughugh.
+  String s = ly_symbol2string (funcname);
+  SCM proc = get_elt_property (s.ch_C());
+  if (gh_procedure_p (proc))
+    gh_call1 (proc, this->self_scm ());
+  
   status_i_= final;
+
 }
 
 Molecule
 Score_element::get_molecule ()  const
 {
   SCM proc = get_elt_property ("molecule-callback");
+
+  SCM mol = SCM_EOL;
   if (gh_procedure_p (proc)) 
-    return create_molecule (gh_apply (proc, gh_list (this->self_scm_, SCM_UNDEFINED)));
+    mol = gh_apply (proc, gh_list (this->self_scm (), SCM_UNDEFINED));
+
+    
+  SCM origin =get_elt_property ("origin");
+  if (!unsmob_input (origin))
+    origin =ly_symbol2scm ("no-origin");
+  
+  if (gh_pair_p (mol))
+    {
+      // ugr.
+       mol = gh_cons (gh_list (origin, gh_car (mol), SCM_UNDEFINED), gh_cdr (mol));
+    }
+
+
+  Molecule m (create_molecule (mol));
 
-  return Molecule ();
+  /*
+    This is almost the same as setting molecule-callback to #f, but
+    this retains the dimensions of this element, which means that you
+    can erase elements individually.  */
+  if (to_boolean (get_elt_property ("transparent")))
+    m = Molecule (m.extent_box (), SCM_EOL);
+
+  return m;
 }
 
 
@@ -273,47 +316,27 @@ Score_element::do_break_processing()
 {
 }
 
-void
-Score_element::after_line_breaking ()
-{
-}
-
-
-void
-Score_element::before_line_breaking ()
-{
-}
 
-void
-Score_element::do_space_processing ()
-{
-}
 
-void
-Score_element::do_add_processing()
-{
-}
 
 
-MAKE_SCHEME_SCORE_ELEMENT_CALLBACKS(Score_element)
+MAKE_SCHEME_CALLBACK(Score_element,brew_molecule,1)
 
-  /*
+/*
   ugh.
  */  
-
-Molecule 
-Score_element::do_brew_molecule () const
+SCM
+Score_element::brew_molecule (SCM smob) 
 {
-  SCM glyph = get_elt_property ("glyph");
+  Score_element * sc = unsmob_element (smob);
+  SCM glyph = sc->get_elt_property ("glyph");
   if (gh_string_p (glyph))
     {
-      return lookup_l ()->afm_find (String (ly_scm2string (glyph)));
+      return sc->lookup_l ()->afm_find (String (ly_scm2string (glyph))).create_scheme ();
     }
   else
     {
-      Molecule m ;
-      m.set_empty (true);
-      return m;
+      return SCM_EOL;
     }
 }
 
@@ -329,8 +352,8 @@ Score_element::add_dependency (Score_element*e)
 {
   if (e)
     {
-      Pointer_group_interface gi (this, "dependencies");
-      gi.add_element (e);
+      Pointer_group_interface ::add_element (this, "dependencies",e);
+
     }
   else
     programming_error ("Null dependency added");
@@ -358,7 +381,7 @@ Score_element::handle_broken_smobs (SCM src, SCM criterion)
          if (i && i->break_status_dir () != d)
            {
              Item *br = i->find_prebroken_piece (d);
-             return  (br) ? br->self_scm_ : SCM_UNDEFINED;
+             return  (br) ? br->self_scm () : SCM_UNDEFINED;
            }
        }
       else
@@ -380,7 +403,7 @@ Score_element::handle_broken_smobs (SCM src, SCM criterion)
              || (sc->common_refpoint (line, X_AXIS)
                  && sc->common_refpoint (line, Y_AXIS)))
            {
-             return sc->self_scm_;
+             return sc->self_scm ();
            }
          return SCM_UNDEFINED;
        }
@@ -430,9 +453,9 @@ Score_element::handle_broken_dependencies()
        {
          Score_element * sc = s->broken_into_l_arr_[i];
          Line_of_score * l = sc->line_l ();
-         sc->pointer_alist_ =
-           handle_broken_smobs (pointer_alist_,
-                                l ? l->self_scm_ : SCM_UNDEFINED);
+         sc->mutable_property_alist_ =
+           handle_broken_smobs (mutable_property_alist_,
+                                l ? l->self_scm () : SCM_UNDEFINED);
        }
     }
 
@@ -441,13 +464,13 @@ Score_element::handle_broken_dependencies()
 
   if (line && common_refpoint (line, X_AXIS) && common_refpoint (line, Y_AXIS))
     {
-      pointer_alist_
-       = handle_broken_smobs (pointer_alist_,
-                              line ? line->self_scm_ : SCM_UNDEFINED);
+      mutable_property_alist_
+       = handle_broken_smobs (mutable_property_alist_,
+                              line ? line->self_scm () : SCM_UNDEFINED);
     }
   else if (dynamic_cast <Line_of_score*> (this))
     {
-      pointer_alist_ = handle_broken_smobs (pointer_alist_,
+      mutable_property_alist_ = handle_broken_smobs (mutable_property_alist_,
                                            SCM_UNDEFINED);
     }
   else
@@ -472,14 +495,16 @@ Score_element::handle_broken_dependencies()
 void
 Score_element::suicide ()
 {
-  property_alist_ = SCM_EOL;
-  pointer_alist_ = SCM_EOL;
-  set_extent_callback (0, Y_AXIS);
-  set_extent_callback (0, X_AXIS);
+  mutable_property_alist_ = SCM_EOL;
+  immutable_property_alist_ = SCM_EOL;
+
+  set_extent_callback (SCM_EOL, Y_AXIS);
+  set_extent_callback (SCM_EOL, X_AXIS);
 
   for (int a= X_AXIS; a <= Y_AXIS; a++)
     {
-      dim_cache_[a].off_callbacks_.clear ();
+      dim_cache_[a].offset_callbacks_ = SCM_EOL;
+      dim_cache_[a].offsets_left_ = 0;
     }
 }
 
@@ -497,7 +522,12 @@ Score_element::find_broken_piece (Line_of_score*) const
 void
 Score_element::translate_axis (Real y, Axis a)
 {
-  dim_cache_[a].offset_ += y;
+  if (isinf (y) || isnan (y))
+    programming_error (_(INFINITY_MSG));
+  else
+    {
+      dim_cache_[a].offset_ += y;
+    }
 }  
 
 Real
@@ -521,15 +551,17 @@ Real
 Score_element::get_offset (Axis a) const
 {
   Score_element *me = (Score_element*) this;
-  while (dim_cache_[a].off_callbacks_.size ())
+  while (dim_cache_[a].offsets_left_)
     {
-      Offset_callback c = dim_cache_[a].off_callbacks_[0];
-      me->dim_cache_[a].off_callbacks_.del (0);
-      Real r =  (*c) (me,a );
+      int l = --me->dim_cache_[a].offsets_left_;
+      SCM cb = scm_list_ref (dim_cache_[a].offset_callbacks_,  gh_int2scm (l));
+      SCM retval = gh_call2 (cb, self_scm (), gh_int2scm (a));
+
+      Real r =  gh_scm2double (retval);
       if (isinf (r) || isnan (r))
        {
+         programming_error (INFINITY_MSG);
          r = 0.0;
-         programming_error ("Infinity or NaN encountered");
        }
       me->dim_cache_[a].offset_ +=r;
     }
@@ -537,36 +569,51 @@ Score_element::get_offset (Axis a) const
 }
 
 
-Interval
-Score_element::point_dimension_callback (Score_element const* , Axis)
+MAKE_SCHEME_CALLBACK(Score_element,point_dimension_callback,2);
+SCM
+Score_element::point_dimension_callback (SCM , SCM )
 {
-  return Interval (0,0);
+  return ly_interval2scm ( Interval (0,0));
 }
 
 bool
 Score_element::empty_b (Axis a)const
 {
-  return !dim_cache_[a].extent_callback_l_;
+  return ! (gh_pair_p (dim_cache_[a].dimension_ ) ||
+           gh_procedure_p (dim_cache_[a].dimension_ ));
 }
 
+/*
+  TODO: add
+
+    Score_element *refpoint
+
+  to arguments?
+ */
 Interval
-Score_element::extent (Axis a) const
+Score_element::extent (Score_element * refp, Axis a) const
 {
+  Real x = relative_coordinate (refp, a);
+
+  
   Dimension_cache * d = (Dimension_cache *)&dim_cache_[a];
-  if (!d->extent_callback_l_)
+  Interval ext ;   
+  if (gh_pair_p (d->dimension_))
+    ;
+  else if (gh_procedure_p (d->dimension_))
     {
-      d->dim_.set_empty ();
-    }
-  else if (!d->valid_b_)
-    {
-      d->dim_= (*d->extent_callback_l_ ) (this, a);
-      d->valid_b_ = true;
+      /*
+       FIXME: add doco on types, and should typecheck maybe? 
+       */
+      d->dimension_= gh_call2 (d->dimension_, self_scm(), gh_int2scm (a));
     }
+  else
+    return ext;
 
-  Interval ext = d->dim_;
-  
-  if (empty_b (a)) 
+  if (!gh_pair_p (d->dimension_))
     return ext;
+  
+  ext = ly_scm2interval (d->dimension_);
 
   SCM extra = get_elt_property (a == X_AXIS
                                ? "extra-extent-X"
@@ -590,6 +637,8 @@ Score_element::extent (Axis a) const
       ext.unite (Interval (s * gh_scm2double (gh_car (extra)),
                           s * gh_scm2double (gh_cdr (extra))));
     }
+
+  ext.translate (x);
   
   return ext;
 }
@@ -605,9 +654,9 @@ Score_element *
 Score_element::common_refpoint (Score_element const* s, Axis a) const
 {
   /*
-    I don't like the quadratic aspect of this code. Maybe this should
-    be rewritten some time, but the largest chain of parents might be
-    10 high or so, so it shouldn't be a real issue. */
+    I don't like the quadratic aspect of this code, but I see no other
+    way. The largest chain of parents might be 10 high or so, so
+    it shouldn't be a real issue. */
   for (Score_element const *c = this; c; c = c->dim_cache_[a].parent_l_)
     for (Score_element const * d = s; d; d = d->dim_cache_[a].parent_l_)
       if (d == c)
@@ -631,66 +680,76 @@ Score_element::common_refpoint (SCM elist, Axis a) const
   return common;
 }
 
-char const *
+String
 Score_element::name () const
 {
-  return classname (this);
+  SCM meta = get_elt_property ("meta");
+  SCM nm = scm_assoc (ly_symbol2scm ("name"), meta);
+  nm =  (gh_pair_p (nm)) ? gh_cdr (nm) : SCM_EOL;
+  return  gh_string_p (nm) ?ly_scm2string (nm) :  classname (this);  
 }
 
 void
-Score_element::add_offset_callback (Offset_callback cb, Axis a)
+Score_element::add_offset_callback (SCM cb, Axis a)
 {
-  dim_cache_[a].off_callbacks_.push (cb);
+  if (!has_offset_callback_b (cb, a))
+  {
+    dim_cache_[a].offset_callbacks_ = gh_cons (cb, dim_cache_[a].offset_callbacks_ );
+    dim_cache_[a].offsets_left_ ++;
+  }
 }
 
 bool
-Score_element::has_extent_callback_b (Extent_callback cb, Axis a)const
+Score_element::has_extent_callback_b (SCM cb, Axis a)const
 {
-  return cb == dim_cache_[a].extent_callback_l_;
+  return scm_equal_p (cb, dim_cache_[a].dimension_);
 }
 
+
 bool
-Score_element::has_offset_callback_b (Offset_callback cb, Axis a)const
+Score_element::has_extent_callback_b (Axis a) const
 {
-  for (int i= dim_cache_[a].off_callbacks_.size (); i--;)
-    {
-      if (dim_cache_[a].off_callbacks_[i] == cb)
-       return true;
-    }
-  return false;
+  return gh_procedure_p (dim_cache_[a].dimension_);
+}
+
+bool
+Score_element::has_offset_callback_b (SCM cb, Axis a)const
+{
+  return scm_memq (cb, dim_cache_[a].offset_callbacks_) != SCM_BOOL_F;
 }
 
 void
-Score_element::set_extent_callback (Dim_cache_callback dc, Axis a)
+Score_element::set_extent_callback (SCM dc, Axis a)
 {
-  dim_cache_[a].extent_callback_l_ = dc ;
+  dim_cache_[a].dimension_ =dc;
 }
 
-                                   
 void
 Score_element::set_parent (Score_element *g, Axis a)
 {
   dim_cache_[a].parent_l_ = g;
 }
 
-void
-Score_element::fixup_refpoint ()
+MAKE_SCHEME_CALLBACK(Score_element,fixup_refpoint,1);
+SCM
+Score_element::fixup_refpoint (SCM smob)
 {
+  Score_element *me = unsmob_element (smob);
   for (int a = X_AXIS; a < NO_AXES; a ++)
     {
       Axis ax = (Axis)a;
-      Score_element * parent = parent_l (ax);
+      Score_element * parent = me->parent_l (ax);
 
       if (!parent)
        continue;
       
-      if (parent->line_l () != line_l () && line_l ())
+      if (parent->line_l () != me->line_l () && me->line_l ())
        {
-         Score_element * newparent = parent->find_broken_piece (line_l ());
-         set_parent (newparent, ax);
+         Score_element * newparent = parent->find_broken_piece (me->line_l ());
+         me->set_parent (newparent, ax);
        }
 
-      if (Item * i  = dynamic_cast<Item*> (this))
+      if (Item * i  = dynamic_cast<Item*> (me))
        {
          Item *parenti = dynamic_cast<Item*> (parent);
 
@@ -700,11 +759,12 @@ Score_element::fixup_refpoint ()
              if (my_dir!= parenti->break_status_dir())
                {
                  Item *newparent =  parenti->find_prebroken_piece (my_dir);
-                 set_parent (newparent, ax);
+                 me->set_parent (newparent, ax);
                }
            }
        }
     }
+  return smob;
 }
 
 
@@ -713,29 +773,32 @@ Score_element::fixup_refpoint ()
   SMOB funcs
  ****************************************************/
 
-#include "ly-smobs.icc"
 
 IMPLEMENT_UNSMOB(Score_element, element);
 IMPLEMENT_SMOBS(Score_element);
+IMPLEMENT_DEFAULT_EQUAL_P(Score_element);
 
 SCM
 Score_element::mark_smob (SCM ses)
 {
-  Score_element * s = SMOB_TO_TYPE (Score_element, ses);
-  if (s->self_scm_ != ses)
+  Score_element * s = (Score_element*) SCM_CELL_WORD_1(ses);
+  scm_gc_mark (s->immutable_property_alist_);
+  scm_gc_mark (s->mutable_property_alist_);
+
+  for (int a =0 ; a < 2; a++)
     {
-      programming_error ("SMOB marking gone awry");
-      return SCM_EOL;
+      scm_gc_mark (s->dim_cache_[a].offset_callbacks_);
+      scm_gc_mark (s->dim_cache_[a].dimension_);
     }
-  scm_gc_mark (s->pointer_alist_);
-
-  s->do_derived_mark ();
+  
   if (s->parent_l (Y_AXIS))
-    scm_gc_mark (s->parent_l (Y_AXIS)->self_scm_);
+    scm_gc_mark (s->parent_l (Y_AXIS)->self_scm ());
   if (s->parent_l (X_AXIS))
-    scm_gc_mark (s->parent_l (X_AXIS)->self_scm_);
+    scm_gc_mark (s->parent_l (X_AXIS)->self_scm ());
 
-  return s->property_alist_;
+  if (s->original_l_)
+    scm_gc_mark (s->original_l_->self_scm ());
+  return s->do_derived_mark ();
 }
 
 int
@@ -744,7 +807,7 @@ Score_element::print_smob (SCM s, SCM port, scm_print_state *)
   Score_element *sc = (Score_element *) gh_cdr (s);
      
   scm_puts ("#<Score_element ", port);
-  scm_puts ((char *)sc->name (), port);
+  scm_puts ((char *)sc->name ().ch_C(), port);
 
   /*
     don't try to print properties, that is too much hassle.
@@ -753,25 +816,15 @@ Score_element::print_smob (SCM s, SCM port, scm_print_state *)
   return 1;
 }
 
-void
-Score_element::do_derived_mark ()
-{
-}
-
-void
-Score_element::do_smobify_self ()
-{
-}
-
 SCM
-Score_element::equal_p (SCM a, SCM b)
+Score_element::do_derived_mark ()
 {
-  return gh_cdr(a) == gh_cdr(b) ? SCM_BOOL_T : SCM_BOOL_F;
+  return SCM_EOL;
 }
 
 
 SCM
-Score_element::ly_set_elt_property (SCM elt, SCM sym, SCM val)
+ly_set_elt_property (SCM elt, SCM sym, SCM val)
 {
   Score_element * sc = unsmob_element (elt);
 
@@ -779,12 +832,12 @@ Score_element::ly_set_elt_property (SCM elt, SCM sym, SCM val)
     {
       error ("Not a symbol");
       ly_display_scm (sym);
-      return SCM_UNDEFINED;
+      return SCM_UNSPECIFIED;
     }
 
   if (sc)
     {
-      sc->property_alist_ = scm_assq_set_x (sc->property_alist_, sym, val);
+      sc->set_elt_property (sym, val);
     }
   else
     {
@@ -792,43 +845,74 @@ Score_element::ly_set_elt_property (SCM elt, SCM sym, SCM val)
       ly_display_scm (elt);
     }
 
-  return SCM_UNDEFINED;
+  return SCM_UNSPECIFIED;
 }
 
 
 SCM
-Score_element::ly_get_elt_property (SCM elt, SCM sym)
+ly_get_elt_property (SCM elt, SCM sym)
 {
   Score_element * sc = unsmob_element (elt);
   
   if (sc)
     {
-      SCM s = scm_assq(sym, sc->property_alist_);
-
-      if (s != SCM_BOOL_F)
-       return gh_cdr (s); 
-      else
-       return SCM_UNDEFINED;
+      return sc->get_elt_property (sym);
     }
   else
     {
       error ("Not a score element");
       ly_display_scm (elt);
     }
-  return SCM_UNDEFINED;
+  return SCM_UNSPECIFIED;
+}
+
+
+void
+Score_element::discretionary_processing()
+{
 }
 
 
+
+SCM
+spanner_get_bound (SCM slur, SCM dir)
+{
+  return dynamic_cast<Spanner*> (unsmob_element (slur))->get_bound (to_dir (dir))->self_scm ();
+}
+
+
+
+static SCM interfaces_sym;
 static void
 init_functions ()
 {
-  scm_make_gsubr ("ly-get-elt-property", 2, 0, 0, (SCM(*)(...))Score_element::ly_get_elt_property);
-  scm_make_gsubr ("ly-set-elt-property", 3, 0, 0, (SCM(*)(...))Score_element::ly_set_elt_property);
+  interfaces_sym = scm_permanent_object (ly_symbol2scm ("interfaces"));
+
+  scm_make_gsubr ("ly-get-elt-property", 2, 0, 0, (Scheme_function_unknown)ly_get_elt_property);
+  scm_make_gsubr ("ly-set-elt-property", 3, 0, 0, (Scheme_function_unknown)ly_set_elt_property);
+  scm_make_gsubr ("ly-get-spanner-bound", 2 , 0, 0, (Scheme_function_unknown) spanner_get_bound);
 }
 
-ADD_SCM_INIT_FUNC(scoreelt, init_functions);
+bool
+Score_element::has_interface (SCM k)
+{
+  SCM ifs = get_elt_property (interfaces_sym);
+
+  return scm_memq (k, ifs) != SCM_BOOL_F;
+}
 
 void
-Score_element::discretionary_processing()
+Score_element::set_interface (SCM k)
 {
+  if (has_interface (k))
+    return ;
+  else
+    {
+      set_elt_property (interfaces_sym,
+                       gh_cons  (k, get_elt_property (interfaces_sym)));
+    }
 }
+
+
+ADD_SCM_INIT_FUNC(scoreelt, init_functions);
+IMPLEMENT_TYPE_P(Score_element, "ly-element?");