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