2 performance.cc -- implement Performance
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1999 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 "lily-version.hh"
25 #include "killing-cons.tcc"
27 Performance::Performance ()
30 audio_elem_p_list_
= 0;
34 Performance::~Performance()
36 delete audio_elem_p_list_
;
40 Performance::output (Midi_stream
& midi_stream
)
42 int tracks_i
= audio_staff_l_arr_
.size() + 1;
45 int clocks_per_4_i
= 384;
47 midi_stream
<< Midi_header (1, tracks_i
, clocks_per_4_i
);
48 output_header_track (midi_stream
);
50 *mlog
<< _ ("Track ... ");
52 for (int i
=0; i
< audio_staff_l_arr_
.size (); i
++)
54 *mlog
<< '[' << flush
;
55 Audio_staff
*s
= audio_staff_l_arr_
[i
];
60 Aargh, let's hear it for the MIDI standard.
61 MIDI players tend to ignore instrument settings on
62 channel 10, the percussion channel by default.
66 s
->output (midi_stream
, channel
++);
67 *mlog
<< ']' << flush
;
72 Performance::output_header_track (Midi_stream
& midi_stream
)
74 Midi_track midi_track
;
76 // perhaps multiple text events?
77 String str
= String (_("Creator: "));
78 if (no_timestamps_global_b
)
79 str
+= gnu_lilypond_str ();
81 str
+= gnu_lilypond_version_str();
85 This seems silly, but in fact the audio elements should
86 be generated elsewhere: not midi-specific.
88 Audio_text
creator_a (Audio_text::TEXT
, str
);
89 Midi_text
creator (&creator_a
);
90 midi_track
.add (Moment (0), &creator
);
92 str
= _("Automatically generated");
93 if (no_timestamps_global_b
)
100 str
= str
.left_str (str
.length_i() - 1);
102 Audio_text
generate_a (Audio_text::TEXT
, str
);
103 Midi_text
generate (&generate_a
);
104 midi_track
.add (Moment (0), &generate
);
106 str
= _f ("from musical definition: %s", origin_str_
);
108 Audio_text
from_a (Audio_text::TEXT
, str
);
109 Midi_text
from (&from_a
);
110 midi_track
.add (Moment (0), &from
);
112 Audio_text
track_name_a (Audio_text::TRACK_NAME
, "Track "
113 + String_convert::i2dec_str (0, 0, '0'));
114 Midi_text
track_name (&track_name_a
);
116 midi_track
.add (Moment (0), &track_name
);
118 // Some sequencers read track 0 last.
119 // Audio_tempo tempo_a (midi_l_->get_tempo_i (Moment (1, 4)));
120 // Midi_tempo tempo (&tempo_a);
121 // midi_track.add (Moment (0), &tempo);
123 midi_stream
<< midi_track
;
127 Performance::add_element (Audio_element
*p
)
129 if (Audio_staff
*s
=dynamic_cast<Audio_staff
*> (p
))
131 audio_staff_l_arr_
.push (s
);
133 else if (Audio_column
*c
= dynamic_cast<Audio_column
*>(p
))
135 c
->performance_l_
= this;
137 audio_elem_p_list_
= new Killing_cons
<Audio_element
> (p
, audio_elem_p_list_
);
141 Performance::print() const
144 DEBUG_OUT
<< "Performance { ";
145 DEBUG_OUT
<< "Items: ";
146 for (Cons
<Audio_element
>* i
=audio_elem_p_list_
; i
; i
= i
->next_
)
153 Performance::process()
157 String out
= midi_l_
->get_default_output ();
161 out
= default_outname_base_global
;
164 int def
= midi_l_
->get_next_default_count ();
167 out
+= "-" + to_str (def
);
173 Midi_stream
midi_stream (out
);
174 *mlog
<< _f ("MIDI output to %s...", out
) << endl
;
175 target_str_global_array
.push (out
);
177 output (midi_stream
);