]> git.donarmstrong.com Git - lilypond.git/blob - lily/grob-scheme.cc
beam: knee_b fix
[lilypond.git] / lily / grob-scheme.cc
1 #include "grob.hh"
2 #include "warn.hh"
3 #include "spanner.hh"
4 #include "item.hh"
5 #include "paper-def.hh"
6
7 LY_DEFINE(ly_set_grob_property,"ly-set-grob-property!", 3, 0, 0,
8   (SCM grob, SCM sym, SCM val),
9   "Set @var{sym} in grob @var{grob} to value @var{val}")
10 {
11   Grob * sc = unsmob_grob (grob);
12   SCM_ASSERT_TYPE(sc, grob, SCM_ARG1, __FUNCTION__, "grob");
13   SCM_ASSERT_TYPE(gh_symbol_p (sym), sym, SCM_ARG2, __FUNCTION__, "symbol");  
14
15   if (!type_check_assignment (sym, val, ly_symbol2scm ("backend-type?")))
16     error ("typecheck failed");
17       
18   sc->internal_set_grob_property (sym, val);
19   return SCM_UNSPECIFIED;
20 }
21
22 LY_DEFINE(ly_get_grob_property,
23           "ly-get-grob-property", 2, 0, 0, (SCM grob, SCM sym),
24           "Get the value of a value in grob @var{g} of property @var{sym}. It
25 will return @code{'()} (end-of-list) if @var{g} doesn't have @var{sym} set.
26
27 Grob properties are stored as GUILE association lists, with symbols as
28 keys. All lookup functions identify undefined properties with
29 end-of-list (i.e. @code{'()} in Scheme or @code{SCM_EOL} in C)
30
31 Properties are stored in two ways:
32 @itemize @bullet
33 @item mutable properties.
34 Grob properties that change from object to object. The storage of
35 these are private to a grob. For example pointers to other grobs are
36 always stored in the mutable properties.
37
38 @item immutable properties.
39 Grob properties that are shared across different grobs of the same
40 type. The storage is shared, and hence it is read-only. Typically, this
41 is used to store function callbacks, and default settings. They are
42 initially read from @file{scm/grob-description.scm}.
43 @end itemize
44
45 ")
46 {
47   Grob * sc = unsmob_grob (grob);
48   SCM_ASSERT_TYPE(sc, grob, SCM_ARG1, __FUNCTION__, "grob");
49   SCM_ASSERT_TYPE(gh_symbol_p (sym), sym, SCM_ARG2, __FUNCTION__, "symbol");  
50
51   return sc->internal_get_grob_property (sym);
52 }
53
54 LY_DEFINE(spanner_get_bound, "ly-get-spanner-bound", 2 , 0, 0,
55           (SCM slur, SCM dir),
56           "Get one of the bounds of @var{spanner}. @var{dir} may be @code{-1} for
57 left, and @code{1} for right.
58 ")
59 {
60   Spanner * sl = dynamic_cast<Spanner*> (unsmob_grob (slur));
61   SCM_ASSERT_TYPE(sl, slur, SCM_ARG1, __FUNCTION__, "spanner grob");
62   SCM_ASSERT_TYPE(ly_dir_p (dir), slur, SCM_ARG2, __FUNCTION__, "dir");
63   return sl->get_bound (to_dir (dir))->self_scm ();
64 }
65
66 LY_DEFINE(ly_get_paper_var,"ly-get-paper-variable", 2, 0, 0,
67   (SCM grob, SCM sym),
68   "Get a variable from the \\paper block.")
69 {
70   Grob * sc = unsmob_grob (grob);
71   SCM_ASSERT_TYPE(sc, grob, SCM_ARG1, __FUNCTION__, "grob");
72   SCM_ASSERT_TYPE(gh_symbol_p (sym), sym, SCM_ARG2, __FUNCTION__, "symbol");  
73
74   return sc->get_paper () ->get_scmvar_scm (sym);
75 }
76
77
78
79 LY_DEFINE(ly_get_extent, "ly-get-extent", 3, 0, 0,
80           (SCM grob, SCM refp, SCM axis),
81           "Get the extent in @var{axis} direction of @var{grob} relative to the
82 grob @var{refp}")
83 {
84   Grob * sc = unsmob_grob (grob);
85   Grob * ref = unsmob_grob (refp);
86   SCM_ASSERT_TYPE(sc, grob, SCM_ARG1, __FUNCTION__, "grob");
87   SCM_ASSERT_TYPE(ref, refp, SCM_ARG2, __FUNCTION__, "grob");
88   
89   SCM_ASSERT_TYPE(ly_axis_p (axis), axis, SCM_ARG3, __FUNCTION__, "axis");
90
91   return ly_interval2scm ( sc->extent (ref, Axis (gh_scm2int (axis))));
92 }
93
94 LY_DEFINE (ly_get_parent,   "ly-get-parent", 2, 0, 0, (SCM grob, SCM axis),
95            "Get the parent of @var{grob}.  @var{axis} can be 0 for the X-axis, 1
96 for the Y-axis.")
97 {
98   Grob * sc = unsmob_grob (grob);
99   SCM_ASSERT_TYPE(sc, grob, SCM_ARG1, __FUNCTION__, "grob");
100   SCM_ASSERT_TYPE(ly_axis_p (axis), axis, SCM_ARG2, __FUNCTION__, "axis");
101
102   Grob * par = sc->get_parent (Axis (gh_scm2int (axis)));
103   return par ? par->self_scm() : SCM_EOL;
104 }
105
106 /* ly prefix? */
107 LY_DEFINE (get_system,
108            "get-system",
109            1, 0, 0, (SCM grob),
110            "
111 Return the System Grob of @var{grob}.
112 ")
113 {
114   Grob *me = unsmob_grob (grob);
115   SCM_ASSERT_TYPE (me, grob, SCM_ARG1, __FUNCTION__, "grob");
116   
117   if (Grob *g = me->get_system ())
118     return g->self_scm ();
119     
120   return SCM_EOL;
121 }
122
123 /* ly prefix? */
124 LY_DEFINE (get_original,
125            "get-original",
126            1, 0, 0, (SCM grob),
127            "
128 Return the original Grob of @var{grob}
129 ")
130 {
131   Grob *me = unsmob_grob (grob);
132   SCM_ASSERT_TYPE (me, grob, SCM_ARG1, __FUNCTION__, "grob");
133   return me->original_ ? me->original_->self_scm () : me->self_scm ();
134 }
135
136
137 /* ly prefix? spanner in name? */
138 LY_DEFINE (get_broken_into,
139           "get-broken-into", 1, 0, 0, (SCM spanner),
140            "
141 Return broken-into list for @var{spanner}.
142 "
143 )
144 {
145   ///  Spanner *me = unsmob_spanner (spanner);
146   Spanner *me = dynamic_cast<Spanner*> (unsmob_grob (spanner));
147   SCM_ASSERT_TYPE (me, spanner, SCM_ARG1, __FUNCTION__, "spanner");
148
149   SCM s = SCM_EOL;
150   for (int i = me->broken_intos_.size (); i; i--)
151     s = gh_cons (me->broken_intos_[i-1]->self_scm (), s);
152   return s;
153 }
154