MIDI export of a part crashes

• Nov 28, 2018 - 01:11
Reported version
P0 - Critical
S3 - Major

In libmscore/rendermidi.cpp at the place where events->registerChannel(channel) is called, channel is -1. This leads to a crash later when that is reinterpreted as 255 (uchar).

In 2.x the channel was set to the correct value here. In master, it’s only correctly set for the, no pun intended, master score, not for the parts/excerpts.


I can reproduce it if I load a score which already contains parts. Generating them from scratch and exporting a part works well.

In reply to by dmitrio95

In my case, it was a score from 2.x… so perhaps the MIDI channel assignment for the instruments used in the excerpts is only done by 3.0 when creating new parts, but not for existing ones, whereas 2.x did that on the fly (and didn’t save it to the MSCX)?

Anyway, I did track it down with a debugging fprintf before the registerChannel line (there’s only one call), so it’s definitely happening.

It seems that functions that does MIDI mapping was moved to MasterScore in f281db5f22b0411ace9d7d6ea472579f6f4321f0, and it probably stopped being called for non-master scores even earlier. So no MIDI channels mapping is done for parts, and the reason why all works well on recreating parts from scratch is mostly occasional: Instrument object containing channel information just gets copied from master score to the excerpt on extracting parts.

Given that, I have the following questions:
1) What is the purpose at all in having different instruments in master score and in excerpts? I can change instrument for a part in master score and it does not get reflected in excerpts and vice versa, and it seems to work the same way in MuseScore 2.X. It seems there is no way to synchronize instrument changes between master score and parts. It reflects not only in MIDI export but also in playback on note entry or selection. By the way, mid-score instrument change marks seem to synchronize well in MuseScore 2.X.
2) If we still need to have different instruments in master score and excerpts, why isn't then MIDI mapping done for them?

Not sure these questions have proper answers but maybe someone could have some ideas on what is better to do with this.

In reply to by dmitrio95

Also, in a master score with more than 16 instruments (more than 14 even, I think), a second MIDI port is used to map the next batch. This is unnecessary overhead for parts.

I believe that parts should have their own instrument to MIDI channel mapping, so that we end up with a contiguous list of channels used.

I can now convert all files without valgrind complaining (except about possible memory leaks, but that’s not a bug).

Thanks for the quick fix!