2 context-scheme.cc -- Context bindings
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2005 Jan Nieuwenhuizen <janneke@gnu.org>
7 Han-Wen Nienhuys <hanwen@cs.uu.nl>
11 #include "context-def.hh"
13 LY_DEFINE (ly_context_id, "ly:context-id",
14 1, 0, 0, (SCM context),
15 "Return the id string of @var{context}, "
16 "i.e. for @code{\\context Voice = one .. } "
17 "return the string @code{one}.")
19 Context *tr = unsmob_context (context);
20 SCM_ASSERT_TYPE (tr, context, SCM_ARG1, __FUNCTION__, "Context");
22 return scm_makfrom0str (tr->id_string ().to_str0 ());
25 LY_DEFINE (ly_context_name, "ly:context-name",
26 1, 0, 0, (SCM context),
27 "Return the name of @var{context}, "
28 "i.e. for @code{\\context Voice = one .. } "
29 "return the symbol @code{Voice}.")
31 Context *tr = unsmob_context (context);
32 SCM_ASSERT_TYPE (tr, context, SCM_ARG1, __FUNCTION__, "Context");
33 return ly_symbol2scm (tr->context_name ().to_str0 ());
36 LY_DEFINE (ly_context_grob_definition, "ly:context-grob-definition",
37 2, 0, 0, (SCM context, SCM name),
38 "Return the definition of @var{name} (a symbol) within @var{context} "
41 Context *tr = unsmob_context (context);
42 SCM_ASSERT_TYPE (tr, context, SCM_ARG1, __FUNCTION__, "Context");
43 SCM_ASSERT_TYPE (scm_is_symbol (name), name, SCM_ARG2, __FUNCTION__, "symbol");
45 return updated_grob_properties (tr, name);
48 LY_DEFINE (ly_context_pushpop_property, "ly:context-pushpop-property",
49 3, 1, 0, (SCM context, SCM grob, SCM eltprop, SCM val),
50 "Do a single @code{\\override} or @code{\\revert} operation "
51 "in @var{context}. The grob definition @code{grob} is extended "
52 "with @code{eltprop} (if @var{val} is specified) "
53 "or reverted (if unspecified).")
55 Context *tg = unsmob_context (context);
56 SCM_ASSERT_TYPE (tg, context, SCM_ARG1, __FUNCTION__, "context");
57 SCM_ASSERT_TYPE (scm_is_symbol (grob), grob, SCM_ARG2, __FUNCTION__, "symbol");
58 SCM_ASSERT_TYPE (scm_is_symbol (eltprop), eltprop, SCM_ARG3, __FUNCTION__, "symbol");
60 execute_pushpop_property (tg, grob, eltprop, val);
62 return SCM_UNSPECIFIED;
65 LY_DEFINE (ly_context_property, "ly:context-property",
66 2, 0, 0, (SCM c, SCM name),
67 "Return the value of @var{name} from context @var{c}")
69 Context *t = unsmob_context (c);
71 SCM_ASSERT_TYPE (tr, c, SCM_ARG1, __FUNCTION__, "Translator group");
72 SCM_ASSERT_TYPE (scm_is_symbol (name), name, SCM_ARG2, __FUNCTION__, "symbol");
74 return tr->internal_get_property (name);
77 LY_DEFINE (ly_context_set_property, "ly:context-set-property!",
78 3, 0, 0, (SCM context, SCM name, SCM val),
79 "Set value of property @var{name} in context @var{context} "
82 Context *tr = unsmob_context (context);
83 SCM_ASSERT_TYPE (tr, context, SCM_ARG1, __FUNCTION__, "Context");
84 SCM_ASSERT_TYPE (scm_is_symbol (name), name, SCM_ARG2, __FUNCTION__, "symbol");
86 tr->internal_set_property (name, val);
88 return SCM_UNSPECIFIED;
91 LY_DEFINE (ly_context_property_where_defined, "ly:context-property-where-defined",
92 2, 0, 0, (SCM context, SCM name),
93 "Return the context above @var{context} "
94 "where @var{name} is defined.")
96 Context *tr = unsmob_context (context);
97 SCM_ASSERT_TYPE (tr, context, SCM_ARG1, __FUNCTION__, "Context");
98 SCM_ASSERT_TYPE (scm_is_symbol (name), name, SCM_ARG2, __FUNCTION__, "symbol");
100 tr = tr->where_defined (name);
102 return tr->self_scm ();
107 LY_DEFINE (ly_unset_context_property, "ly:context-unset-property", 2, 0, 0,
108 (SCM context, SCM name),
109 "Unset value of property @var{name} in context @var{context}.")
111 Context *tr = unsmob_context (context);
112 SCM_ASSERT_TYPE (tr, context, SCM_ARG1, __FUNCTION__, "Context");
113 SCM_ASSERT_TYPE (scm_is_symbol (name), name, SCM_ARG2, __FUNCTION__, "symbol");
115 tr->unset_property (name);
116 return SCM_UNSPECIFIED;
119 LY_DEFINE (ly_context_parent, "ly:context-parent",
120 1, 0, 0, (SCM context),
121 "Return the parent of @var{context}, @code{#f} if none.")
123 Context *tr = unsmob_context (context);
124 SCM_ASSERT_TYPE (tr, context, SCM_ARG1, __FUNCTION__, "Context");
126 tr = tr->get_parent_context ();
128 return tr->self_scm ();
133 /* FIXME: todo: should support translator IDs, and creation? */
134 LY_DEFINE (ly_context_find, "ly:context-find",
135 2, 0, 0, (SCM context, SCM name),
136 "Find a parent of @var{context} that has name or alias @var{name}. "
137 "Return @code{#f} if not found.")
139 Context *tr = unsmob_context (context);
140 SCM_ASSERT_TYPE (tr, context, SCM_ARG1, __FUNCTION__, "context");
141 SCM_ASSERT_TYPE (scm_is_symbol (name), name, SCM_ARG2, __FUNCTION__, "symbol");
145 if (tr->is_alias (name))
146 return tr->self_scm ();
147 tr = tr->get_parent_context ();
153 LY_DEFINE (ly_context_now, "ly:context-now",
154 1, 0, 0, (SCM context),
155 "Return now-moment of context CONTEXT")
157 Context *ctx = unsmob_context (context);
158 SCM_ASSERT_TYPE (ctx, context, SCM_ARG1, __FUNCTION__, "Context");
159 return ctx->now_mom ().smobbed_copy ();