4 // source file of the LilyPond music typesetter
6 // (c) 1997 Jan Nieuwenhuizen <jan@digicash.com>
11 #include "mi2mu-global.hh"
12 #include "mudela-item.hh"
13 #include "mudela-stream.hh"
15 extern String filename_str_g;
17 static int const INDENT_i = 8;
19 Mudela_stream::Mudela_stream (String filename_str)
21 filename_str_ = filename_str;
22 pending_indent_i_ = 0;
25 comment_mode_b_ = false;
32 Mudela_stream::~Mudela_stream()
36 warning (_("lily indent level: ") + String (indent_i_));
40 Mudela_stream::operator << (String str)
42 static String word_sep_str = "{} \t\n";
43 while (str.length_i())
45 int i = str.index_any_i (word_sep_str) + 1;
48 String word = str.left_str (i);
49 str = str.mid_str (i, str.length_i());
50 output_wrapped (word);
56 Mudela_stream::operator << (Mudela_item& mudela_item_r)
58 mudela_item_r.output (*this);
64 Mudela_stream::handle_pending_indent()
66 *os_p_ << String ('\t', pending_indent_i_);
67 column_i_ += pending_indent_i_ * INDENT_i;
68 pending_indent_i_ = 0;
72 Mudela_stream::header()
74 *os_p_ << _("% Creator: ") << mi2mu_version_str() << "\n";
75 *os_p_ << _("% Automatically generated, at ");
78 *os_p_ << _("% from input file: ");
79 // *os_p_ << midi_parser_l_g->filename_str_;
81 *os_p_ << filename_str_g;
84 *os_p_ << "\\version \"0.1.6\";\n";
90 os_p_ = new ofstream (filename_str_.ch_C ());
92 error (_("can't open: `") + filename_str_ + "\'");
96 Mudela_stream::output (String str)
98 for (int i = 0; i < str.length_i(); i++)
105 handle_pending_indent();
106 if (column_i_ == indent_i_ * INDENT_i)
116 if (pending_indent_i_)
118 handle_pending_indent();
123 handle_pending_indent();
124 comment_mode_b_ = true;
129 handle_pending_indent();
131 column_i_ += INDENT_i;
135 pending_indent_i_ = indent_i_;
137 comment_mode_b_ = false;
140 handle_pending_indent();
149 Mudela_stream::output_wrapped (String str)
151 // enough room left -> doit
152 if (column_i_ + str.length_i() <= wrap_column_i_)
158 // we're at BOL already; this will never fit -> doit
159 if (column_i_ == indent_i_ * INDENT_i)
166 // preserve comment mode
168 output (String ("\n%"));
170 output (String ("\n"));