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