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