Skip to content

Commit a82e800

Browse files
author
Andrew Mee
committed
* umpToBytestream.h
* Fixed lastRPN/NRPN fields to be channel based as reported - thanks!
1 parent fd2fc1f commit a82e800

File tree

1 file changed

+59
-55
lines changed

1 file changed

+59
-55
lines changed

include/umpToBytestream.h

Lines changed: 59 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ class umpToBytestream{
3939
int writeIndex = 0;
4040
int bufferLength = 0;
4141

42+
uint8_t lastRunningStatus = 255;
43+
uint8_t lastRPN_MSB[16];
44+
uint8_t lastRPN_LSB[16];
45+
uint8_t lastNRPN_MSB[16];
46+
uint8_t lastNRPN_LSB[16];
47+
4248
void increaseWrite(){
4349
bufferLength++;
4450
writeIndex++;
@@ -61,11 +67,7 @@ class umpToBytestream{
6167
uint8_t group;
6268

6369
uint8_t filterByGroup = 255;
64-
uint8_t lastRunningStatus = 255;
65-
uint8_t lastRPN_MSB = 255;
66-
uint8_t lastRPN_LSB = 255;
67-
uint8_t lastNRPN_MSB = 255;
68-
uint8_t lastNRPN_LSB = 255;
70+
6971
bool enableRunningStatus = false;
7072

7173
umpToBytestream(){
@@ -85,10 +87,12 @@ class umpToBytestream{
8587
writeIndex = 0;
8688
bufferLength = 0;
8789
lastRunningStatus = 255;
88-
lastRPN_MSB = 255;
89-
lastRPN_LSB = 255;
90-
lastNRPN_MSB = 255;
91-
lastNRPN_LSB = 255;
90+
for (int ch = 0; ch < 16; ch++) {
91+
lastRPN_MSB[ch] = 255;
92+
lastRPN_LSB[ch] = 255;
93+
lastNRPN_MSB[ch] = 255;
94+
lastNRPN_LSB[ch] = 255;
95+
}
9296
}
9397

9498
bool availableBS(){
@@ -268,60 +272,60 @@ class umpToBytestream{
268272
}
269273
case RPN: {//rpn
270274
stsCh = CC + channel;
271-
if(lastRPN_MSB != val1 || lastRPN_LSB != val2)
272-
{
275+
if(lastRPN_MSB[channel] != val1 || lastRPN_LSB[channel] != val2)
276+
{
277+
checkRunningStatusAndAddByte(stsCh);
278+
bsOut[writeIndex] = 101;increaseWrite();
279+
bsOut[writeIndex] = val1;increaseWrite();
280+
checkRunningStatusAndAddByte(stsCh);
281+
bsOut[writeIndex] = 100;increaseWrite();
282+
bsOut[writeIndex] = val2;increaseWrite();
283+
lastRPN_MSB[channel] = val1;
284+
lastRPN_LSB[channel] = val2;
285+
lastNRPN_MSB[channel] = 255;
286+
lastNRPN_LSB[channel] = 255;
287+
}
288+
289+
290+
uint16_t val14bit = (uint16_t)M2Utils::scaleDown(UMP , 32, 14);
291+
292+
//bsOut[writeIndex] = CC + channel;increaseWrite();
273293
checkRunningStatusAndAddByte(stsCh);
274-
bsOut[writeIndex] = 101;increaseWrite();
275-
bsOut[writeIndex] = val1;increaseWrite();
294+
bsOut[writeIndex] = 6;increaseWrite();
295+
bsOut[writeIndex] = (val14bit >> 7) & 0x7F;increaseWrite();
296+
//bsOut[writeIndex] = CC + channel;increaseWrite();
276297
checkRunningStatusAndAddByte(stsCh);
277-
bsOut[writeIndex] = 100;increaseWrite();
278-
bsOut[writeIndex] = val2;increaseWrite();
279-
lastRPN_MSB = val1;
280-
lastRPN_LSB = val2;
281-
lastNRPN_MSB = 255;
282-
lastNRPN_LSB = 255;
283-
}
284-
285-
286-
uint16_t val14bit = (uint16_t)M2Utils::scaleDown(UMP , 32, 14);
287-
288-
//bsOut[writeIndex] = CC + channel;increaseWrite();
289-
checkRunningStatusAndAddByte(stsCh);
290-
bsOut[writeIndex] = 6;increaseWrite();
291-
bsOut[writeIndex] = (val14bit >> 7) & 0x7F;increaseWrite();
292-
//bsOut[writeIndex] = CC + channel;increaseWrite();
293-
checkRunningStatusAndAddByte(stsCh);
294-
bsOut[writeIndex] = 38;increaseWrite();
295-
bsOut[writeIndex] = val14bit & 0x7F;increaseWrite();
298+
bsOut[writeIndex] = 38;increaseWrite();
299+
bsOut[writeIndex] = val14bit & 0x7F;increaseWrite();
296300

297-
break;
298-
}
301+
break;
302+
}
299303
case NRPN: { //nrpn
300304
stsCh = CC + channel;
301-
if(lastRPN_MSB != val1 || lastRPN_LSB != val2)
302-
{
305+
if(lastNRPN_MSB[channel] != val1 || lastNRPN_LSB[channel] != val2)
306+
{
307+
checkRunningStatusAndAddByte(stsCh);
308+
bsOut[writeIndex] = 99;increaseWrite();
309+
bsOut[writeIndex] = val1;increaseWrite();
310+
checkRunningStatusAndAddByte(stsCh);
311+
bsOut[writeIndex] = 98;increaseWrite();
312+
bsOut[writeIndex] = val2;increaseWrite();
313+
lastRPN_MSB[channel] = 255;
314+
lastRPN_LSB[channel] = 255;
315+
lastNRPN_MSB[channel] = val1;
316+
lastNRPN_LSB[channel] = val2;
317+
}
318+
319+
uint16_t val14bit = (uint16_t)M2Utils::scaleDown(UMP, 32, 14);
320+
303321
checkRunningStatusAndAddByte(stsCh);
304-
bsOut[writeIndex] = 99;increaseWrite();
305-
bsOut[writeIndex] = val1;increaseWrite();
322+
bsOut[writeIndex] = 6;increaseWrite();
323+
bsOut[writeIndex] = (val14bit >> 7) & 0x7F;increaseWrite();
306324
checkRunningStatusAndAddByte(stsCh);
307-
bsOut[writeIndex] = 98;increaseWrite();
308-
bsOut[writeIndex] = val2;increaseWrite();
309-
lastRPN_MSB = 255;
310-
lastRPN_LSB = 255;
311-
lastNRPN_MSB = val1;
312-
lastNRPN_LSB = val2;
325+
bsOut[writeIndex] = 38;increaseWrite();
326+
bsOut[writeIndex] = val14bit & 0x7F;increaseWrite();
327+
break;
313328
}
314-
315-
uint16_t val14bit = (uint16_t)M2Utils::scaleDown(UMP, 32, 14);
316-
317-
checkRunningStatusAndAddByte(stsCh);
318-
bsOut[writeIndex] = 6;increaseWrite();
319-
bsOut[writeIndex] = (val14bit >> 7) & 0x7F;increaseWrite();
320-
checkRunningStatusAndAddByte(stsCh);
321-
bsOut[writeIndex] = 38;increaseWrite();
322-
bsOut[writeIndex] = val14bit & 0x7F;increaseWrite();
323-
break;
324-
}
325329
case PROGRAM_CHANGE: { //Program change
326330
if (ump64word1 & 0x1) {
327331
checkRunningStatusAndAddByte(CC + channel);

0 commit comments

Comments
 (0)