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.cut (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: ");
75 if (no_timestamps_b_g)
76 *os_p_ << "GNU LilyPond\n";
78 *os_p_ << mi2mu_version_str() << "\n";
79 *os_p_ << _("% Automatically generated");
80 if (no_timestamps_b_g)
86 *os_p_ << ctime (&t) << "%\n";
88 *os_p_ << _("% from input file: ");
89 // *os_p_ << midi_parser_l_g->filename_str_;
91 *os_p_ << filename_str_g;
94 *os_p_ << "\\version \"0.1.9\";\n";
100 os_p_ = new ofstream (filename_str_.ch_C ());
102 error (_("can't open: `") + filename_str_ + "\'");
106 Mudela_stream::output (String str)
108 for (int i = 0; i < str.length_i(); i++)
115 handle_pending_indent();
116 if (column_i_ == indent_i_ * INDENT_i)
126 if (pending_indent_i_)
128 handle_pending_indent();
133 handle_pending_indent();
134 comment_mode_b_ = true;
139 handle_pending_indent();
141 column_i_ += INDENT_i;
145 pending_indent_i_ = indent_i_;
147 comment_mode_b_ = false;
150 handle_pending_indent();
159 Mudela_stream::output_wrapped (String str)
161 // enough room left -> doit
162 if (column_i_ + str.length_i() <= wrap_column_i_)
168 // we're at BOL already; this will never fit -> doit
169 if (column_i_ == indent_i_ * INDENT_i)
176 // preserve comment mode
178 output (String ("\n%"));
180 output (String ("\n"));