MIDI export of a part crashes
Reported version
3.0
Priority
P0 - Critical
Type
Functional
Frequency
Once
Severity
S3 - Major
Reproducibility
Always
Status
closed
Regression
Yes
Workaround
No
Project
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.
Comments
Is it reproducible with any part or some particular score?
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 I can reproduce it if I load… 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.
I have also seen sound in parts stop after save/reload, I believe for the same reason - see https://musescore.org/en/node/109941#comment-846289. Definitiely a critical issue even if we keep having playback of parts play the score instead.
In reply to It seems that functions that… 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.
This patch prevents crashes but does nothing to channels mapping: https://github.com/musescore/MuseScore/pull/4389.
I hope to find a better solution in the future though.
Fixed in branch master, commit bb81e1048c
fix #278918, fix #279284: a quick fix for crash on parts export to various formats
Fixed in branch master, commit de2f2dabb9
Merge pull request #4389 from dmitrio95/parts-midi-export-dirty
fix #278918, fix #279284: a quick fix for crash on parts export to various formats
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!
Automatically closed -- issue fixed for 2 weeks with no activity.