Lmms: Export MIDI - Note velocity

Created on 4 Jan 2019  路  5Comments  路  Source: LMMS/lmms

Our note velocity go from 0 - 200 but midi note velocity is 0 - 127. In our export code we set anything over 127 to 127 so a track using the full range in lmms will export wrong.

https://github.com/LMMS/lmms/blob/7f0593c601a7f48fda193139f2d6bb3d76f10384/plugins/MidiExport/MidiExport.cpp#L277

Example issue reported in the forum: https://lmms.io/forum/viewtopic.php?f=7&t=29497

Can we just divide note velocity in two when exporting?
Example, crude but working:

mnote.volume = qMin(qRound(base_volume * 0.635 * LocaleHelper::toDouble(note.attribute("vol", "100"))), 127);

@PhysSong

bug

All 5 comments

Change title because I got it wrong. Our velocity seem to go from 0-200. To convert we need to multiply our velocity by 127/200=0.635 to use the full dynamic of the MIDI velocity range. Updated snippet above.

Example, crude but working:

mnote.volume = qMin(qRound(base_volume * 0.635 * LocaleHelper::toDouble(note.attribute("vol", "100"))), 127);

It looks fine to me. I think 0.635 might look unclear at the first look though. We can either add a comment or write this as (127.f / 200.f).

We can either add a comment or write this as (127.f / 200.f).

Yeah, something is needed or there will be confusion later on. I think a comment with that piece of math and then use const double convertToMIDI = 0.635.

MIDI import may have to be changed too. I'm curious if the internal values were given headroom over original MIDI for a particular reason.

https://github.com/LMMS/lmms/blob/7f0593c601a7f48fda193139f2d6bb3d76f10384/plugins/MidiImport/MidiImport.cpp#L429

noteEvt->get_loud() / 0.635f );

Equivalent action on import.

_Edit: With this change you can import/export/import... etc. and the values will remain the same. Without the volume will be continuously going down for every import action. Not that people are going to do this more than one way and more than once. Not many anyway._

@zonkmachine Nice catch, thank you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Wallacoloo picture Wallacoloo  路  3Comments

softrabbit picture softrabbit  路  3Comments

demmm picture demmm  路  3Comments

Andrewer11 picture Andrewer11  路  3Comments

Gabrielxd195 picture Gabrielxd195  路  3Comments