From 39481ab571992ab074cf88bac48be752abf3be28 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Sun, 17 Dec 2023 15:08:52 -0500 Subject: [PATCH] fix velocity input --- src/engine/engine.cpp | 7 +++++++ src/engine/engine.h | 3 +++ src/gui/gui.cpp | 4 ++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index f8af13d80..a7ed96807 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -2185,6 +2185,13 @@ int DivEngine::getMaxVolumeChan(int ch) { return chan[ch].volMax>>8; } +int DivEngine::mapVelocity(int ch, float vel) { + if (ch<0) return 0; + if (ch>=chans) return 0; + if (disCont[dispatchOfChan[ch]].dispatch==NULL) return 0; + return disCont[dispatchOfChan[ch]].dispatch->mapVelocity(dispatchChanOfChan[ch],vel); +} + unsigned char DivEngine::getOrder() { return prevOrder; } diff --git a/src/engine/engine.h b/src/engine/engine.h index fe0cd0991..c3cd0ff72 100644 --- a/src/engine/engine.h +++ b/src/engine/engine.h @@ -851,6 +851,9 @@ class DivEngine { // get channel max volume int getMaxVolumeChan(int chan); + // map MIDI velocity to volume + int mapVelocity(int ch, float vel); + // get current order unsigned char getOrder(); diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index a9efea15b..1683c434d 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -1216,7 +1216,7 @@ void FurnaceGUI::noteInput(int num, int key, int vol) { if (latchVol!=-1) { pat->data[cursor.y][3]=MIN(maxVol,latchVol); } else if (vol!=-1) { - pat->data[cursor.y][3]=(vol*maxVol)/127; + pat->data[cursor.y][3]=e->mapVelocity(cursor.xCoarse,pow((float)vol/127.0f,midiMap.volExp)); } if (latchEffect!=-1) pat->data[cursor.y][4]=latchEffect; if (latchEffectVal!=-1) pat->data[cursor.y][5]=latchEffectVal; @@ -3776,7 +3776,7 @@ bool FurnaceGUI::loop() { noteInput( msg.data[0]-12, 0, - midiMap.volInput?((int)(pow((double)msg.data[1]/127.0,midiMap.volExp)*127.0)):-1 + midiMap.volInput?msg.data[1]:-1 ); } } else {