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