]> git.donarmstrong.com Git - lilypond.git/blob - lily/context-scheme.cc
* scripts/lilypond-book.py (do_file): do not overwrite input file.
[lilypond.git] / lily / context-scheme.cc
1 #include "context.hh"
2 #include "context-def.hh"
3
4
5 LY_DEFINE(ly_context_id,
6           "ly:context-id", 1,0,0,  (SCM context),
7           "Return the id string of @var{context}, i.e. for @code{\\context Voice "
8 "= one .. } it will return the string @code{one}.")
9 {
10   Context * tr =   (unsmob_context (context));
11   SCM_ASSERT_TYPE(tr, context, SCM_ARG1, __FUNCTION__, "Context");
12
13   return scm_makfrom0str (tr->id_string_. to_str0 ());
14 }
15
16
17 LY_DEFINE(ly_context_name,
18           "ly:context-name", 1,0,0,  (SCM context),
19           "Return the name of @var{context}, i.e. for @code{\\context Voice "
20 "= one .. } it will return the symbol @code{Voice}.")
21 {
22   Context * tr =   (unsmob_context (context));
23   SCM_ASSERT_TYPE(tr, context, SCM_ARG1, __FUNCTION__, "Context");
24
25   return unsmob_context_def (tr->definition_)->get_context_name (); 
26 }
27
28
29 LY_DEFINE(ly_context_pushpop_property,
30           "ly:context-pushpop-property", 3, 1, 0,
31           (SCM context, SCM grob, SCM eltprop, SCM val),
32           "Do a single @code{\\override} or @code{\\revert} operation "
33           "in @var{context}. The grob definition @code{grob} is extended with "
34           "@code{eltprop} (if @var{val} is specified) "
35           "or reverted (if  unspecified).")
36 {
37   Context *tg =  (unsmob_context (context));
38
39   SCM_ASSERT_TYPE(tg, context, SCM_ARG1, __FUNCTION__, "context");
40   SCM_ASSERT_TYPE(gh_symbol_p (grob), grob, SCM_ARG2, __FUNCTION__, "symbol");
41   SCM_ASSERT_TYPE(gh_symbol_p (eltprop), eltprop, SCM_ARG3, __FUNCTION__, "symbol");
42
43   execute_pushpop_property (tg, grob, eltprop, val);
44
45   return SCM_UNDEFINED;
46 }
47
48
49 LY_DEFINE(ly_context_property,
50           "ly:context-property", 2, 0, 0,
51           (SCM context, SCM name),
52           "retrieve the value of @var{name} from context @var{context}")
53 {
54   Context *t = unsmob_context (context);
55   Context * tr=    (t);
56   SCM_ASSERT_TYPE(tr, context, SCM_ARG1, __FUNCTION__, "Translator group");
57   SCM_ASSERT_TYPE(gh_symbol_p (name), name, SCM_ARG2, __FUNCTION__, "symbol");
58
59   return tr->internal_get_property (name);
60   
61 }
62
63 LY_DEFINE(ly_context_set_property,
64           "ly:context-set-property!", 3, 0, 0,
65           (SCM context, SCM name, SCM val),
66           "set value of property @var{name} in context @var{context} to @var{val}.")
67 {
68   Context *t = unsmob_context (context);
69   Context * tr=    (t);
70
71   SCM_ASSERT_TYPE(tr, context, SCM_ARG1, __FUNCTION__, "Context");
72   SCM_ASSERT_TYPE(gh_symbol_p (name), name, SCM_ARG2, __FUNCTION__, "symbol");
73
74   tr->internal_set_property (name, val);
75
76   return SCM_UNSPECIFIED;
77 }
78
79
80 LY_DEFINE(ly_context_property_where_defined,
81           "ly:context-property-where-defined", 2, 0, 0,
82           (SCM context, SCM name),
83           "Return the context above @var{context} where @var{name}  is defined.")
84 {
85   Context *t = unsmob_context (context);
86   Context * tr =  (t);
87   SCM_ASSERT_TYPE(tr, context, SCM_ARG1, __FUNCTION__, "Context");
88   SCM_ASSERT_TYPE(gh_symbol_p (name), name, SCM_ARG2, __FUNCTION__, "symbol");
89
90
91   tr = tr->where_defined (name);
92
93   if (tr)
94     return tr->self_scm();
95
96   return SCM_EOL;
97 }
98
99 LY_DEFINE(ly_unset_context_property,
100           "ly:unset-context-property", 2, 0, 0,
101           (SCM context, SCM name),
102           "Unset value of property @var{name} in context @var{context}.")
103 {
104   Context *t = unsmob_context (context);
105   Context * tr =  (t);
106   SCM_ASSERT_TYPE(tr, context, SCM_ARG1, __FUNCTION__, "Context");
107   SCM_ASSERT_TYPE(gh_symbol_p (name), name, SCM_ARG2, __FUNCTION__, "symbol");
108
109   tr->unset_property (name);
110
111   return SCM_UNSPECIFIED;
112 }
113
114
115
116 LY_DEFINE(ly_context_parent,
117           "ly:context-parent", 1, 0, 0,
118           (SCM context),
119           "Return the parent of @var{context}, #f if none.")
120 {
121   Context *t = unsmob_context (context);
122   Context * tr=    (t);
123
124   SCM_ASSERT_TYPE(tr, context, SCM_ARG1, __FUNCTION__, "Context");
125
126   tr =  tr->daddy_context_ ;
127   if (tr)
128     return tr->self_scm();
129   else
130     return SCM_BOOL_F;
131 }
132
133 /*
134   Todo: should support translator IDs, and creation?
135  */
136 LY_DEFINE(ly_translator_find,
137           "ly:translator-find", 2, 0,0,
138           (SCM context, SCM name),
139           "Find a parent of @var{context} that has name or alias @var{name}. "
140           "Return @code{#f} if not found." )
141 {
142   Context * tr=    ( unsmob_context (context));
143
144   SCM_ASSERT_TYPE(tr, context, SCM_ARG1, __FUNCTION__, "context");
145   SCM_ASSERT_TYPE(gh_symbol_p (name), name, SCM_ARG2, __FUNCTION__, "symbol");
146   
147   while (tr)
148     {
149       if (tr->is_alias (name))
150         return tr->self_scm();
151       tr =  tr->daddy_context_ ;
152     }
153   
154   return SCM_BOOL_F;
155 }
156
157
158 LY_DEFINE(ly_context_properties,
159           "ly:context-properties", 1, 0, 0,
160           (SCM context),
161           "Return all properties  of @var{context} in an alist.")
162 {
163   Context *t = unsmob_context (context);
164   Context * tr= (t);
165
166   SCM_ASSERT_TYPE(tr, context, SCM_ARG1, __FUNCTION__, "Context");
167
168   return tr->properties_as_alist ();
169 }