Make negative step sizes work on output in data mode, and also with pb in key mode.
This commit is contained in:
parent
94f59441cd
commit
52fa84bf12
25
midizap.c
25
midizap.c
|
@ -67,6 +67,16 @@ static int16_t pbvalue[16] =
|
||||||
{8192, 8192, 8192, 8192, 8192, 8192, 8192, 8192,
|
{8192, 8192, 8192, 8192, 8192, 8192, 8192, 8192,
|
||||||
8192, 8192, 8192, 8192, 8192, 8192, 8192, 8192};
|
8192, 8192, 8192, 8192, 8192, 8192, 8192, 8192};
|
||||||
|
|
||||||
|
static int dataval(int val, int min, int max)
|
||||||
|
{
|
||||||
|
if (!val || val > max)
|
||||||
|
return max;
|
||||||
|
else if (val < min)
|
||||||
|
return min;
|
||||||
|
else
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
send_midi(uint8_t portno, int status, int data, int step, int incr, int index, int dir)
|
send_midi(uint8_t portno, int status, int data, int step, int incr, int index, int dir)
|
||||||
{
|
{
|
||||||
|
@ -78,8 +88,7 @@ send_midi(uint8_t portno, int status, int data, int step, int incr, int index, i
|
||||||
switch (status & 0xf0) {
|
switch (status & 0xf0) {
|
||||||
case 0x90:
|
case 0x90:
|
||||||
if (!index) {
|
if (!index) {
|
||||||
msg[2] = step?step:127;
|
msg[2] = dataval(step, 0, 127);
|
||||||
if (msg[2] > 127) msg[2] = 127;
|
|
||||||
} else {
|
} else {
|
||||||
msg[2] = 0;
|
msg[2] = 0;
|
||||||
}
|
}
|
||||||
|
@ -110,8 +119,7 @@ send_midi(uint8_t portno, int status, int data, int step, int incr, int index, i
|
||||||
msg[2] = ccvalue[chan][data];
|
msg[2] = ccvalue[chan][data];
|
||||||
}
|
}
|
||||||
} else if (!index) {
|
} else if (!index) {
|
||||||
msg[2] = step?step:127;
|
msg[2] = dataval(step, 0, 127);
|
||||||
if (msg[2] > 127) msg[2] = 127;
|
|
||||||
} else {
|
} else {
|
||||||
msg[2] = 0;
|
msg[2] = 0;
|
||||||
}
|
}
|
||||||
|
@ -133,8 +141,7 @@ send_midi(uint8_t portno, int status, int data, int step, int incr, int index, i
|
||||||
}
|
}
|
||||||
msg[2] = kpvalue[chan][data];
|
msg[2] = kpvalue[chan][data];
|
||||||
} else if (!index) {
|
} else if (!index) {
|
||||||
msg[2] = step?step:127;
|
msg[2] = dataval(step, 0, 127);
|
||||||
if (msg[2] > 127) msg[2] = 127;
|
|
||||||
} else {
|
} else {
|
||||||
msg[2] = 0;
|
msg[2] = 0;
|
||||||
}
|
}
|
||||||
|
@ -156,8 +163,7 @@ send_midi(uint8_t portno, int status, int data, int step, int incr, int index, i
|
||||||
}
|
}
|
||||||
msg[1] = cpvalue[chan];
|
msg[1] = cpvalue[chan];
|
||||||
} else if (!index) {
|
} else if (!index) {
|
||||||
msg[1] = step?step:127;
|
msg[1] = dataval(step, 0, 127);
|
||||||
if (msg[1] > 127) msg[1] = 127;
|
|
||||||
} else {
|
} else {
|
||||||
msg[1] = 0;
|
msg[1] = 0;
|
||||||
}
|
}
|
||||||
|
@ -180,8 +186,7 @@ send_midi(uint8_t portno, int status, int data, int step, int incr, int index, i
|
||||||
}
|
}
|
||||||
pbval = pbvalue[chan];
|
pbval = pbvalue[chan];
|
||||||
} else if (!index) {
|
} else if (!index) {
|
||||||
pbval = 8192+(step?step:8191);
|
pbval = 8192+dataval(step, -8192, 8191);
|
||||||
if (pbval > 16383) pbval = 16383;
|
|
||||||
} else {
|
} else {
|
||||||
// we use 8192 (center) as the "home" (a.k.a. "off") value, so the pitch
|
// we use 8192 (center) as the "home" (a.k.a. "off") value, so the pitch
|
||||||
// will only bend up, never down below the center value
|
// will only bend up, never down below the center value
|
||||||
|
|
14
readconfig.c
14
readconfig.c
|
@ -826,7 +826,7 @@ parse_midi(char *tok, char *s, int lhs, int mode,
|
||||||
// step size
|
// step size
|
||||||
if (*p == '[') {
|
if (*p == '[') {
|
||||||
if (sscanf(++p, "%d%n", &l, &n) == 1) {
|
if (sscanf(++p, "%d%n", &l, &n) == 1) {
|
||||||
if (l <= 0) return 0; // must be positive
|
if (!l || (lhs && l<0)) return 0; // must be nonzero / positive on lhs
|
||||||
p += n;
|
p += n;
|
||||||
if (*p != ']') return 0;
|
if (*p != ']') return 0;
|
||||||
p++;
|
p++;
|
||||||
|
@ -892,6 +892,7 @@ parse_midi(char *tok, char *s, int lhs, int mode,
|
||||||
} else if (strcmp(s, "pb") == 0) {
|
} else if (strcmp(s, "pb") == 0) {
|
||||||
// pitch bend, no data byte
|
// pitch bend, no data byte
|
||||||
*status = 0xe0 | k; *data = 0;
|
*status = 0xe0 | k; *data = 0;
|
||||||
|
// negative step size is always permitted on rhs here, even in key mode
|
||||||
// step size only permitted on lhs if incremental
|
// step size only permitted on lhs if incremental
|
||||||
if (lhs && *step && !*incr) return 0;
|
if (lhs && *step && !*incr) return 0;
|
||||||
if (lhs && !*step) *step = 1; // default
|
if (lhs && !*step) *step = 1; // default
|
||||||
|
@ -899,6 +900,8 @@ parse_midi(char *tok, char *s, int lhs, int mode,
|
||||||
} else if (strcmp(s, "cp") == 0) {
|
} else if (strcmp(s, "cp") == 0) {
|
||||||
// channel pressure, no data byte
|
// channel pressure, no data byte
|
||||||
*status = 0xd0 | k; *data = 0;
|
*status = 0xd0 | k; *data = 0;
|
||||||
|
// negative step size not permitted on rhs in key mode
|
||||||
|
if (!lhs && *step < 0 && !mode) return 0;
|
||||||
// step size only permitted on lhs if incremental
|
// step size only permitted on lhs if incremental
|
||||||
if (lhs && *step && !*incr) return 0;
|
if (lhs && *step && !*incr) return 0;
|
||||||
if (lhs && !*step) *step = 1; // default
|
if (lhs && !*step) *step = 1; // default
|
||||||
|
@ -913,6 +916,8 @@ parse_midi(char *tok, char *s, int lhs, int mode,
|
||||||
// control change
|
// control change
|
||||||
if (m < 0 || m > 127) return 0;
|
if (m < 0 || m > 127) return 0;
|
||||||
*status = 0xb0 | k; *data = m;
|
*status = 0xb0 | k; *data = m;
|
||||||
|
// negative step size not permitted on rhs in key mode
|
||||||
|
if (!lhs && *step < 0 && !mode) return 0;
|
||||||
// step size only permitted on lhs if incremental
|
// step size only permitted on lhs if incremental
|
||||||
if (lhs && *step && !*incr) return 0;
|
if (lhs && *step && !*incr) return 0;
|
||||||
if (lhs && !*step) *step = 1; // default
|
if (lhs && !*step) *step = 1; // default
|
||||||
|
@ -921,12 +926,17 @@ parse_midi(char *tok, char *s, int lhs, int mode,
|
||||||
// key pressure
|
// key pressure
|
||||||
if (m < 0 || m > 127) return 0;
|
if (m < 0 || m > 127) return 0;
|
||||||
*status = 0xa0 | k; *data = m;
|
*status = 0xa0 | k; *data = m;
|
||||||
|
// negative step size not permitted on rhs in key mode
|
||||||
|
if (!lhs && *step < 0 && !mode) return 0;
|
||||||
// step size only permitted on lhs if incremental
|
// step size only permitted on lhs if incremental
|
||||||
if (lhs && *step && !*incr) return 0;
|
if (lhs && *step && !*incr) return 0;
|
||||||
if (lhs && !*step) *step = 1; // default
|
if (lhs && !*step) *step = 1; // default
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
if (lhs && *step) return 0; // step size not permitted on lhs
|
// negative step size not permitted on rhs
|
||||||
|
if (!lhs && *step < 0) return 0;
|
||||||
|
// step size not permitted on lhs
|
||||||
|
if (lhs && *step) return 0;
|
||||||
// we must be looking at a MIDI note here, with m denoting the
|
// we must be looking at a MIDI note here, with m denoting the
|
||||||
// octave number; first character is the note name (must be a..g);
|
// octave number; first character is the note name (must be a..g);
|
||||||
// optionally, the second character may denote an accidental (# or b)
|
// optionally, the second character may denote an accidental (# or b)
|
||||||
|
|
Loading…
Reference in New Issue