]> git.donarmstrong.com Git - lilypond.git/blob - lily/midi-stream.cc
partial: 0.0.39-1.jcn
[lilypond.git] / lily / midi-stream.cc
1 //
2 // midistream.cc
3 //
4 // source file of the 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, int tracks_i, int clocks_per_4_i ) 
19 {
20     filename_str_ = filename_str;
21     tracks_i_ = tracks_i;
22     clocks_per_4_i_ = clocks_per_4_i;
23     os_p_ = 0;
24     open();
25     header();
26 }
27
28 Midi_stream::~Midi_stream()
29 {
30     delete os_p_;
31 }
32
33 Midi_stream&
34 Midi_stream::operator <<( String str )
35 {
36     // still debugging...
37     if ( check_debug )
38         str = String_convert::bin2hex_str( str );
39     // string now 1.0.26-2 handles binary streaming
40     *os_p_ << str;
41     return *this;
42 }
43
44 Midi_stream&
45 Midi_stream::operator <<( Midi_item const& mitem_c_r )
46 {
47     mitem_c_r.output_midi( *this );
48     if ( check_debug )
49         *os_p_ << "\n";
50     return *this;
51 }
52
53 Midi_stream&
54 Midi_stream::operator <<( int i )
55 {
56     // output binary string ourselves
57     *this << Midi_item::i2varint_str( i );
58     return *this;
59 }
60
61 void
62 Midi_stream::header()
63 {
64 //    *os_p_ << "% Creator: " << get_version();
65 //    *os_p_ << "% Automatically generated, at ";
66 //    time_t t(time(0));
67 //    *os_p_ << ctime(&t);
68
69 //                4D 54 68 64     MThd
70 //    String str = "MThd";
71 //                00 00 00 06     chunk length
72 //                00 01   format 1
73 //                00 01   one track
74 //                00 60   96 per quarter-note
75
76 //    char const ch_c_l = "0000" "0006" "0001" "0001" "0060";
77 //    str += String_convert::hex2bin_str( ch_c_l );
78 //    *os_p_ << str;
79
80 //      *this << Midi_header( 1, 1, tempo_i_ );
81       *this << Midi_header( 1, tracks_i_, clocks_per_4_i_ );
82 }
83
84 void
85 Midi_stream::open()
86 {
87     os_p_ = new ofstream( filename_str_ );
88     if ( !*os_p_ )
89         error ("can't open `" + filename_str_ + "\'" );
90 }