2 performance.cc -- implement Performance
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2004 Jan Nieuwenhuizen <janneke@gnu.org>
11 #include "audio-column.hh"
12 #include "audio-item.hh"
13 #include "audio-staff.hh"
14 #include "file-name.hh"
15 #include "lily-version.hh"
17 #include "midi-item.hh"
18 #include "midi-stream.hh"
19 #include "performance.hh"
21 #include "string-convert.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_staffs_
.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
);
49 progress_indication ("\n");
50 progress_indication (_ ("Track ... "));
52 for (int i
=0; i
< audio_staffs_
.size (); i
++)
54 Audio_staff
*s
= audio_staffs_
[i
];
56 progress_indication ("[" + to_string (i
)) ;
59 MIDI players tend to ignore instrument settings on
60 channel 10, the percussion channel by default.
62 if (channel
% 16 == 9)
67 Huh? Why does each staff also have a separate channel? We
68 should map channels to voices, not staves. --hwn.
72 s
->channel_
= channel
% 16;
74 warning ("MIDI channel wrapped around. Remapping modulo 16.");
77 s
->output (midi_stream
, channel
++);
79 progress_indication ("]");
85 Performance::output_header_track (Midi_stream
& midi_stream
)
87 Midi_track midi_track
;
89 midi_track
.channel_
= 9;
91 // perhaps multiple text events?
93 String str
= String (_ ("Creator: "));
94 id_string
= String_convert::pad_to (gnu_lilypond_version_string (), 30);
98 This seems silly, but in fact the audio elements should
99 be generated elsewhere: not midi-specific.
101 Audio_text
creator_a (Audio_text::TEXT
, str
);
102 Midi_text
creator (&creator_a
);
103 midi_track
.add (Moment (0), &creator
);
105 /* Better not translate this */
106 str
= "Generated automatically by: ";
109 Audio_text
generate_a (Audio_text::TEXT
, str
);
110 Midi_text
generate (&generate_a
);
111 midi_track
.add (Moment (0), &generate
);
116 str
= str
.left_string (str
.length () - 1);
117 str
= String_convert::pad_to (str
, 60);
119 Audio_text
at_a (Audio_text::TEXT
, str
);
120 Midi_text
at (&at_a
);
121 midi_track
.add (Moment (0), &at
);
125 // str = _f ("from musical definition: %s", origin_string_);
127 Audio_text
from_a (Audio_text::TEXT
, str
);
128 Midi_text
from (&from_a
);
129 midi_track
.add (Moment (0), &from
);
131 Audio_text
track_name_a (Audio_text::TRACK_NAME
, "Track "
132 + String_convert::int2dec (0, 0, '0'));
133 Midi_text
track_name (&track_name_a
);
135 midi_track
.add (Moment (0), &track_name
);
137 // Some sequencers read track 0 last.
138 // Audio_tempo tempo_a (midi_->get_tempo (Moment (Rational (1, 4))));
139 // Midi_tempo tempo (&tempo_a);
140 // midi_track.add (Moment (0), &tempo);
142 midi_stream
<< midi_track
;
146 Performance::add_element (Audio_element
*p
)
148 if (Audio_staff
*s
=dynamic_cast<Audio_staff
*> (p
))
150 audio_staffs_
.push (s
);
152 audio_elem_p_list_
= new Killing_cons
<Audio_element
> (p
, audio_elem_p_list_
);
156 Performance::process (String out
)
161 /* Maybe a bit crude, but we had this before */
162 File_name
file_name (out
);
163 file_name
.ext_
= "midi";
164 out
= file_name
.to_string ();
166 Midi_stream
midi_stream (out
);
167 progress_indication (_f ("MIDI output to `%s'...", out
));
169 output (midi_stream
);
170 progress_indication ("\n");
171 return SCM_UNDEFINED
;