2 performance.cc -- implement Performance
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2004 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 "input-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_staffs_
.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_staffs_
.size (); i
++)
55 Audio_staff
*s
= audio_staffs_
[i
];
57 progress_indication ("[" + to_string (i
)) ;
60 MIDI players tend to ignore instrument settings on
61 channel 10, the percussion channel by default.
63 if (channel
% 16 == 9)
68 Huh? Why does each staff also have a separate channel? We
69 should map channels to voices, not staves. --hwn.
73 s
->channel_
= channel
% 16;
75 warning ("MIDI channel wrapped around. Remapping modulo 16.");
78 s
->output (midi_stream
, channel
++);
80 progress_indication ("]");
86 Performance::output_header_track (Midi_stream
& midi_stream
)
88 Midi_track midi_track
;
90 midi_track
.channel_
= 9;
92 // perhaps multiple text events?
94 String str
= String (_ ("Creator: "));
95 id_string
= String_convert::pad_to (gnu_lilypond_version_string (), 30);
99 This seems silly, but in fact the audio elements should
100 be generated elsewhere: not midi-specific.
102 Audio_text
creator_a (Audio_text::TEXT
, str
);
103 Midi_text
creator (&creator_a
);
104 midi_track
.add (Moment (0), &creator
);
106 /* Better not translate this */
107 str
= "Generated automatically by: ";
110 Audio_text
generate_a (Audio_text::TEXT
, str
);
111 Midi_text
generate (&generate_a
);
112 midi_track
.add (Moment (0), &generate
);
117 str
= str
.left_string (str
.length () - 1);
118 str
= String_convert::pad_to (str
, 60);
120 Audio_text
at_a (Audio_text::TEXT
, str
);
121 Midi_text
at (&at_a
);
122 midi_track
.add (Moment (0), &at
);
126 // str = _f ("from musical definition: %s", origin_string_);
128 Audio_text
from_a (Audio_text::TEXT
, str
);
129 Midi_text
from (&from_a
);
130 midi_track
.add (Moment (0), &from
);
132 Audio_text
track_name_a (Audio_text::TRACK_NAME
, "Track "
133 + String_convert::int2dec (0, 0, '0'));
134 Midi_text
track_name (&track_name_a
);
136 midi_track
.add (Moment (0), &track_name
);
138 // Some sequencers read track 0 last.
139 // Audio_tempo tempo_a (midi_->get_tempo (Moment (Rational (1, 4))));
140 // Midi_tempo tempo (&tempo_a);
141 // midi_track.add (Moment (0), &tempo);
143 midi_stream
<< midi_track
;
147 Performance::add_element (Audio_element
*p
)
149 if (Audio_staff
*s
=dynamic_cast<Audio_staff
*> (p
))
151 audio_staffs_
.push (s
);
153 else if (Audio_column
*c
= dynamic_cast<Audio_column
*> (p
))
155 c
->performance_
= this;
157 audio_elem_p_list_
= new Killing_cons
<Audio_element
> (p
, audio_elem_p_list_
);
161 Performance::process (String out
)
166 /* Maybe a bit crude, but we had this before */
167 Path p
= split_path (out
);
169 out
= p
.to_string ();
171 Midi_stream
midi_stream (out
);
172 progress_indication (_f ("MIDI output to `%s'...", out
));
174 global_input_file
->target_strings_
.push (out
);
176 output (midi_stream
);
177 progress_indication ("\n");
178 return SCM_UNDEFINED
;