]> git.donarmstrong.com Git - lilypond.git/blob - lily/score-performer.cc
release: 0.0.78
[lilypond.git] / lily / score-performer.cc
1 /*
2   score-performer.cc -- implement Score_performer
3
4   (c) 1996, 1997 Jan Nieuwenhuizen <jan@digicash.com>
5  */
6
7 #include <time.h>
8 #include "score-performer.hh"
9 #include "input-translator.hh"
10 #include "midi-def.hh"
11 #include "midi-item.hh"
12 #include "midi-stream.hh"
13 #include "string-convert.hh"
14 #include "debug.hh"
15 #include "main.hh"
16 #include "score.hh"
17 #include "source-file.hh"
18 #include "source.hh"
19
20 IMPLEMENT_IS_TYPE_B1(Score_performer,Performer_group_performer);
21 ADD_THIS_PERFORMER(Score_performer);
22
23 Score_performer::Score_performer()
24 {
25     midi_l_ = 0;
26 }
27
28 Score_performer::~Score_performer()
29 {
30 }
31
32 Translator* 
33 Score_performer::ancestor_l( int l ) 
34
35     return Global_translator::ancestor_l( l );
36 }
37
38 int 
39 Score_performer::depth_i() const 
40
41     return Global_translator::depth_i();
42 }
43
44 void
45 Score_performer::finish()
46 {
47     Performer_group_performer::do_removal_processing();
48
49
50     Midi_stream output_stream( midi_l_->outfile_str_, midi_item_p_arr_.size() + 1, 384 );    
51     *mlog << "MIDI output to " << midi_l_->outfile_str_ << " ..." << endl;    
52
53     header( output_stream);
54     int track_i = 1;
55     for (int i=0; i<  midi_item_p_arr_.size(); i++) {
56         Midi_item * it_p = midi_item_p_arr_[i];
57         
58         if ( it_p->is_type_b( Midi_track::static_name()))
59             ((Midi_track*)it_p )->number_i_ = track_i ++;
60         output_stream<< *it_p;
61     }
62     *output_stream.os_p_ << flush;
63     *mlog << endl;
64 }
65
66 void
67 Score_performer::play_event(Midi_item*m)
68 {
69     midi_item_p_arr_.push(m);
70 }
71
72 Moment
73 Score_performer::get_mom() const
74 {
75     return now_mom_;
76 }
77
78 void
79 Score_performer::header(Midi_stream &output_stream)
80 {
81     Midi_track midi_track;
82     
83     time_t t = time( 0 );
84
85     // perhaps multiple text events?
86     String str = String( "Creator: " ) + get_version_str() + "\n";
87
88     Midi_text creator( Midi_text::TEXT, str );
89     midi_track.add( Moment( 0 ), &creator );
90
91     str = "Automatically generated at ";
92     str += ctime( &t );
93     str = str.left_str( str.length_i() - 1 );
94     str += "\n";
95     Midi_text generate( Midi_text::TEXT, str );
96     midi_track.add( Moment( 0 ), &generate );
97
98     str = "from musical definition: ";
99
100     str += score_l_->location_str();
101     Midi_text from( Midi_text::TEXT, str );
102     midi_track.add( Moment( 0 ), &from );
103
104     Midi_text track_name( Midi_text::TRACK_NAME, "Track " 
105                           + String_convert::i2dec_str( 0, 0, '0' ) );
106     midi_track.add( Moment( 0 ), &track_name );
107
108     output_stream  << midi_track;
109 }
110
111 void 
112 Score_performer::prepare( Moment m )
113 {
114     now_mom_ = m;
115 }
116
117 void 
118 Score_performer::process()
119 {
120     process_requests();
121     prev_mom_ = now_mom_;
122 }
123
124 void
125 Score_performer::set_score(Score* score_l )
126 {
127     Global_translator::set_score( score_l );
128     midi_l_ = score_l->midi_p_;
129 }
130
131 void
132 Score_performer::start()
133 {
134     if ( midi_l_->outfile_str_ == "" )
135         midi_l_->outfile_str_ = default_out_fn + ".midi";
136 }
137
138
139 int
140 Score_performer::get_tempo_i()const
141 {
142     return midi_l_->get_tempo_i(Moment( 1, 4 ));
143 }