2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1998--2009 Jan Nieuwenhuizen <janneke@gnu.org>
5 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 LilyPond is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 LilyPond is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
22 #include "context-def.hh"
23 #include "dispatcher.hh"
25 LY_DEFINE (ly_context_current_moment,
26 "ly:context-current-moment",
27 1, 0, 0, (SCM context),
28 "Return the current moment of @var{context}.")
30 Context *tr = unsmob_context (context);
32 LY_ASSERT_SMOB (Context, context, 1);
34 return tr->now_mom ().smobbed_copy ();
37 LY_DEFINE (ly_context_id, "ly:context-id",
38 1, 0, 0, (SCM context),
39 "Return the ID string of @var{context},"
40 " i.e., for @code{\\context Voice = one @dots{}}"
41 " return the string @code{one}.")
43 Context *tr = unsmob_context (context);
45 LY_ASSERT_SMOB (Context, context, 1);
47 return ly_string2scm (tr->id_string ());
50 LY_DEFINE (ly_context_name, "ly:context-name",
51 1, 0, 0, (SCM context),
52 "Return the name of @var{context},"
53 " i.e., for @code{\\context Voice = one @dots{}}"
54 " return the symbol @code{Voice}.")
56 LY_ASSERT_SMOB (Context, context, 1);
58 Context *tr = unsmob_context (context);
60 return ly_symbol2scm (tr->context_name ().c_str ());
63 LY_DEFINE (ly_context_grob_definition, "ly:context-grob-definition",
64 2, 0, 0, (SCM context, SCM name),
65 "Return the definition of @var{name} (a symbol) within"
66 " @var{context} as an alist.")
68 Context *tr = unsmob_context (context);
70 LY_ASSERT_SMOB (Context, context, 1);
71 LY_ASSERT_TYPE (ly_is_symbol, name, 2);
73 return updated_grob_properties (tr, name);
76 LY_DEFINE (ly_context_pushpop_property, "ly:context-pushpop-property",
77 3, 1, 0, (SCM context, SCM grob, SCM eltprop, SCM val),
78 "Do a single @code{\\override} or @code{\\revert} operation"
79 " in @var{context}. The grob definition @var{grob} is extended"
80 " with @var{eltprop} (if @var{val} is specified) or reverted"
83 Context *tg = unsmob_context (context);
85 LY_ASSERT_SMOB (Context, context, 1);
86 LY_ASSERT_TYPE (ly_is_symbol, grob, 2);
87 LY_ASSERT_TYPE (ly_is_symbol, eltprop, 3);
89 execute_pushpop_property (tg, grob, eltprop, val);
91 return SCM_UNSPECIFIED;
94 LY_DEFINE (ly_context_property, "ly:context-property",
95 2, 0, 0, (SCM context, SCM sym),
96 "Return the value for property @var{sym} in @var{context}.")
98 LY_ASSERT_SMOB (Context, context, 1);
99 LY_ASSERT_TYPE (ly_is_symbol, sym, 2);
101 Context *t = unsmob_context (context);
102 return t->internal_get_property (sym);
105 LY_DEFINE (ly_context_set_property_x, "ly:context-set-property!",
106 3, 0, 0, (SCM context, SCM name, SCM val),
107 "Set value of property @var{name} in context @var{context}"
110 LY_ASSERT_SMOB (Context, context, 1);
111 LY_ASSERT_TYPE (ly_is_symbol, name, 2);
113 Context *tr = unsmob_context (context);
115 tr->set_property (name, val);
117 return SCM_UNSPECIFIED;
120 LY_DEFINE (ly_context_property_where_defined, "ly:context-property-where-defined",
121 2, 0, 0, (SCM context, SCM name),
122 "Return the context above @var{context}"
123 " where @var{name} is defined.")
125 LY_ASSERT_SMOB (Context, context, 1);
126 LY_ASSERT_TYPE (ly_is_symbol, name, 2);
128 Context *tr = unsmob_context (context);
131 tr = tr->where_defined (name, &val);
133 return tr->self_scm ();
138 LY_DEFINE (ly_context_unset_property, "ly:context-unset-property", 2, 0, 0,
139 (SCM context, SCM name),
140 "Unset value of property @var{name} in context @var{context}.")
142 LY_ASSERT_SMOB (Context, context, 1);
143 LY_ASSERT_TYPE (ly_is_symbol, name, 2);
144 Context *tr = unsmob_context (context);
146 tr->unset_property (name);
147 return SCM_UNSPECIFIED;
150 LY_DEFINE (ly_context_parent, "ly:context-parent",
151 1, 0, 0, (SCM context),
152 "Return the parent of @var{context}, @code{#f} if none.")
154 LY_ASSERT_SMOB (Context, context, 1);
155 Context *tr = unsmob_context (context);
157 tr = tr->get_parent_context ();
159 return tr->self_scm ();
164 /* FIXME: todo: should support translator IDs, and creation? */
165 LY_DEFINE (ly_context_find, "ly:context-find",
166 2, 0, 0, (SCM context, SCM name),
167 "Find a parent of @var{context} that has name or alias @var{name}."
168 " Return @code{#f} if not found.")
170 LY_ASSERT_SMOB (Context, context, 1);
171 LY_ASSERT_TYPE (ly_is_symbol, name, 2);
172 Context *tr = unsmob_context (context);
176 if (tr->is_alias (name))
177 return tr->self_scm ();
178 tr = tr->get_parent_context ();
184 LY_DEFINE (ly_context_now, "ly:context-now",
185 1, 0, 0, (SCM context),
186 "Return @code{now-moment} of context @var{context}.")
188 LY_ASSERT_SMOB (Context, context, 1);
189 Context *ctx = unsmob_context (context);
190 return ctx->now_mom ().smobbed_copy ();
193 LY_DEFINE (ly_context_event_source, "ly:context-event-source",
194 1, 0, 0, (SCM context),
195 "Return @code{event-source} of context @var{context}.")
197 LY_ASSERT_SMOB (Context, context, 1);
198 Context *ctx = unsmob_context (context);
199 return ctx->event_source ()->self_scm ();
202 LY_DEFINE (ly_context_events_below, "ly:context-events-below",
203 1, 0, 0, (SCM context),
204 "Return a @code{stream-distributor} that distributes all events"
205 " from @var{context} and all its subcontexts.")
207 LY_ASSERT_SMOB (Context, context, 1);
208 Context *ctx = unsmob_context (context);
209 return ctx->events_below ()->self_scm ();