Fixes Issue 1504, allowing feather beam line breaking.
[lilypond/patrick.git] / lily / midi-stream.cc
blobc7a48ad706d1ee04456b214e7bf65f7e6ac34b18
1 /*
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"
22 #include <cerrno>
23 using namespace std;
25 #include "international.hh"
26 #include "main.hh"
27 #include "midi-chunk.hh"
28 #include "misc.hh"
29 #include "program-option.hh"
30 #include "stream.hh"
31 #include "string-convert.hh"
32 #include "warn.hh"
34 Midi_stream::Midi_stream (string file_name)
36 file_name_string_ = file_name;
37 out_file_ = fopen (file_name.c_str (), "wb");
38 if (!out_file_)
39 error (_f ("cannot open for write: %s: %s", file_name, strerror (errno)));
42 Midi_stream::~Midi_stream ()
44 fclose (out_file_);
47 void
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 ()));
58 void
59 Midi_stream::write (Midi_chunk const &midi)
61 string str = midi.to_string ();
63 return write (str);