2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1997--2011 Jan Nieuwenhuizen <janneke@gnu.org>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
20 #include "midi-stream.hh"
25 #include "international.hh"
27 #include "midi-chunk.hh"
29 #include "program-option.hh"
31 #include "string-convert.hh"
34 Midi_stream::Midi_stream (string file_name
)
36 file_name_string_
= file_name
;
37 out_file_
= fopen (file_name
.c_str (), "wb");
39 error (_f ("cannot open for write: %s: %s", file_name
, strerror (errno
)));
42 Midi_stream::~Midi_stream ()
48 Midi_stream::write (string str
)
50 size_t sz
= sizeof (Byte
);
51 size_t n
= str
.length ();
52 size_t written
= fwrite (str
.data (), sz
, n
, out_file_
);
54 if (written
!= sz
* n
)
55 warning (_f ("cannot write to file: `%s'", str
.data ()));
59 Midi_stream::write (Midi_chunk
const &midi
)
61 string str
= midi
.to_string ();