musescore / MuseScore

MuseScore is an open source and free music notation software. For support, contribution, bug reports, visit MuseScore.org. Fork and make pull requests!
https://musescore.org
Other
12.22k stars 2.65k forks source link

MIDI export (piano at least) incorrect handling of velocity and dynamics #20788

Open Linwood-F opened 9 months ago

Linwood-F commented 9 months ago

Issue type

Import/export issue

Bug description

In the changes from 3.x to 4.x and how velocity (vs velocity offset) are handled, the midi export does not work as expected. In particular, if a note is left at the default 64 velocity in the score, dynamics (e.g. p, mf, f) affect it. If you change that note to, say, 63 -- then it is output as 63 in the midi file ignoring dynamics.

This makes it impractical to use velocity as a mechanism for fine tuning midi output, e.g. to emphasize one voice or notes slightly.

I believe that all velocity settings should be treated the same with respect to dynamics, and indeed if you play a score back from within musescore, it is; it appears to be only different on midi export.

I am labeling this as a regression however in 3.x I do not know if this precise presentation of the issue occurred, as in 3.x there was a velocity offset that served this purpose.

Steps to reproduce

  1. Create a score with 3 measures, one staff, several notes in each measure.
  2. In the first couple notes in each measure change the velocity to 40 and 50 leaving other notes 64 (default).
  3. In the first measure put "p" as a dynamic, then "mf" then "f" in the last.
  4. Play -- you'll hear the 40/50 notes quieter but they will change measure to measure (use "pppp" or "ffff" if in doubt).
  5. Export midi, and either dump the file or create a new score from it. The actual midi velocities are 40 and 50 in all three measures for the changed notes, but vary by the dynamic for the others.

I'm going to try to include a score and midi output as well.

Screenshots/Screen recordings

No response

MuseScore Version

4.2

Regression

Yes, this used to work in MuseScore 3.x and now is broken

Operating system

Windows 10

Additional context

Apparently I cannot attach an actual mscz, but it takes moments to reproduce the score from the image. The dump is a filtering of the output midi to just the note-on value and the last column is the velocity in the midi file. Of significance is how "40" and "50" are never changed but 64 is.

Velocities_In_Midi_File_Dump Velocity_Score

Linwood-F commented 9 months ago

I've tried to search for related issues. One is here but has no midi detail (found by Marc Sabatella, thank you):

https://github.com/musescore/MuseScore/issues/19207

While I suggest the issue is in Midi Export, I do not think it is in the exportmidi.cpp module itself, since I see no references there to velocity and scaling, I think it relates to how other output mechanisms are recording the need to scale and where exportmidi pulls data, but I am lost in the playback code itself. I tried tracing back through event/NPlayEvent (my best guess but I think it may be further back).

TeeDeeY commented 5 months ago

The midi import should be looked at as well.

Open new score, add a C note. Check properties/playback/velocity. It is 64. Export midi, drag/drop midi file into musescore. Check note - properties/playback/velocity is 80.

The imported note is louder due to the “user velocity” being 80 instead of default 64.