#include "grob.hh"
#include <cstring>
-#include <math.h>
#include "main.hh"
#include "input-smob.hh"
#include "warn.hh"
-#include "group-interface.hh"
+#include "pointer-group-interface.hh"
#include "misc.hh"
#include "paper-score.hh"
#include "stencil.hh"
#include "ly-smobs.icc"
#include "output-def.hh"
+MAKE_SCHEME_CALLBACK(Grob, same_axis_parent_positioning, 2);
+SCM
+Grob::same_axis_parent_positioning (SCM element_smob, SCM axis)
+{
+ Grob *me = unsmob_grob (element_smob);
+ Axis ax = Axis (scm_to_int (axis));
+
+ Grob *par = me->get_parent (ax);
+ if (par)
+ par->get_property ("positioning-done");
+
+ return scm_from_double (0.0);
+}
+
+MAKE_SCHEME_CALLBACK(Grob,other_axis_parent_positioning, 2);
+SCM
+Grob::other_axis_parent_positioning (SCM element_smob, SCM axis)
+{
+ Grob *me = unsmob_grob (element_smob);
+ Axis ax = other_axis ((Axis) scm_to_int (axis));
+
+ Grob *par = me->get_parent (ax);
+ if (par)
+ par->get_property ("positioning-done");
+
+ return scm_from_double (0.0);
+}
+
+
+
Grob *
Grob::clone (int count) const
{
pscore_ = 0;
status_ = 0;
original_ = 0;
+ interfaces_ = SCM_EOL;
immutable_property_alist_ = basicprops;
mutable_property_alist_ = SCM_EOL;
-
+ object_alist_ = SCM_EOL;
+ property_callbacks_ = SCM_EOL;
+
/* We do smobify_self () as the first step. Since the object lives
on the heap, none of its SCM variables are protected from
GC. After smobify_self (), they are. */
/*
We always get a new key object for a new grob.
*/
- scm_gc_unprotect_object (key_->self_scm ());
+ if (key_)
+ ((Object_key *)key_)->unprotect ();
+
SCM meta = get_property ("meta");
if (scm_is_pair (meta))
- {
- SCM ifs = scm_assoc (ly_symbol2scm ("interfaces"), meta);
-
- /* Switch off interface checks for the moment. */
- bool itc = do_internal_type_checking_global;
- do_internal_type_checking_global = false;
- internal_set_property (ly_symbol2scm ("interfaces"), scm_cdr (ifs));
- do_internal_type_checking_global = itc;
- }
+ interfaces_ = scm_cdr (scm_assoc (ly_symbol2scm ("interfaces"), meta));
/* TODO:
creation. Convenient eg. when using \override with
StaffSymbol. */
- char const *onames[] = {"X-offset-callbacks", "Y-offset-callbacks"};
- char const *xnames[] = {"X-extent", "Y-extent"};
- char const *enames[] = {"X-extent-callback", "Y-extent-callback"};
+ property_callbacks_ = get_property ("callbacks");
+
+ SCM off_callbacks[] = {
+ get_property ("X-offset-callbacks"),
+ get_property ("Y-offset-callbacks")
+ };
+ SCM extents[] = {
+ get_property ("X-extent"),
+ get_property ("Y-extent")
+ };
+ SCM extent_callbacks[] = {
+ get_property ("X-extent-callback"),
+ get_property ("Y-extent-callback")
+ };
for (int a = X_AXIS; a <= Y_AXIS; a++)
{
- SCM l = get_property (onames[a]);
+ SCM l = off_callbacks[a];
if (scm_ilength (l) >= 0)
{
else
programming_error ("[XY]-offset-callbacks must be a list");
- SCM cb = get_property (enames[a]);
+ SCM cb = extent_callbacks[a];
if (cb == SCM_BOOL_F)
- {
- dim_cache_[a].dimension_ = SCM_BOOL_F;
- }
+ dim_cache_[a].dimension_ = SCM_BOOL_F;
- SCM xt = get_property (xnames[a]);
+ SCM xt = extents[a];
if (is_number_pair (xt))
- {
- dim_cache_[a].dimension_ = xt;
- }
- else if (ly_c_procedure_p (cb))
- {
- dim_cache_[a].dimension_callback_ = cb;
- }
+ dim_cache_[a].dimension_ = xt;
+ else if (ly_is_procedure (cb))
+ dim_cache_[a].dimension_callback_ = cb;
else if (cb == SCM_EOL
- && ly_c_procedure_p (get_property ("print-function")))
+ && ly_is_procedure (ly_assoc_get (ly_symbol2scm ("stencil"),
+ property_callbacks_, SCM_BOOL_F)))
dim_cache_[a].dimension_callback_ = stencil_extent_proc;
}
+
}
Grob::Grob (Grob const &s, int copy_index)
: dim_cache_ (s.dim_cache_)
{
- key_ = new Copied_key (s.key_, copy_index);
+ key_ = (use_object_keys) ? new Copied_key (s.key_, copy_index) : 0;
original_ = (Grob *) & s;
self_scm_ = SCM_EOL;
immutable_property_alist_ = s.immutable_property_alist_;
- mutable_property_alist_ = SCM_EOL;
+ mutable_property_alist_ = ly_deep_copy (s.mutable_property_alist_);
+ interfaces_ = s.interfaces_;
+ property_callbacks_ = s.property_callbacks_;
+ object_alist_ = SCM_EOL;
- /* No properties are copied. That is the job of
- handle_broken_dependencies. */
- status_ = s.status_;
pscore_ = 0;
smobify_self ();
- scm_gc_unprotect_object (key_->self_scm ());
+ if (key_)
+ ((Object_key *)key_)->unprotect ();
}
Grob::~Grob ()
{
Interval ext = me->extent (refp, a);
if (ext.is_empty ())
- {
- ext.add_point (me->relative_coordinate (refp, a));
- }
+ ext.add_point (me->relative_coordinate (refp, a));
return ext;
}
Output_def *
Grob::get_layout () const
{
- return pscore_ ? pscore_->layout_ : 0;
-}
-
-/* Recursively track all dependencies of this Grob. The status_ field
- is used as a mark-field. It is marked with BUSY during execution
- of this function, and marked with FINAL when finished.
-
- FUNCPTR is the function to call to update this element. */
-void
-Grob::calculate_dependencies (int final, int busy, SCM funcname)
-{
- if (status_ >= final)
- return;
-
- if (status_ == busy)
- {
- programming_error ("Element is busy, come back later");
- return;
- }
-
- status_ = busy;
-
- for (SCM d = get_property ("dependencies"); scm_is_pair (d);
- d = scm_cdr (d))
- unsmob_grob (scm_car (d))->calculate_dependencies (final, busy, funcname);
-
- SCM proc = internal_get_property (funcname);
- if (ly_c_procedure_p (proc))
- scm_call_1 (proc, this->self_scm ());
-
- status_ = final;
+ return pscore_ ? pscore_->layout () : 0;
}
Stencil *
return 0;
SCM stil = get_property ("stencil");
- if (unsmob_stencil (stil))
- return unsmob_stencil (stil);
-
- stil = get_uncached_stencil ();
- if (is_live ())
- {
- Grob *me = (Grob *) this;
- me->set_property ("stencil", stil);
- }
-
return unsmob_stencil (stil);
}
-SCM
-Grob::get_uncached_stencil () const
+Stencil
+Grob::get_print_stencil () const
{
- SCM proc = get_property ("print-function");
-
- SCM stil = SCM_EOL;
- if (ly_c_procedure_p (proc))
- stil = scm_apply_0 (proc, scm_list_n (this->self_scm (), SCM_UNDEFINED));
+ SCM stil = get_property ("stencil");
+ Stencil retval;
if (Stencil *m = unsmob_stencil (stil))
{
+ retval = *m;
if (to_boolean (get_property ("transparent")))
- stil = Stencil (m->extent_box (), SCM_EOL).smobbed_copy ();
+ retval = Stencil (m->extent_box (), SCM_EOL);
else
{
SCM expr = m->expr ();
if (point_and_click_global)
expr = scm_list_3 (ly_symbol2scm ("grob-cause"), self_scm (), expr);
-
- stil = Stencil (m->extent_box (), expr).smobbed_copy ();
+
+ retval = Stencil (m->extent_box (), expr);
}
/* color support... see interpret_stencil_expression () for more... */
color,
m->expr ());
- stil = Stencil (m->extent_box (), expr).smobbed_copy ();
+ retval = Stencil (m->extent_box (), expr);
}
+
}
- return stil;
+ return retval;
}
/*
return 0;
}
-void
-Grob::add_dependency (Grob *e)
-{
- if (e)
- Pointer_group_interface::add_grob (this, ly_symbol2scm ("dependencies"),
- e);
- else
- programming_error ("Null dependency added");
-}
void
Grob::handle_broken_dependencies ()
/* THIS, SP is the original spanner. We use a special function
because some Spanners have enormously long lists in their
properties, and a special function fixes FOO */
- for (SCM s = mutable_property_alist_; scm_is_pair (s); s = scm_cdr (s))
- sp->substitute_one_mutable_property (scm_caar (s), scm_cdar (s));
-
+ {
+ for (SCM s = object_alist_; scm_is_pair (s); s = scm_cdr (s))
+ sp->substitute_one_mutable_property (scm_caar (s), scm_cdar (s));
+ }
System *system = get_system ();
if (is_live ()
- && system && common_refpoint (system, X_AXIS)
+ && system
+ && common_refpoint (system, X_AXIS)
&& common_refpoint (system, Y_AXIS))
- substitute_mutable_properties (system
- ? system->self_scm () : SCM_UNDEFINED,
- mutable_property_alist_);
+ substitute_object_links (system->self_scm (), object_alist_);
else if (dynamic_cast<System *> (this))
- substitute_mutable_properties (SCM_UNDEFINED, mutable_property_alist_);
+ substitute_object_links (SCM_UNDEFINED, object_alist_);
else
/* THIS element is `invalid'; it has been removed from all
dependencies, so let's junk the element itself.
return;
mutable_property_alist_ = SCM_EOL;
+ object_alist_ = SCM_EOL;
+ property_callbacks_ = SCM_EOL;
immutable_property_alist_ = SCM_EOL;
+ interfaces_ = SCM_EOL;
set_extent (SCM_EOL, Y_AXIS);
set_extent (SCM_EOL, X_AXIS);
Grob::handle_prebroken_dependencies ()
{
/* Don't do this in the derived method, since we want to keep access to
- mutable_property_alist_ centralized. */
+ object_alist_ centralized. */
if (original_)
{
Item *it = dynamic_cast<Item *> (this);
- substitute_mutable_properties (scm_int2num (it->break_status_dir ()),
- original_->mutable_property_alist_);
+ substitute_object_links (scm_from_int (it->break_status_dir ()),
+ original_->object_alist_);
}
}
while (dim_cache_[a].offsets_left_)
{
int l = --me->dim_cache_[a].offsets_left_;
- SCM cb = scm_list_ref (dim_cache_[a].offset_callbacks_, scm_int2num (l));
- SCM retval = scm_call_2 (cb, self_scm (), scm_int2num (a));
+ SCM cb = scm_list_ref (dim_cache_[a].offset_callbacks_, scm_from_int (l));
+ SCM retval = scm_call_2 (cb, self_scm (), scm_from_int (a));
Real r = scm_to_double (retval);
if (isinf (r) || isnan (r))
Grob::is_empty (Axis a) const
{
return !(scm_is_pair (dim_cache_[a].dimension_)
- || ly_c_procedure_p (dim_cache_[a].dimension_callback_));
+ || ly_is_procedure (dim_cache_[a].dimension_callback_));
}
void
Grob::flush_extent_cache (Axis axis)
{
Dimension_cache *d = &dim_cache_[axis];
- if (ly_c_procedure_p (d->dimension_callback_)
+ if (ly_is_procedure (d->dimension_callback_)
&& scm_is_pair (d->dimension_))
{
d->dimension_ = SCM_EOL;
SCM dimpair = d->dimension_;
if (scm_is_pair (dimpair))
;
- else if (ly_c_procedure_p (d->dimension_callback_)
+ else if (ly_is_procedure (d->dimension_callback_)
&& d->dimension_ == SCM_EOL)
- d->dimension_ = scm_call_2 (d->dimension_callback_, self_scm (), scm_int2num (a));
+ d->dimension_ = scm_call_2 (d->dimension_callback_, self_scm (), scm_from_int (a));
else
return ext;
ext = ly_scm2interval (d->dimension_);
- SCM extra = get_property (a == X_AXIS
- ? "extra-X-extent"
- : "extra-Y-extent");
+ SCM extra = (a == X_AXIS)
+ ? get_property ("extra-X-extent")
+ : get_property ("extra-Y-extent");
/* Signs ? */
if (scm_is_pair (extra))
ext[SMALLER] += scm_to_double (scm_car (extra));
}
- extra = get_property (a == X_AXIS
- ? "minimum-X-extent"
- : "minimum-Y-extent");
+ extra = (a == X_AXIS)
+ ? get_property ("minimum-X-extent")
+ : get_property ("minimum-Y-extent");
+
if (scm_is_pair (extra))
ext.unite (Interval (scm_to_double (scm_car (extra)),
scm_to_double (scm_cdr (extra))));
SCM meta = get_property ("meta");
SCM nm = scm_assoc (ly_symbol2scm ("name"), meta);
nm = (scm_is_pair (nm)) ? scm_cdr (nm) : SCM_EOL;
- return scm_is_symbol (nm) ? ly_symbol2string (nm) : classname (this);
+ return scm_is_symbol (nm) ? ly_symbol2string (nm) : this->class_name ();
}
void
dim_cache_[a].parent_ = g;
}
-MAKE_SCHEME_CALLBACK (Grob, fixup_refpoint, 1);
-SCM
-Grob::fixup_refpoint (SCM smob)
+void
+Grob::fixup_refpoint ()
{
- Grob *me = unsmob_grob (smob);
for (int a = X_AXIS; a < NO_AXES; a++)
{
Axis ax = (Axis)a;
- Grob *parent = me->get_parent (ax);
+ Grob *parent = get_parent (ax);
if (!parent)
continue;
- if (parent->get_system () != me->get_system () && me->get_system ())
+ if (parent->get_system () != get_system () && get_system ())
{
- Grob *newparent = parent->find_broken_piece (me->get_system ());
- me->set_parent (newparent, ax);
+ Grob *newparent = parent->find_broken_piece (get_system ());
+ set_parent (newparent, ax);
}
- if (Item *i = dynamic_cast<Item *> (me))
+ if (Item *i = dynamic_cast<Item *> (this))
{
Item *parenti = dynamic_cast<Item *> (parent);
if (my_dir != parenti->break_status_dir ())
{
Item *newparent = parenti->find_prebroken_piece (my_dir);
- me->set_parent (newparent, ax);
+ set_parent (newparent, ax);
}
}
}
}
- return smob;
}
void
void
Grob::programming_error (String s) const
{
- s = "Programming error: " + s;
- warning (s);
-}
-
-/****************************************************
- SMOB funcs
-****************************************************/
-
-IMPLEMENT_SMOBS (Grob);
-IMPLEMENT_DEFAULT_EQUAL_P (Grob);
-
-SCM
-Grob::mark_smob (SCM ses)
-{
- Grob *s = (Grob *) SCM_CELL_WORD_1 (ses);
- scm_gc_mark (s->immutable_property_alist_);
- scm_gc_mark (s->key_->self_scm ());
- for (int a = 0; a < 2; a++)
- {
- scm_gc_mark (s->dim_cache_[a].offset_callbacks_);
- scm_gc_mark (s->dim_cache_[a].dimension_);
- scm_gc_mark (s->dim_cache_[a].dimension_callback_);
-
- /* Do not mark the parents. The pointers in the mutable
- property list form two tree like structures (one for X
- relations, one for Y relations). Marking these can be done
- in limited stack space. If we add the parents, we will jump
- between X and Y in an erratic manner, leading to much more
- recursion depth (and core dumps if we link to pthreads). */
- }
-
- if (s->original_)
- scm_gc_mark (s->original_->self_scm ());
-
- if (s->pscore_)
- scm_gc_mark (s->pscore_->layout_->self_scm ());
-
- s->do_derived_mark ();
- return s->mutable_property_alist_;
-}
-
-int
-Grob::print_smob (SCM s, SCM port, scm_print_state *)
-{
- Grob *sc = (Grob *) SCM_CELL_WORD_1 (s);
-
- scm_puts ("#<Grob ", port);
- scm_puts ((char *) sc->name ().to_str0 (), port);
+ SCM cause = self_scm ();
+ while (Grob *g = unsmob_grob (cause))
+ cause = g->get_property ("cause");
- /* Do not print properties, that is too much hassle. */
- scm_puts (" >", port);
- return 1;
-}
+ s = _f ("programming error: %s", s);
-SCM
-Grob::do_derived_mark () const
-{
- return SCM_EOL;
+ if (Music *m = unsmob_music (cause))
+ m->origin ()->message (s);
+ else
+ ::message (s);
}
-
void
Grob::discretionary_processing ()
{
bool
Grob::internal_has_interface (SCM k)
{
- SCM ifs = get_property ("interfaces");
-
- return scm_c_memq (k, ifs) != SCM_BOOL_F;
+ return scm_c_memq (k, interfaces_) != SCM_BOOL_F;
}
Grob *
return s;
}
-IMPLEMENT_TYPE_P (Grob, "ly:grob?");
-
ADD_INTERFACE (Grob, "grob-interface",
"A grob represents a piece of music notation\n"
"\n"
"Mutable properties are variables that are specific to one grob. Typically, "
"lists of other objects, or results from computations are stored in"
"mutable properties: every call to set-grob-property (or its C++ equivalent) "
- "sets a mutable property. ",
- "X-offset-callbacks Y-offset-callbacks X-extent-callback stencil cause "
- "Y-extent-callback print-function extra-offset spacing-procedure "
- "context staff-symbol interfaces dependencies X-extent Y-extent extra-X-extent "
- "meta layer before-line-breaking-callback "
- "color "
+ "sets a mutable property. "
+ "\n\n"
+ "The properties @code{after-line-breaking} and @code{before-line-breaking} "
+ "are dummies that are not user-serviceable. "
+
+ ,
+
+ /* properties */
+ "X-extent "
+ "X-extent-callback "
+ "X-offset-callbacks "
+ "Y-extent "
+ "Y-extent-callback "
+ "Y-offset-callbacks "
+ "after-line-breaking "
"axis-group-parent-X "
"axis-group-parent-Y "
- "after-line-breaking-callback extra-Y-extent minimum-X-extent "
- "minimum-Y-extent transparent tweak-count tweak-rank");
+ "before-line-breaking "
+ "callbacks "
+ "cause "
+ "color "
+ "context "
+ "extra-X-extent "
+ "extra-Y-extent "
+ "extra-offset "
+ "interfaces "
+ "layer "
+ "meta "
+ "minimum-X-extent "
+ "minimum-Y-extent "
+ "print-function "
+ "spacing-procedure "
+ "staff-symbol "
+ "stencil "
+ "transparent"
+ );
+