From 0311b7509dcf8a75a165283cac6d7e53c12c6275 Mon Sep 17 00:00:00 2001 From: Albert Graef Date: Sat, 11 Jul 2015 06:50:46 +0200 Subject: [PATCH 1/6] midi->osc conversion: only use recorded values for variable conversions, not constants or ranges --- src/pair.c | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/src/pair.c b/src/pair.c index e9d508c..0e1d506 100644 --- a/src/pair.c +++ b/src/pair.c @@ -1760,14 +1760,8 @@ int try_match_midi(PAIRHANDLE ph, uint8_t msg[], uint8_t strict_match, uint8_t* } else { - // value not in message, grab previously recorded value -ag - float val = p->regs[i+p->argc_in_path]; - // prescribed range of the message (if it's not a constant, then this is set to default 0) - float min = p->osc_val[i + p->argc_in_path], - max = p->osc_rangemax[i + p->argc_in_path]; - // fall back to default value if the recorded value falls out of the prescribed range - if (p->osc_const[i+p->argc_in_path] && (val < min || val > max)) - val = min; + // value not in message, grab default or previously recorded value -ag + float val = p->osc_const[i+p->argc_in_path]?p->osc_val[i+p->argc_in_path]:p->regs[i+p->argc_in_path]; load_osc_value( oscm, p->types[i], val ); } } @@ -1806,11 +1800,7 @@ int try_match_midi(PAIRHANDLE ph, uint8_t msg[], uint8_t strict_match, uint8_t* else { //we have no idea what should be in these, so just load a previously recorded value or the defaults - float val = p->regs[i+p->argc_in_path]; - float min = p->osc_val[i + p->argc_in_path], - max = p->osc_rangemax[i + p->argc_in_path]; - if (p->osc_const[i+p->argc_in_path] && (val < min || val > max)) - val = min; + float val = p->osc_const[i+p->argc_in_path]?p->osc_val[i+p->argc_in_path]:p->regs[i+p->argc_in_path]; load_osc_value( oscm, p->types[i], val ); } } @@ -1840,11 +1830,8 @@ int try_match_midi(PAIRHANDLE ph, uint8_t msg[], uint8_t strict_match, uint8_t* } else { - // value not in message, grab previously recorded value -ag - float val = p->regs[i]; - float min = p->osc_val[i], max = p->osc_rangemax[i]; - if (p->osc_const[i] && (val < min || val > max)) - val = min; + // value not in message, grab default or previously recorded value -ag + float val = p->osc_const[i]?p->osc_val[i]:p->regs[i]; sprintf(chunk, p->path[i], (int)val); } strcat(path, chunk); From 4d836599d9820a924f11f5cc9537ca8acc56a816 Mon Sep 17 00:00:00 2001 From: Albert Graef Date: Sat, 11 Jul 2015 07:22:13 +0200 Subject: [PATCH 2/6] midi->osc conversion: midi arg #0 should be channel number, not the entire status byte --- src/pair.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/pair.c b/src/pair.c index 0e1d506..9b100db 100644 --- a/src/pair.c +++ b/src/pair.c @@ -1749,8 +1749,15 @@ int try_match_midi(PAIRHANDLE ph, uint8_t msg[], uint8_t strict_match, uint8_t* { int midival = mymsg[place]; float val; - if(p->opcode == 0xE0 && place == 1)//pitchbend is special case (14 bit number) + if(place == 0) { + //this is the status byte, actual argument is the channel + //number in the lo-nibble + midival &= 0xF; + } + else if(p->opcode == 0xE0 && place == 1) + { + //pitchbend is special case (14 bit number) midival += mymsg[place+1]*128; } val = p->osc_scale[i+p->argc_in_path]*((float)midival - p->midi_offset[place]) / p->midi_scale[place] + p->osc_offset[i+p->argc_in_path]; From 0b201cad9a967ed314d9b6c8b261576481add7fd Mon Sep 17 00:00:00 2001 From: Albert Graef Date: Sat, 11 Jul 2015 07:52:58 +0200 Subject: [PATCH 3/6] midi->osc conversion: correct midi arg #0 in non-linearity checks --- src/pair.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pair.c b/src/pair.c index 9b100db..c7d3c62 100644 --- a/src/pair.c +++ b/src/pair.c @@ -1858,6 +1858,8 @@ int try_match_midi(PAIRHANDLE ph, uint8_t msg[], uint8_t strict_match, uint8_t* uint8_t y1 = mymsg[i], y2 = mymsg[j]; float a1 = p->midi_scale[i], a2 = p->midi_scale[j]; float b1 = p->midi_offset[i], b2 = p->midi_offset[j]; + if (i==0) y1 &= 0xF; + if (j==0) y2 &= 0xF; if ((y1-b1)*a2 != (y2-b2)*a1) return 0; } } From 51b3a9d22b36a538cf22284cde854deb1eeac340 Mon Sep 17 00:00:00 2001 From: Albert Graef Date: Sat, 11 Jul 2015 15:19:43 +0200 Subject: [PATCH 4/6] revert commit 0d895bc --- src/pair.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pair.c b/src/pair.c index c7d3c62..6701a87 100644 --- a/src/pair.c +++ b/src/pair.c @@ -1073,7 +1073,7 @@ int get_pair_mapping(char* config, PAIR* p, int n) j = get_pair_osc_arg_index(var, argnames, p->argc_in_path + p->argc,k++); if(j >=0 ) p->midi_map[i] = j; - while(j >=0 && p->osc_map[j] == -1) + while(j >=0) { p->osc_map[j] = i; //check for additional copies From 6f95821ee06d438d11c588f41f0635fb6884c34b Mon Sep 17 00:00:00 2001 From: Albert Graef Date: Sat, 11 Jul 2015 16:11:35 +0200 Subject: [PATCH 5/6] midi->osc conversion: account for rounding of MIDI arguments in non-linearity checks --- src/pair.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pair.c b/src/pair.c index 6701a87..908f6cd 100644 --- a/src/pair.c +++ b/src/pair.c @@ -1860,7 +1860,8 @@ int try_match_midi(PAIRHANDLE ph, uint8_t msg[], uint8_t strict_match, uint8_t* float b1 = p->midi_offset[i], b2 = p->midi_offset[j]; if (i==0) y1 &= 0xF; if (j==0) y2 &= 0xF; - if ((y1-b1)*a2 != (y2-b2)*a1) return 0; + // give some leeway here to account for the rounding of MIDI arguments + if (y1 != ((int)((y2-b2)*a1/a2+b1))) return 0; } } } From 0d2235b34510fefc37837e90318a52ca42133dc5 Mon Sep 17 00:00:00 2001 From: Albert Graef Date: Sun, 12 Jul 2015 05:18:03 +0200 Subject: [PATCH 6/6] corrections for rev. 4d83659 and 0b201ca --- src/pair.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/pair.c b/src/pair.c index 908f6cd..51ea274 100644 --- a/src/pair.c +++ b/src/pair.c @@ -1826,8 +1826,15 @@ int try_match_midi(PAIRHANDLE ph, uint8_t msg[], uint8_t strict_match, uint8_t* { int midival = mymsg[place]; float val; - if(p->opcode == 0xE0 && place == 1)//pitchbend is special case (14 bit number) + if(!p->raw_midi && place == 0) { + //this is the status byte, actual argument is the channel + //number in the lo-nibble + midival &= 0xF; + } + else if(p->opcode == 0xE0 && place == 1) + { + //pitchbend is special case (14 bit number) midival += mymsg[place+1]*128; } val = p->osc_scale[i]*(midival - p->midi_offset[place]) / p->midi_scale[place] + p->osc_offset[i]; @@ -1858,8 +1865,11 @@ int try_match_midi(PAIRHANDLE ph, uint8_t msg[], uint8_t strict_match, uint8_t* uint8_t y1 = mymsg[i], y2 = mymsg[j]; float a1 = p->midi_scale[i], a2 = p->midi_scale[j]; float b1 = p->midi_offset[i], b2 = p->midi_offset[j]; - if (i==0) y1 &= 0xF; - if (j==0) y2 &= 0xF; + if (!p->raw_midi) + { + if (i==0) y1 &= 0xF; + if (j==0) y2 &= 0xF; + } // give some leeway here to account for the rounding of MIDI arguments if (y1 != ((int)((y2-b2)*a1/a2+b1))) return 0; }