- /* map each context (voice) to its own channel */
- Context *c = inf.origin_contexts (this)[0];
- string id = c->id_string ();
- int channel = channel_map_.size ();
- /* MIDI players tend to ignore instrument settings on channel
- 10, the percussion channel. */
- if (channel % 16 == 9)
- channel_map_[""] = channel++;
-
- map<string, int>::const_iterator i = channel_map_.find (id);
- if (i != channel_map_.end ())
- channel = i->second;
- else
- channel_map_[id] = channel;
-
- ai->channel_ = channel;
- audio_staff_->add_audio_item (ai);
+ /* 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");
+ if (channel_mapping == ly_symbol2scm ("voice"))
+ channel_ = get_channel (voice);
+ string str = new_instrument_string ();
+ if (str.length ())
+ {
+ if (channel_mapping != ly_symbol2scm ("voice"))
+ channel_ = get_channel (str);
+ set_instrument (channel_, voice);
+ set_instrument_name (voice);
+ }
+ Audio_staff* audio_staff = get_audio_staff (voice);
+ ai->channel_ = channel_;
+ if (Audio_dynamic *d = dynamic_cast<Audio_dynamic *> (inf.elem_))
+ dynamic_map_[voice] = d->volume_;
+ if (Real d = get_dynamic (voice))
+ if (Audio_note *n = dynamic_cast<Audio_note *> (inf.elem_))
+ n->volume_ = d;
+ audio_staff->add_audio_item (ai);