]> git.donarmstrong.com Git - lilypond.git/blob - lily/output-def.cc
* lily/output-def-scheme.cc: new file.
[lilypond.git] / lily / output-def.cc
1 /*
2   music-output-def.cc -- implement Output_def
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "output-def.hh"
10
11 #include "context-def.hh"
12 #include "file-path.hh"
13 #include "global-context.hh"
14 #include "interval.hh"
15 #include "ly-module.hh"
16 #include "main.hh"
17 #include "output-def.hh"
18 #include "scm-hash.hh"
19 #include "warn.hh"
20
21 #include "ly-smobs.icc"
22
23 Output_def::Output_def ()
24 {
25   scope_ = SCM_EOL;
26   parent_ = 0;
27   smobify_self ();
28
29   scope_ = ly_make_anonymous_module (false);
30 }
31
32 Output_def::Output_def (Output_def const &s)
33 {
34   scope_ = SCM_EOL;
35   parent_ = 0;
36   smobify_self ();
37
38   input_origin_ = s.input_origin_;
39   scope_ = ly_make_anonymous_module (false);
40   if (ly_c_module_p (s.scope_))
41     ly_module_copy (scope_, s.scope_);
42 }
43
44 Output_def::~Output_def ()
45 {
46 }
47
48 IMPLEMENT_SMOBS (Output_def);
49 IMPLEMENT_DEFAULT_EQUAL_P (Output_def);
50
51 SCM
52 Output_def::mark_smob (SCM m)
53 {
54   Output_def *mo = (Output_def*) SCM_CELL_WORD_1 (m);
55
56   /* FIXME: why is this necessary?
57      all paper_ should be protected by themselves. */
58   if (mo->parent_)
59     scm_gc_mark (mo->parent_->self_scm ());
60
61   return mo->scope_;
62 }
63
64 void
65 assign_context_def (Output_def * m, SCM transdef)
66 {
67   Context_def *tp = unsmob_context_def (transdef);
68   assert (tp);
69
70   if (tp)
71     {
72       SCM sym = tp->get_context_name ();
73       m->set_variable (sym, transdef);
74     }  
75 }
76
77 /* find the translator for NAME. NAME must be a symbol. */
78 SCM
79 find_context_def (Output_def const *m, SCM name)
80 {  
81   Context_def *cd = unsmob_context_def (m->lookup_variable (name));
82   return cd ? cd->self_scm () : SCM_EOL;
83 }
84
85 int
86 Output_def::print_smob (SCM s, SCM p, scm_print_state *)
87 {
88   Output_def * def = unsmob_output_def (s);
89   scm_puts ("#< ", p);
90   scm_puts (classname (def), p);
91   
92   (void)def;
93   scm_puts (">", p);
94   return 1;
95 }
96
97 Real
98 Output_def::get_dimension (SCM s) const
99 {
100   SCM val = lookup_variable (s);
101   return scm_to_double (val);
102 }
103
104 SCM
105 Output_def::lookup_variable (SCM sym) const
106 {
107   SCM var = ly_module_lookup (scope_, sym);
108   if (SCM_VARIABLEP (var) && SCM_VARIABLE_REF(var) != SCM_UNDEFINED)
109     return SCM_VARIABLE_REF (var);
110   
111   if (parent_)
112     return parent_->lookup_variable (sym);
113   
114   return SCM_EOL;
115 }
116
117 SCM
118 Output_def::c_variable (String s) const
119 {
120   return lookup_variable (ly_symbol2scm (s.to_str0 ()));
121 }
122
123 void
124 Output_def::set_variable (SCM sym, SCM val)
125 {
126   scm_module_define (scope_, sym, val);
127 }
128
129   
130 /* FIXME.  This is broken until we have a generic way of
131    putting lists inside the \layout block.  */
132 Interval
133 line_dimensions_int (Output_def *def, int n)
134 {
135   Real lw = def->get_dimension (ly_symbol2scm ("linewidth"));
136   Real ind = n ? 0.0 : def->get_dimension (ly_symbol2scm ("indent"));
137   return Interval (ind, lw);
138 }
139
140