lilypond-0.1.46
[lilypond.git] / lily / midi-stream.cc
blobefc244c5de69538a56b997c85f5be076d2ce8112
1 //
2 // midistream.cc
3 //
4 // source file of the GNU LilyPond music typesetter
5 //
6 // (c) 1997 Jan Nieuwenhuizen <jan@digicash.com>
8 #include <fstream.h>
9 #include <time.h>
10 #include "string.hh"
11 #include "string-convert.hh"
12 #include "main.hh"
13 #include "misc.hh"
14 #include "midi-item.hh"
15 #include "midi-stream.hh"
16 #include "debug.hh"
18 Midi_stream::Midi_stream (String filename_str)
20 filename_str_ = filename_str;
21 os_p_ = 0;
22 open ();
25 Midi_stream::~Midi_stream ()
27 *os_p_ << flush; // ugh. Share with tex_stream.
28 if (!*os_p_)
30 warning (_ ("error syncing file (disk full?)"));
31 exit_status_i_ = 1;
33 delete os_p_;
36 Midi_stream&
37 Midi_stream::operator << (String str)
39 *os_p_ << str;
40 return *this;
43 Midi_stream&
44 Midi_stream::operator << (Midi_item const& mitem_c_r)
46 // *this <<mitem_c_r.str ();
47 String str = mitem_c_r.str ();
48 if (check_debug && !monitor->silent_b ("Midistrings"))
50 str = String_convert::bin2hex_str (str) + "\n";
51 // ugh, should have separate debugging output with Midi*::print routines
52 int i = str.index_i ("0a");
53 while (i >= 0)
55 str[i] = '\n';
56 str[i + 1] = '\t';
57 i = str.index_i ("0a");
61 *os_p_ << str;
62 return *this;
65 Midi_stream&
66 Midi_stream::operator << (int i)
68 // output binary string ourselves
69 *this << Midi_item::i2varint_str (i);
70 return *this;
73 void
74 Midi_stream::open ()
76 os_p_ = new ofstream (filename_str_.ch_C ());
77 if (!*os_p_)
78 error (_ ("can't open `") + filename_str_ + "\'");