Release: update news.
[lilypond/patrick.git] / lily / context-scheme.cc
blob043bfaa924ffaba1098bcb6b499a822d22e51911
1 /*
2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1998--2011 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/>.
21 #include "context.hh"
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"
81 " (if unspecified).")
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, 1, 0, (SCM context, SCM sym, SCM def),
96 "Return the value for property @var{sym} in @var{context}."
97 " If @var{def} is given, and property value is @code{'()},"
98 " return @var{def}.")
100 LY_ASSERT_SMOB (Context, context, 1);
101 LY_ASSERT_TYPE (ly_is_symbol, sym, 2);
103 Context *t = unsmob_context (context);
104 SCM result = t->internal_get_property (sym);
105 return def != SCM_UNDEFINED && scm_is_null (result) ? def : result;
108 LY_DEFINE (ly_context_set_property_x, "ly:context-set-property!",
109 3, 0, 0, (SCM context, SCM name, SCM val),
110 "Set value of property @var{name} in context @var{context}"
111 " to @var{val}.")
113 LY_ASSERT_SMOB (Context, context, 1);
114 LY_ASSERT_TYPE (ly_is_symbol, name, 2);
116 Context *tr = unsmob_context (context);
118 tr->set_property (name, val);
120 return SCM_UNSPECIFIED;
123 LY_DEFINE (ly_context_property_where_defined, "ly:context-property-where-defined",
124 2, 0, 0, (SCM context, SCM name),
125 "Return the context above @var{context}"
126 " where @var{name} is defined.")
128 LY_ASSERT_SMOB (Context, context, 1);
129 LY_ASSERT_TYPE (ly_is_symbol, name, 2);
131 Context *tr = unsmob_context (context);
133 SCM val;
134 tr = tr->where_defined (name, &val);
135 if (tr)
136 return tr->self_scm ();
138 return SCM_EOL;
141 LY_DEFINE (ly_context_unset_property, "ly:context-unset-property", 2, 0, 0,
142 (SCM context, SCM name),
143 "Unset value of property @var{name} in context @var{context}.")
145 LY_ASSERT_SMOB (Context, context, 1);
146 LY_ASSERT_TYPE (ly_is_symbol, name, 2);
147 Context *tr = unsmob_context (context);
149 tr->unset_property (name);
150 return SCM_UNSPECIFIED;
153 LY_DEFINE (ly_context_parent, "ly:context-parent",
154 1, 0, 0, (SCM context),
155 "Return the parent of @var{context}, @code{#f} if none.")
157 LY_ASSERT_SMOB (Context, context, 1);
158 Context *tr = unsmob_context (context);
160 tr = tr->get_parent_context ();
161 if (tr)
162 return tr->self_scm ();
163 else
164 return SCM_BOOL_F;
167 /* FIXME: todo: should support translator IDs, and creation? */
168 LY_DEFINE (ly_context_find, "ly:context-find",
169 2, 0, 0, (SCM context, SCM name),
170 "Find a parent of @var{context} that has name or alias @var{name}."
171 " Return @code{#f} if not found.")
173 LY_ASSERT_SMOB (Context, context, 1);
174 LY_ASSERT_TYPE (ly_is_symbol, name, 2);
175 Context *tr = unsmob_context (context);
177 while (tr)
179 if (tr->is_alias (name))
180 return tr->self_scm ();
181 tr = tr->get_parent_context ();
184 return SCM_BOOL_F;
187 LY_DEFINE (ly_context_now, "ly:context-now",
188 1, 0, 0, (SCM context),
189 "Return @code{now-moment} of context @var{context}.")
191 LY_ASSERT_SMOB (Context, context, 1);
192 Context *ctx = unsmob_context (context);
193 return ctx->now_mom ().smobbed_copy ();
196 LY_DEFINE (ly_context_event_source, "ly:context-event-source",
197 1, 0, 0, (SCM context),
198 "Return @code{event-source} of context @var{context}.")
200 LY_ASSERT_SMOB (Context, context, 1);
201 Context *ctx = unsmob_context (context);
202 return ctx->event_source ()->self_scm ();
205 LY_DEFINE (ly_context_events_below, "ly:context-events-below",
206 1, 0, 0, (SCM context),
207 "Return a @code{stream-distributor} that distributes all events"
208 " from @var{context} and all its subcontexts.")
210 LY_ASSERT_SMOB (Context, context, 1);
211 Context *ctx = unsmob_context (context);
212 return ctx->events_below ()->self_scm ();