]> git.donarmstrong.com Git - lilypond.git/blob - lily/midi-stream.cc
release: 0.1.21
[lilypond.git] / lily / midi-stream.cc
1 //
2 // midistream.cc
3 //
4 // source file of the GNU LilyPond music typesetter
5 //
6 // (c) 1997 Jan Nieuwenhuizen <jan@digicash.com>
7
8 #include <fstream.h>
9 #include <time.h>
10 #include "string.hh"
11 #include "string-convert.hh"
12 #include "main.hh"
13 #include "misc.hh"
14 #include "midi-item.hh"
15 #include "midi-stream.hh"
16 #include "debug.hh"
17
18 Midi_stream::Midi_stream (String filename_str)
19 {
20   filename_str_ = filename_str;
21   os_p_ = 0;
22   open();
23 }
24
25 Midi_stream::~Midi_stream()
26 {
27   *os_p_ << flush;              // ugh. Share with tex_stream.
28   if (!*os_p_)
29     {
30       warning("error syncing file (disk full?)");
31       exit_status_i_ = 1;
32     }  
33   delete os_p_;
34 }
35
36 Midi_stream&
37 Midi_stream::operator <<(String str)
38 {
39   if (check_debug && !monitor->silence("Midistrings"))
40     str = String_convert::bin2hex_str (str);
41   
42   *os_p_ << str;
43
44   if (check_debug && !monitor->silence("Midistrings"))
45     *os_p_ << "\n";
46
47   return *this;
48 }
49
50 Midi_stream&
51 Midi_stream::operator <<(Midi_item const& mitem_c_r)
52 {
53   //    *this << mitem_c_r.str();
54   mitem_c_r.output (this);
55   if (check_debug && !monitor->silence("Midistrings"))
56     *os_p_ << "\n";
57   return *this;
58 }
59
60 Midi_stream&
61 Midi_stream::operator <<(int i)
62 {
63   // output binary string ourselves
64   *this << Midi_item::i2varint_str (i);
65   return *this;
66 }
67
68 void
69 Midi_stream::open()
70 {
71   os_p_ = new ofstream (filename_str_.ch_C ());
72   if (!*os_p_)
73     error ("can't open `" + filename_str_ + "\'");
74 }