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