]> git.donarmstrong.com Git - lilypond.git/blob - lily/midi-stream.cc
release: 0.1.46
[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   *os_p_ << str;
40   return *this;
41 }
42
43 Midi_stream&
44 Midi_stream::operator << (Midi_item const& mitem_c_r)
45 {
46 //    *this <<mitem_c_r.str (); 
47   String str = mitem_c_r.str ();
48   if (check_debug && !monitor->silent_b ("Midistrings")) 
49     {
50     str = String_convert::bin2hex_str (str) + "\n";
51     // ugh, should have separate debugging output with Midi*::print routines
52     int i = str.index_i ("0a");
53     while (i >= 0)
54       {
55         str[i] = '\n';
56         str[i + 1] = '\t';
57         i = str.index_i ("0a");
58       }
59     }
60
61   *os_p_ << str;
62   return *this;
63 }
64
65 Midi_stream&
66 Midi_stream::operator << (int i)
67 {
68   // output binary string ourselves
69   *this << Midi_item::i2varint_str (i);
70   return *this;
71 }
72
73 void
74 Midi_stream::open ()
75 {
76   os_p_ = new ofstream (filename_str_.ch_C ());
77   if (!*os_p_)
78     error (_ ("can't open `") + filename_str_ + "\'");
79 }