]> git.donarmstrong.com Git - lilypond.git/blob - lily/midi-stream.cc
Web-ja: update introduction
[lilypond.git] / lily / midi-stream.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1997--2015 Jan Nieuwenhuizen <janneke@gnu.org>
5
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.
10
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.
15
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/>.
18 */
19
20 #include "midi-stream.hh"
21
22 #include <cerrno>
23 using namespace std;
24
25 #include "international.hh"
26 #include "main.hh"
27 #include "midi-chunk.hh"
28 #include "misc.hh"
29 #include "program-option.hh"
30 #include "string-convert.hh"
31 #include "warn.hh"
32
33 Midi_stream::Midi_stream (const string &file_name)
34 {
35   file_name_string_ = file_name;
36   out_file_ = fopen (file_name.c_str (), "wb");
37   if (!out_file_)
38     error (_f ("cannot open for write: %s: %s", file_name, strerror (errno)));
39 }
40
41 Midi_stream::~Midi_stream ()
42 {
43   fclose (out_file_);
44 }
45
46 void
47 Midi_stream::write (const string &str)
48 {
49   size_t sz = sizeof (Byte);
50   size_t n = str.length ();
51   size_t written = fwrite (str.data (), sz, n, out_file_);
52
53   if (written != sz * n)
54     warning (_f ("cannot write to file: `%s'", file_name_string_.c_str ()));
55 }
56
57 void
58 Midi_stream::write (Midi_chunk const &midi)
59 {
60   string str = midi.to_string ();
61
62   return write (str);
63 }
64