]> git.donarmstrong.com Git - lilypond.git/blob - lily/midi-stream.cc
(parse_symbol_list): Bugfix.
[lilypond.git] / lily / midi-stream.cc
1 /*
2   midi-stream.cc -- implement Midi_stream
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997--2005 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include "midi-stream.hh"
10
11 #include <errno.h>
12
13 #include "stream.hh"
14 #include "string-convert.hh"
15 #include "main.hh"
16 #include "misc.hh"
17 #include "midi-item.hh"
18 #include "warn.hh"
19 #include "program-option.hh"
20
21 Midi_stream::Midi_stream (String file_name)
22 {
23   file_name_string_ = file_name;
24   out_file_ = fopen (file_name.to_str0 (), "wb");
25   if (!out_file_)
26     error (_f ("can't open for write: %s: %s", file_name, strerror (errno)));
27 }
28
29 Midi_stream::~Midi_stream ()
30 {
31   fclose (out_file_);
32 }
33
34 Midi_stream &
35 Midi_stream::operator << (String str)
36 {
37   size_t sz = sizeof (Byte);
38   size_t n = str.length ();
39   size_t written = fwrite (str.get_bytes (),
40                            sz, n, out_file_);
41
42   if (written != sz * n)
43     warning (_ ("can't write to file: `%s'"));
44
45   return *this;
46 }
47
48 Midi_stream &
49 Midi_stream::operator << (Midi_item const &midi_c_r)
50 {
51   String str = midi_c_r.to_string ();
52
53   // ugh, should have separate debugging output with Midi*::print routines
54   if (do_midi_debugging_global)
55     {
56       str = String_convert::bin2hex (str) + "\n";
57       for (int i = str.index ("0a"); i >= 0; i = str.index ("0a"))
58         {
59           str[i] = '\n';
60           str[i + 1] = '\t';
61         }
62     }
63
64   return operator << (str);
65 }
66
67 Midi_stream&
68 Midi_stream::operator << (int i)
69 {
70   // output binary string ourselves
71   *this << Midi_item::i2varint_string (i);
72   return *this;
73 }
74