ErrorHandler
There are a few error messages in HISE that will usually show up a dark overlay with a (questionably worded) message and some buttons to react on it. Unfortunately, the amount of customizability is pretty low so this acts as a good way to detect whether a plugin was made with HISE or not.
Now you can completely deactivate the overlay using the preprocessor HISE_DEACTIVATE_OVERLAY
when compiling your plugin, but this is just shooting the messenger and will leave your user completely in the dark why there is no audio coming out of the plugin or which sample was not found.
This object offers a better solution with a customizable error callback that will be executed whenever the overlay would appear, so you can react on it in a way that is more consistent with your UI.
In order to use it, just call Engine.createErrorHandler() and then use its methods to customize the way you want to react to HISE error events.
Be aware that as soon as you create this object, it will deactivate the standard overlay automatically (so it's basically the same as compiling with HISE_DEACTIVATE_OVERLAY
).
Class methods
clearAllErrors
Clear all states.
ErrorHandler.clearAllErrors()
This will remove all error states (including the ones that are masked by the current error).
clearErrorLevel
Clears a state. If there is another error, it will send it again.
ErrorHandler.clearErrorLevel(int stateToClear)
Call this function if the user has resolved the error. It will then check for other errors and call the error callback again if there is another error pending.
The errors are prioritized automatically, so eg. an invalid license error will always supercede a missing samples error or a audio driver initialisation issue
getCurrentErrorLevel
Returns the current error level (and -1 if there is no error).
ErrorHandler.getCurrentErrorLevel()
Returns the current error level that the user should care about. This might not be the only error (and you can query the amount of pending issues with getNumActiveErrors()
). It will return an integer that you can compare against one of the constants of this class (all error states are available as constant, eg. eh.LicenseNotFound
).
getErrorMessage
Returns the current error message.
ErrorHandler.getErrorMessage()
This will return the message that should be displayed to the user. It is either a custom string from you calling Engine.showErrorMessage()
or one of the predefined error messages from HISE.
getNumActiveErrors
Returns the number of currently active errors. Edit on GitHub
ErrorHandler.getNumActiveErrors()
setCustomMessageToShow
Overrides the default HISE error messages with custom text.
ErrorHandler.setCustomMessageToShow(int state, String messageToShow)
If you don't like the wording of these messages, the days of messing around with the source code are finally over because you can use this method to override the default error messages for all error events.
setErrorCallback
Sets a function with two arguments (int state, String message) that will be notified at error events.
ErrorHandler.setErrorCallback(var errorCallback)
This method will register a callback that will be notified whenever an error event occurs. You can use this as starting point to setup your custom error handling that fits into your UI.
Be aware that this function is called only with the most important error and if you clear the error while an error with a lower priority is in the queue, it will fire that callback again.
simulateErrorEvent
Causes an error event to be sent through the system (for development purposes only).
ErrorHandler.simulateErrorEvent(int state)
If you're creating your custom error handling, the chances are great that you want to check how it behaves in a controlled environment so this method allows you to create artificial error events that you can then catch and handle gracefully. (In the compiled plugin this method will not do anything).