4 // source file of the LilyPond music typesetter
6 // (c) 1997 Jan Nieuwenhuizen <jan@digicash.com>
10 #include "mi2mu-global.hh"
11 #include "my-midi-parser.hh"
12 #include "mudela-item.hh"
13 #include "mudela-stream.hh"
15 static int const INDENT_i = 8;
17 Mudela_stream::Mudela_stream (String filename_str)
19 filename_str_ = filename_str;
22 comment_mode_b_ = false;
29 Mudela_stream::~Mudela_stream()
33 warning ("lily indent level: " + String (indent_i_));
37 Mudela_stream::operator << (String str)
39 static String word_sep_str = "{} \t\n";
40 while (str.length_i())
42 int i = str.index_any_i (word_sep_str) + 1;
45 String word = str.left_str (i);
46 str = str.mid_str (i, str.length_i());
47 output_wrapped (word);
53 Mudela_stream::operator << (Mudela_item& mudela_item_r)
55 mudela_item_r.output (*this);
61 Mudela_stream::handle_pending_indent()
63 *os_p_ << String ('\t', pending_indent_i_);
64 column_i_ += pending_indent_i_ * INDENT_i;
65 pending_indent_i_ = 0;
69 Mudela_stream::header()
71 *os_p_ << "% Creator: " << mi2mu_version_str() << "\n";
72 *os_p_ << "% Automatically generated, at ";
75 *os_p_ << "% from input file: ";
76 *os_p_ << midi_parser_l_g->filename_str_;
79 *os_p_ << "\\version \"0.1.1\";\n";
85 os_p_ = new ofstream (filename_str_);
87 error ("can't open: `" + filename_str_ + "\'");
91 Mudela_stream::output (String str)
93 for (int i = 0; i < str.length_i(); i++)
100 handle_pending_indent();
101 if (column_i_ == indent_i_ * INDENT_i)
111 if (pending_indent_i_)
113 handle_pending_indent();
118 handle_pending_indent();
119 comment_mode_b_ = true;
124 handle_pending_indent();
126 column_i_ += INDENT_i;
130 pending_indent_i_ = indent_i_;
132 comment_mode_b_ = false;
135 handle_pending_indent();
144 Mudela_stream::output_wrapped (String str)
146 // enough room left -> doit
147 if (column_i_ + str.length_i() <= wrap_column_i_)
153 // we're at BOL already; this will never fit -> doit
154 if (column_i_ == indent_i_ * INDENT_i)
161 // preserve comment mode
163 output (String ("\n%"));
165 output (String ("\n"));