]> git.donarmstrong.com Git - lilypond.git/blob - lily/score-performer.cc
release: 0.0.77.jcn1
[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     *mlog << endl;
63 }
64
65 void
66 Score_performer::play_event(Midi_item*m)
67 {
68     midi_item_p_arr_.push(m);
69 }
70
71 Moment
72 Score_performer::get_mom() const
73 {
74     return now_mom_;
75 }
76
77 void
78 Score_performer::header(Midi_stream &output_stream)
79 {
80     Midi_track midi_track;
81     
82     time_t t = time( 0 );
83
84     // perhaps multiple text events?
85     String str = String( "Creator: " ) + get_version_str() + "\n";
86
87     Midi_text creator( Midi_text::TEXT, str );
88     midi_track.add( Moment( 0 ), &creator );
89
90     str = "Automatically generated at ";
91     str += ctime( &t );
92     str = str.left_str( str.length_i() - 1 );
93     str += "\n";
94     Midi_text generate( Midi_text::TEXT, str );
95     midi_track.add( Moment( 0 ), &generate );
96
97     str = "from musical definition: ";
98
99     str += score_l_->location_str();
100     Midi_text from( Midi_text::TEXT, str );
101     midi_track.add( Moment( 0 ), &from );
102
103     Midi_text track_name( Midi_text::TRACK_NAME, "Track " 
104                           + String_convert::i2dec_str( 0, 0, '0' ) );
105     midi_track.add( Moment( 0 ), &track_name );
106
107     output_stream  << midi_track;
108 }
109
110 void 
111 Score_performer::prepare( Moment m )
112 {
113     now_mom_ = m;
114 }
115
116 void 
117 Score_performer::process()
118 {
119     process_requests();
120     prev_mom_ = now_mom_;
121 }
122
123 void
124 Score_performer::set_score(Score* score_l )
125 {
126     Global_translator::set_score( score_l );
127     midi_l_ = score_l->midi_p_;
128 }
129
130 void
131 Score_performer::start()
132 {
133     if ( midi_l_->outfile_str_ == "" )
134         midi_l_->outfile_str_ = default_out_fn + ".midi";
135 }
136
137
138 int
139 Score_performer::get_tempo_i()const
140 {
141     return midi_l_->get_tempo_i(Moment( 1, 4 ));
142 }