2 performance.cc -- implement Performance
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2001 Jan Nieuwenhuizen <janneke@gnu.org>
12 #include "string-convert.hh"
14 #include "midi-def.hh"
15 #include "midi-item.hh"
16 #include "midi-stream.hh"
17 #include "audio-column.hh"
18 #include "audio-item.hh"
19 #include "audio-staff.hh"
20 #include "performance.hh"
22 #include "file-results.hh"
23 #include "file-path.hh"
24 #include "lily-version.hh"
26 #include "killing-cons.tcc"
28 Performance::Performance ()
31 audio_elem_p_list_
= 0;
35 Performance::~Performance ()
37 delete audio_elem_p_list_
;
41 Performance::output (Midi_stream
& midi_stream
)
43 int tracks_i
= audio_staff_l_arr_
.size () + 1;
46 int clocks_per_4_i
= 384;
48 midi_stream
<< Midi_header (1, tracks_i
, clocks_per_4_i
);
49 output_header_track (midi_stream
);
50 progress_indication ("\n");
51 progress_indication (_ ("Track ... "));
53 for (int i
=0; i
< audio_staff_l_arr_
.size (); i
++)
55 Audio_staff
*s
= audio_staff_l_arr_
[i
];
57 progress_indication ("[" + to_str (i
)) ;
60 MIDI players tend to ignore instrument settings on
61 channel 10, the percussion channel by default.
65 if (s
->channel_i_
< 0)
66 s
->channel_i_
= channel
;
67 s
->output (midi_stream
, channel
++);
69 progress_indication ("]");
75 Performance::output_header_track (Midi_stream
& midi_stream
)
77 Midi_track midi_track
;
79 midi_track
.channel_i_
= 9;
81 // perhaps multiple text events?
83 String str
= String (_ ("Creator: "));
84 id_str
= String_convert::pad_to (gnu_lilypond_version_str (), 40);
89 This seems silly, but in fact the audio elements should
90 be generated elsewhere: not midi-specific.
92 Audio_text
creator_a (Audio_text::TEXT
, str
);
93 Midi_text
creator (&creator_a
);
94 midi_track
.add (Moment (0), &creator
);
96 /* Better not translate this */
97 str
= "Generated automatically by: ";
102 str
= str
.left_str (str
.length_i () - 1);
105 Pad out time stamps to 120 chars. */
107 str
= String_convert::pad_to (str
, 120);
109 Audio_text
generate_a (Audio_text::TEXT
, str
);
110 Midi_text
generate (&generate_a
);
111 midi_track
.add (Moment (0), &generate
);
113 str
= _f ("from musical definition: %s", origin_str_
);
115 Audio_text
from_a (Audio_text::TEXT
, str
);
116 Midi_text
from (&from_a
);
117 midi_track
.add (Moment (0), &from
);
119 Audio_text
track_name_a (Audio_text::TRACK_NAME
, "Track "
120 + String_convert::i2dec_str (0, 0, '0'));
121 Midi_text
track_name (&track_name_a
);
123 midi_track
.add (Moment (0), &track_name
);
125 // Some sequencers read track 0 last.
126 // Audio_tempo tempo_a (midi_l_->get_tempo_i (Moment (Rational (1, 4))));
127 // Midi_tempo tempo (&tempo_a);
128 // midi_track.add (Moment (0), &tempo);
130 midi_stream
<< midi_track
;
134 Performance::add_element (Audio_element
*p
)
136 if (Audio_staff
*s
=dynamic_cast<Audio_staff
*> (p
))
138 audio_staff_l_arr_
.push (s
);
140 else if (Audio_column
*c
= dynamic_cast<Audio_column
*> (p
))
142 c
->performance_l_
= this;
144 audio_elem_p_list_
= new Killing_cons
<Audio_element
> (p
, audio_elem_p_list_
);
149 Performance::process ()
151 String out
= output_name_global
;
154 int def
= midi_l_
->get_next_score_count ();
157 Path p
= split_path (out
);
158 p
.base
+= "-" + to_str (def
);
162 /* Maybe a bit crude, but we had this before */
163 Path p
= split_path (out
);
167 Midi_stream
midi_stream (out
);
168 progress_indication (_f ("MIDI output to `%s'...", out
));
169 target_str_global_array
.push (out
);
171 output (midi_stream
);
172 progress_indication ("\n");