]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-outputter.cc
release: 1.3.54
[lilypond.git] / lily / paper-outputter.cc
1 /*
2   paper-outputter.cc -- implement Paper_outputter
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   Jan Nieuwenhuizen <janneke@gnu.org>
8 */
9
10 #include <time.h>
11 #include <fstream.h>
12 #include <math.h>
13 #include <iostream.h>
14
15 #include "dimensions.hh"
16 #include "dictionary-iter.hh"
17 #include "virtual-methods.hh"
18 #include "paper-outputter.hh"
19 #include "paper-stream.hh"
20 #include "molecule.hh"
21 #include "array.hh"
22 #include "string-convert.hh"
23 #include "debug.hh"
24 #include "lookup.hh"
25 #include "main.hh"
26 #include "scope.hh"
27 #include "identifier.hh"
28 #include "lily-version.hh"
29
30
31 /*
32   Ugh, this is messy.
33  */
34
35 Paper_outputter::Paper_outputter (Paper_stream  * ps )
36 {
37  /*
38    lilypond -f scm x.ly
39    guile -s x.scm
40   */
41   verbatim_scheme_b_ =  output_global_ch == String ("scm");
42
43   if (verbatim_scheme_b_)
44     {
45         *ps << ""
46           ";;; Usage: guile -s x.scm > x.tex\n"
47           "(primitive-load-path 'lily.scm)\n"
48           "(scm-tex-output)\n"
49           ";(scm-ps-output)\n"
50           "(map (lambda (x) (display (eval x))) '(\n"
51         ;
52     }
53
54   stream_p_ = ps;
55 }
56
57 Paper_outputter::~Paper_outputter ()
58 {
59   if (verbatim_scheme_b_)
60     {
61       *stream_p_ << "))";
62     }
63   delete stream_p_;
64 }
65
66
67 void
68 Paper_outputter::output_header ()
69 {
70   if (safe_global_b)
71     {
72       gh_define ("security-paranoia", SCM_BOOL_T);      
73     }
74
75   SCM exp = gh_list (ly_symbol2scm ((String (output_global_ch) + "-scm").ch_C()),
76                      ly_quote_scm (ly_symbol2scm ("all-definitions")),
77                      SCM_UNDEFINED);
78   exp = scm_eval (exp);
79   scm_eval (exp);
80   
81   String creator;
82   if (no_timestamps_global_b)
83     creator = gnu_lilypond_str ();
84   else
85     creator = gnu_lilypond_version_str ();
86   
87   String generate;
88   if (no_timestamps_global_b)
89     generate = ".";
90   else
91     {
92       generate = _ (", at ");
93       time_t t (time (0));
94       generate += ctime (&t);
95       generate = generate.left_str (generate.length_i () - 1);
96     }
97
98   SCM args_scm = 
99     gh_list (ly_str02scm (creator.ch_l ()),
100              ly_str02scm (generate.ch_l ()), SCM_UNDEFINED);
101
102
103   SCM scm = gh_cons (ly_symbol2scm ("header"), args_scm);
104   output_scheme (scm);
105 }
106
107
108
109 void
110 Paper_outputter::output_comment (String str)
111 {
112   output_scheme (gh_list (ly_symbol2scm ("comment"),
113                           ly_str02scm ((char*)str.ch_C()),
114                           SCM_UNDEFINED)
115                  );
116 }
117
118
119 void
120 Paper_outputter::output_scheme (SCM scm)
121 {
122   /*
123     we don't rename dump_scheme, because we might in the future want
124     to remember Scheme. We don't now, because it sucks up a lot of memory.
125   */
126   dump_scheme (scm);
127 }
128
129
130 void
131 Paper_outputter::dump_scheme (SCM s)
132 {
133   if  (verbatim_scheme_b_)
134     {
135       SCM result =  scm_eval (scm_listify (ly_symbol2scm ("scm->string"),
136                                            ly_quote_scm (gh_car (s)), SCM_UNDEFINED));
137           
138       *stream_p_ << ly_scm2string (result);
139     }
140   else
141     {
142       SCM result = scm_eval (s);
143       char *c=gh_scm2newstr (result, NULL);
144   
145       *stream_p_ << c;
146       free (c);
147     }
148 }
149 void
150 Paper_outputter::output_scope (Scope *scope, String prefix)
151 {
152   for (Scope_iter i (*scope); i.ok (); i++)
153     {
154       if (dynamic_cast<String_identifier*> (i.val ()))
155         {
156           String val = *i.val()->access_content_String (false);
157
158           output_String_def (prefix + i.key (), val);
159         }
160       else if(dynamic_cast<Real_identifier*> (i.val ()))
161         {
162           Real val  = *i.val ()->access_content_Real (false);
163
164           output_Real_def (prefix + i.key (), val);       
165         }
166       else if (dynamic_cast<int_identifier*> (i.val ()))
167         {
168           int val  = *i.val ()->access_content_int (false);       
169           
170           output_int_def (prefix + i.key (), val);        
171         }
172     }
173 }
174
175 void
176 Paper_outputter::output_version ()
177 {
178   String id_str = "Lily was here";
179   if (no_timestamps_global_b)
180     id_str += ".";
181   else
182     id_str += String (", ") + version_str ();
183
184   output_String_def ( "mudelatagline", id_str);
185   output_String_def ( "LilyPondVersion", version_str ());
186 }
187
188
189
190 void
191 Paper_outputter::output_font_def (int i, String str)
192 {
193   SCM scm = gh_list (ly_symbol2scm ("font-def"),
194                      gh_int2scm (i),
195                      ly_str02scm (str.ch_l ()),
196                      SCM_UNDEFINED);
197
198   output_scheme (scm);
199 }
200
201 void
202 Paper_outputter::output_Real_def (String k, Real v)
203 {
204   
205   SCM scm = gh_list (ly_symbol2scm ("lily-def"),
206                      ly_str02scm (k.ch_l ()),
207                      ly_str02scm (to_str(v).ch_l ()),
208                      SCM_UNDEFINED);
209   output_scheme (scm);
210 }
211
212 void
213 Paper_outputter::output_String_def (String k, String v)
214 {
215   
216   SCM scm = gh_list (ly_symbol2scm ("lily-def"),
217                      ly_str02scm (k.ch_l ()),
218                      ly_str02scm (v.ch_l ()),
219                      SCM_UNDEFINED);
220   output_scheme (scm);
221 }
222
223 void
224 Paper_outputter::output_int_def (String k, int v)
225 {
226   SCM scm = gh_list (ly_symbol2scm ("lily-def"),
227                      ly_str02scm (k.ch_l ()),
228                      ly_str02scm (to_str (v).ch_l ()),
229                      SCM_UNDEFINED);
230   output_scheme (scm);
231 }
232
233
234
235
236