2 midi-stream.cc -- implement Midi_stream
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2005 Jan Nieuwenhuizen <janneke@gnu.org>
9 #include "midi-stream.hh"
15 #include "string-convert.hh"
18 #include "midi-item.hh"
20 #include "program-option.hh"
22 Midi_stream::Midi_stream (String file_name)
24 file_name_string_ = file_name;
25 out_file_ = fopen (file_name.to_str0 (), "wb");
27 error (_f ("can't open for write: %s: %s", file_name, strerror (errno)));
30 Midi_stream::~Midi_stream ()
36 Midi_stream::operator << (String str)
38 size_t sz = sizeof (Byte);
39 size_t n = str.length ();
40 size_t written = fwrite (str.get_bytes (),
43 if (written != sz * n)
44 warning (_ ("can't write to file: `%s'"));
50 Midi_stream::operator << (Midi_item const &midi_c_r)
52 String str = midi_c_r.to_string ();
54 // ugh, should have separate debugging output with Midi*::print routines
55 if (do_midi_debugging_global)
57 str = String_convert::bin2hex (str) + "\n";
58 for (int i = str.index ("0a"); i >= 0; i = str.index ("0a"))
65 return operator << (str);
69 Midi_stream::operator << (int i)
71 // output binary string ourselves
72 *this << Midi_item::i2varint_string (i);