Identify what is causing delay for app to receive MIDI command

I have a universal (x86 64-bit + ARM 64-bit) macOS desktop app that responds to MIDI commands that are received via MidiPortMBS. The first thing my app does is display a status “light” on the UI when a command is received. Generally these MIDI commands are sent from a sound editing app called Pro Tools.

A user has sent me a video showing my app display MIDI activity more than one second after a command has been sent by Pro Tools. This delay is not consistent, usually happening he says when my app has been idle (not received MIDI commands) for some time.

I’m assuming that this is happening because macOS is busy scheduling other tasks and not allowing my app to respond in a timely manner. Apart from asking the user to quit all apps not required, is there something I can get the user to check, maybe in Activity Monitor to see what might be causing this?

I’ve also been reading about renice. Given this is only happening for an end user, although he has an IT department on hand, would this be something worth exploring? I’ve also found the following UI app to set the nice value: CPUSetter but would prefer not to have to ask the user to enter a renice command in terminal or run this additional app each time he runs my app.

Thanks in advance for any help.

Please use class NSProcessInfoActivityMBS to tell macOS that you are working on it.

Thanks. So are you recommending to use ‘NSProcessInfoMBS.NSActivityBackground’ in something like the following code to tell macOS that the app is performing something in the background that hasn’t been initiated by the user?

dim Activity as NSProcessInfoActivityMBS // property in app

dim ProcessInfo as NSProcessInfoMBS = NSProcessInfoMBS.processInfo
self.Activity = ProcessInfo.beginActivity(NSProcessInfoMBS.NSActivityBackground, "Backup running")

If so, do you see any issue calling this in App.Open and just leaving the app running in this mode?

Many thanks as always Christian.

You may tell macOS and play with different values.
Also you can run a Timer with e.g. 50ms to prevent your app from sleeping longer.

Okay. I’ll try the above in case this makes a difference and get my client to try. However, my app already contains a class that contains an AUPlayerMBS which is called every 30 seconds from a timer to play a very short audio WAV at 0 volume. With this timer running I can see in Activity Monitor that my app shows “Preventing Sleep” = Yes. So I’m not sure it’s an issue where the app goes to sleep but somehow goes down the macOS ranking in terms of priority. Maybe NSActivityBackground will help with this. Thanks