* stepmake/stepmake/metafont-rules.make: backport 1.7 fixes.
[lilypond.git] / lily / grob-scheme.cc
blob0e42044ba7d5f4599a4a38af48d056ce2e7eb4db
1 #include "grob.hh"
2 #include "warn.hh"
3 #include "spanner.hh"
4 #include "item.hh"
5 #include "paper-def.hh"
6 #include "system.hh"
8 LY_DEFINE(ly_set_grob_property,"ly-set-grob-property!", 3, 0, 0,
9 (SCM grob, SCM sym, SCM val),
10 "Set @var{sym} in grob @var{grob} to value @var{val}")
12 Grob * sc = unsmob_grob (grob);
13 SCM_ASSERT_TYPE(sc, grob, SCM_ARG1, __FUNCTION__, "grob");
14 SCM_ASSERT_TYPE(gh_symbol_p (sym), sym, SCM_ARG2, __FUNCTION__, "symbol");
16 if (!type_check_assignment (sym, val, ly_symbol2scm ("backend-type?")))
17 error ("typecheck failed");
19 sc->internal_set_grob_property (sym, val);
20 return SCM_UNSPECIFIED;
23 LY_DEFINE(ly_get_grob_property,
24 "ly-get-grob-property", 2, 0, 0, (SCM grob, SCM sym),
25 "Get the value of a value in grob @var{g} of property @var{sym}. It
26 will return @code{'()} (end-of-list) if @var{g} doesn't have @var{sym} set.
28 Grob properties are stored as GUILE association lists, with symbols as
29 keys. All lookup functions identify undefined properties with
30 end-of-list (i.e. @code{'()} in Scheme or @code{SCM_EOL} in C)
32 Properties are stored in two ways:
33 @itemize @bullet
34 @item mutable properties.
35 Grob properties that change from object to object. The storage of
36 these are private to a grob. For example pointers to other grobs are
37 always stored in the mutable properties.
39 @item immutable properties.
40 Grob properties that are shared across different grobs of the same
41 type. The storage is shared, and hence it is read-only. Typically, this
42 is used to store function callbacks, and default settings. They are
43 initially read from @file{scm/grob-description.scm}.
44 @end itemize
48 Grob * sc = unsmob_grob (grob);
49 SCM_ASSERT_TYPE(sc, grob, SCM_ARG1, __FUNCTION__, "grob");
50 SCM_ASSERT_TYPE(gh_symbol_p (sym), sym, SCM_ARG2, __FUNCTION__, "symbol");
52 return sc->internal_get_grob_property (sym);
55 LY_DEFINE(spanner_get_bound, "ly-get-spanner-bound", 2 , 0, 0,
56 (SCM slur, SCM dir),
57 "Get one of the bounds of @var{spanner}. @var{dir} may be @code{-1} for
58 left, and @code{1} for right.
61 Spanner * sl = dynamic_cast<Spanner*> (unsmob_grob (slur));
62 SCM_ASSERT_TYPE(sl, slur, SCM_ARG1, __FUNCTION__, "spanner grob");
63 SCM_ASSERT_TYPE(ly_dir_p (dir), slur, SCM_ARG2, __FUNCTION__, "dir");
64 return sl->get_bound (to_dir (dir))->self_scm ();
67 LY_DEFINE(ly_get_paper_var,"ly-get-paper-variable", 2, 0, 0,
68 (SCM grob, SCM sym),
69 "Get a variable from the \\paper block.")
71 Grob * sc = unsmob_grob (grob);
72 SCM_ASSERT_TYPE(sc, grob, SCM_ARG1, __FUNCTION__, "grob");
73 SCM_ASSERT_TYPE(gh_symbol_p (sym), sym, SCM_ARG2, __FUNCTION__, "symbol");
75 return sc->get_paper () ->get_scmvar_scm (sym);
80 LY_DEFINE(ly_get_extent, "ly-get-extent", 3, 0, 0,
81 (SCM grob, SCM refp, SCM axis),
82 "Get the extent in @var{axis} direction of @var{grob} relative to the
83 grob @var{refp}")
85 Grob * sc = unsmob_grob (grob);
86 Grob * ref = unsmob_grob (refp);
87 SCM_ASSERT_TYPE(sc, grob, SCM_ARG1, __FUNCTION__, "grob");
88 SCM_ASSERT_TYPE(ref, refp, SCM_ARG2, __FUNCTION__, "grob");
90 SCM_ASSERT_TYPE(ly_axis_p (axis), axis, SCM_ARG3, __FUNCTION__, "axis");
92 return ly_interval2scm ( sc->extent (ref, Axis (gh_scm2int (axis))));
95 LY_DEFINE (ly_get_parent, "ly-get-parent", 2, 0, 0, (SCM grob, SCM axis),
96 "Get the parent of @var{grob}. @var{axis} can be 0 for the X-axis, 1
97 for the Y-axis.")
99 Grob * sc = unsmob_grob (grob);
100 SCM_ASSERT_TYPE(sc, grob, SCM_ARG1, __FUNCTION__, "grob");
101 SCM_ASSERT_TYPE(ly_axis_p (axis), axis, SCM_ARG2, __FUNCTION__, "axis");
103 Grob * par = sc->get_parent (Axis (gh_scm2int (axis)));
104 return par ? par->self_scm() : SCM_EOL;
107 /* ly prefix? */
108 LY_DEFINE (get_system,
109 "get-system",
110 1, 0, 0, (SCM grob),
112 Return the System Grob of @var{grob}.
115 Grob *me = unsmob_grob (grob);
116 SCM_ASSERT_TYPE (me, grob, SCM_ARG1, __FUNCTION__, "grob");
118 if (System *g = me->get_system ())
119 return g->self_scm ();
121 return SCM_EOL;
124 /* ly prefix? */
125 LY_DEFINE (get_original,
126 "get-original",
127 1, 0, 0, (SCM grob),
129 Return the original Grob of @var{grob}
132 Grob *me = unsmob_grob (grob);
133 SCM_ASSERT_TYPE (me, grob, SCM_ARG1, __FUNCTION__, "grob");
134 return me->original_ ? me->original_->self_scm () : me->self_scm ();
138 /* ly prefix? spanner in name? */
140 TODO: maybe we should return a vector -- random access is more
141 logical for this list?
144 LY_DEFINE (get_broken_into,
145 "get-broken-into", 1, 0, 0, (SCM spanner),
147 Return broken-into list for @var{spanner}.
151 /// Spanner *me = unsmob_spanner (spanner);
152 Spanner *me = dynamic_cast<Spanner*> (unsmob_grob (spanner));
153 SCM_ASSERT_TYPE (me, spanner, SCM_ARG1, __FUNCTION__, "spanner");
155 SCM s = SCM_EOL;
156 for (int i = me->broken_intos_.size (); i; i--)
157 s = gh_cons (me->broken_intos_[i-1]->self_scm (), s);
158 return s;