5 #include "paper-def.hh"
9 LY_DEFINE (ly_set_grob_property,"ly:set-grob-property!", 3, 0, 0,
10 (SCM grob, SCM sym, SCM val),
11 "Set @var{sym} in grob @var{grob} to value @var{val}")
13 Grob * sc = unsmob_grob (grob);
14 SCM_ASSERT_TYPE (sc, grob, SCM_ARG1, __FUNCTION__, "grob");
15 SCM_ASSERT_TYPE (gh_symbol_p (sym), sym, SCM_ARG2, __FUNCTION__, "symbol");
17 if (!type_check_assignment (sym, val, ly_symbol2scm ("backend-type?")))
18 error ("typecheck failed");
20 sc->internal_set_grob_property (sym, val);
21 return SCM_UNSPECIFIED;
24 LY_DEFINE (ly_get_grob_property,
25 "ly:get-grob-property", 2, 0, 0, (SCM grob, SCM sym),
26 "Get the value of a value in grob @var{g} of property @var{sym}. It\n"
27 "will return @code{'()} (end-of-list) if @var{g} doesn't have @var{sym} set.\n"
29 "Grob properties are stored as GUILE association lists, with symbols as\n"
30 "keys. All lookup functions identify undefined properties with\n"
31 "end-of-list (i.e. @code{'()} in Scheme or @code{SCM_EOL} in C)\n"
33 "Properties are stored in two ways:\n"
35 "@item mutable properties.\n"
36 "Grob properties that change from object to object. The storage of\n"
37 "these are private to a grob. For example pointers to other grobs are\n"
38 "always stored in the mutable properties.\n"
40 "@item immutable properties.\n"
41 "Grob properties that are shared across different grobs of the same\n"
42 "type. The storage is shared, and hence it is read-only. Typically, this\n"
43 "is used to store function callbacks, and default settings. They are\n"
44 "initially read from @file{scm/grob-description.scm}.\n"
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,
57 "Get one of the bounds of @var{spanner}. @var{dir} is @code{-1} "
58 "for left, and @code{1} for right.")
60 Spanner * sl = dynamic_cast<Spanner*> (unsmob_grob (slur));
61 SCM_ASSERT_TYPE (sl, slur, SCM_ARG1, __FUNCTION__, "spanner grob");
62 SCM_ASSERT_TYPE (is_direction (dir), slur, SCM_ARG2, __FUNCTION__, "dir");
63 return sl->get_bound (to_dir (dir))->self_scm ();
66 /* TODO: make difference between scaled and unscalead variable in
67 calling (i.e different funcs.) */
68 LY_DEFINE (ly_get_paper_var,"ly:get-paper-variable", 2, 0, 0,
70 "Get a variable from the \\paper block.")
72 Grob * sc = unsmob_grob (grob);
73 SCM_ASSERT_TYPE (sc, grob, SCM_ARG1, __FUNCTION__, "grob");
74 SCM_ASSERT_TYPE (gh_symbol_p (sym), sym, SCM_ARG2, __FUNCTION__, "symbol");
76 return sc->get_paper () ->lookup_variable (sym);
79 /* TODO: make difference between scaled and unscalead variable in
80 calling (i.e different funcs.) */
81 LY_DEFINE (ly_grob_paper,"ly:grob-paper", 1, 0, 0,
83 "Get \\paper definition from a grob.")
85 Grob * sc = unsmob_grob (grob);
86 SCM_ASSERT_TYPE (sc, grob, SCM_ARG1, __FUNCTION__, "grob");
88 return sc->get_paper ()->self_scm ();
94 LY_DEFINE (ly_get_extent, "ly:get-extent", 3, 0, 0,
95 (SCM grob, SCM refp, SCM axis),
96 "Get the extent in @var{axis} direction of @var{grob} relative to "
97 "the grob @var{refp}")
99 Grob * sc = unsmob_grob (grob);
100 Grob * ref = unsmob_grob (refp);
101 SCM_ASSERT_TYPE (sc, grob, SCM_ARG1, __FUNCTION__, "grob");
102 SCM_ASSERT_TYPE (ref, refp, SCM_ARG2, __FUNCTION__, "grob");
104 SCM_ASSERT_TYPE (is_axis (axis), axis, SCM_ARG3, __FUNCTION__, "axis");
106 return ly_interval2scm ( sc->extent (ref, Axis (gh_scm2int (axis))));
109 LY_DEFINE (ly_get_parent, "ly:get-parent", 2, 0, 0, (SCM grob, SCM axis),
110 "Get the parent of @var{grob}. @var{axis} is 0 for the X-axis, "
113 Grob * sc = unsmob_grob (grob);
114 SCM_ASSERT_TYPE (sc, grob, SCM_ARG1, __FUNCTION__, "grob");
115 SCM_ASSERT_TYPE (is_axis (axis), axis, SCM_ARG2, __FUNCTION__, "axis");
117 Grob * par = sc->get_parent (Axis (gh_scm2int (axis)));
118 return par ? par->self_scm () : SCM_EOL;
121 LY_DEFINE (ly_get_system,
124 "Return the System Grob of @var{grob}.")
126 Grob *me = unsmob_grob (grob);
127 SCM_ASSERT_TYPE (me, grob, SCM_ARG1, __FUNCTION__, "grob");
129 if (System *g = me->get_system ())
130 return g->self_scm ();
135 LY_DEFINE (ly_get_original,
138 "Return the original Grob of @var{grob}")
140 Grob *me = unsmob_grob (grob);
141 SCM_ASSERT_TYPE (me, grob, SCM_ARG1, __FUNCTION__, "grob");
142 return me->original_ ? me->original_->self_scm () : me->self_scm ();
146 /* ly prefix? spanner in name? */
147 /* TODO: maybe we should return a vector -- random access is more
148 logical for this list? */
150 LY_DEFINE (get_broken_into,
151 "ly:get-broken-into", 1, 0, 0, (SCM spanner),
152 "Return broken-into list for @var{spanner}.")
154 /// Spanner *me = unsmob_spanner (spanner);
155 Spanner *me = dynamic_cast<Spanner*> (unsmob_grob (spanner));
156 SCM_ASSERT_TYPE (me, spanner, SCM_ARG1, __FUNCTION__, "spanner");
159 for (int i = me->broken_intos_.size (); i; i--)
160 s = gh_cons (me->broken_intos_[i-1]->self_scm (), s);
165 LY_DEFINE (ly_grob_suicide,
166 "ly:grob-suicide", 1, 0, 0, (SCM g),
169 Grob *me = unsmob_grob (g);
170 SCM_ASSERT_TYPE (me, g, SCM_ARG1, __FUNCTION__, "grob");
173 return SCM_UNDEFINED;
178 LY_DEFINE (ly_grob_translate_axis_x,
179 "ly:grob-translate-axis!", 3, 0, 0,
180 (SCM g, SCM d, SCM a),
181 "Translate @var{g} on axis @var{a} over distance @var{d}.")
183 Grob *me = unsmob_grob (g);
184 SCM_ASSERT_TYPE (me, g, SCM_ARG1, __FUNCTION__, "grob");
185 SCM_ASSERT_TYPE (gh_number_p (d), d, SCM_ARG2, __FUNCTION__, "dimension");
186 SCM_ASSERT_TYPE (is_axis (a), a, SCM_ARG3, __FUNCTION__, "axis");
188 me->translate_axis (gh_scm2double (d),
189 Axis (gh_scm2int (a)));
190 return SCM_UNDEFINED;
195 LY_DEFINE (ly_spanner_p,
196 "ly:spanner?", 1, 0, 0,
198 "Is @var{g} a spanner object?")
200 Grob *me = unsmob_grob (g);
201 bool b = dynamic_cast<Spanner*> (me);
203 return gh_bool2scm (b);
206 LY_DEFINE (ly_item_p,
209 "Is @var{g} a item object?")
211 Grob *me = unsmob_grob (g);
212 bool b = dynamic_cast<Item*> (me);
214 return gh_bool2scm (b);
218 LY_DEFINE (ly_item_break_dir,
219 "ly:item-break-dir", 1, 0, 0,
221 "The break status dir of @var{it}.")
223 Item * me = dynamic_cast<Item*> ( unsmob_grob (it));
224 SCM_ASSERT_TYPE (me, it, SCM_ARG1, __FUNCTION__, "Item");
226 return gh_int2scm (me->break_status_dir ());