]> git.donarmstrong.com Git - lilypond.git/blob - lily/midi-stream.cc
patch::: 0.1.1.jcn1: zachte pats
[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, 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     if ( check_debug )
37         str = String_convert::bin2hex_str( str );
38     
39     *os_p_ << str;
40
41     if ( check_debug )
42         *os_p_ << "\n";
43
44     return *this;
45 }
46
47 Midi_stream&
48 Midi_stream::operator <<( Midi_item const& mitem_c_r )
49 {
50 //    *this << mitem_c_r.str();
51     mitem_c_r.output( this );
52     if ( check_debug )
53         *os_p_ << "\n";
54     return *this;
55 }
56
57 Midi_stream&
58 Midi_stream::operator <<( int i )
59 {
60     // output binary string ourselves
61     *this << Midi_item::i2varint_str( i );
62     return *this;
63 }
64
65 void
66 Midi_stream::header()
67 {
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       *this << Midi_header( 1, tracks_i_, clocks_per_4_i_ );
77 }
78
79 void
80 Midi_stream::open()
81 {
82     os_p_ = new ofstream( filename_str_ );
83     if ( !*os_p_ )
84         error ("can't open `" + filename_str_ + "\'" );
85 }