]> git.donarmstrong.com Git - lilypond.git/blob - lily/midi-stream.cc
Revert "Issue 4550 (2/2) Avoid "using namespace std;" in included files"
[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 using std::string;
34
35 Midi_stream::Midi_stream (const string &file_name)
36 {
37   file_name_string_ = file_name;
38   out_file_ = fopen (file_name.c_str (), "wb");
39   if (!out_file_)
40     error (_f ("cannot open for write: %s: %s", file_name, strerror (errno)));
41 }
42
43 Midi_stream::~Midi_stream ()
44 {
45   fclose (out_file_);
46 }
47
48 void
49 Midi_stream::write (const string &str)
50 {
51   size_t sz = sizeof (Byte);
52   size_t n = str.length ();
53   size_t written = fwrite (str.data (), sz, n, out_file_);
54
55   if (written != sz * n)
56     warning (_f ("cannot write to file: `%s'", str.data ()));
57 }
58
59 void
60 Midi_stream::write (Midi_chunk const &midi)
61 {
62   string str = midi.to_string ();
63
64   return write (str);
65 }
66