]> git.donarmstrong.com Git - lilypond.git/blob - lily/midi-stream.cc
release: 0.1.61
[lilypond.git] / lily / midi-stream.cc
1 //
2 // midi-stream.cc
3 //
4 // source file of the GNU LilyPond music typesetter
5 //
6 // (c)  1997--1998 Jan Nieuwenhuizen <jan@digicash.com>
7
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"
16
17 Midi_stream::Midi_stream (String filename_str)
18 {
19   filename_str_ = filename_str;
20   os_p_ = 0;
21   open ();
22 }
23
24 Midi_stream::~Midi_stream ()
25 {
26   *os_p_ << flush;              // ugh. Share with tex_stream.
27   if (!*os_p_)
28     {
29       warning (_ ("error syncing file (disk full?)"));
30       exit_status_i_ = 1;
31     }
32   delete os_p_;
33 }
34
35 Midi_stream&
36 Midi_stream::operator << (String str)
37 {
38   *os_p_ << str;
39   return *this;
40 }
41
42 Midi_stream&
43 Midi_stream::operator << (Midi_item const& mitem_c_r)
44 {
45 //    *this <<mitem_c_r.str (); 
46   String str = mitem_c_r.str ();
47   if (check_debug && !monitor->silent_b ("Midistrings")) 
48     {
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)
53       {
54         str[i] = '\n';
55         str[i + 1] = '\t';
56         i = str.index_i ("0a");
57       }
58     }
59
60   *os_p_ << str;
61   return *this;
62 }
63
64 Midi_stream&
65 Midi_stream::operator << (int i)
66 {
67   // output binary string ourselves
68   *this << Midi_item::i2varint_str (i);
69   return *this;
70 }
71
72 void
73 Midi_stream::open ()
74 {
75   os_p_ = new ofstream (filename_str_.ch_C ());
76   if (!*os_p_)
77     error (_ ("can't open `") + filename_str_ + "\'");
78 }