]> git.donarmstrong.com Git - lilypond.git/blob - lily/midi-stream.cc
b353f92dc7af742d5aef3c44f088d9cc05254f1e
[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--2001 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include <fstream.h>
10 #include "paper-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   *os_p_ << str;
39   return *this;
40 }
41
42 Midi_stream&
43 Midi_stream::operator << (Midi_item const& midi_c_r)
44 {
45   String str = midi_c_r.str ();
46
47
48   if (midi_debug_global_b)
49     {
50      str = String_convert::bin2hex_str (str) + "\n";
51     // ugh, should have separate debugging output with Midi*::print routines
52     int i = str.index_i ("0a");
53     while (i >= 0)
54       {
55         str[i] = '\n';
56         str[i + 1] = '\t';
57         i = str.index_i ("0a");
58       }
59     }
60
61   *os_p_ << str;
62   return *this;
63 }
64
65 Midi_stream&
66 Midi_stream::operator << (int i)
67 {
68   // output binary string ourselves
69   *this << Midi_item::i2varint_str (i);
70   return *this;
71 }
72