Skip to content

Commit e6ce8a2

Browse files
committed
ALSA: ump: Transmit RPN/NRPN message at each MSB/LSB data reception
The UMP 1.1 spec says that an RPN/NRPN should be sent when one of the following occurs: * a CC 38 is received * a subsequent CC 6 is received * a CC 98, 99, 100, and 101 is received, indicating the last RPN/NRPN message has ended and a new one has started That said, we should send a partial data even if it's not fully filled. Let's change the UMP conversion helper code to follow that rule. Link: https://patch.msgid.link/[email protected] Signed-off-by: Takashi Iwai <[email protected]>
1 parent 3dab73a commit e6ce8a2

File tree

2 files changed

+33
-17
lines changed

2 files changed

+33
-17
lines changed

include/sound/ump_convert.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ struct ump_cvt_to_ump_bank {
1313
unsigned char cc_nrpn_msb, cc_nrpn_lsb;
1414
unsigned char cc_data_msb, cc_data_lsb;
1515
unsigned char cc_bank_msb, cc_bank_lsb;
16+
bool cc_data_msb_set, cc_data_lsb_set;
1617
};
1718

1819
/* context for converting from MIDI1 byte stream to UMP packet */

sound/core/ump_convert.c

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -287,25 +287,37 @@ static int cvt_legacy_system_to_ump(struct ump_cvt_to_ump *cvt,
287287
return 4;
288288
}
289289

290-
static void fill_rpn(struct ump_cvt_to_ump_bank *cc,
291-
union snd_ump_midi2_msg *midi2)
290+
static int fill_rpn(struct ump_cvt_to_ump_bank *cc,
291+
union snd_ump_midi2_msg *midi2,
292+
bool flush)
292293
{
294+
if (!(cc->cc_data_lsb_set || cc->cc_data_msb_set))
295+
return 0; // skip
296+
/* when not flushing, wait for complete data set */
297+
if (!flush && (!cc->cc_data_lsb_set || !cc->cc_data_msb_set))
298+
return 0; // skip
299+
293300
if (cc->rpn_set) {
294301
midi2->rpn.status = UMP_MSG_STATUS_RPN;
295302
midi2->rpn.bank = cc->cc_rpn_msb;
296303
midi2->rpn.index = cc->cc_rpn_lsb;
297-
cc->rpn_set = 0;
298-
cc->cc_rpn_msb = cc->cc_rpn_lsb = 0;
299-
} else {
304+
} else if (cc->nrpn_set) {
300305
midi2->rpn.status = UMP_MSG_STATUS_NRPN;
301306
midi2->rpn.bank = cc->cc_nrpn_msb;
302307
midi2->rpn.index = cc->cc_nrpn_lsb;
303-
cc->nrpn_set = 0;
304-
cc->cc_nrpn_msb = cc->cc_nrpn_lsb = 0;
308+
} else {
309+
return 0; // skip
305310
}
311+
306312
midi2->rpn.data = upscale_14_to_32bit((cc->cc_data_msb << 7) |
307313
cc->cc_data_lsb);
314+
315+
cc->rpn_set = 0;
316+
cc->nrpn_set = 0;
317+
cc->cc_rpn_msb = cc->cc_rpn_lsb = 0;
308318
cc->cc_data_msb = cc->cc_data_lsb = 0;
319+
cc->cc_data_msb_set = cc->cc_data_lsb_set = 0;
320+
return 1;
309321
}
310322

311323
/* convert to a MIDI 1.0 Channel Voice message */
@@ -318,6 +330,7 @@ static int cvt_legacy_cmd_to_ump(struct ump_cvt_to_ump *cvt,
318330
struct ump_cvt_to_ump_bank *cc;
319331
union snd_ump_midi2_msg *midi2 = (union snd_ump_midi2_msg *)data;
320332
unsigned char status, channel;
333+
int ret;
321334

322335
BUILD_BUG_ON(sizeof(union snd_ump_midi1_msg) != 4);
323336
BUILD_BUG_ON(sizeof(union snd_ump_midi2_msg) != 8);
@@ -358,24 +371,29 @@ static int cvt_legacy_cmd_to_ump(struct ump_cvt_to_ump *cvt,
358371
case UMP_MSG_STATUS_CC:
359372
switch (buf[1]) {
360373
case UMP_CC_RPN_MSB:
374+
ret = fill_rpn(cc, midi2, true);
361375
cc->rpn_set = 1;
362376
cc->cc_rpn_msb = buf[2];
363-
return 0; // skip
377+
return ret;
364378
case UMP_CC_RPN_LSB:
379+
ret = fill_rpn(cc, midi2, true);
365380
cc->rpn_set = 1;
366381
cc->cc_rpn_lsb = buf[2];
367-
return 0; // skip
382+
return ret;
368383
case UMP_CC_NRPN_MSB:
384+
ret = fill_rpn(cc, midi2, true);
369385
cc->nrpn_set = 1;
370386
cc->cc_nrpn_msb = buf[2];
371-
return 0; // skip
387+
return ret;
372388
case UMP_CC_NRPN_LSB:
389+
ret = fill_rpn(cc, midi2, true);
373390
cc->nrpn_set = 1;
374391
cc->cc_nrpn_lsb = buf[2];
375-
return 0; // skip
392+
return ret;
376393
case UMP_CC_DATA:
394+
cc->cc_data_msb_set = 1;
377395
cc->cc_data_msb = buf[2];
378-
return 0; // skip
396+
return fill_rpn(cc, midi2, false);
379397
case UMP_CC_BANK_SELECT:
380398
cc->bank_set = 1;
381399
cc->cc_bank_msb = buf[2];
@@ -385,12 +403,9 @@ static int cvt_legacy_cmd_to_ump(struct ump_cvt_to_ump *cvt,
385403
cc->cc_bank_lsb = buf[2];
386404
return 0; // skip
387405
case UMP_CC_DATA_LSB:
406+
cc->cc_data_lsb_set = 1;
388407
cc->cc_data_lsb = buf[2];
389-
if (cc->rpn_set || cc->nrpn_set)
390-
fill_rpn(cc, midi2);
391-
else
392-
return 0; // skip
393-
break;
408+
return fill_rpn(cc, midi2, false);
394409
default:
395410
midi2->cc.index = buf[1];
396411
midi2->cc.data = upscale_7_to_32bit(buf[2]);

0 commit comments

Comments
 (0)