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

Pitch bend threshold #3

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions config.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ const ConfigParam default_config[] = {
{"iP1MPEpb", "48 "}, // MPE pitch bend range [12/24/48/96]
{"fP1thres", "0.0 "}, // Key sensitivity threshold [0-1]
{"fP1bendS", "0.25 "}, // Pitch bend range in semitones [-4.0-4.0]
{"fP1bendZ", "0.0 "}, // Pitch bend threshold [0-0.5]
{"fP1presS", "1.0 "}, // Key pressure factor [0-4]
{"fP1veloS", "1.0 "}, // Key velocity factor [0-4]
{"fP1tiltS", "1.0 "}, // Key tilt factor [-4.0-4.0]
Expand All @@ -219,6 +220,7 @@ const ConfigParam default_config[] = {
{"iP2MPEpb", " "}, // MPE pitch bend range [12/24/48/96]
{"fP2thres", " "}, // Key sensitivity threshold [0-1]
{"fP2bendS", " "}, // Pitch bend range in semitones [-4.0-4.0]
{"fP2bendZ", " "}, // Pitch bend threshold [0-0.5]
{"fP2presS", " "}, // Key pressure factor [0-4]
{"fP2veloS", " "}, // Key velocity factor [0-4]
{"fP2tiltS", " "}, // Key tilt factor [-4.0-4.0]
Expand All @@ -245,6 +247,7 @@ const ConfigParam default_config[] = {
{"iP3MPEpb", " "}, // MPE pitch bend range [12/24/48/96]
{"fP3thres", " "}, // Key sensitivity threshold [0-1]
{"fP3bendS", " "}, // Pitch bend range in semitones [-4.0-4.0]
{"fP3bendZ", " "}, // Pitch bend threshold [0-0.5]
{"fP3presS", " "}, // Key pressure factor [0-4]
{"fP3veloS", " "}, // Key velocity factor [0-4]
{"fP3tiltS", " "}, // Key tilt factor [-4.0-4.0]
Expand All @@ -271,6 +274,7 @@ const ConfigParam default_config[] = {
{"iP4MPEpb", " "}, // MPE pitch bend range [12/24/48/96]
{"fP4thres", " "}, // Key sensitivity threshold [0-1]
{"fP4bendS", " "}, // Pitch bend range in semitones [-4.0-4.0]
{"fP4bendZ", " "}, // Pitch bend threshold [0-0.5]
{"fP4presS", " "}, // Key pressure factor [0-4]
{"fP4veloS", " "}, // Key velocity factor [0-4]
{"fP4tiltS", " "}, // Key tilt factor [-4.0-4.0]
Expand All @@ -297,6 +301,7 @@ const ConfigParam default_config[] = {
{"iP5MPEpb", " "}, // MPE pitch bend range [12/24/48/96]
{"fP5thres", " "}, // Key sensitivity threshold [0-1]
{"fP5bendS", " "}, // Pitch bend range in semitones [-4.0-4.0]
{"fP5bendZ", " "}, // Pitch bend threshold [0-0.5]
{"fP5presS", " "}, // Key pressure factor [0-4]
{"fP5veloS", " "}, // Key velocity factor [0-4]
{"fP5tiltS", " "}, // Key tilt factor [-4.0-4.0]
Expand All @@ -323,6 +328,7 @@ const ConfigParam default_config[] = {
{"iP6MPEpb", " "}, // MPE pitch bend range [12/24/48/96]
{"fP6thres", " "}, // Key sensitivity threshold [0-1]
{"fP6bendS", " "}, // Pitch bend range in semitones [-4.0-4.0]
{"fP6bendZ", " "}, // Pitch bend threshold [0-0.5]
{"fP6presS", " "}, // Key pressure factor [0-4]
{"fP6veloS", " "}, // Key velocity factor [0-4]
{"fP6tiltS", " "}, // Key tilt factor [-4.0-4.0]
Expand All @@ -349,6 +355,7 @@ const ConfigParam default_config[] = {
{"iP7MPEpb", " "}, // MPE pitch bend range [12/24/48/96]
{"fP7thres", " "}, // Key sensitivity threshold [0-1]
{"fP7bendS", " "}, // Pitch bend range in semitones [-4.0-4.0]
{"fP7bendZ", " "}, // Pitch bend threshold [0-0.5]
{"fP7presS", " "}, // Key pressure factor [0-4]
{"fP7veloS", " "}, // Key velocity factor [0-4]
{"fP7tiltS", " "}, // Key tilt factor [-4.0-4.0]
Expand All @@ -375,6 +382,7 @@ const ConfigParam default_config[] = {
{"iP8MPEpb", " "}, // MPE pitch bend range [12/24/48/96]
{"fP8thres", " "}, // Key sensitivity threshold [0-1]
{"fP8bendS", " "}, // Pitch bend range in semitones [-4.0-4.0]
{"fP8bendZ", " "}, // Pitch bend threshold [0-0.5]
{"fP8presS", " "}, // Key pressure factor [0-4]
{"fP8veloS", " "}, // Key velocity factor [0-4]
{"fP8tiltS", " "}, // Key tilt factor [-4.0-4.0]
Expand Down
1 change: 1 addition & 0 deletions config_editor/config.htm
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
iPxMPEpb: {text:"MPE pitch bend range", help:"[12/24/48/96]", check:function(x) {return clamp(x, 1, 127);}},
fPxthres: {text:"Key sensitivity threshold", help:"higher value increases note trigger force [0.0-1.0]", check:function(x) {return clamp(x, 0, 1);}},
fPxbendS: {text:"Pitch bend range", help:"in semitones [-4.0-4.0]", check:function(x) {return clamp(x, -10, 10);}},
fPxbendZ: {text:"Pitch bend threshold", help:"[0.0,0.5]", check:function(x) {return clamp(x, 0, 0.5);}},
fPxpresS: {text:"Key pressure factor", help:"[0.0-4.0]", check:function(x) {return clamp(x, 0, 10);}},
fPxveloS: {text:"Key velocity factor", help:"[0.0-4.0]", check:function(x) {return clamp(x, 0, 10);}},
fPxtiltS: {text:"Key tilt (y) factor", help:"[-4.0-4.0]", check:function(x) {return clamp(x, -10, 10);}},
Expand Down
24 changes: 21 additions & 3 deletions synth_control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ class Instrument {
int midi_channel_offset = 1;
float midi_bend_range = 48.0;
float bend_sensitivity = 1.0f;
float bend_threshold = 0.0f;
float y_sensitivity = 1.0f;
float pres_sensitivity = 1.0f;
float velo_sensitivity = 1.0f;
Expand Down Expand Up @@ -950,7 +951,9 @@ class Instrument {
}

void update_voice(int but) {
float pb = bend_sensitivity * pow3(buttons[but].but_x);
float x = buttons[but].but_x;
// https://www.desmos.com/calculator/2ka73q4kpj
float pb = bend_sensitivity * pow3(1.0f / (1.0f - bend_threshold)) * (min(0, pow3(x + bend_threshold)) + max(0, pow3(x - bend_threshold)));
float presf = buttons[but].pres * pres_sensitivity;
float velof = buttons[but].vpres * velo_sensitivity;
float y = clamp(buttons[but].but_y * y_sensitivity, -1.0f, 1.0f);
Expand All @@ -959,7 +962,7 @@ class Instrument {
*(synth_interface->note[voice]) = buttons[but].note + pb;
*(synth_interface->pres[voice]) = presf;
*(synth_interface->vpres[voice]) = velof;
*(synth_interface->but_x[voice]) = buttons[but].but_x;
*(synth_interface->but_x[voice]) = x;
*(synth_interface->but_y[voice]) = y;
#endif

Expand Down Expand Up @@ -999,7 +1002,7 @@ class Instrument {
buttons[but].last_pres = pres;
}
if (config.mpe_x < 120) {
int bend = 64.5 + buttons[but].but_x * 64;
int bend = 64.5 + x * 64;
bend = clamp(bend, 0, 127);
if (bend != buttons[but].last_bend) {
MidiSend3(MIDI_CONTROL_CHANGE | (midi_channel_offset + buttons[but].voice),
Expand Down Expand Up @@ -1342,6 +1345,12 @@ void load_preset(int n) {
dis.bend_sensitivity = f * 2;
}

strset(key, 3, "bendZ");
f = getConfigFloat(key);
if (f >= 0 && f <= 0.5f) {
dis.bend_threshold = f;
}

strset(key, 3, "presS");
f = getConfigFloat(key);
if (f >= 0.0f && f <= 10.0f) {
Expand Down Expand Up @@ -1691,6 +1700,15 @@ float config_but(int but, int type, float adjust) {
return adjust - a;
} return 0;
// row 2: 1 3 5 7 9 11
case (5): { // knob: pitchbend threshold
float rem = 0;
if (type > 0) {
dis.bend_threshold = clamp_rem(dis.bend_threshold + adjust * 0.125f, 0, 0.5f, &rem);
}
led_updown_dial(dis.bend_threshold * 16);
led_rgb3(dis.bend_threshold * 64.0f, 0, 0);
return rem * 8;
}
case (11): // debug setting for easy testing
if (type == 0) {
if (dis.portamento & 1) {
Expand Down