Nitpick: ly:spanner-bound grob name slur -> spanner.
[lilypond.git] / lily / context-scheme.cc
blob9ce9a9baa0a2f88f3ffbd0d84efa32cbbb9da1a4
1 /*
2 context-scheme.cc -- Context bindings
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2009 Jan Nieuwenhuizen <janneke@gnu.org>
7 Han-Wen Nienhuys <hanwen@xs4all.nl>
8 */
10 #include "context.hh"
11 #include "context-def.hh"
12 #include "dispatcher.hh"
14 LY_DEFINE (ly_context_id, "ly:context-id",
15 1, 0, 0, (SCM context),
16 "Return the ID string of @var{context},"
17 " i.e., for @code{\\context Voice = one @dots{}}"
18 " return the string @code{one}.")
20 Context *tr = unsmob_context (context);
22 LY_ASSERT_SMOB (Context, context, 1);
24 return ly_string2scm (tr->id_string ());
27 LY_DEFINE (ly_context_name, "ly:context-name",
28 1, 0, 0, (SCM context),
29 "Return the name of @var{context},"
30 " i.e., for @code{\\context Voice = one @dots{}}"
31 " return the symbol @code{Voice}.")
33 LY_ASSERT_SMOB (Context, context, 1);
35 Context *tr = unsmob_context (context);
37 return ly_symbol2scm (tr->context_name ().c_str ());
40 LY_DEFINE (ly_context_grob_definition, "ly:context-grob-definition",
41 2, 0, 0, (SCM context, SCM name),
42 "Return the definition of @var{name} (a symbol) within"
43 " @var{context} as an alist.")
45 Context *tr = unsmob_context (context);
47 LY_ASSERT_SMOB (Context, context, 1);
48 LY_ASSERT_TYPE (ly_is_symbol, name, 2);
50 return updated_grob_properties (tr, name);
53 LY_DEFINE (ly_context_pushpop_property, "ly:context-pushpop-property",
54 3, 1, 0, (SCM context, SCM grob, SCM eltprop, SCM val),
55 "Do a single @code{\\override} or @code{\\revert} operation"
56 " in @var{context}. The grob definition @var{grob} is extended"
57 " with @var{eltprop} (if @var{val} is specified) or reverted"
58 " (if unspecified).")
60 Context *tg = unsmob_context (context);
62 LY_ASSERT_SMOB (Context, context, 1);
63 LY_ASSERT_TYPE (ly_is_symbol, grob, 2);
64 LY_ASSERT_TYPE (ly_is_symbol, eltprop, 3);
66 execute_pushpop_property (tg, grob, eltprop, val);
68 return SCM_UNSPECIFIED;
71 LY_DEFINE (ly_context_property, "ly:context-property",
72 2, 0, 0, (SCM c, SCM name),
73 "Return the value of @var{name} from context @var{c}.")
75 LY_ASSERT_SMOB (Context, c, 1);
76 LY_ASSERT_TYPE (ly_is_symbol, name, 2);
78 Context *t = unsmob_context (c);
79 return t->internal_get_property (name);
82 LY_DEFINE (ly_context_set_property_x, "ly:context-set-property!",
83 3, 0, 0, (SCM context, SCM name, SCM val),
84 "Set value of property @var{name} in context @var{context}"
85 " to @var{val}.")
87 LY_ASSERT_SMOB (Context, context, 1);
88 LY_ASSERT_TYPE (ly_is_symbol, name, 2);
90 Context *tr = unsmob_context (context);
92 tr->set_property (name, val);
94 return SCM_UNSPECIFIED;
97 LY_DEFINE (ly_context_property_where_defined, "ly:context-property-where-defined",
98 2, 0, 0, (SCM context, SCM name),
99 "Return the context above @var{context}"
100 " where @var{name} is defined.")
102 LY_ASSERT_SMOB (Context, context, 1);
103 LY_ASSERT_TYPE (ly_is_symbol, name, 2);
105 Context *tr = unsmob_context (context);
107 SCM val;
108 tr = tr->where_defined (name, &val);
109 if (tr)
110 return tr->self_scm ();
112 return SCM_EOL;
115 LY_DEFINE (ly_context_unset_property, "ly:context-unset-property", 2, 0, 0,
116 (SCM context, SCM name),
117 "Unset value of property @var{name} in context @var{context}.")
119 LY_ASSERT_SMOB (Context, context, 1);
120 LY_ASSERT_TYPE (ly_is_symbol, name, 2);
121 Context *tr = unsmob_context (context);
123 tr->unset_property (name);
124 return SCM_UNSPECIFIED;
127 LY_DEFINE (ly_context_parent, "ly:context-parent",
128 1, 0, 0, (SCM context),
129 "Return the parent of @var{context}, @code{#f} if none.")
131 LY_ASSERT_SMOB (Context, context, 1);
132 Context *tr = unsmob_context (context);
134 tr = tr->get_parent_context ();
135 if (tr)
136 return tr->self_scm ();
137 else
138 return SCM_BOOL_F;
141 /* FIXME: todo: should support translator IDs, and creation? */
142 LY_DEFINE (ly_context_find, "ly:context-find",
143 2, 0, 0, (SCM context, SCM name),
144 "Find a parent of @var{context} that has name or alias @var{name}."
145 " Return @code{#f} if not found.")
147 LY_ASSERT_SMOB (Context, context, 1);
148 LY_ASSERT_TYPE (ly_is_symbol, name, 2);
149 Context *tr = unsmob_context (context);
151 while (tr)
153 if (tr->is_alias (name))
154 return tr->self_scm ();
155 tr = tr->get_parent_context ();
158 return SCM_BOOL_F;
161 LY_DEFINE (ly_context_now, "ly:context-now",
162 1, 0, 0, (SCM context),
163 "Return @code{now-moment} of context @var{context}.")
165 LY_ASSERT_SMOB (Context, context, 1);
166 Context *ctx = unsmob_context (context);
167 return ctx->now_mom ().smobbed_copy ();
170 LY_DEFINE (ly_context_event_source, "ly:context-event-source",
171 1, 0, 0, (SCM context),
172 "Return @code{event-source} of context @var{context}.")
174 LY_ASSERT_SMOB (Context, context, 1);
175 Context *ctx = unsmob_context (context);
176 return ctx->event_source ()->self_scm ();
179 LY_DEFINE (ly_context_events_below, "ly:context-events-below",
180 1, 0, 0, (SCM context),
181 "Return a @code{stream-distributor} that distributes all events"
182 " from @var{context} and all its subcontexts.")
184 LY_ASSERT_SMOB (Context, context, 1);
185 Context *ctx = unsmob_context (context);
186 return ctx->events_below ()->self_scm ();