Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move all this code to one pair of functions #3189

Closed
baconpaul opened this issue Nov 21, 2020 · 1 comment · Fixed by #3197
Closed

Move all this code to one pair of functions #3189

baconpaul opened this issue Nov 21, 2020 · 1 comment · Fixed by #3197
Labels
Bug Report Item submitted using the Bug Report template Code Refactoring General code refactoring and cleanup issues like names, unused variables, warnings, fixme
Milestone

Comments

@baconpaul
Copy link
Collaborator

src//common/Parameter.cpp:         i = (int)((1 / 0.99) * (ef - 0.005) * (float)(val_max.i - val_min.i) + 0.5) + val_min.i;
src//common/Parameter.cpp:         float fv = 0.005 + 0.99 * ((float)(i - val_min.i)) / ((float)(val_max.i - val_min.i));
src//common/Parameter.cpp:      return 0.005 + 0.99 * ((float)(val.i - val_min.i)) / ((float)(val_max.i - val_min.i));
src//common/Parameter.cpp:      return 0.005 + 0.99 * ((float)(val_default.i - val_min.i)) / ((float)(val_max.i - val_min.i));
src//common/Parameter.cpp:      val.i = (int)((1 / 0.99) * (v - 0.005) * (float)(val_max.i - val_min.i) + 0.5) + val_min.i;
src//common/gui/CMenuAsSlider.cpp:         float r = 0.005 + 0.99 * ( iv - iMin ) / ( float) ( iMax - iMin );
src//common/gui/CMenuAsSlider.cpp:                   float r = 0.005 + 0.99 * ( iv - iMin ) / ( float) ( iMax - iMin );
src//common/gui/CNumberField.cpp:   i_value = (int)((1 / 0.99) * (val - 0.005) * (float)(i_max - i_min) + 0.5) + i_min;
src//common/gui/CNumberField.cpp:      i_value = (int)((1.f / 0.99f) * (value - 0.005f) * (float)(i_max - i_min) + 0.5) + i_min;
src//common/gui/CNumberField.cpp:   i_value = (int)((1.f / 0.99f) * (value - 0.005f) * (float)(i_max - i_min) + 0.5) + i_min;
src//common/gui/SurgeGUIEditor.cpp:                  val = 0.005 + 0.99 * ( (float)( im ) / (n_scenemodes-1) );
src//common/gui/SurgeGUIEditor.cpp:               fval = 0.005 + 0.99 * ((float)(guiscenemode) / (n_scenemodes - 1));

I'm going to add the inline functions to Parameter.h now to fix #3096 in one spot but want to get all of these too. May choose to not do it in the same commit though so added an issue.

@baconpaul baconpaul added Code Refactoring General code refactoring and cleanup issues like names, unused variables, warnings, fixme Bug Report Item submitted using the Bug Report template labels Nov 21, 2020
@baconpaul baconpaul added this to the 1.8.0 milestone Nov 21, 2020
@baconpaul
Copy link
Collaborator Author

The functions to use are in Parameter so Parameter:: then

   static inline float intScaledToFloat( int v, int vmax, int vmin = 0 ) 
   static inline int intUnscaledFromFloat( float f, int vmax, int vmin = 0 ) 

baconpaul added a commit to baconpaul/surge that referenced this issue Nov 22, 2020
That 0.005 + 0.99* blah code was all over the place and caused automation and other errors if mis-used.
Make it a function. Apply the function everywhere.
Closes surge-synthesizer#3189
baconpaul added a commit that referenced this issue Nov 22, 2020
That 0.005 + 0.99* blah code was all over the place and caused automation and other errors if mis-used.
Make it a function. Apply the function everywhere.
Closes #3189
@mkruselj mkruselj added this to the 1.8.0 milestone Jan 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Report Item submitted using the Bug Report template Code Refactoring General code refactoring and cleanup issues like names, unused variables, warnings, fixme
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants