This article covers how to add NSM support to your application. It assumes you can include a C header, and set C type callbacks. It is quite easy to add NSM support to most programs as there is a header file that does the OSC handling for us, and we are provided with a callback when an open or save event occurs.
This tutorial covers only the basic open / save functionality of NSM. It is capable of much more, please see the NSM API for details. I’ll first describe what happens in pseudo code, and then in actual code.
- Check the “NSM_URL” environment varibale: if it exists, NSM is running.
- If NSM_URL does NOT exist: ignore session management.
- Else create an NSM client.
- NSM says what session to open: including JACK client to use.
- Setup program to use JACK client name, and load session as specified.
- Periodically call nsm_check() to see if we have events to handle.
- Save event: we get a callback. Save over the previously loaded session.
- SIGTERM is sent to our process when we should quit: that should be handled gracefully
Its very easy to add NSM support to most programs! The only reason it could be difficult is due to JACK being setup too soon in the program, before NSM tells the program what client name to use. I’ve encountered this in Luppp: however it is quite possible to refactor the initialization stage, and make this work.
NSM is a joy to use, the more applications that support it, the better! If you’ve been thinking about implementing support, please take this post as the final encouragement to do it: user-exerperience will improve.