#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"
pscore_ = 0;
status_ = 0;
original_ = 0;
+ interfaces_ = SCM_EOL;
immutable_property_alist_ = basicprops;
mutable_property_alist_ = SCM_EOL;
+ object_alist_ = 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
We always get a new key object for a new grob.
*/
if (key_)
- scm_gc_unprotect_object (key_->self_scm ());
+ ((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"};
+ 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;
- }
+ dim_cache_[a].dimension_ = xt;
else if (ly_is_procedure (cb))
- {
- dim_cache_[a].dimension_callback_ = cb;
- }
+ dim_cache_[a].dimension_callback_ = cb;
else if (cb == SCM_EOL
&& ly_is_procedure (get_property ("print-function")))
dim_cache_[a].dimension_callback_ = stencil_extent_proc;
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_;
+ object_alist_ = SCM_EOL;
/* No properties are copied. That is the job of
handle_broken_dependencies. */
smobify_self ();
if (key_)
- scm_gc_unprotect_object (key_->self_scm ());
+ ((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;
}
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);
+ extract_grob_set (this, "dependencies", deps);
+ for (int i = 0; i < deps.size (); i++)
+ deps[i]->calculate_dependencies (final, busy, funcname);
SCM proc = internal_get_property (funcname);
if (ly_is_procedure (proc))
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 ();
}
/* 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;
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))
;
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))));
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 = _f ("programming error: %s", s);
- message (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_);
-
- if (s->key_)
- 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_->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"
"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");
+ "minimum-Y-extent transparent");