From 482f5de0fe3c5f2e28241f5584e6a40990c769b2 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Sun, 14 Jul 2024 19:58:33 -0500 Subject: [PATCH] prepare to add function for mapping vol to percent --- src/engine/dispatch.h | 8 ++++++++ src/engine/platform/abstract.cpp | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/src/engine/dispatch.h b/src/engine/dispatch.h index 6757fe1e8..aa355f488 100644 --- a/src/engine/dispatch.h +++ b/src/engine/dispatch.h @@ -681,6 +681,14 @@ class DivDispatch { */ virtual int mapVelocity(int ch, float vel); + /** + * map chip volume to gain. + * @param ch the chip channel. -1 means N/A. + * @param vol input volume. + * @return output gain fron 0.0 to 1.0. + */ + virtual float getGain(int ch, int vol); + /** * get the lowest note in a portamento. * @param ch the channel in question. diff --git a/src/engine/platform/abstract.cpp b/src/engine/platform/abstract.cpp index 14370f297..441ec1bff 100644 --- a/src/engine/platform/abstract.cpp +++ b/src/engine/platform/abstract.cpp @@ -107,6 +107,11 @@ int DivDispatch::mapVelocity(int ch, float vel) { return round(vel*volMax); } +float DivDispatch::getGain(int ch, int vol) { + const float volMax=MAX(1,dispatch(DivCommand(DIV_CMD_GET_VOLMAX,MAX(ch,0)))); + return (float)vol/volMax; +} + int DivDispatch::getPortaFloor(int ch) { return 0x00; }