]> git.donarmstrong.com Git - lilypond.git/blob - lily/midi-stream.cc
midi fix
[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--2002 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 "debug.hh"
18 #include "scm-option.hh"
19
20 Midi_stream::Midi_stream (String filename)
21 {
22   filename_str_ = filename;
23 #if __GCC__ > 2
24   os_p_ = open_file_stream (filename, ios::out|ios::bin);
25 #else
26   os_p_ = open_file_stream (filename, ios::out|ios::binary);
27 #endif
28 }
29
30 Midi_stream::~Midi_stream ()
31 {
32   close_file_stream (os_p_);
33 }
34
35 Midi_stream&
36 Midi_stream::operator << (String str)
37 {
38   Byte * b = str.byte_l();
39   for (int sz = str.length_i (); sz--;)
40     *os_p_ << *b ++;
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.str ();
48
49
50   if (midi_debug_global_b)
51     {
52      str = String_convert::bin2hex_str (str) + "\n";
53     // ugh, should have separate debugging output with Midi*::print routines
54     int i = str.index_i ("0a");
55     while (i >= 0)
56       {
57         str[i] = '\n';
58         str[i + 1] = '\t';
59         i = str.index_i ("0a");
60       }
61     }
62   else
63     {
64       Byte * b = str.byte_l();
65       for (int sz = str.length_i (); sz--;)
66         *os_p_ << *b++;
67     }
68   
69   return *this;
70 }
71
72 Midi_stream&
73 Midi_stream::operator << (int i)
74 {
75   // output binary string ourselves
76   *this << Midi_item::i2varint_str (i);
77   return *this;
78 }
79