+ {
+ /* map each context (voice) to its own track */
+ Context *c = inf.origin_contexts (this)[0];
+ string voice;
+ if (c->is_alias (ly_symbol2scm ("Voice")))
+ voice = c->id_string ();
+ SCM channel_mapping = get_property ("midiChannelMapping");
+ string str = new_instrument_string ();
+ if (channel_mapping != ly_symbol2scm ("instrument"))
+ channel_ = get_channel (voice);
+ else if (channel_ < 0 && str.empty ())
+ channel_ = get_channel (str);
+ if (str.length ())
+ {
+ if (channel_mapping != ly_symbol2scm ("voice"))
+ channel_ = get_channel (str);
+ set_instrument (channel_, voice);
+ set_instrument_name (voice);
+ }
+ ai->channel_ = channel_;
+ bool encode_dynamics_as_velocity_ = true;
+ if (encode_dynamics_as_velocity_)
+ {
+ if (Audio_note *n = dynamic_cast<Audio_note *> (inf.elem_))
+ {
+ // Keep track of the notes played in the current voice in this
+ // translation time step (for adjusting their dynamics later in
+ // stop_translation_timestep).
+ note_map_[voice].push_back (n);
+ }
+ else if (Audio_dynamic *d = dynamic_cast<Audio_dynamic *> (inf.elem_))
+ {
+ dynamic_map_[voice] = d;
+ // Output volume as velocity: must disable Midi_dynamic output
+ d->silent_ = true;
+ }
+ }
+ Audio_staff *audio_staff = get_audio_staff (voice);
+ audio_staff->add_audio_item (ai);
+ }