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