(Which properties to
[lilypond.git] / lily / midi-stream.cc
blobe5c760e7c07dc8e62dffd8dd22509a4d92027d72
1 /*
2 midi-stream.cc -- implement Midi_stream
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2004 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
10 #include "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 "warn.hh"
18 #include "scm-option.hh"
20 Midi_stream::Midi_stream (String filename)
22 filename_string_ = filename;
23 out_file_ = fopen (filename.to_str0(), "wb");
26 Midi_stream::~Midi_stream ()
28 fclose (out_file_);
31 Midi_stream&
32 Midi_stream::operator << (String str)
34 size_t sz = sizeof (Byte);
35 size_t n = str.length ();
36 size_t written = fwrite (str.get_bytes (),
37 sz, n, out_file_);
39 if (written != sz * n)
40 warning (_ ("Could not write file. Disk full?"));
42 return *this;
45 Midi_stream&
46 Midi_stream::operator << (Midi_item const& midi_c_r)
48 String str = midi_c_r.to_string ();
50 // ugh, should have separate debugging output with Midi*::print routines
51 if (midi_debug_global_b)
53 str = String_convert::bin2hex (str) + "\n";
54 for (int i = str.index ("0a"); i >= 0; i = str.index ("0a"))
56 str[i] = '\n';
57 str[i + 1] = '\t';
61 return operator << (str);
64 Midi_stream&
65 Midi_stream::operator << (int i)
67 // output binary string ourselves
68 *this << Midi_item::i2varint_string (i);
69 return *this;