Range Mapping

You might know the Range Mapper node in Xpresso. A very handy tool to map one value range to another, optionally applying a spline curve. Here is how you can do the same in C++.

inline Real MapRange(Real value, Real min_input, Real max_input, Real min_output, Real max_output, SplineData *curve = NULL)
  Real inrange = max_input - min_input;
  if (CompareFloatTolerant(inrange, RCO 0.0)) value = RCO 0.0;  // Prevent DivByZero error
  else value = (value - min_input) / inrange;             // Map input range to [0.0 ... 1.0]

  if (curve) value = curve->GetPoint(value).y;            // Apply spline curve

  return  min_output + (max_output - min_output) * value; // Map to output range and return result

Frank Willeke

worked with computers since more than 20 years | got hooked on computer graphics back on the AMIGA | started programming at the age of 13 | relesed some successful plugins for cinema 4d | started working for maxon computer gmbh in 2009 | now contributing to cinema 4d as a senior developer making electronic music since 1993 | playing the electric guitar since 1995 age of 14 | first live gigs in 1997 | playing the bass guitar 2005 | playing keyboards and synths since 2012 experimenting with photography since 2003