]> git.donarmstrong.com Git - lilypond.git/blob - lily/context-scheme.cc
Update source file headers. Fixes using standard GNU package conventions.
[lilypond.git] / lily / context-scheme.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1998--2009 Jan Nieuwenhuizen <janneke@gnu.org>
5   Han-Wen Nienhuys <hanwen@xs4all.nl>
6
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.
11
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.
16
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/>.
19 */
20
21 #include "context.hh"
22 #include "context-def.hh"
23 #include "dispatcher.hh"
24
25 LY_DEFINE (ly_context_id, "ly:context-id",
26            1, 0, 0, (SCM context),
27            "Return the ID string of @var{context},"
28            " i.e., for @code{\\context Voice = one @dots{}}"
29            " return the string @code{one}.")
30 {
31   Context *tr = unsmob_context (context);
32
33   LY_ASSERT_SMOB (Context, context, 1);
34
35   return ly_string2scm (tr->id_string ());
36 }
37
38 LY_DEFINE (ly_context_name, "ly:context-name",
39            1, 0, 0, (SCM context),
40            "Return the name of @var{context},"
41            " i.e., for @code{\\context Voice = one @dots{}}"
42            " return the symbol @code{Voice}.")
43 {
44   LY_ASSERT_SMOB (Context, context, 1);
45
46   Context *tr = unsmob_context (context);
47
48   return ly_symbol2scm (tr->context_name ().c_str ());
49 }
50
51 LY_DEFINE (ly_context_grob_definition, "ly:context-grob-definition",
52            2, 0, 0, (SCM context, SCM name),
53            "Return the definition of @var{name} (a symbol) within"
54            " @var{context} as an alist.")
55 {
56   Context *tr = unsmob_context (context);
57   
58   LY_ASSERT_SMOB (Context, context, 1);
59   LY_ASSERT_TYPE (ly_is_symbol, name, 2);
60
61   return updated_grob_properties (tr, name);
62 }
63
64 LY_DEFINE (ly_context_pushpop_property, "ly:context-pushpop-property",
65            3, 1, 0, (SCM context, SCM grob, SCM eltprop, SCM val),
66            "Do a single @code{\\override} or @code{\\revert} operation"
67            " in @var{context}.  The grob definition @var{grob} is extended"
68            " with @var{eltprop} (if @var{val} is specified) or reverted"
69            " (if unspecified).")
70 {
71   Context *tg = unsmob_context (context);
72
73   LY_ASSERT_SMOB (Context, context, 1);
74   LY_ASSERT_TYPE (ly_is_symbol, grob, 2);
75   LY_ASSERT_TYPE (ly_is_symbol, eltprop, 3);
76
77   execute_pushpop_property (tg, grob, eltprop, val);
78
79   return SCM_UNSPECIFIED;
80 }
81
82 LY_DEFINE (ly_context_property, "ly:context-property",
83            2, 0, 0, (SCM context, SCM sym),
84            "Return the value for property @var{sym} in @var{context}.")
85 {
86   LY_ASSERT_SMOB (Context, context, 1);
87   LY_ASSERT_TYPE (ly_is_symbol, sym, 2);
88
89   Context *t = unsmob_context (context);
90   return t->internal_get_property (sym);
91 }
92
93 LY_DEFINE (ly_context_set_property_x, "ly:context-set-property!",
94            3, 0, 0, (SCM context, SCM name, SCM val),
95            "Set value of property @var{name} in context @var{context}"
96            " to @var{val}.")
97 {
98   LY_ASSERT_SMOB (Context, context, 1);
99   LY_ASSERT_TYPE (ly_is_symbol, name, 2);
100
101   Context *tr = unsmob_context (context);
102
103   tr->set_property (name, val);
104
105   return SCM_UNSPECIFIED;
106 }
107
108 LY_DEFINE (ly_context_property_where_defined, "ly:context-property-where-defined",
109            2, 0, 0, (SCM context, SCM name),
110            "Return the context above @var{context}"
111            " where @var{name} is defined.")
112 {
113   LY_ASSERT_SMOB (Context, context, 1);
114   LY_ASSERT_TYPE (ly_is_symbol, name, 2);
115   
116   Context *tr = unsmob_context (context);
117
118   SCM val;
119   tr = tr->where_defined (name, &val);
120   if (tr)
121     return tr->self_scm ();
122
123   return SCM_EOL;
124 }
125
126 LY_DEFINE (ly_context_unset_property, "ly:context-unset-property", 2, 0, 0,
127            (SCM context, SCM name),
128            "Unset value of property @var{name} in context @var{context}.")
129 {
130   LY_ASSERT_SMOB (Context, context, 1);
131   LY_ASSERT_TYPE (ly_is_symbol, name, 2);
132   Context *tr = unsmob_context (context);
133   
134   tr->unset_property (name);
135   return SCM_UNSPECIFIED;
136 }
137
138 LY_DEFINE (ly_context_parent, "ly:context-parent",
139            1, 0, 0, (SCM context),
140            "Return the parent of @var{context}, @code{#f} if none.")
141 {
142   LY_ASSERT_SMOB (Context, context, 1);
143   Context *tr = unsmob_context (context);
144
145   tr = tr->get_parent_context ();
146   if (tr)
147     return tr->self_scm ();
148   else
149     return SCM_BOOL_F;
150 }
151
152 /* FIXME: todo: should support translator IDs, and creation? */
153 LY_DEFINE (ly_context_find, "ly:context-find",
154            2, 0, 0, (SCM context, SCM name),
155            "Find a parent of @var{context} that has name or alias @var{name}."
156            "  Return @code{#f} if not found.")
157 {
158   LY_ASSERT_SMOB (Context, context, 1);
159   LY_ASSERT_TYPE (ly_is_symbol, name, 2);
160   Context *tr = unsmob_context (context);
161
162   while (tr)
163     {
164       if (tr->is_alias (name))
165         return tr->self_scm ();
166       tr = tr->get_parent_context ();
167     }
168
169   return SCM_BOOL_F;
170 }
171
172 LY_DEFINE (ly_context_now, "ly:context-now",
173            1, 0, 0, (SCM context),
174            "Return @code{now-moment} of context @var{context}.")
175 {
176   LY_ASSERT_SMOB (Context, context, 1);
177   Context *ctx = unsmob_context (context);
178   return ctx->now_mom ().smobbed_copy ();
179 }
180
181 LY_DEFINE (ly_context_event_source, "ly:context-event-source",
182            1, 0, 0, (SCM context),
183            "Return @code{event-source} of context @var{context}.")
184 {
185   LY_ASSERT_SMOB (Context, context, 1);
186   Context *ctx = unsmob_context (context);
187   return ctx->event_source ()->self_scm ();
188 }
189
190 LY_DEFINE (ly_context_events_below, "ly:context-events-below",
191            1, 0, 0, (SCM context),
192            "Return a @code{stream-distributor} that distributes all events"
193            " from @var{context} and all its subcontexts.")
194 {
195   LY_ASSERT_SMOB (Context, context, 1);
196   Context *ctx = unsmob_context (context);
197   return ctx->events_below ()->self_scm ();
198 }