subclass.
*/
-Score_element::Score_element()
+
+#define INFINITY_MSG "Infinity or NaN encountered"
+
+Score_element::Score_element(SCM basicprops)
{
- // junkme.
- used_b_ = false;
set_extent_callback (molecule_extent, X_AXIS);
set_extent_callback (molecule_extent, Y_AXIS);
- used_b_ = false;
pscore_l_=0;
lookup_l_ =0;
status_i_ = 0;
self_scm_ = SCM_EOL;
original_l_ = 0;
- property_alist_ = SCM_EOL;
- 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);
+ set_elt_property ("dependencies", SCM_EOL);
+
+ if (get_elt_property ("interfaces") == SCM_UNDEFINED)
+ set_elt_property ("interfaces", SCM_EOL);
}
: dim_cache_ (s.dim_cache_)
{
self_scm_ = SCM_EOL;
- used_b_ = true;
original_l_ =(Score_element*) &s;
- property_alist_ = s.property_alist_;
- 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_;
Score_element::~Score_element()
{
+ // this goes awry when score-elements are copied...
+
+ /*
+ Kijk goed naar hoe smobify en unsmobify werken. unsmobify_self
+ is te gebruiken wanneer C++ geheugen beheer weer overneemt van
+ GUILE. --hwn */
}
-// should also have one that takes SCM arg.
+
SCM
-Score_element::get_elt_property (String nm) const
+Score_element::get_elt_property (const char *nm) const
{
- SCM sym = ly_symbol2scm (nm.ch_C());
- SCM s = scm_assq(sym, property_alist_);
-
- if (s != SCM_BOOL_F)
- return gh_cdr (s);
-
- /*
- JUNKME
- */
- if (pscore_l_)
- {
- SCM sym2 = ly_symbol2scm ((name () + ("::" + nm)).ch_C());
- SCM val;
-
- // should probably check for Type::sym as well.
- Paper_def * p= pscore_l_->paper_l_;
- if (p->default_properties_.try_retrieve (sym2, &val))
- return val;
- else if (p->default_properties_.try_retrieve (sym, &val))
- return val;
- }
-
- return SCM_UNDEFINED;
+ SCM sym = ly_symbol2scm (nm);
+ return get_elt_property (sym);
}
SCM
-Score_element::get_elt_pointer (const char *nm) const
+Score_element::get_elt_property (SCM sym) const
{
- SCM sym = ly_symbol2scm (nm);
- SCM s = scm_assq(sym, pointer_alist_);
+ SCM s = scm_assq(sym, mutable_property_alist_);
+ if (s != SCM_BOOL_F)
+ return gh_cdr (s);
- return (s == SCM_BOOL_F) ? SCM_UNDEFINED : gh_cdr (s);
+ s = scm_assq (sym, immutable_property_alist_);
+ return (s == SCM_BOOL_F) ? SCM_UNDEFINED : gh_cdr (s);
}
+/*
+ Remove the value associated with KEY, and return it. The result is
+ that a next call will yield SCM_UNDEFINED (and not the underlying
+ `basic' property.
+*/
SCM
Score_element::remove_elt_property (const char* key)
{
- SCM s = get_elt_property (key);
- SCM sym = ly_symbol2scm (key);
-
- property_alist_ = gh_cons (gh_cons (sym, SCM_UNDEFINED), property_alist_);
-
- return s;
+ SCM val = get_elt_property (key);
+ if (val != SCM_UNDEFINED)
+ set_elt_property (key, SCM_UNDEFINED);
+ return val;
}
void
-Score_element::set_elt_property (String k, SCM v)
+Score_element::set_elt_property (const char* k, SCM v)
{
- SCM s = ly_symbol2scm (k.ch_C ());
- // non destructive
- property_alist_ = gh_cons (gh_cons (s, v),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 )
+Score_element::molecule_extent (Score_element *s, Axis a)
{
- Molecule m = s->do_brew_molecule();
+ Molecule m = s->get_molecule ();
return m.extent(a);
}
Interval
-Score_element::preset_extent (Score_element const *s , Axis a )
+Score_element::preset_extent (Score_element *s , Axis a)
{
SCM ext = s->get_elt_property ((a == X_AXIS)
? "extent-X"
}
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);
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
{
- if (to_boolean (get_elt_property ("transparent")))
- return Molecule ();
+ SCM proc = get_elt_property ("molecule-callback");
+ if (gh_procedure_p (proc))
+ return create_molecule (gh_apply (proc, gh_list (this->self_scm_, SCM_UNDEFINED)));
- return do_brew_molecule ();
+ return Molecule ();
}
{
}
-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_CALLBACK(Score_element,brew_molecule)
+
/*
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;
}
}
{
Score_element * sc = s->broken_into_l_arr_[i];
Line_of_score * l = sc->line_l ();
- sc->pointer_alist_ =
- handle_broken_smobs (pointer_alist_,
+ sc->mutable_property_alist_ =
+ handle_broken_smobs (mutable_property_alist_,
l ? l->self_scm_ : SCM_UNDEFINED);
}
}
if (line && common_refpoint (line, X_AXIS) && common_refpoint (line, Y_AXIS))
{
- pointer_alist_
- = handle_broken_smobs (pointer_alist_,
+ 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
void
Score_element::suicide ()
{
- property_alist_ = SCM_EOL;
- pointer_alist_ = SCM_EOL;
+ mutable_property_alist_ = SCM_EOL;
+ immutable_property_alist_ = SCM_EOL;
set_extent_callback (0, Y_AXIS);
set_extent_callback (0, X_AXIS);
-}
+ for (int a= X_AXIS; a <= Y_AXIS; a++)
+ {
+ dim_cache_[a].off_callbacks_.clear ();
+ }
+}
void
Score_element::handle_prebroken_dependencies()
{
}
-
-bool
-Score_element::linked_b() const
-{
- return used_b_;
-}
-
Score_element*
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
if (isinf (r) || isnan (r))
{
r = 0.0;
- programming_error ("Infinity or NaN encountered");
+ programming_error (INFINITY_MSG);
}
me->dim_cache_[a].offset_ +=r;
}
Interval
-Score_element::point_dimension_callback (Score_element const* , Axis)
+Score_element::point_dimension_callback (Score_element* , Axis)
{
return Interval (0,0);
}
}
else if (!d->valid_b_)
{
- d->dim_= (*d->extent_callback_l_ ) (this, a);
+ d->dim_= (*d->extent_callback_l_ ) ((Score_element*)this, a);
d->valid_b_ = true;
}
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)
dim_cache_[a].parent_l_ = g;
}
-void
-Score_element::fixup_refpoint ()
+MAKE_SCHEME_CALLBACK(Score_element,fixup_refpoint);
+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);
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;
}
programming_error ("SMOB marking gone awry");
return SCM_EOL;
}
- scm_gc_mark (s->pointer_alist_);
- return s->property_alist_;
+ scm_gc_mark ( s->immutable_property_alist_);
+
+ s->do_derived_mark ();
+ if (s->parent_l (Y_AXIS))
+ 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_);
+
+ return s->mutable_property_alist_;
}
int
return 1;
}
+void
+Score_element::do_derived_mark ()
+{
+}
+
void
Score_element::do_smobify_self ()
{
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);
if (sc)
{
- sc->property_alist_ = scm_assq_set_x (sc->property_alist_, sym, val);
+ sc->set_elt_property (sym, val);
}
else
{
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
{
}
+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, (SCM(*)(...))ly_get_elt_property);
+ scm_make_gsubr ("ly-set-elt-property", 3, 0, 0, (SCM(*)(...))ly_set_elt_property);
+ scm_make_gsubr ("ly-get-spanner-bound", 2 , 0, 0, (SCM(*)(...)) spanner_get_bound);
}
-ADD_SCM_INIT_FUNC(scoreelt, init_functions);
+bool
+Score_element::has_interface (SCM k)
+{
+ if (mutable_property_alist_ == SCM_EOL)
+ return false;
+
+ 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);
+