]> git.donarmstrong.com Git - lilypond.git/blob - lily/midi-stream.cc
* flower
[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 "stream.hh"
12 #include "string-convert.hh"
13 #include "main.hh"
14 #include "misc.hh"
15 #include "midi-item.hh"
16 #include "warn.hh"
17 #include "scm-option.hh"
18
19 Midi_stream::Midi_stream (String file_name)
20 {
21   file_name_string_ = file_name;
22   out_file_ = fopen (file_name.to_str0 (), "wb");
23 }
24
25 Midi_stream::~Midi_stream ()
26 {
27   fclose (out_file_);
28 }
29
30 Midi_stream &
31 Midi_stream::operator<< (String str)
32 {
33   size_t sz = sizeof (Byte);
34   size_t n = str.length ();
35   size_t written = fwrite (str.get_bytes (),
36                            sz, n, out_file_);
37
38   if (written != sz * n)
39     warning (_ ("could not write file: `%s'"));
40
41   return *this;
42 }
43
44 Midi_stream &
45 Midi_stream::operator<< (Midi_item const &midi_c_r)
46 {
47   String str = midi_c_r.to_string ();
48
49   // ugh, should have separate debugging output with Midi*::print routines
50   if (midi_debug_global_b)
51     {
52       str = String_convert::bin2hex (str) + "\n";
53       for (int i = str.index ("0a"); i >= 0; i = str.index ("0a"))
54         {
55           str[i] = '\n';
56           str[i + 1] = '\t';
57         }
58     }
59
60   return operator << (str);
61 }
62
63 Midi_stream&
64 Midi_stream::operator << (int i)
65 {
66   // output binary string ourselves
67   *this << Midi_item::i2varint_string (i);
68   return *this;
69 }
70