From 12752933271d7cf5ba48b8170e23c23c77257244 Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Sat, 24 Oct 2020 15:58:29 -0700 Subject: [PATCH] Add utility function to convert panning values from [0,127] to [-1,1] --- include/amuse/Voice.hpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/amuse/Voice.hpp b/include/amuse/Voice.hpp index f3b035e..13211fc 100644 --- a/include/amuse/Voice.hpp +++ b/include/amuse/Voice.hpp @@ -15,6 +15,13 @@ #include "amuse/Studio.hpp" namespace amuse { +constexpr float convertMusyXPanToAmusePan(uint32_t pan) { + // Amuse expects pan values to be between [-1,1] while MusyX expects pan to be between [0,127], we need to make sure + // to map the values properly, we do this by subtracting the center value and then dividing, thus forcing [0, 127] into + // [-1,1], we must also make sure clamp the result so we don't over or underflow. + return std::clamp(static_cast(pan - 64) / 63.f, -1.f, 1.f); +} + class IBackendVoice; struct Keymap; struct LayerMapping;