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