gbevin / SendMIDI

Multi-platform command-line tool to send out MIDI messages
https://uwyn.com
GNU General Public License v3.0
705 stars 51 forks source link

Help with slow communication #53

Open jordikt opened 3 months ago

jordikt commented 3 months ago

I am using SendMIDI since version 1.2.0

I have always got a small delay (around half second) when I hit ENTER in the command-line and the midi command is received by the DAW.

The same midi command is received immediately by the DAW if I send it using Bome Midi Translator Pro, so I assume that this delay is not caused by the "receiver", and it is caused by the sender.

Today I have seen again Geert's youtube tutorial, and the LinnStrument receives the midi commands immediately, so I wonder what is wrong in my setup. I am not an expert with Terminal, so maybe I am doing something wrong with the command-line?

As example, this line plays/pauses Cubase:

sendmidi dev 'IAC Everybody > CubaseMidi' channel 1 cc 31 127

If I type it in Terminal and I hit Enter, Cubase takes half second to play/pause. If I send the same cc with a shortcut via Bome Midi Translator Pro, Cubase plays/pauses immediately.

I want to use SendMIDI without any delay!! I will appreciate any help!!

gbevin commented 3 months ago

Bome Midi Translator Pro is already running when you send the command, that's why the MIDI envoy is instant. On the commandline, your computer needs to load sendmidi first and then send the command. Loading sendmidi on my computer only takes a few milliseconds, so I'm surprised that it takes half a second for you. Not sure how to improve that though.

Could you type this in the command line:

time sendmidi list

and look at the reported times? (see screenshot)

Screenshot 2024-07-24 at 1 21 41 PM
jordikt commented 3 months ago

Thanks for your reply, Geert

Reported times for sendmidi list:

time sendmidi list
IAC Everybody > TotalmixMackie
IAC TotalmixMackie > Everybody
IAC Everybody > CubaseMackie
IAC CubaseMackie > Everybody
IAC Everybody > CubaseMidi
IAC CubaseMidi > Everybody
IAC X2<>JV1010<>TD15K
IAC Everybody > SD+ Midi
IAC SD+ Midi > Everybody
IAC Everybody > MidiForce
IAC Midiforce > Everybody
IAC Everybody > LiveMackie
IAC LiveMackie > Everybody
Fireface UFX+ (23968278) Port 1
Fireface UFX+ (23968278) Port 2
Fireface UFX+ (23968278) MADI optical
Fireface UFX+ (23968278) MADI coaxial
sendmidi list  0,01s user 0,01s system 31% cpu 0,073 total

And reported times for two sendmidi cc that plays/pauses Cubase:

time sendmidi dev 'IAC Everybody > CubaseMidi' channel 1 cc 31 127
sendmidi dev 'IAC Everybody > CubaseMidi' channel 1 cc 31 127  0,02s user 0,01s system 29% cpu 0,086 total
time sendmidi dev 'IAC Everybody > CubaseMidi' channel 1 cc 31 127
sendmidi dev 'IAC Everybody > CubaseMidi' channel 1 cc 31 127  0,01s user 0,01s system 36% cpu 0,064 total

The delay I am experiencing from executing the order in Terminal and hear the order executed is noticeable. I guess that it should be around half second, but maybe I am wrong and it is lower than that. Anyway, it is a noticeable latency for the ears.

It has sense what you say regarding Bome: it is always running. The same happens with other apps: there is no noticeable latency if I send the same cc from Pocket Midi, Stream Deck or other hardware devices.

I wonder if it would be possible to keep sendmidi running to reduce the latency. What do you think? I suppose that keeping sendmidi running wouldn't cause any problem for the performace of the computer.

If you think it would be a good improvement, we could have new commands for that, something like:

-k or --keep -> keep sendmidi running after executing any command -q or --quit -> quit sendmidi after executing any command (by default)

gbevin commented 3 months ago

I'm questioning the usefulness of keeping it running since you'll still have to type in commands. There no buttons with predefined behavior to press. Typing commands takes a lot of time.

jordikt commented 3 months ago

I don't type sendmidi commands in terminal very often.

On the contrary, I type sendmidi commands in terminal only for testing the command-line works correctly. Once I know the command-line does what I want, I copy it and paste it on:

From my point of view, in my use case, the best of sendmidi is the freedom to send any midi message from any app that can run terminal commands. The only disadvantage I have is the latency.

So, IMO, it would be very useful to keep sendmidi running if we can reduce latency for all users that want to use sendmidi as I do.

gbevin commented 3 months ago

None of those things would work with keeping sendmidi running, the flow would be sendmidi listening for user input on the terminal when it's running, which is typically done with the keyboard. Any of those ways of running you describe would still have to load sendmidi and provide the arguments to execute. I'm still not seeing what the advantages would be. Sendmidi is not a GUI application, it's a terminal one.

jordikt commented 3 months ago

I'm sorry Geert, I don't understand what you mean. I've lost your train of thought.

Let's say I run this applescript:

if application "Cubase 12" is running then
do shell script "sendmidi dev 'IAC Everybody > CubaseMidi' channel 1 cc 31 127"
return 1
else
return 0
end if

Would Cubase receive this cc message faster if sendmidi is running? Or it doesn't matter if sendmidi is running or not because the latency will always be the same?

gbevin commented 3 months ago

That script still runs sendmidi as a command line tool, it still has to load it from disk: sendmidi dev 'IAC Everybody > CubaseMidi' channel 1 cc 31 127

jordikt commented 3 months ago

If sendmidi was always running in the background, it would be not necessary to load it, isn't it? In that scenario it would send the midi commands faster than now. It makes sense or I am missing something?

gbevin commented 3 months ago

It would, that's what sendmidi in that command does, it loads it.