Last active
June 22, 2016 00:37
-
-
Save hotwatermorning/b52bcd5856bace21c23e7b5720791731 to your computer and use it in GitHub Desktop.
adjust slider scensitivity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void WaveformComponent::sliderValueChanged (juce::Slider *slider) | |
{ | |
if(slider == &zoom_slider_) { | |
double v = slider->getValue(); | |
int const size_min = 64; //! 2^6 | |
int const size_max = 16384; //! 2^14 | |
//! スライダーの感度を調整する変数。 | |
//! 値を大きくするほど、center位置でのズーム率が下がる | |
double const amount = JUCE_LIVE_CONSTANT(1024); | |
double const min_x = log(size_min + amount); | |
double const max_x = log(size_max + amount); | |
double r = v / slider->getMaximum(); | |
double const current_x = r * (max_x - min_x) + min_x; | |
int new_size = (int)std::round(exp(current_x)) - amount; | |
if(new_size < size_min) { | |
new_size = size_min; | |
} | |
if(new_size > size_max) { | |
new_size = size_max; | |
} | |
SetViewSize(new_size); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment