]> git.donarmstrong.com Git - lilypond.git/blob - lily/midi-stream.cc
string() -> to_string()
[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   for (int sz = str.length (); sz--;)
36     {
37       fputc (*b, out_file_);
38       b++;
39     }
40   return *this;
41 }
42
43 Midi_stream&
44 Midi_stream::operator << (Midi_item const& midi_c_r)
45 {
46   String str = midi_c_r.to_string ();
47
48
49   if (midi_debug_global_b)
50     {
51      str = String_convert::bin2hex (str) + "\n";
52     // ugh, should have separate debugging output with Midi*::print routines
53     int i = str.index ("0a");
54     while (i >= 0)
55       {
56         str[i] = '\n';
57         str[i + 1] = '\t';
58         i = str.index ("0a");
59       }
60     }
61   else
62     {
63       Byte * b = str.get_bytes ();
64       for (int sz = str.length (); sz--;)
65         {
66           fputc (*b, out_file_);
67           b++;
68         }
69     }
70   
71   return *this;
72 }
73
74 Midi_stream&
75 Midi_stream::operator << (int i)
76 {
77   // output binary string ourselves
78   *this << Midi_item::i2varint_string (i);
79   return *this;
80 }
81