lilypond-1.3.147
[lilypond.git] / src / midi-stream.cc
blob3630831ac68a8bcc11bb50582067d913ea2862a5
1 //
2 // midi-stream.cc
3 //
4 // source file of the LilyPond music typesetter
5 //
6 // (c) 1997 Jan Nieuwenhuizen <jan@digicash.com>
8 #include <fstream.h>
9 #include <time.h>
10 #include "main.hh"
11 #include "misc.hh"
12 #include "midi-item.hh"
13 #include "midi-stream.hh"
14 #include "debug.hh"
15 #include "string-convert.hh"
17 Midi_stream::Midi_stream( String filename_str, int tracks_i, int clocks_per_4_i )
19 filename_str_ = filename_str;
20 tracks_i_ = tracks_i;
21 clocks_per_4_i_ = clocks_per_4_i;
22 os_p_ = 0;
23 open();
24 header();
27 Midi_stream::~Midi_stream()
29 delete os_p_;
32 Midi_stream&
33 Midi_stream::operator <<( String str )
35 // still debugging...
36 if ( check_debug )
37 str = String_convert::bin2hex_str( str );
38 // string now 1.0.26-2 handles binary streaming
39 *os_p_ << str;
40 return *this;
43 Midi_stream&
44 Midi_stream::operator <<( Midi_item& mitem_r )
46 mitem_r.output_midi( *this );
47 if ( check_debug )
48 *os_p_ << "\n";
49 return *this;
52 Midi_stream&
53 Midi_stream::operator <<( int i )
55 // output binary string ourselves
56 *this << Midi_item::i2varint_str( i );
57 return *this;
60 void
61 Midi_stream::header()
63 // *os_p_ << "% Creator: " << get_version();
64 // *os_p_ << "% Automatically generated, at ";
65 // time_t t(time(0));
66 // *os_p_ << ctime(&t);
68 // 4D 54 68 64 MThd
69 // String str = "MThd";
70 // 00 00 00 06 chunk length
71 // 00 01 format 1
72 // 00 01 one track
73 // 00 60 96 per quarter-note
75 // char const ch_c_l = "0000" "0006" "0001" "0001" "0060";
76 // str += String_convert::hex2bin_str( ch_c_l );
77 // *os_p_ << str;
79 // *this << Midi_header( 1, 1, tempo_i_ );
80 *this << Midi_header( 1, tracks_i_, clocks_per_4_i_ );
83 void
84 Midi_stream::open()
86 os_p_ = new ofstream( filename_str_ );
87 if ( !*os_p_ )
88 error ("can't open `" + filename_str_ + "\'" );