]> git.donarmstrong.com Git - lilypond.git/blob - lily/translator-scheme.cc
* scm/chords-ignatzek.scm: new file.
[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   tr->internal_set_property (name, val);
40
41   return SCM_UNSPECIFIED;
42 }
43
44
45 LY_DEFINE(ly_context_parent,
46           "ly:context-parent", 1, 0, 0,
47           (SCM context),
48           "Return the parent of @var{context}, #f if none.")
49 {
50   Translator *t = unsmob_translator (context);
51   Translator_group* tr=   dynamic_cast<Translator_group*> (t);
52
53   SCM_ASSERT_TYPE(tr, context, SCM_ARG1, __FUNCTION__, "Context");
54
55   tr =  tr->daddy_trans_ ;
56   if (tr)
57     return tr->self_scm();
58   else
59     return SCM_BOOL_F;
60 }
61
62
63
64 LY_DEFINE(ly_context_properties,
65           "ly:context-properties", 1, 0, 0,
66           (SCM context),
67           "Return all properties  of @var{context} in an alist.")
68 {
69   Translator *t = unsmob_translator (context);
70   Translator_group* tr=   dynamic_cast<Translator_group*> (t);
71
72   SCM_ASSERT_TYPE(tr, context, SCM_ARG1, __FUNCTION__, "Context");
73
74   return tr->properties_as_alist ();
75 }
76
77
78
79 LY_DEFINE(ly_translator_name,
80           "ly:translator-name", 1,0,0,  (SCM trans),
81           "Return the type name of the translator @var{trans}.")
82 {
83   Translator* tr =  unsmob_translator (trans);
84   SCM_ASSERT_TYPE(tr, trans, SCM_ARG1, __FUNCTION__, "Context");
85
86   char const* nm = classname (tr);
87   return scm_makfrom0str (nm);
88 }
89
90 LY_DEFINE(ly_translator_description,
91           "ly:translator-description",
92           1,0,0, (SCM me),
93           "Return an alist of properties of  translator @var{me}.")
94 {
95   Translator *tr =unsmob_translator (me);
96   SCM_ASSERT_TYPE (tr, me, SCM_ARG1, __FUNCTION__, "Context");
97
98   return tr->translator_description ();
99 }
100
101
102 int
103 Translator::print_smob (SCM s, SCM port, scm_print_state *)
104 {
105   Translator *sc = (Translator *) ly_cdr (s);
106      
107   scm_puts ("#<Translator ", port);
108   if (Translator_def *d=unsmob_translator_def (sc->definition_))
109     {
110       scm_display (d->type_name_, port);
111     }
112   else
113     scm_display (ly_translator_name (s), port);
114
115   scm_display (sc->simple_trans_list_, port);
116
117   /*
118     don't try to print properties, that is too much hassle.
119    */
120   scm_puts (" >", port);
121   
122   return 1;
123 }