2 midi-stream.cc -- implement Midi_stream
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2006 Jan Nieuwenhuizen <janneke@gnu.org>
9 #include "midi-stream.hh"
14 #include "international.hh"
16 #include "midi-item.hh"
18 #include "program-option.hh"
20 #include "string-convert.hh"
23 Midi_stream::Midi_stream (string file_name)
25 file_name_string_ = file_name;
26 out_file_ = fopen (file_name.c_str (), "wb");
28 error (_f ("cannot open for write: %s: %s", file_name, strerror (errno)));
31 Midi_stream::~Midi_stream ()
37 Midi_stream::operator << (string str)
39 size_t sz = sizeof (Byte);
40 size_t n = str.length ();
41 size_t written = fwrite (str.data (), sz, n, out_file_);
43 if (written != sz * n)
44 warning (_ ("cannot 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 (ssize i = str.find ("0a"); i != NPOS; i = str.find ("0a"))
65 return operator << (str);
69 Midi_stream::operator << (int i)
71 // output binary string ourselves
72 *this << Midi_item::i2varint_string (i);