]> git.donarmstrong.com Git - lilypond.git/blob - lily/context-scheme.cc
(LY_DEFINE): ly:context-grob-definition takes two arguments.
[lilypond.git] / lily / context-scheme.cc
1 /*
2   context-scheme.cc --
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1998--2004 Jan Nieuwenhuizen <janneke@gnu.org>
7                  Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 */
9
10 #include "context.hh"
11 #include "context-def.hh"
12
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}.")
18 {
19   Context *tr = unsmob_context (context);
20   SCM_ASSERT_TYPE (tr, context, SCM_ARG1, __FUNCTION__, "Context");
21
22   return scm_makfrom0str (tr->id_string (). to_str0 ());
23 }
24
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}.")
30 {
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 ()); 
34 }
35
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} "
39            "as an alist")
40 {
41   Context *tr = unsmob_context (context);
42   SCM_ASSERT_TYPE (tr, context, SCM_ARG1, __FUNCTION__, "Context");
43   SCM_ASSERT_TYPE (ly_c_symbol_p (name), name, SCM_ARG2, __FUNCTION__, "symbol");
44
45     
46   return updated_grob_properties (tr, name);
47 }
48
49
50 LY_DEFINE (ly_context_pushpop_property, "ly:context-pushpop-property",
51            3, 1, 0, (SCM context, SCM grob, SCM eltprop, SCM val),
52            "Do a single @code{\\override} or @code{\\revert} operation "
53            "in @var{context}.  The grob definition @code{grob} is extended "
54            "with @code{eltprop} (if @var{val} is specified) "
55            "or reverted (if  unspecified).")
56 {
57   Context *tg = unsmob_context (context);
58   SCM_ASSERT_TYPE (tg, context, SCM_ARG1, __FUNCTION__, "context");
59   SCM_ASSERT_TYPE (ly_c_symbol_p (grob), grob, SCM_ARG2, __FUNCTION__, "symbol");
60   SCM_ASSERT_TYPE (ly_c_symbol_p (eltprop), eltprop, SCM_ARG3, __FUNCTION__, "symbol");
61
62   execute_pushpop_property (tg, grob, eltprop, val);
63
64   return SCM_UNSPECIFIED;
65 }
66
67 LY_DEFINE (ly_context_property, "ly:context-property",
68            2, 0, 0, (SCM c, SCM name),
69           "Return the value of @var{name} from context @var{c}")
70 {
71   Context *t = unsmob_context (c);
72   Context * tr= (t);
73   SCM_ASSERT_TYPE (tr, c, SCM_ARG1, __FUNCTION__, "Translator group");
74   SCM_ASSERT_TYPE (ly_c_symbol_p (name), name, SCM_ARG2, __FUNCTION__, "symbol");
75
76   return tr->internal_get_property (name);
77 }
78
79 LY_DEFINE (ly_context_set_property, "ly:context-set-property!",
80            3, 0, 0, (SCM context, SCM name, SCM val),
81            "Set value of property @var{name} in context @var{context} "
82            "to @var{val}.")
83 {
84   Context *tr = unsmob_context (context);
85   SCM_ASSERT_TYPE (tr, context, SCM_ARG1, __FUNCTION__, "Context");
86   SCM_ASSERT_TYPE (ly_c_symbol_p (name), name, SCM_ARG2, __FUNCTION__, "symbol");
87
88   tr->internal_set_property (name, val);
89
90   return SCM_UNSPECIFIED;
91 }
92
93 LY_DEFINE (ly_context_property_where_defined, "ly:context-property-where-defined",
94            2, 0, 0, (SCM context, SCM name),
95            "Return the context above @var{context} "
96            "where @var{name} is defined.")
97 {
98   Context *tr = unsmob_context (context);
99   SCM_ASSERT_TYPE (tr, context, SCM_ARG1, __FUNCTION__, "Context");
100   SCM_ASSERT_TYPE (ly_c_symbol_p (name), name, SCM_ARG2, __FUNCTION__, "symbol");
101
102   tr = tr->where_defined (name);
103   if (tr)
104     return tr->self_scm ();
105
106   return SCM_EOL;
107 }
108
109 LY_DEFINE (ly_unset_context_property, "ly:context-unset-property", 2, 0, 0,
110            (SCM context, SCM name),
111            "Unset value of property @var{name} in context @var{context}.")
112 {
113   Context *tr = unsmob_context (context);
114   SCM_ASSERT_TYPE (tr, context, SCM_ARG1, __FUNCTION__, "Context");
115   SCM_ASSERT_TYPE (ly_c_symbol_p (name), name, SCM_ARG2, __FUNCTION__, "symbol");
116
117   tr->unset_property (name);
118   return SCM_UNSPECIFIED;
119 }
120
121 LY_DEFINE (ly_context_parent, "ly:context-parent",
122            1, 0, 0, (SCM context),
123            "Return the parent of @var{context}, @code{#f} if none.")
124 {
125   Context *tr = unsmob_context (context);
126   SCM_ASSERT_TYPE (tr, context, SCM_ARG1, __FUNCTION__, "Context");
127
128   tr = tr->get_parent_context () ;
129   if (tr)
130     return tr->self_scm ();
131   else
132     return SCM_BOOL_F;
133 }
134
135 /* FIXME: todo: should support translator IDs, and creation? */
136 LY_DEFINE (ly_context_find, "ly:context-find",
137            2, 0, 0, (SCM context, SCM name),
138            "Find a parent of @var{context} that has name or alias @var{name}. "
139            "Return @code{#f} if not found.")
140 {
141   Context *tr = unsmob_context (context);
142   SCM_ASSERT_TYPE (tr, context, SCM_ARG1, __FUNCTION__, "context");
143   SCM_ASSERT_TYPE (ly_c_symbol_p (name), name, SCM_ARG2, __FUNCTION__, "symbol");
144   
145   while (tr)
146     {
147       if (tr->is_alias (name))
148         return tr->self_scm ();
149       tr =  tr->get_parent_context () ;
150     }
151   
152   return SCM_BOOL_F;
153 }