zynaddsubfx

ZynAddSubFX open source synthesizer
Log | Files | Refs | Submodules | LICENSE

commit 73542104578dc507336bf9da8b65bb44f0a736e9
parent f9d2c2518147fb87d22f87c7139ce24c0517a324
Author: Christopher A. Oliver <caowasteland@gmail.com>
Date:   Sun, 29 Nov 2015 19:11:36 -0500

Make transform for tipwin number an arbitrary function not slope, intcpt.

Now tipwins can display parameter values that aren't linearly related
to the knob value().

Diffstat:
Msrc/UI/ADnoteUI.fl | 4++--
Msrc/UI/Fl_Osc_TSlider.H | 6++----
Msrc/UI/Fl_Osc_TSlider.cpp | 16+++++++---------
Msrc/UI/OscilGenUI.fl | 4++--
Msrc/UI/PADnoteUI.fl | 2+-
Msrc/UI/SUBnoteUI.fl | 6+++---
Msrc/UI/WidgetPDial.cpp | 17++++++++---------
Msrc/UI/WidgetPDial.h | 6++----
8 files changed, 27 insertions(+), 34 deletions(-)

diff --git a/src/UI/ADnoteUI.fl b/src/UI/ADnoteUI.fl @@ -89,7 +89,7 @@ class PhaseSlider {: {public Fl_Osc_TSlider} } { code { set_rounding(1); reset_value=0; - setTransform(180.0/64, 0); + set_transform([](float x){return 180.0f*x/64.0f;}); } {}} Function {set_scope(Fl_Oscilloscope *newscope)} { } { code { oscope = newscope; } {} } @@ -572,7 +572,7 @@ o->redraw();} Fl_Dial bendadjdial { label Bend tooltip {How the frequency varies according to the pitch wheel} xywh {64 270 15 15} box ROUND_UP_BOX labelsize 10 align 8 minimum -64 maximum 63 step 1 - code0 {o->init("PBendAdjust");o->reset_value=24;o->set_transform(1.0/24, 0);o->set_rounding(2);} + code0 {o->init("PBendAdjust");o->reset_value=24;o->set_transform([](float x){return x/24.0f;});o->set_rounding(2);} class Fl_Osc_Dial } Fl_Slider {} { diff --git a/src/UI/Fl_Osc_TSlider.H b/src/UI/Fl_Osc_TSlider.H @@ -10,12 +10,10 @@ class Fl_Osc_TSlider:public Fl_Osc_Slider Fl_Osc_TSlider(int x, int y, int w, int h, const char *label = 0); ~Fl_Osc_TSlider(); int handle(int event); - void setTransform(float scale = 1.0, float offset = 0.0); - float transform(float x); + void set_transform(float (*transformer)(float)); void set_rounding(unsigned int digits = 0); private: class TipWin * tipwin; - float value_offset; - float value_scale; + float (*transform)(float); }; #endif diff --git a/src/UI/Fl_Osc_TSlider.cpp b/src/UI/Fl_Osc_TSlider.cpp @@ -3,9 +3,13 @@ //Copyright (c) 2015 Christopher Oliver //License: GNU GPL version 2 or later +static float identity(float value) +{ + return value; +} Fl_Osc_TSlider::Fl_Osc_TSlider(int x, int y, int w, int h, const char *label) - :Fl_Osc_Slider(x, y, w, h, label), value_offset(0.0), value_scale(1.0) + :Fl_Osc_Slider(x, y, w, h, label), transform(identity) { Fl_Group *save = Fl_Group::current(); tipwin = new TipWin(); @@ -53,13 +57,7 @@ int Fl_Osc_TSlider::handle(int event) return super; } -void Fl_Osc_TSlider::setTransform(float scale, float offset) -{ - value_offset = offset; - value_scale = scale; -} - -float Fl_Osc_TSlider::transform(float x) +void Fl_Osc_TSlider::set_transform(float (*transformer)(float)) { - return value_scale * x + value_offset; + transform = transformer; } diff --git a/src/UI/OscilGenUI.fl b/src/UI/OscilGenUI.fl @@ -195,12 +195,12 @@ make_window(); mag->osc = osc; mag->loc = loc; mag->reset_value = 63; -mag->setTransform(-1, 63); +mag->set_transform([](float x){return 63.0f - x;}); phase->osc = osc; phase->loc = loc; phase->reset_value = 64; phase->set_rounding(1); -phase->setTransform(-180.0/64, 180.0); +phase->set_transform([](float x){return 180*(1 - x/64.0f);}); osc->createLink(loc+"magnitude"+to_s(n), mag); osc->createLink(loc+"phase"+to_s(n), phase); diff --git a/src/UI/PADnoteUI.fl b/src/UI/PADnoteUI.fl @@ -712,7 +712,7 @@ cbwidget->do_callback();} Fl_Dial bendadjustdial { label Bend tooltip {How the frequency varies according to the pitch wheel} xywh {60 278 15 15} box ROUND_UP_BOX labelsize 10 align 8 minimum -64 maximum 63 step 1 - code0 {o->init("PBendAdjust");o->reset_value=24;o->set_transform(1.0/24, 0);o->set_rounding(2);} + code0 {o->init("PBendAdjust");o->reset_value=24;o->set_transform([](float x){return x/24.0f;});o->set_rounding(2);} class Fl_Osc_Dial } Fl_Check_Button hz440 { diff --git a/src/UI/SUBnoteUI.fl b/src/UI/SUBnoteUI.fl @@ -107,11 +107,11 @@ harmonic->show(); mag->reset_value=127; mag->ext = "Phmag" + to_s(n); mag->oscRegister(mag->ext.c_str()); -mag->setTransform(-1, 127); +mag->set_transform([](float x){return 127.0f - x;}); bw->reset_value=63; bw->ext = "Phrelbw" + to_s(n); bw->oscRegister(bw->ext.c_str()); -bw->setTransform(-1, 63); +bw->set_transform([](float x){return 63.0f - x;}); osc->requestValue(base+"Phrelbw"+to_s(n)); end();} {} @@ -290,7 +290,7 @@ freqsettingsui->redraw();} Fl_Dial bendadjdial { label Bend tooltip {How the frequency varies according to the pitch wheel} xywh {448 53 15 15} box ROUND_UP_BOX labelsize 10 align 8 minimum -64 maximum 63 step 1 - code0 {o->init("PBendAdjust"); o->reset_value=24;o->set_transform(1.0/24, 0);o->set_rounding(2);} + code0 {o->init("PBendAdjust"); o->reset_value=24;o->set_transform([](float x){return x/24.0f;});o->set_rounding(2);} class Fl_Osc_Dial } Fl_Check_Button hz440 { diff --git a/src/UI/WidgetPDial.cpp b/src/UI/WidgetPDial.cpp @@ -10,10 +10,15 @@ //static int numobj = 0; +static float identity(float value) +{ + return value; +} + WidgetPDial::WidgetPDial(int x, int y, int w, int h, const char *label) :Fl_Dial(x, y, w, h, label), reset_value(0), integer_step(true), use_rounding(false), oldvalue(0.0f), pos(false), textset(false), - value_offset(0.0), value_scale(1.0) + transform(identity) { //cout << "[" << label << "] There are now " << ++numobj << endl; Fl_Group *save = Fl_Group::current(); @@ -255,14 +260,8 @@ void WidgetPDial::resetPos() pos = false; } -void WidgetPDial::set_transform(float scale, float offset) +void WidgetPDial::set_transform(float (*transformer)(float)) { - value_offset = offset; - value_scale = scale; + transform = transformer; use_rounding = true; } - -float WidgetPDial::transform(float x) -{ - return value_scale * x + value_offset; -} diff --git a/src/UI/WidgetPDial.h b/src/UI/WidgetPDial.h @@ -15,8 +15,7 @@ class WidgetPDial:public Fl_Dial void draw(); void pdialcolor(int r, int g, int b); void tooltip(const char *c); - void set_transform(float scale = 1.0, float offset = 0.0); - float transform(float x); + void set_transform(float (*transformer)(float)); void set_rounding(unsigned int digits = 0); float reset_value; protected: @@ -30,8 +29,7 @@ class WidgetPDial:public Fl_Dial bool pos; bool textset; class TipWin * tipwin; - float value_offset; - float value_scale; + float (*transform)(float); int mod_state; }; #endif