tttapa / MIDI_controller

This is a library for creating a MIDI controller using an Arduino or Teensy board.
GNU General Public License v3.0
404 stars 69 forks source link

Mapping logarithmic potentiometers to linear curve #109

Closed kraftZeug closed 3 years ago

kraftZeug commented 3 years ago

First of all, I'd like to send you many many thanks for your code! It saved me a lot of time for my project (an electric guitar with onboard midi-controller) and it allowed me to focus on buiding and electronics

Description of the problem or question

This is more of a question than an issue. I have no clue on how to integrate a function to map a logarithmic curve to a linear one. Could you point me to the right direction?

Arduino board: Teensy 3.2

tttapa commented 3 years ago

As mentioned in the README, the MIDI Controller library is no longer supported. It has been replaced by the Control Surface library.

With that library, you can use the CCPotentiometer-Map example.

You could use the following mapping function:

analog_t log2lin(analog_t in) {
    constexpr analog_t max    = FilteredAnalog<7>::getMaxRawValue();
    // Tweak the position of the "knee" to match your potentiometer's spec
    constexpr uint32_t x_knee = max / 2; 
    constexpr uint32_t y_knee = max / 8;

    return in < y_knee
               ? in * x_knee / y_knee
               : (in - y_knee) * (max - x_knee) / (max - y_knee) + x_knee;
}
kraftZeug commented 3 years ago

Yes! Thank you very much! I'll go check Control Surface.