2 score-performer.cc -- implement Score_performer
4 (c) 1996, 1997 Jan Nieuwenhuizen <jan@digicash.com>
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"
17 #include "source-file.hh"
20 IMPLEMENT_IS_TYPE_B1(Score_performer,Performer_group_performer);
21 ADD_THIS_PERFORMER(Score_performer);
23 Score_performer::Score_performer()
28 Score_performer::~Score_performer()
33 Score_performer::ancestor_l( int l )
35 return Global_translator::ancestor_l( l );
39 Score_performer::depth_i() const
41 return Global_translator::depth_i();
45 Score_performer::finish()
47 Performer_group_performer::do_removal_processing();
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;
53 header( output_stream);
55 for (int i=0; i< midi_item_p_arr_.size(); i++) {
56 Midi_item * it_p = midi_item_p_arr_[i];
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;
62 *output_stream.os_p_ << flush;
67 Score_performer::play_event(Midi_item*m)
69 midi_item_p_arr_.push(m);
73 Score_performer::get_mom() const
79 Score_performer::header(Midi_stream &output_stream)
81 Midi_track midi_track;
85 // perhaps multiple text events?
86 String str = String( "Creator: " ) + get_version_str() + "\n";
88 Midi_text creator( Midi_text::TEXT, str );
89 midi_track.add( Moment( 0 ), &creator );
91 str = "Automatically generated at ";
93 str = str.left_str( str.length_i() - 1 );
95 Midi_text generate( Midi_text::TEXT, str );
96 midi_track.add( Moment( 0 ), &generate );
98 str = "from musical definition: ";
100 str += score_l_->location_str();
101 Midi_text from( Midi_text::TEXT, str );
102 midi_track.add( Moment( 0 ), &from );
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 );
108 output_stream << midi_track;
112 Score_performer::prepare( Moment m )
118 Score_performer::process()
121 prev_mom_ = now_mom_;
125 Score_performer::set_score(Score* score_l )
127 Global_translator::set_score( score_l );
128 midi_l_ = score_l->midi_p_;
132 Score_performer::start()
134 if ( midi_l_->outfile_str_ == "" )
135 midi_l_->outfile_str_ = default_out_fn + ".midi";
140 Score_performer::get_tempo_i()const
142 return midi_l_->get_tempo_i(Moment( 1, 4 ));