]> git.donarmstrong.com Git - lilypond.git/blob - lily/translator-scheme.cc
*** empty log message ***
[lilypond.git] / lily / translator-scheme.cc
1 /*   
2 translator-scheme.cc --  implement 
3
4 source file of the GNU LilyPond music typesetter
5
6 (c) 2002--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7
8  */
9
10 #include "translator.hh"
11 #include "translator-def.hh"
12
13 #include "translator-group.hh"
14 #include "lily-guile.hh"
15
16 LY_DEFINE(ly_get_context_property,
17           "ly:get-context-property", 2, 0, 0,
18           (SCM context, SCM name),
19           "retrieve the value of @var{name} from context @var{context}")
20 {
21   Translator *t = unsmob_translator (context);
22   Translator_group* tr=   dynamic_cast<Translator_group*> (t);
23   SCM_ASSERT_TYPE(tr, context, SCM_ARG1, __FUNCTION__, "Translator group");
24   SCM_ASSERT_TYPE(gh_symbol_p (name), name, SCM_ARG2, __FUNCTION__, "symbol");
25
26   return tr->internal_get_property (name);
27   
28 }
29
30 LY_DEFINE(ly_set_context_property,
31           "ly:set-context-property", 3, 0, 0,
32           (SCM context, SCM name, SCM val),
33           "set value of property @var{name} in context @var{context} to @var{val}.")
34 {
35   Translator *t = unsmob_translator (context);
36   Translator_group* tr=   dynamic_cast<Translator_group*> (t);
37
38   SCM_ASSERT_TYPE(tr, context, SCM_ARG1, __FUNCTION__, "Context");
39   SCM_ASSERT_TYPE(gh_symbol_p (name), name, SCM_ARG2, __FUNCTION__, "symbol");
40
41   tr->internal_set_property (name, val);
42
43   return SCM_UNSPECIFIED;
44 }
45
46
47 LY_DEFINE(ly_context_property_where_defined,
48           "ly:context-property-where-defined", 2, 0, 0,
49           (SCM context, SCM name),
50           "Return the context above @var{context} where @var{name}  is defined.")
51 {
52   Translator *t = unsmob_translator (context);
53   Translator_group* tr = dynamic_cast<Translator_group*> (t);
54   SCM_ASSERT_TYPE(tr, context, SCM_ARG1, __FUNCTION__, "Context");
55   SCM_ASSERT_TYPE(gh_symbol_p (name), name, SCM_ARG2, __FUNCTION__, "symbol");
56
57
58   tr = tr->where_defined (name);
59
60   if (tr)
61     return tr->self_scm();
62
63   return SCM_EOL;
64 }
65
66 LY_DEFINE(ly_unset_context_property,
67           "ly:unset-context-property", 2, 0, 0,
68           (SCM context, SCM name),
69           "Unset value of property @var{name} in context @var{context}.")
70 {
71   Translator *t = unsmob_translator (context);
72   Translator_group* tr = dynamic_cast<Translator_group*> (t);
73   SCM_ASSERT_TYPE(tr, context, SCM_ARG1, __FUNCTION__, "Context");
74   SCM_ASSERT_TYPE(gh_symbol_p (name), name, SCM_ARG2, __FUNCTION__, "symbol");
75
76   tr->unset_property (name);
77
78   return SCM_UNSPECIFIED;
79 }
80
81
82
83 LY_DEFINE(ly_context_parent,
84           "ly:context-parent", 1, 0, 0,
85           (SCM context),
86           "Return the parent of @var{context}, #f if none.")
87 {
88   Translator *t = unsmob_translator (context);
89   Translator_group* tr=   dynamic_cast<Translator_group*> (t);
90
91   SCM_ASSERT_TYPE(tr, context, SCM_ARG1, __FUNCTION__, "Context");
92
93   tr =  tr->daddy_trans_ ;
94   if (tr)
95     return tr->self_scm();
96   else
97     return SCM_BOOL_F;
98 }
99
100
101
102 LY_DEFINE(ly_context_properties,
103           "ly:context-properties", 1, 0, 0,
104           (SCM context),
105           "Return all properties  of @var{context} in an alist.")
106 {
107   Translator *t = unsmob_translator (context);
108   Translator_group* tr=   dynamic_cast<Translator_group*> (t);
109
110   SCM_ASSERT_TYPE(tr, context, SCM_ARG1, __FUNCTION__, "Context");
111
112   return tr->properties_as_alist ();
113 }
114
115
116
117 LY_DEFINE(ly_translator_name,
118           "ly:translator-name", 1,0,0,  (SCM trans),
119           "Return the type name of the translator @var{trans}.")
120 {
121   Translator* tr =  unsmob_translator (trans);
122   SCM_ASSERT_TYPE(tr, trans, SCM_ARG1, __FUNCTION__, "Context");
123
124   char const* nm = classname (tr);
125   return scm_makfrom0str (nm);
126 }
127
128 LY_DEFINE(ly_translator_description,
129           "ly:translator-description",
130           1,0,0, (SCM me),
131           "Return an alist of properties of  translator @var{me}.")
132 {
133   Translator *tr =unsmob_translator (me);
134   SCM_ASSERT_TYPE (tr, me, SCM_ARG1, __FUNCTION__, "Context");
135
136   return tr->translator_description ();
137 }
138
139
140 int
141 Translator::print_smob (SCM s, SCM port, scm_print_state *)
142 {
143   Translator *sc = (Translator *) ly_cdr (s);
144      
145   scm_puts ("#<Translator ", port);
146   if (Translator_def *d=unsmob_translator_def (sc->definition_))
147     {
148       scm_display (d->type_name_, port);
149     }
150   else
151     scm_display (ly_translator_name (s), port);
152
153   scm_display (sc->simple_trans_list_, port);
154
155   /*
156     don't try to print properties, that is too much hassle.
157    */
158   scm_puts (" >", port);
159   
160   return 1;
161 }