4 // source file of the LilyPond music typesetter
6 // (c) 1997--1998, 1998 Jan Nieuwenhuizen <janneke@gnu.org>
11 #include "midi2ly-global.hh"
12 #include "mudela-item.hh"
13 #include "mudela-stream.hh"
14 #include "string-convert.hh"
16 extern String filename_str_g
;
18 static int const INDENT_i
= 8;
20 Mudela_stream::Mudela_stream (String filename_str
)
22 filename_str_
= filename_str
;
23 pending_indent_i_
= 0;
26 comment_mode_b_
= false;
33 Mudela_stream::~Mudela_stream ()
37 warning (_f ("lily indent level: %d", indent_i_
));
41 Mudela_stream::operator << (char c
)
48 Mudela_stream::operator << (String s
)
50 static String word_sep_str
= "{} \t\n";
53 int i
= s
.index_any_i (word_sep_str
) + 1;
56 String word
= s
.left_str (i
);
57 s
= s
.cut_str (i
, s
.length_i());
58 output_wrapped (word
);
64 Mudela_stream::operator << (Mudela_item
& mudela_item_r
)
66 mudela_item_r
.output (*this);
72 Mudela_stream::handle_pending_indent()
74 *os_p_
<< String_convert::char_str ('\t', pending_indent_i_
);
75 column_i_
+= pending_indent_i_
* INDENT_i
;
76 pending_indent_i_
= 0;
80 Mudela_stream::header()
82 /* Maybe better not to translate these? */
83 *os_p_
<< _ ("% Creator: ");
84 if (no_timestamps_b_g
)
85 *os_p_
<< "GNU LilyPond\n";
87 *os_p_
<< midi2ly_version_str() << '\n';
88 *os_p_
<< _ ("% Automatically generated");
89 if (no_timestamps_b_g
)
93 *os_p_
<< _ (", at ");
95 *os_p_
<< ctime (&t
) << "%\n";
97 *os_p_
<< _ ("% from input file: ");
98 // *os_p_ << midi_parser_l_g->filename_str_;
100 *os_p_
<< filename_str_g
;
103 *os_p_
<< "\\version \"1.3.76\";\n";
107 Mudela_stream::open()
109 os_p_
= new ofstream (filename_str_
.ch_C ());
111 error (_f ("can't open file: `%s'", filename_str_
));
115 Mudela_stream::output (String str
)
117 for (int i
= 0; i
< str
.length_i(); i
++)
124 handle_pending_indent();
125 if (column_i_
== indent_i_
* INDENT_i
)
135 if (pending_indent_i_
)
137 handle_pending_indent();
142 handle_pending_indent();
143 comment_mode_b_
= true;
148 handle_pending_indent();
150 column_i_
+= INDENT_i
;
154 pending_indent_i_
= indent_i_
;
156 comment_mode_b_
= false;
159 handle_pending_indent();
168 Mudela_stream::output_wrapped (String str
)
170 // enough room left -> doit
171 if (column_i_
+ str
.length_i() <= wrap_column_i_
)
177 // we're at BOL already; this will never fit -> doit
178 if (column_i_
== indent_i_
* INDENT_i
)
185 // preserve comment mode
187 output (String ("\n%"));
189 output (String ("\n"));