I’m trying to make a menu for the big genes where when I cycle trough the menu, the previous values of the pots are saved and if you want to change the value, you have to turn this pot beyond the saved value in either direction. So called “pot pickup” I believe, although I’m not sure of this terminology.
The function I wrote for this works in three parts.
Suppose we want to change the pitch of osc1 or osc2 using the same pot.
in inlets
P1 frac32.positive
in Local Data I define
char* state[2] = {"osc1", "osc2"};
int numstates = *(&state + 1) - state - 1;
int currentstate;
int prevstate;
bool ppwait1; // a variable that tells me to wait for the pot
int osc1pitch_hold; // a variable to store the value when in other menu
char osc1pitch_c[10]; // var to display with a bar the variable
int osc2pitch_hold; // a variable to store the value when in other menu
char osc2pitch_c[10]; // var to display with a bar the variable
// pot pickup function
int32_t ppchange (int in, int* hold, bool &ppwait){
// if (timer==0) LogTextMessage((char*)(ppwait));
if (ppwait==true){
if (abs(in - *hold)>>20 < 2) {
ppwait = false;
}
return *hold; ///goes to out!
} else {
*hold = in;
return in; ///goes to out!
}
}
//append int tot str for displaying a value
char* addItoS(int i, char* s, char* c){
int32_t v = __SSAT(i,28)>>21;
strcpy(&c[2],s);
c[0] = 1;
if(v >= 0)
c[1] = (uint8_t)(v + 1); // must not be zero !
else
c[1] = (uint8_t)(256 + v);
return c;
}
[potpickuptester.axp|attachment](upload://yEAWD9ljXnC2rkLZB0KTYjijPKs.axp) (5.7 KB)
I also send the values out using this adapted midi function
//midiCCthin for sending the values to my controls in the patch
void midiCCout(int v, int cc, int channel){
if (((lsend>v+(1<<19))||(v>lsend+(1<<19))) && (timer>60)) {
lsend = v;
PatchMidiInHandler(MIDI_DEVICE_INTERNAL ,0,MIDI_CONTROL_CHANGE + (channel-1),cc,__USAT(v>>20,7));
timer = 0;
} else {
timer++;
}
}
I init my values in init code
//osc1
osc1pitch_hold = 29<<20;
//osc2
osc2pitch_hold = 29<<20;
and somewhere in K-rate code i do
if (state[currentstate] == "osc1"){
outlet_S1mode = 0;
midiCCout(ppchange (inlet_P1, &osc1pitch_hold, ppwait1), 1, 1);
outlet_S1L1 = addItoS(osc1pitch_hold,"o1frq",osc1pitch_c);
}
if (state[currentstate] == "osc2"){
outlet_S1mode = 0;
midiCCout(ppchange (inlet_P1, &osc2pitch_hold, ppwait1), 2, 1);
outlet_S1L1 = addItoS(osc2pitch_hold,"o2frq",osc2pitch_c);
}
This works,. but only sometimes so it seems. As soon as the patch grows, and the menu is getting bigger, it starts dropping values.
Is there a better way to do this?
I made a very minimal version, but I’m sure this used to work while now it fails at even the simplest combo. What am I doing wrong?