4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2004 Jan Nieuwenhuizen <janneke@gnu.org>
7 Han-Wen Nienhuys <hanwen@cs.uu.nl>
14 #include "paper-def.hh"
18 LY_DEFINE (ly_grob_set_property
,"ly:grob-set-property!", 3, 0, 0,
19 (SCM grob
, SCM sym
, SCM val
),
20 "Set @var{sym} in grob @var{grob} to value @var{val}")
22 Grob
* sc
= unsmob_grob (grob
);
23 SCM_ASSERT_TYPE (sc
, grob
, SCM_ARG1
, __FUNCTION__
, "grob");
24 SCM_ASSERT_TYPE (gh_symbol_p (sym
), sym
, SCM_ARG2
, __FUNCTION__
, "symbol");
26 if (!type_check_assignment (sym
, val
, ly_symbol2scm ("backend-type?")))
27 error ("typecheck failed");
29 sc
->internal_set_property (sym
, val
);
30 return SCM_UNSPECIFIED
;
33 LY_DEFINE (ly_get_property
, "ly:grob-property",
34 2, 0, 0, (SCM grob
, SCM sym
),
35 "Return the value of a value in grob @var{g} of property @var{sym}. "
36 "It will return @code{' ()} (end-of-list) "
37 "if @var{sym} is undefined in @var{g}."
41 Grob
*sc
= unsmob_grob (grob
);
42 SCM_ASSERT_TYPE (sc
, grob
, SCM_ARG1
, __FUNCTION__
, "grob");
43 SCM_ASSERT_TYPE (gh_symbol_p (sym
), sym
, SCM_ARG2
, __FUNCTION__
, "symbol");
45 return sc
->internal_get_property (sym
);
48 LY_DEFINE (spanner_get_bound
, "ly:spanner-get-bound", 2 , 0, 0,
50 "Get one of the bounds of @var{spanner}. @var{dir} is @code{-1} "
51 "for left, and @code{1} for right.")
53 Spanner
* sl
= dynamic_cast<Spanner
*> (unsmob_grob (slur
));
54 SCM_ASSERT_TYPE (sl
, slur
, SCM_ARG1
, __FUNCTION__
, "spanner grob");
55 SCM_ASSERT_TYPE (is_direction (dir
), slur
, SCM_ARG2
, __FUNCTION__
, "dir");
56 return sl
->get_bound (to_dir (dir
))->self_scm ();
59 /* TODO: make difference between scaled and unscalead variable in
60 calling (i.e different funcs.) */
61 LY_DEFINE (ly_grob_paper
,"ly:grob-paper", 1, 0, 0,
63 "Get @code{\\paper} definition from grob @var{g}.")
65 Grob
* sc
= unsmob_grob (g
);
66 SCM_ASSERT_TYPE (sc
, g
, SCM_ARG1
, __FUNCTION__
, "grob");
68 return sc
->get_paper ()->self_scm ();
72 LY_DEFINE(ly_grob_alist_chain
, "ly:grob-alist-chain",
75 "Get an alist chain for grob @var{g}, with @var{global} as the "
76 "global default. If unspecified, @code{font-defaults} "
77 "from the paper block is taken. "
80 Grob
* sc
= unsmob_grob (g
);
81 SCM_ASSERT_TYPE (sc
, g
, SCM_ARG1
, __FUNCTION__
, "grob");
83 if (global
== SCM_UNDEFINED
)
84 global
= sc
->get_paper ()->lookup_variable (ly_symbol2scm ("font-defaults"));
86 return sc
->get_property_alist_chain (global
);
90 LY_DEFINE (ly_get_extent
, "ly:grob-extent", 3, 0, 0,
91 (SCM grob
, SCM refp
, SCM axis
),
92 "Get the extent in @var{axis} direction of @var{grob} relative to "
93 "the grob @var{refp}")
95 Grob
* sc
= unsmob_grob (grob
);
96 Grob
* ref
= unsmob_grob (refp
);
97 SCM_ASSERT_TYPE (sc
, grob
, SCM_ARG1
, __FUNCTION__
, "grob");
98 SCM_ASSERT_TYPE (ref
, refp
, SCM_ARG2
, __FUNCTION__
, "grob");
100 SCM_ASSERT_TYPE (is_axis (axis
), axis
, SCM_ARG3
, __FUNCTION__
, "axis");
102 return ly_interval2scm ( sc
->extent (ref
, Axis (gh_scm2int (axis
))));
105 LY_DEFINE (ly_get_parent
, "ly:grob-parent", 2, 0, 0, (SCM grob
, SCM axis
),
106 "Get the parent of @var{grob}. @var{axis} is 0 for the X-axis, "
109 Grob
* sc
= unsmob_grob (grob
);
110 SCM_ASSERT_TYPE (sc
, grob
, SCM_ARG1
, __FUNCTION__
, "grob");
111 SCM_ASSERT_TYPE (is_axis (axis
), axis
, SCM_ARG2
, __FUNCTION__
, "axis");
113 Grob
*par
= sc
->get_parent (Axis (gh_scm2int (axis
)));
114 return par
? par
->self_scm () : SCM_EOL
;
117 LY_DEFINE (ly_get_system
, "ly:grob-system",
119 "Return the System Grob of @var{g}.")
121 Grob
*me
= unsmob_grob (g
);
122 SCM_ASSERT_TYPE (me
, g
, SCM_ARG1
, __FUNCTION__
, "grob");
124 if (System
*g
= me
->get_system ())
125 return g
->self_scm ();
130 LY_DEFINE (ly_get_original
, "ly:grob-original",
132 "Return the unbroken original Grob of @var{grob}.")
134 Grob
*me
= unsmob_grob (grob
);
135 SCM_ASSERT_TYPE (me
, grob
, SCM_ARG1
, __FUNCTION__
, "grob");
136 return me
->original_
? me
->original_
->self_scm () : me
->self_scm ();
139 /* FIXME: ly prefix? spanner in name? */
140 /* TODO: maybe we should return a vector -- random access is more
141 logical for this list? */
142 LY_DEFINE (get_broken_into
, "ly:spanner-broken-into",
143 1, 0, 0, (SCM spanner
),
144 "Return broken-into list for @var{spanner}.")
146 Spanner
*me
= dynamic_cast<Spanner
*> (unsmob_grob (spanner
));
147 SCM_ASSERT_TYPE (me
, spanner
, SCM_ARG1
, __FUNCTION__
, "spanner");
150 for (int i
= me
->broken_intos_
.size (); i
--;)
151 s
= gh_cons (me
->broken_intos_
[i
]->self_scm (), s
);
155 LY_DEFINE (ly_grob_suicide
, "ly:grob-suicide",
159 Grob
*me
= unsmob_grob (g
);
160 SCM_ASSERT_TYPE (me
, g
, SCM_ARG1
, __FUNCTION__
, "grob");
163 return SCM_UNDEFINED
;
166 LY_DEFINE (ly_grob_translate_axis_x
, "ly:grob-translate-axis!",
167 3, 0, 0, (SCM g
, SCM d
, SCM a
),
168 "Translate @var{g} on axis @var{a} over distance @var{d}.")
170 Grob
*me
= unsmob_grob (g
);
171 SCM_ASSERT_TYPE (me
, g
, SCM_ARG1
, __FUNCTION__
, "grob");
172 SCM_ASSERT_TYPE (gh_number_p (d
), d
, SCM_ARG2
, __FUNCTION__
, "dimension");
173 SCM_ASSERT_TYPE (is_axis (a
), a
, SCM_ARG3
, __FUNCTION__
, "axis");
175 me
->translate_axis (gh_scm2double (d
), Axis (gh_scm2int (a
)));
176 return SCM_UNDEFINED
;
179 LY_DEFINE (ly_spanner_p
, "ly:spanner?",
181 "Is @var{g} a spanner object?")
183 Grob
*me
= unsmob_grob (g
);
184 bool b
= dynamic_cast<Spanner
*> (me
);
186 return gh_bool2scm (b
);
189 LY_DEFINE (ly_item_p
, "ly:item?",
191 "Is @var{g} an @code{Item} object?")
193 Grob
*me
= unsmob_grob (g
);
194 bool b
= dynamic_cast<Item
*> (me
);
195 return gh_bool2scm (b
);
198 LY_DEFINE (ly_item_break_dir
, "ly:item-break-dir",
200 "The break status dir of item @var{it}. @code{-1} is end of "
201 "line, @code{0} unbroken, and @code{1} begin of line.")
203 Item
*me
= dynamic_cast<Item
*> (unsmob_grob (it
));
204 SCM_ASSERT_TYPE (me
, it
, SCM_ARG1
, __FUNCTION__
, "Item");
205 return gh_int2scm (me
->break_status_dir ());