]> git.donarmstrong.com Git - lilypond.git/blob - lily/midi-stream.cc
976130a3f001cabcf542edb2d118fb156e918ce9
[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 //    *this <<midi_c_r.str (); 
41   String str = midi_c_r.str ();
42   if (flower_dstream && !flower_dstream->silent_b ("Midistrings")) 
43     {
44     str = String_convert::bin2hex_str (str) + "\n";
45     // ugh, should have separate debugging output with Midi*::print routines
46     int i = str.index_i ("0a");
47     while (i >= 0)
48       {
49         str[i] = '\n';
50         str[i + 1] = '\t';
51         i = str.index_i ("0a");
52       }
53     }
54
55   *os_p_ << str;
56   return *this;
57 }
58
59 Midi_stream&
60 Midi_stream::operator << (int i)
61 {
62   // output binary string ourselves
63   *this << Midi_item::i2varint_str (i);
64   return *this;
65 }
66