amidi: add delay option
PATCH 1/1 amidi: add delay option
This patch adds a new options to amidi tool to add a delay (in milliseconds) to each MIDI message.
This is very useful when sending firmware updates to a remote device via SysEx or any other use that requires this delay in between messages.
--- amidi/amidi.1 | 14 ++++++++++++ amidi/amidi.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 81 insertions(+), 5 deletions(-)
amidi/amidi.1 +14 -0
@@ -111,6 +111,12 @@ to stop receiving data. Does not ignore Active Sensing bytes (FEh) when saving or printing received MIDI commands. +.TP +.I \-D, \-\-delay=mseconds +Adds a delay in between each MIDI message sent to a device. It is +useful when sending firmware updates via SysEx messages to a remote +device. + .SH EXAMPLES .TP
@@ -121,6 +127,14 @@ to port .I hw:0. .TP +.B amidi \-p hw:1,0,0 -s firmware.syx \-D 100 +will send the MIDI commands in +.I firmware.syx +to port +.I hw:1,0,0 +with 100 milliseconds delay in between MIDI messages. + +.TP .B amidi \-S 'F0 43 10 4C 00 00 7E 00 F7' sends an XG Reset to the default port.
amidi/amidi.c +67 -5
114 lines not on this page · raw message
Signature · 1 line
2.9.2
amidi/amidi.c static void parse_data(void) · line 330
Quoted 11 lines · Felipe F. Tonello
This patch adds a new options to amidi tool to add a delay (in milliseconds) to each MIDI message.
This is very useful when sending firmware updates to a remote device via SysEx or any other use that requires this delay in between messages.
amidi/amidi.c +5
-0+case 0xf4 : +case 0xf5 : +return 0 ;/* ignore */ +case 0xf7 : +return 0 ;/* ignore */
Silent data loss is bad.
amidi/amidi.c static void parse_data(void) · line 335
Quoted 2 lines
amidi/amidi.c +2
-0+ case 0x00 ... 0x7f: +return rstate_len ?: rstate_len -1 ;
rstate_len - 1 == -1
amidi/amidi.c int main(int argc, char *argv[]) · line 594
Quoted 6 lines
amidi/amidi.c +6
-0+int len =message_length (*data); + +/* check for variable length */ +if (len ==-1 ) { +int i =0 ; +while (data[i++] !=0xf7 );
Possible buffer overflow.
amidi/amidi.c int main(int argc, char *argv[]) · line 599
Quoted 2 lines
amidi/amidi.c +2
-0+if (len >0 && + (err =snd_rawmidi_write (output, data, len)) <0 ) {
Same here.
The most robust way to find message boundaries probably would be a state machine. However, there is actually no requirement to find all message boundaries; the _actual_ requirement is to insert pauses between SysEx messages. So don't bother to try to parse everything; just search for F0 or F7.
Regards,
Clemens
Hi Clemens,
Quoted 7 lines · Clemens Ladisch
Quoted 5 lines · Felipe F. Tonello
This patch adds a new options to amidi tool to add a delay (in milliseconds) to each MIDI message.
This is very useful when sending firmware updates to a remote device via SysEx or any other use that requires this delay in between messages.
Quoted 7 lines
amidi/amidi.c static void parse_data(void) · line 330
Quoted 5 lines
amidi/amidi.c +5
-0+case 0xf4 : +case 0xf5 : +return 0 ;/* ignore */ +case 0xf7 : +return 0 ;/* ignore */ Silent data loss is bad.
What do you mean by that?
Quoted 5 lines
amidi/amidi.c static void parse_data(void) · line 335
Quoted 3 lines
amidi/amidi.c +2
-0+ case 0x00 ... 0x7f: +return rstate_len ?: rstate_len -1 ;
rstate_len- 1 == -1
?
That's why there is this condition, if rstate_len is zero, than it returns 0.
Quoted 9 lines
amidi/amidi.c int main(int argc, char *argv[]) · line 594
Quoted 7 lines
amidi/amidi.c +6
-0+int len =message_length (*data); + +/* check for variable length */ +if (len ==-1 ) { +int i =0 ; +while (data[i++] !=0xf7 );Possible buffer overflow.
True. I could check while data + i < send_data + send_data_length.
Quoted 5 lines
amidi/amidi.c int main(int argc, char *argv[]) · line 599
Quoted 3 lines
amidi/amidi.c +2
-0+if (len >0 && + (err =snd_rawmidi_write (output, data, len)) <0 ) {Same here.
This would be solved by previous boundaries check.
Quoted 7 lines
The most robust way to find message boundaries probably would be a state machine. However, there is actually no requirement to find all message boundaries; the _actual_ requirement is to insert pauses between SysEx messages. So don't bother to try to parse everything; just search for F0 or F7.
Well, I tough it would be useful to work in any type of MIDI message not just SysEx. So, do you think only SysEx then?
Signature · 1 line
Felipe
Quoted 11 lines · Felipe Ferreri Tonello
Quoted 8 lines · Clemens Ladisch
amidi/amidi.c static void parse_data(void) · line 330
Quoted 5 lines · Felipe F. Tonello
amidi/amidi.c +5
-0+case 0xf4 : +case 0xf5 : +return 0 ;/* ignore */ +case 0xf7 : +return 0 ;/* ignore */ Silent data loss is bad.
What do you mean by that?
When you want to send the byte F5, this code will silently drop it.
Quoted 9 lines
Quoted 4 lines
amidi/amidi.c static void parse_data(void) · line 335
Quoted 2 lines
amidi/amidi.c +2
-0+ case 0x00 ... 0x7f: +return rstate_len ?: rstate_len -1 ;
rstate_len- 1 == -1?
That's why there is this condition, if
rstate_lenis zero, than it returns 0.
There is not need to use rstate_len when its value is already known and does not affect the computation; it could just be written as:
return rstate_len ?: -1;
Quoted 8 lines
Quoted 5 lines
The most robust way to find message boundaries probably would be a state machine. However, there is actually no requirement to find all message boundaries; the _actual_ requirement is to insert pauses between SysEx messages. So don't bother to try to parse everything; just search for F0 or F7.
Well, I tough it would be useful to work in any type of MIDI message not just SysEx.
But there is no _actual_ use case, where somebody actually needed it. And as shown by all those problems, handling all types of messages makes the code too complex.
Regards,
Clemens
Hi Clemens,
Quoted 11 lines · Clemens Ladisch
Quoted 10 lines · Felipe Ferreri Tonello
Quoted 8 lines · Clemens Ladisch
amidi/amidi.c static void parse_data(void) · line 330
Quoted 5 lines · Felipe F. Tonello
amidi/amidi.c +5
-0+case 0xf4 : +case 0xf5 : +return 0 ;/* ignore */ +case 0xf7 : +return 0 ;/* ignore */ Silent data loss is bad.
Quoted 3 lines
Quoted 1 line
What do you mean by that?
When you want to send the byte F5, this code will silently drop it.
I see your point, you are right. Although, as we know, the underlying driver won't send this byte anyway, but that is not for the application to decide.
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
amidi/amidi.c static void parse_data(void) · line 335
Quoted 3 lines
amidi/amidi.c +2
-0+ case 0x00 ... 0x7f: +return rstate_len ?: rstate_len -1 ;
rstate_len- 1 == -1?
Quoted 7 lines
Quoted 2 lines
That's why there is this condition, if
rstate_lenis zero, than it returns 0.There is not need to use
rstate_lenwhen its value is already known and does not affect the computation; it could just be written as:return rstate_len ?: -1;
Right, that was not the original intent, so this code was actually wrong. But I will remove it anyway based on your comment below.
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
The most robust way to find message boundaries probably would be a state machine. However, there is actually no requirement to find all message boundaries; the _actual_ requirement is to insert pauses between SysEx messages. So don't bother to try to parse everything; just search for F0 or F7.
Quoted 6 lines
Quoted 2 lines
Well, I tough it would be useful to work in any type of MIDI message not just SysEx.
But there is no _actual_ use case, where somebody actually needed it. And as shown by all those problems, handling all types of messages makes the code too complex.
True. So I will make sure to add this to the documentation.
Signature · 1 line
Felipe
On Fri, 12 Aug 2016, Clemens Ladisch wrote:
Off topic here but: what happened to that patch you proposed (requested by me) to enable/disable filtering of MIDI Clock messages, just like already exists for MIDI Active Sensing messages?
Signature · 1 line
MT