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