Docs: Add new procedure for barNumberVisibility
[lilypond/mpolesky.git] / lily / midi-stream.cc
blob8b84798f6200ec454577493aed020b6dff2c0dbc
1 /*
2 midi-stream.cc -- implement Midi_stream
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2009 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
9 #include "midi-stream.hh"
11 #include <cerrno>
12 using namespace std;
14 #include "international.hh"
15 #include "main.hh"
16 #include "midi-chunk.hh"
17 #include "misc.hh"
18 #include "program-option.hh"
19 #include "stream.hh"
20 #include "string-convert.hh"
21 #include "warn.hh"
23 Midi_stream::Midi_stream (string file_name)
25 file_name_string_ = file_name;
26 out_file_ = fopen (file_name.c_str (), "wb");
27 if (!out_file_)
28 error (_f ("cannot open for write: %s: %s", file_name, strerror (errno)));
31 Midi_stream::~Midi_stream ()
33 fclose (out_file_);
36 void
37 Midi_stream::write (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 (_f ("cannot write to file: `%s'", str.data ()));
47 void
48 Midi_stream::write (Midi_chunk const &midi)
50 string str = midi.to_string ();
52 return write (str);