]> git.donarmstrong.com Git - lilypond.git/blob - lily/midi-stream.cc
(operator <<): Also write MIDI string when
[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--2003 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9
10 #include "stream.hh"
11 #include "string.hh"
12 #include "string-convert.hh"
13 #include "main.hh"
14 #include "misc.hh"
15 #include "midi-item.hh"
16 #include "midi-stream.hh"
17 #include "warn.hh"
18 #include "scm-option.hh"
19
20 Midi_stream::Midi_stream (String filename)
21 {
22   filename_string_ = filename;
23   out_file_ = fopen (filename.to_str0(), "wb");
24 }
25
26 Midi_stream::~Midi_stream ()
27 {
28   fclose (out_file_);
29 }
30
31 Midi_stream&
32 Midi_stream::operator << (String str)
33 {
34   Byte *b = str.get_bytes ();
35 #if 0
36   for (int sz = str.length (); sz--;)
37     {
38       fputc (*b, out_file_);
39       b++;
40     }
41 #else
42   for (int i = 0, n = str.length (); i < n; i++)
43     fputc (b[i], out_file_);
44 #endif
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 (midi_debug_global_b)
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