]> git.donarmstrong.com Git - lilypond.git/blob - lily/translator-scheme.cc
* scm/music-functions.scm (set-octavation): new function.
[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   return tr->where_defined (name)->self_scm();
58 }
59
60 LY_DEFINE(ly_unset_context_property,
61           "ly:unset-context-property", 2, 0, 0,
62           (SCM context, SCM name),
63           "Unset value of property @var{name} in context @var{context}.")
64 {
65   Translator *t = unsmob_translator (context);
66   Translator_group* tr = dynamic_cast<Translator_group*> (t);
67   SCM_ASSERT_TYPE(tr, context, SCM_ARG1, __FUNCTION__, "Context");
68   SCM_ASSERT_TYPE(gh_symbol_p (name), name, SCM_ARG2, __FUNCTION__, "symbol");
69
70   tr->unset_property (name);
71
72   return SCM_UNSPECIFIED;
73 }
74
75
76
77 LY_DEFINE(ly_context_parent,
78           "ly:context-parent", 1, 0, 0,
79           (SCM context),
80           "Return the parent of @var{context}, #f if none.")
81 {
82   Translator *t = unsmob_translator (context);
83   Translator_group* tr=   dynamic_cast<Translator_group*> (t);
84
85   SCM_ASSERT_TYPE(tr, context, SCM_ARG1, __FUNCTION__, "Context");
86
87   tr =  tr->daddy_trans_ ;
88   if (tr)
89     return tr->self_scm();
90   else
91     return SCM_BOOL_F;
92 }
93
94
95
96 LY_DEFINE(ly_context_properties,
97           "ly:context-properties", 1, 0, 0,
98           (SCM context),
99           "Return all properties  of @var{context} in an alist.")
100 {
101   Translator *t = unsmob_translator (context);
102   Translator_group* tr=   dynamic_cast<Translator_group*> (t);
103
104   SCM_ASSERT_TYPE(tr, context, SCM_ARG1, __FUNCTION__, "Context");
105
106   return tr->properties_as_alist ();
107 }
108
109
110
111 LY_DEFINE(ly_translator_name,
112           "ly:translator-name", 1,0,0,  (SCM trans),
113           "Return the type name of the translator @var{trans}.")
114 {
115   Translator* tr =  unsmob_translator (trans);
116   SCM_ASSERT_TYPE(tr, trans, SCM_ARG1, __FUNCTION__, "Context");
117
118   char const* nm = classname (tr);
119   return scm_makfrom0str (nm);
120 }
121
122 LY_DEFINE(ly_translator_description,
123           "ly:translator-description",
124           1,0,0, (SCM me),
125           "Return an alist of properties of  translator @var{me}.")
126 {
127   Translator *tr =unsmob_translator (me);
128   SCM_ASSERT_TYPE (tr, me, SCM_ARG1, __FUNCTION__, "Context");
129
130   return tr->translator_description ();
131 }
132
133
134 int
135 Translator::print_smob (SCM s, SCM port, scm_print_state *)
136 {
137   Translator *sc = (Translator *) ly_cdr (s);
138      
139   scm_puts ("#<Translator ", port);
140   if (Translator_def *d=unsmob_translator_def (sc->definition_))
141     {
142       scm_display (d->type_name_, port);
143     }
144   else
145     scm_display (ly_translator_name (s), port);
146
147   scm_display (sc->simple_trans_list_, port);
148
149   /*
150     don't try to print properties, that is too much hassle.
151    */
152   scm_puts (" >", port);
153   
154   return 1;
155 }