Skip to content

Commit

Permalink
MIDI import/export: map note volume and MIDI velocity with their full…
Browse files Browse the repository at this point in the history
… range (#4785)

* MIDI export: map volume to MIDI velocity correctly

* MIDI import: map MIDI velocity to note volume with full range
  • Loading branch information
PhysSong authored and zonkmachine committed Jan 21, 2019
1 parent 6df6f12 commit c1ae1ed
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion plugins/MidiExport/MidiExport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@ void MidiExport::writePattern(MidiNoteVector &pat, QDomNode n,
// TODO interpret pan="0" fxch="0" pitchrange="1"
MidiNote mnote;
mnote.pitch = qMax(0, qMin(127, note.attribute("key", "0").toInt() + base_pitch));
mnote.volume = qMin(qRound(base_volume * LocaleHelper::toDouble(note.attribute("vol", "100"))), 127);
// Map from LMMS volume to MIDI velocity
mnote.volume = qMin(qRound(base_volume * LocaleHelper::toDouble(note.attribute("vol", "100")) * (127.0 / 200.0)), 127);
mnote.time = base_time + note.attribute("pos", "0").toInt();
mnote.duration = note.attribute("len", "0").toInt();
pat.push_back(mnote);
Expand Down
2 changes: 1 addition & 1 deletion plugins/MidiImport/MidiImport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ bool MidiImport::readSMF( TrackContainer* tc )
Note n( (ticks < 1 ? 1 : ticks ),
noteEvt->get_start_time() * ticksPerBeat,
noteEvt->get_identifier() - 12,
noteEvt->get_loud());
noteEvt->get_loud() * (200.f / 127.f)); // Map from MIDI velocity to LMMS volume
ch->addNote( n );

}
Expand Down

0 comments on commit c1ae1ed

Please sign in to comment.