lilypond-1.3.28
[lilypond.git] / lily / midi-stream.cc
blob05fb19bc6df4327c5763a89acdb3c34430ec1493
1 //
2 // midi-stream.cc
3 //
4 // source file of the GNU LilyPond music typesetter
5 //
6 // (c) 1997--2000 Jan Nieuwenhuizen <janneke@gnu.org>
8 #include <fstream.h>
9 #include "string.hh"
10 #include "string-convert.hh"
11 #include "main.hh"
12 #include "misc.hh"
13 #include "midi-item.hh"
14 #include "midi-stream.hh"
15 #include "debug.hh"
17 Midi_stream::Midi_stream (String filename_str)
19 filename_str_ = filename_str;
20 os_p_ = 0;
21 open ();
24 Midi_stream::~Midi_stream ()
26 *os_p_ << flush; // ugh. Share with tex_stream.
27 if (!*os_p_)
29 warning (_ ("Error syncing file (disk full?)"));
30 exit_status_i_ = 1;
32 delete os_p_;
35 Midi_stream&
36 Midi_stream::operator << (String str)
38 *os_p_ << str;
39 return *this;
42 Midi_stream&
43 Midi_stream::operator << (Midi_item const& midi_c_r)
45 // *this <<midi_c_r.str ();
46 String str = midi_c_r.str ();
47 if (flower_dstream && !flower_dstream->silent_b ("Midistrings"))
49 str = String_convert::bin2hex_str (str) + "\n";
50 // ugh, should have separate debugging output with Midi*::print routines
51 int i = str.index_i ("0a");
52 while (i >= 0)
54 str[i] = '\n';
55 str[i + 1] = '\t';
56 i = str.index_i ("0a");
60 *os_p_ << str;
61 return *this;
64 Midi_stream&
65 Midi_stream::operator << (int i)
67 // output binary string ourselves
68 *this << Midi_item::i2varint_str (i);
69 return *this;
72 void
73 Midi_stream::open ()
75 os_p_ = new ofstream (filename_str_.ch_C (),ios::out|ios::bin);
76 if (!*os_p_)
77 error (_f ("Can't open file: `%s'", filename_str_));