Assists music production by grouping standalone programs into sessions. Community version of "Non Session Manager".
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

947 lines
36KB

  1. ////
  2. This is "asciidoctor", not plain "asciidoc".
  3. https://asciidoctor.org/docs/user-manual/
  4. 100 characters per line (soft limit).
  5. ////
  6. ////
  7. This documentation is licensed under the Creative Commons Attribution-ShareAlike 2.5 International License.
  8. To view a copy of this license, visit https://creativecommons.org/licenses/by-sa/2.5/legalcode or send a
  9. letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.
  10. A copy of the license has been provided in the file documentation/API/LICENSE.
  11. ////
  12. ////
  13. The revnumber API 1.1.1 below is autogenerated. Please do not touch this line.
  14. ////
  15. :authors: Jonathan Moore Liles, Nils Hilbricht
  16. :revnumber: API 1.1.2
  17. :revremark: License CC-By-SA v2.5
  18. :iconfont-remote!:
  19. :!webfonts:
  20. :sectnums:
  21. :sectnumlevels: 4
  22. :toc:
  23. :toc-title: Table of Contents
  24. :toclevels: 4
  25. = New Session Manager - API
  26. IMPORTANT: "New Session Manager" is a community version of the
  27. link:http://non.tuxfamily.org/nsm/API.html["Non Session Manager" by Jonathan Moore Liles], who also
  28. wrote the majority of this API document, especially the API itself. *The API is the same*. Any
  29. technical changes or differences in behaviour are described in <<API Versions and Behaviour Changes>>.
  30. All other changes to this document can be reviewed by accessing the git log. This document is
  31. licensed under CC-By-Sa v2.5. See link:https://github.com/jackaudio/new-session-manager/tree/master/docs/src/api[LICENSE]
  32. IMPORTANT: The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD
  33. NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as
  34. described in link:https://tools.ietf.org/html/rfc2119[RFC 2119].
  35. The "New Session Manager"-API is used by many music and audio programs in Linux distributions
  36. to allow any number of independent programs to be managed together as part of a logical session
  37. (i.e. a song). Thus, operations such as loading and saving are synchronized.
  38. The API comprises a simple Open Sound Control (OSC) based protocol, along with some behavioral
  39. guidelines, which can easily be implemented by various applications.
  40. This project contains a program called `nsmd` which is an implementation of the server side of
  41. the NSM API. `nsmd` can be controlled by direct OSC messages, or (more commonly) a GUI:
  42. Included in this package is the `nsm-legacy-gui`, which gets symlinked to "non-session-manager`.
  43. Another GUI is "Agordejo". Other applications exist that (partially) support the NSM API and are able
  44. to load clients, but they do not use the New-Session-Manager (or Non-Session-Manager) implementation
  45. and are therefore out of scope for this document.
  46. However, the same server-side API can also be implemented by other programs (such as Carla),
  47. although consistency and robustness will likely suffer if non-NSM compliant clients are allowed to
  48. participate in a session.
  49. There is no direct dependency for client implementations, as long as they
  50. can send and receive OSC.
  51. Some clients use `liblo` (the OSC library), which becomes a dependency if you choose to implement
  52. NSM-support with the provided header file `nsm.h` (`extras/nsm.h/nsm.h` in the git repository).
  53. Some clients use the provided single-file python library `pynsm` (`extras/pynsm/nsmclient.py` in the git repository)
  54. which has no dependencies outside the Python3 standard library.
  55. The aim of this project is to thoroughly define the behavior required of clients. Often the
  56. difficulty with other session-management approaches has been not in implementing code-support for
  57. them, but in not defining rules and behaviour clearly enough.
  58. As written above unambiguous rules are created by using RFC 2119 in this document. For the good of
  59. the user, these rules are meant to be followed and are non-negotiable. If an application does not
  60. conform to this specification it should be considered broken. Consistency across applications under
  61. session management is very important for a good user experience.
  62. == Client Behavior Under Session Management
  63. Most graphical applications make available to the user a common set of file operations, typically
  64. presented under a File or Project menu.
  65. These are: New, Open, Save, Save As, Close and Quit or Exit.
  66. The following sub-sections describe how these options should behave when the application is part of
  67. an NSM session. These rules only apply when session management is active, that is, after the
  68. `announce` handshake described in the <<NSM OSC Protocol>> section. In order to provide a
  69. consistent and predictable user experience, it is critically important for applications to adhere
  70. to these guidelines.
  71. === File Menu
  72. ==== New
  73. This option MAY empty/reset the current file or project (possibly after user confirmation).
  74. It MUST NOT allow the user to create a new project/file in another location.
  75. ==== Open
  76. This option MUST be disabled.
  77. The application MAY elect to implement an option called "Import into Session", which creates a
  78. copy of a file/project which is then saved at the session path provided by NSM.
  79. ==== Save
  80. This option should behave as normal, saving the current file/project as established by the NSM
  81. `open` message.
  82. This option MUST NOT present the user with a choice of where to save the file.
  83. ==== Save As
  84. This option MUST be disabled.
  85. The application MAY elect to implement an option called 'Export from Session', which
  86. creates a copy of the current file/project which is then saved in a user-specified location outside
  87. of the session path provided by NSM.
  88. ==== Close (as distinguished from Quit or Exit)
  89. This option MUST be disabled unless its meaning is to disconnect the application from session
  90. management.
  91. ==== Quit or Exit
  92. This option MAY behave as normal (possibly asking the user to confirm exiting), or MAY do nothing
  93. to only allow quit from the session-manager control.
  94. When the client supports :optional-gui: this option SHOULD be replaced with hiding the client's GUI
  95. so a quit by window manager hides.
  96. === Data Storage
  97. ==== Internal Files
  98. All project specific data created by a client MUST be stored in the per-client storage area
  99. provided by NSM. This includes all recorded audio and MIDI files, snapshots, etc. Only global
  100. configuration items, exports, and renders of the project may be stored elsewhere (wherever the user
  101. specifies).
  102. ==== External Files
  103. Files required by the project but external to it (typically read-only data such as audio samples)
  104. SHOULD be referenced by creating a symbolic link within the assigned session area, and then
  105. referring to the symlink. This allows sessions to be archived and transported simply (e.g. with
  106. "tar -h") by tools that have no knowledge of the project formats of the various clients in the
  107. session. The symlinks thus created should, at the very least, be named after the files they refer
  108. to. Some unique component may be required to prevent collisions.
  109. ==== Session Root and Session Directories
  110. Client programs MUST NOT handle the following themselves. This section is background-information.
  111. NSM follows the link:https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html[XDG Base Directory Specifications]
  112. All existing and new sessions are directories below the session-root, which defaults to
  113. `$XDG_DATA_HOME/nsm/`, which usually results in `$HOME/.local/share/nsm/`.
  114. Each session directory contains a file `session.nsm` with one client per line `name:executable:UID\n`
  115. For example:
  116. ```
  117. JACKPatch:jackpatch:nBEIQ
  118. jack_mixer:jack_mixer:nTXHV
  119. Carla-Rack:carla-rack:nFAOD
  120. ```
  121. `nsmd` loads and saves this file, client names are their self-reported names.
  122. The file format is final and frozen. Additions or changes SHALL NOT be made.
  123. ===== Subdirectories / Hierarchical Structure
  124. Subdirectories MAY be made to organize sessions into meaningful structures, such as album/track or
  125. composer/genre/piece. For example: `Johann Sebastian Bach/Kantaten/Wie schön leuchtet der Morgenstern`.
  126. Which results in the same directory structure on disk. Session names can contain any characters that
  127. are supported by the underlying file system, usually UTF-8.
  128. Subdirectories are created by either `nsmd` itself or by the users themselves, through their file
  129. manager or a GUI (while the session is not open).
  130. The project_name from `/nsm/server/new s:project_name` accepts the format `a/b/c/d`.
  131. Any session itself MUST be a "leaf" in this directory tree. A session MUST NOT contain further
  132. session subdirectories: any directory that contains a file `session.nsm` is the final
  133. element in the hierarchy.
  134. ===== Write-Protection for Session Templates
  135. Write protection for a whole session directory can either happen by "accident" (files from
  136. another user, a network mount etc.) or on purpose, to protect a session template against accidental
  137. changes. The latter is possible with a recursive `chown`, `chmod` or `chattr -R +i session-dir`.
  138. nsmd itself just checks if `session.nsm` is read-only. In this case it will not send the save
  139. command to it's session clients. This does not prevent hypothetical problems when the user
  140. triggers a clients internal save command in a write protected directory. Clients SHOULD handle
  141. their write protected save files themselves.
  142. Advanced contraptions, like overlay filesystems or copy-on-write hardlinks to create read-only
  143. sessions without the clients noticing, are out of scope for nsm.
  144. ===== Lockfiles
  145. Because multiple `nsmd` can run at the same time we need to prevent accidental write-access to the
  146. same session by different nsm-daemons, and subsequently GUIs.
  147. Therefore each currently open session creates a lockfile under `$XDG_RUNTIME_DIR/nsm/` (usually
  148. `/run/user/XXXX/nsm/`) that tells `nsmd` to not open such a locked session. This directory gets
  149. cleaned by the operating system, preventing sessions to stay locked after e.g. a power failure.
  150. If the system is not XDG-compliant nsmd will try to fallback to `/run/user/XXXX`, which must exist
  151. according to the Linux Filesystem Hierarchy Standard. I this also fails the user has to
  152. set $XDG_RUNTIME_DIR manually to start nsmd.
  153. The lockfile is named after the simple session name combined with a numeric ID for the session
  154. root. It is possible that two `nsmd` opened two different session roots, both with the same simple
  155. session name, e.g. "my song". Lockfiles are able to distinguish between those and will not prevent
  156. access in this scenario. The numeric ID is a djb2 hash modulo (%) 65521 of the session root directory
  157. (see `src/file.cpp` function `simple_hash()`).
  158. The lockfile contains, on separate lines:
  159. * The absolute path to the session, including the root-dir, which could be overriden by `nsmd --session-root`, allowing two sessions of the same basic name in different roots.
  160. * the OSC URL of the server that runs this session, the same as `$NSM_URL`.
  161. * the PID of `nsmd`
  162. Example:
  163. ```
  164. /home/johann/.local/share/nsm/cantatas/easter1751
  165. osc.udp://myuser.localdomain:11287/
  166. 3022
  167. ```
  168. ===== Daemon Discovery
  169. Each running `nsmd`, per user, creates a state file under `$XDG_RUNTIME_DIR/nsm/d/` (usually
  170. `/run/user/XXXX/nsm/d/`) that can be used to look up running daemons, even if no session is loaded.
  171. The name of the file is `nsmd` PID and the files contain their daemons osc.udp URL that is
  172. compatible with the --nsm-url parameter of the GUI.
  173. This enables you to e.g. start nsmd at boot with a random free port. Server-control programs such
  174. as GUIs can then use this to look for running servers without requiring the user to look up and
  175. input an osc URL manually as command line parameter.
  176. == NSM OSC Protocol
  177. All message parameters are REQUIRED. All messages MUST be sent from the same socket as the `announce`
  178. message, using the `lo_send_from` method of liblo or its equivalent, as the server uses the return
  179. addresses to distinguish between clients.
  180. Clients MUST create thier OSC servers using the same protocol (UDP,TCP) as found in `NSM_URL`.
  181. `nsmd` itself is using UDP only.
  182. === Establishing a Connection
  183. ==== Announce
  184. At launch, the client MUST check the environment for the value of `NSM_URL`. If present, the client
  185. MUST send the following message to the provided address as soon as it is ready to respond to the
  186. `/nsm/client/open` event:
  187. [source%nowrap,OSC]
  188. ----
  189. /nsm/server/announce s:application_name s:capabilities s:executable_name i:api_version_major i:api_version_minor i:pid
  190. ----
  191. If `NSM_URL` is undefined, invalid, or unreachable, then the client should proceed assuming that
  192. session management is unavailable.
  193. `api_version_major` and `api_version_minor` must be the two parts of the version number of the NSM API
  194. as defined by this document.
  195. Note that if the application intends to register JACK clients, `application_name` MUST be the same as
  196. the name that would normally be passed to `jack_client_open`. For example, Non-Mixer sends
  197. "Non-Mixer" as its `application_name`. Applications MUST NOT register their JACK clients until
  198. receiving an `open` message; the `open` message will provide a unique client name prefix suitable for
  199. passing to JACK. This is probably the most complex requirement of the NSM API, but it isn't
  200. difficult to implement, especially if the application simply wishes to delay its initialization
  201. process briefly while awaiting the `announce` reply and subsequent `open` message.
  202. `capabilities` MUST be a string containing a colon separated list of the special capabilities the
  203. client possesses. e.g. `:dirty:switch:progress:`
  204. `executable_name` MUST be the executable name that the program was launched with. For C programs,
  205. this is simply the value of `argv[0]`. Note that hardcoding the name of the program here is not the
  206. same as using, as the user may have launched the program from a script with a different name using
  207. exec, or have created a symlink to the program. Getting the correct value in scripting languages
  208. like Python can be more challenging.
  209. .Available Client Capabilities
  210. [options="header", stripes=even]
  211. |===
  212. |Name | Description
  213. |switch | client is capable of responding to multiple `open` messages without restarting
  214. |dirty | client knows when it has unsaved changes
  215. |progress | client can send progress updates during time-consuming operations
  216. |message | client can send textual status updates
  217. |optional-gui | client has an optional GUI
  218. |===
  219. ==== Response
  220. The server will respond to the client's announce message with the following message:
  221. [source%nowrap,OSC]
  222. ----
  223. /reply "/nsm/server/announce" s:message s:name_of_session_manager s:capabilities
  224. ----
  225. `message` is a welcome message.
  226. The value of `name_of_session_manager` will depend on the implementation of the NSM server. It
  227. might say "New Session Manager", or it might say "Non Session Manager" etc. This is for display to
  228. the user.
  229. `capabilities` will be a string containing a colon separated list of special server capabilities.
  230. Presently, the server `capabilities` are:
  231. .Available Server Capabilities
  232. [options="header", stripes=even]
  233. |===
  234. |Name | Description
  235. |server-control | client-to-server control
  236. |broadcast | server responds to /nsm/server/broadcast message
  237. |optional-gui | server responds to optional-gui messages. This capability is always present and MUST be supported by any server implementation.
  238. |===
  239. A client should not consider itself to be under session management until it receives this response.
  240. For example, the Non applications activate their "SM" blinkers at this time.
  241. If there is an error, a reply of the following form will be sent to the client:
  242. [source%nowrap,OSC]
  243. ----
  244. /error "/nsm/server/announce" i:error_code s:error_message
  245. ----
  246. The following table defines possible values of `error_code`:
  247. .Response codes
  248. [options="header", stripes=even]
  249. |===
  250. |Code | Meaning
  251. |ERR_GENERAL | General Error
  252. |ERR_INCOMPATIBLE_API | Incompatible API version
  253. |ERR_BLACKLISTED | Client has been blacklisted.
  254. |===
  255. === Server to Client Control Messages
  256. Compliant clients MUST accept the client control messages described in this section. All client
  257. control messages REQUIRE a response. Responses MUST be delivered back to the sender (`nsmd`) from the
  258. same socket used by the client in its `announce` message (by using `lo_send_from`) AFTER the action has
  259. been completed or if an error is encountered. The required response is described in the subsection
  260. for each message.
  261. If there is an error and the action cannot be completed, then `error_code` MUST be set to a valid
  262. error code (see <<Error Code Definitions>>) and `message` to a string describing the problem
  263. (suitable for display to the user).
  264. The reply can take one of the following two forms, where path MUST be the `path` of the message being
  265. replied to (e.g. "nsm/client/save":
  266. [source%nowrap,OSC]
  267. ----
  268. /reply s:path s:message
  269. ----
  270. [source%nowrap,OSC]
  271. ----
  272. /error s:path i:error_code s:message
  273. ----
  274. ==== Quit
  275. There is no message for this. Clients will receive the Unix SIGTERM signal and MUST close cleanly
  276. IMMEDIATELY, without displaying any kind of dialog to the user and regardless of whether or not
  277. unsaved changes would be lost. When a session is closed the application will receive this signal
  278. soon after having responded to a `save` message.
  279. [#server-to-client-control-messages-open]
  280. ==== Open
  281. [source%nowrap,OSC]
  282. ----
  283. /nsm/client/open s:path_to_instance_specific_project s:display_name s:client_id
  284. ----
  285. `path_to_instance_specific_project` is a path name in the form client_name.ID, assigned to the
  286. client for storing its project data. The client MUST choose one of the four strategies below to
  287. save, so that every file in the session can be traced back to a client and, vice versa, a client
  288. name.ID can be used to look up all its files. (For example to clean up the session dir)
  289. * The client has no state and does not save at all
  290. ** and it MUST NOT misuse e.g. ~/.config to save session specific information e.g. synth-instrument settings
  291. * The client may use the path client_name.ID directly, resulting in a file client_name.ID in the session directory
  292. * The client may append its native file extension (e.g. `.json`) to the path client_name.ID
  293. * The client may use the path as directory, creating arbitrary files below, for example recorded .wav.
  294. ** and it MUST NOT use the client ID below this point. This way the data stays transferable by hand to another client instance (in another session).
  295. ** best case practice is to always use the same file names, for example `client_name.ID/savefile.json`
  296. If a project exists at the path, the client MUST immediately open it.
  297. If a project does not exist at the path, then the client MUST immediately create and open a new one
  298. at the specified path or, for clients which hold all their state in memory, store the path for
  299. later use when responding to the `save` message.
  300. No file or directory will be created at the specified path by the server. It is up to the client to
  301. create what it needs.
  302. For clients which HAVE NOT specified the `:switch:` capability, the `open` message will only be
  303. delivered once, immediately following the `announce` response.
  304. For clients which HAVE specified the `:switch:` capability, the client MUST immediately switch to the
  305. specified project or create a new one if it doesn't exist.
  306. Clients which are incapable of switching projects or are prone to crashing upon switching MUST NOT
  307. include `:switch:` in their capability string.
  308. If the user the is allowed to run two or more instances of the application simultaneously
  309. then such an application MUST PRE-PEND the provided `client_id` string, followed by "/", to any
  310. names it registers with common subsystems (e.g. JACK client names). This ensures that multiple
  311. instances of the same application can be restored in any order without scrambling the JACK
  312. connections or causing other conflicts.
  313. The provided `client_id` will be a concatenation of the value of `application_name` sent by the
  314. client in its `announce` message and a unique identifier.
  315. Therefore, applications which create single JACK clients can use the value of `client_id` directly
  316. as their JACK client name.
  317. Applications which register multiple JACK clients (e.g. Carla or Non-Mixer) MUST PRE-PEND
  318. `client_id` value, followed by "/", to the client names they register with JACK and the application
  319. determined part MUST be unique for that (JACK) client.
  320. For example, Carla is a plugin-host that loads each plugin as JACK client.
  321. Suitable JACK client names are: `carla-jack-multi.nBAF/ZynAddSubFx` or `carla-jack-multi.nBAF/Helm`
  322. Please note that ZynAddSubFx and Helm are *not ports* but clients. Each of them can have any number
  323. of audio and midi ports below them.
  324. Note that this means that the application MUST NOT register with JACK (or any
  325. other subsystem requiring unique names) until it receives an `open` message from NSM. Likewise,
  326. applications with the `:switch:` capability should close their JACK clients and re-create them with
  327. using the new `client_id` (renaming JACK-clients is not possible, only ports).
  328. A response is REQUIRED as soon as the open operation has been completed. Ongoing progress MAY be
  329. indicated by sending messages to `/nsm/client/progress`.
  330. ===== Response
  331. The client MUST respond to the 'open' message with:
  332. [source%nowrap,OSC]
  333. ----
  334. /reply "/nsm/client/open" s:message
  335. ----
  336. Or
  337. [source%nowrap,OSC]
  338. ----
  339. /error "/nsm/client/open" i:error_code s:message
  340. ----
  341. .Response codes
  342. [options="header", stripes=even]
  343. |===
  344. |Code | Meaning
  345. |ERR | General Error
  346. |ERR_BAD_PROJECT | An existing project file was found to be corrupt
  347. |ERR_CREATE_FAILED | A new project could not be created
  348. |ERR_UNSAVED_CHANGES | Unsaved changes would be lost
  349. |ERR_NOT_NOW | Operation cannot be completed at this time
  350. |===
  351. ==== Save
  352. [source%nowrap,OSC]
  353. ----
  354. /nsm/client/save
  355. ----
  356. This message will only be delivered after a previous `open` message, and may be sent any number of
  357. times within the course of a session (including zero, if the user aborts the session).
  358. ===== Response
  359. [source%nowrap,OSC]
  360. ----
  361. /reply "/nsm/client/save" s:message
  362. ----
  363. Or
  364. [source%nowrap,OSC]
  365. ----
  366. /error "/nsm/client/save" i:error_code s:message
  367. ----
  368. .Response codes
  369. [options="header", stripes=even]
  370. |===
  371. |Code | Meaning
  372. |ERR | General Error
  373. |ERR_SAVE_FAILED | Project could not be saved
  374. |ERR_NOT_NOW | Operation cannot be completed at this time
  375. |===
  376. === Server to Client Informational Messages
  377. ==== Session is Loaded
  378. Accepting this message is optional. The intent is to signal to clients which may have some
  379. interdependence (say, peer to peer OSC connections) that the session is fully loaded and all their
  380. peers are available. Most clients will not need to act on this message. This message has no meaning
  381. when a session is being built or run; only when it is initially loaded. Clients who intend to act
  382. on this message MUST NOT do so by delaying initialization waiting for it.
  383. [source%nowrap,OSC]
  384. ----
  385. /nsm/client/session_is_loaded
  386. ----
  387. This message does not require a response.
  388. ==== Show Optional Gui
  389. If the client has specified the `optional-gui` capability, then it may receive this message from the
  390. server when the user wishes to change the visibility state of the GUI. It doesn't matter if the
  391. optional GUI is integrated with the program or if it is a separate program \(as is the case with
  392. SooperLooper\). When the GUI is hidden, there should be no window mapped and if the GUI is a
  393. separate program, it should be killed.
  394. [source%nowrap,OSC]
  395. ----
  396. /nsm/client/show_optional_gui
  397. ----
  398. [source%nowrap,OSC]
  399. ----
  400. /nsm/client/hide_optional_gui
  401. ----
  402. This message does not require a response.
  403. === Client to Server Informational Messages
  404. ==== Optional GUI
  405. If the client has specified the `optional-gui` capability, then it MUST send this message whenever
  406. the state of visibility of the optional GUI has changed. It also MUST send this message after its
  407. announce message to indicate the initial visibility state of the optional GUI.
  408. The client SHOULD always start hidden, if not saved as visible. That implies the first load, after
  409. adding to the session, SHOULD always be hidden.
  410. It is the responsibility of the client to remember the visibility state of its GUI across session
  411. loads.
  412. [source%nowrap,OSC]
  413. ----
  414. /nsm/client/gui_is_hidden
  415. ----
  416. [source%nowrap,OSC]
  417. ----
  418. /nsm/client/gui_is_shown
  419. ----
  420. No response will be delivered.
  421. ==== Progress
  422. [source%nowrap,OSC]
  423. ----
  424. /nsm/client/progress f:progress
  425. ----
  426. For potentially time-consuming operations, such as `save` and `open`, progress updates may be
  427. indicated throughout the duration by sending a floating point value between 0.0 and 1.0, 1.0
  428. indicating completion, to the NSM server.
  429. The server will not send a response to these messages, but will relay the information to the user.
  430. Note that even when using the `progress` feature, the final response to the `save` or `open`
  431. message is still REQUIRED.
  432. Clients which intend to send progress messages MUST include `:progress:` in their `announce`
  433. capability string.
  434. ==== Dirtiness
  435. [source%nowrap,OSC]
  436. ----
  437. /nsm/client/is_dirty
  438. ----
  439. [source%nowrap,OSC]
  440. ----
  441. /nsm/client/is_clean
  442. ----
  443. Some clients may be able to inform the server when they have unsaved changes pending. Such clients
  444. may optionally send `is_dirty` and `is_clean` messages.
  445. Clients which have and use this capability MUST include `:dirty:` in their `announce` capability string.
  446. ==== Status Messsages
  447. [source%nowrap,OSC]
  448. ----
  449. /nsm/client/message i:priority s:message
  450. ----
  451. Clients may send miscellaneous status updates to the server for possible display to the user. This
  452. may simply be chatter that is normally written to the console. `priority` MUST be a number from 0
  453. to 3, 3 being the most important.
  454. Clients which have and use this capability MUST include `:message:` in their `announce` capability
  455. string.
  456. === Error Code Definitions
  457. .Error Code Definitions
  458. [options="header", stripes=even]
  459. |===
  460. |Symbolic Name | Integer Value
  461. |ERR_GENERAL | -1
  462. |ERR_INCOMPATIBLE_API | -2
  463. |ERR_BLACKLISTED | -3
  464. |ERR_LAUNCH_FAILED | -4
  465. |ERR_NO_SUCH_FILE | -5
  466. |ERR_NO_SESSION_OPEN | -6
  467. |ERR_UNSAVED_CHANGES | -7
  468. |ERR_NOT_NOW | -8
  469. |ERR_BAD_PROJECT | -9
  470. |ERR_CREATE_FAILED | -10
  471. |===
  472. === Client to Server Control
  473. If the server publishes the `:server-control:` capability, then clients can also initiate action by
  474. the server. For example, a client might implement a 'Save All' option which sends a
  475. `/nsm/server/save` message to the server, rather than requiring the user to switch to the session
  476. management interface to effect the save.
  477. === Server Control API
  478. The session manager not only manages clients via OSC, but it is itself controlled via OSC messages.
  479. The server responds to the following messages.
  480. All of the following messages will be responded to, at the sender's address, with one of the two
  481. following messages:
  482. [source%nowrap,OSC]
  483. ----
  484. /reply s:path s:message
  485. ----
  486. [source%nowrap,OSC]
  487. ----
  488. /error s:path i:error_code s:message
  489. ----
  490. The first parameter of the reply is the path to the message being replied to. The `/error` reply
  491. includes an integer error code (non-zero indicates error). `message` will be a description of the
  492. error.
  493. The possible errors are:
  494. .Responses
  495. [options="header", stripes=even]
  496. |===
  497. |Code |Meaning
  498. |ERR_GENERAL | General Error
  499. |ERR_LAUNCH_FAILED | Launch failed
  500. |ERR_NO_SUCH_FILE | No such file
  501. |ERR_NO_SESSION | No session is open
  502. |ERR_UNSAVED_CHANGES | Unsaved changes would be lost
  503. |===
  504. * `/nsm/server/add s:executable_name`
  505. ** Adds a client to the current session.
  506. * `/nsm/server/save`
  507. ** Saves the current session.
  508. * `/nsm/server/open s:project_name`
  509. ** Saves the current session and loads a new session.
  510. * `/nsm/server/new s:project_name`
  511. ** Saves the current session and creates a new session.
  512. * `/nsm/server/duplicate s:new_project`
  513. ** Saves and closes the current session, makes a copy, and opens it.
  514. * `/nsm/server/close`
  515. ** Saves and closes the current session.
  516. * `/nsm/server/abort`
  517. ** Closes the current session WITHOUT SAVING
  518. * `/nsm/server/quit`
  519. ** Saves and closes the current session and terminates the server.
  520. * `/nsm/server/list`
  521. ** Lists available projects. One `/reply` message will be sent for each existing project.
  522. ** Afer listing the last session one final `/reply` with `/nsm/server/list, ""` will be send. That is an empty string.
  523. ==== Client to Client Communication
  524. If the server includes `:broadcast:` in its capability string, then clients may send broadcast
  525. messages to each other through the NSM server. Clients may send messages to the server at the path
  526. `/nsm/server/broadcast`.
  527. The format of this message is as follows:
  528. [source%nowrap,OSC]
  529. ----
  530. /nsm/server/broadcast s:path [arguments...]
  531. ----
  532. The message will then be relayed to all clients in the session at the path `path` (with the
  533. arguments shifted by one).
  534. For example the message:
  535. [source%nowrap,OSC]
  536. ----
  537. /nsm/server/broadcast /tempomap/update "0,120,4/4:12351234,240,4/4"
  538. ----
  539. Would broadcast the following message to all clients in the session (except for the sender), some
  540. of which might respond to the message by updating their own tempo maps.
  541. [source%nowrap,OSC]
  542. ----
  543. /tempomap/update "0,120,4/4:12351234,240,4/4"
  544. ----
  545. The Non programs use this feature to establish peer to peer OSC communication by symbolic names
  546. (client IDs) without having to remember the OSC URLs of peers across sessions.
  547. == API Versions and Behaviour Changes
  548. Here we will document all technical changes or differences in behaviour together with their API and
  549. project version numbers. The term "original" refers to Non Session Manager and "new" refers to New
  550. Session Manager.
  551. Version numbers follow link:https://semver.org/spec/v2.0.0.html[Semantic Versioning 2.0.0]
  552. .Semantic Versioning Scheme
  553. ```
  554. Given a version number MAJOR.MINOR.PATCH, increment the:
  555. MAJOR version when you make incompatible API changes,
  556. MINOR version when you add functionality in a backwards compatible manner, and
  557. PATCH version when you make backwards compatible bug fixes.
  558. ```
  559. .NSM Version Numbers
  560. [options="header", stripes=even]
  561. |===
  562. |Subject | Version
  563. |Non Session Manager at moment of fork | 1.2 (June 2020)
  564. |Non Session Manager API | 1.0 link:https://github.com/original-male/non/blob/master/session-manager/src/nsmd.C[NON nsmd.C]
  565. |Original API Document | 1.0 link:http://non.tuxfamily.org/nsm/API.html[non.tuxfamily.org/nsm/API.html]
  566. |New Session Manager | 1.6.0
  567. |New Session Manager API | 1.1.2 link:https://github.com/jackaudio/new-session-manager/blob/master/src/nsmd.cpp[NEW nsmd.cpp]
  568. |New API Document | 1.5.0 link:#[Here]
  569. |===
  570. === Guidelines
  571. The most important factor in decision making is to keep client compatibility at 100%.
  572. No client will ever receive an unrequested OSC message except those in API 1.0.0.
  573. Messages that drastically change existing `/nsm/client/` or `/nsm/server` behaviour require an
  574. inrecement to `API_VERSION_MAJOR`, which we want to avoid.
  575. `nsmd` checks if the clients `API_VERSION_MAJOR` is greater than its own and refuses the client
  576. with `ERR_INCOMPATIBLE_API`.
  577. All changes (that concern client/server behaviour) that increment `API_VERSION_MINOR` will be
  578. request-only or gated by new capabilities (e.g. `:optional-gui:`). `nsmd` will not send any
  579. messages if a capability was not sent by the client in <<Announce,`announce`>>. This includes
  580. mostly optional features about requesting extra information.
  581. New actions for server-control, for example a hypothetical `/nsm/server/save_as`, which would be
  582. triggered by the client and would only be *answered* by the server ("no unrequested message") will
  583. increment `API_VERSION_MINOR`.
  584. All changes that increment `API_VERSION_PATCH` will not have any effect on behaviour, except to
  585. fix clear problems, where "problem" is defined by having a different effect than described in this
  586. document, which includes technical problems such as crashes.
  587. All messages regarding GUI-communication that start with `/nsm/gui/...` were undocumented in API
  588. 1.0.0 and only used by `non-session-manager` / `nsm-legacy-gui`. Until properly documented in this
  589. document this part of the API is considered unstable and may change at any time without notice.
  590. However, when changing already existing messages and behaviour it MAY increment `API_VERSION_MINOR`
  591. or `API_VERSION_PATCH`. In that case it will appear in the list below.
  592. Last factor of compatibility is that any unknown message sent to `nsmd` will just print a warning
  593. message to stdout, but will otherwise be ignored. This secures a stable server, even when a client
  594. misbehaves and sends too-new messages outside of announced :capabilites:
  595. === Changes in API Version 1.1.0
  596. Rewritten API document without code changes to adapt to existing code or existing client behaviour:
  597. * Changed versioning scheme to Semantic Versioning with three positions Major.Minor.Patch
  598. * <<Quit or Exit>> SHOULD hide instead of exiting when :optional-gui: is supported and MAY not
  599. act on the quit through menu otherwise.
  600. * <<#server-to-client-control-messages-open,Open>>: Make clear that there are only certain
  601. possibilities for save paths. We added MUST because the rule was just implied before.
  602. * <<#server-to-client-control-messages-open,Open>>: Make clear that the delimiter for
  603. multi-jack clients is "/".
  604. * <<Optional GUI>> SHOULD start hidden, always after a fresh add to the session. After that saving
  605. the visibility state may override it for next time.
  606. * <<Progress>> MUST be announced in :capabilities: . Before there was a lower case "should",
  607. which means nothing. Parallel-examples in the specs cleary say that supporting optional features must be announced first.
  608. ** Same for <<Dirtiness>> and <<Status Messsages>>.
  609. * <<Status Messsages>> have priority numbers between 0 and 3, so they MUST send that.
  610. It was never an arbitrary value.
  611. Code changes:
  612. * <<Server Control API>>: `/nsm/server/list` chain of single OSC messages, one for each session,
  613. is now finalized with sending and empty string "" as session name. Previously this was just
  614. a symbolically irrelevant console message `"Done."`
  615. * Replies to `/nsm/server/save` etc. will now be sent back to the sender and not falsely to the last
  616. client who replied to `/nsm/client/save`. This alone would only require API_VERSION_PATCH
  617. increment, but we are already incrementing minor.
  618. * <<Server Control API>>: `/nsm/server/add` was replying with an undocumented error code on success.
  619. Instead, as this document always specificed, it now sends `"/reply", path, "Launched."`.
  620. Again, this would have been just API_VERSION_PATCH on its own.
  621. Undocumented (Unstable) `/nsm/gui` protocol
  622. * Send client status after a GUI attaches to running server. This
  623. was not happening before, but it was the intention. It was just broken in nsmd.cpp. This alone
  624. would only require API_VERSION_PATCH increment, but we are already incrementing minor.
  625. * Send label "launch error!" when a program is added (or loaded) that
  626. does not exist in $PATH. This requires no adaptation of any client, server or GUI because labels
  627. are arbitrary already and this is not meant for automatic parsing, but as user information.
  628. * `/nsm/gui/session/name` will now always send the same parameter format, regardless of how the session was opened:
  629. simple-session-name, relative session path with subdirs below session-root.
  630. * When a GUI announces itself to nsmd it will receive the absolute path to the session directory
  631. through the message `/nsm/gui/session/root`. This is not a new addition but was already in
  632. non-session-manager git.
  633. === Changes in API Version 1.1.1
  634. * Server-capability :optional-gui: is now mandatory for SERVER implementations. Reasoning:
  635. This is an important core feature of NSM and thus will be treated as such by guaranteeing it to exist.
  636. After looking at all currently known clients and server-implementations it turns out that all servers
  637. support :optional-gui: and the vast majority of clients not only support it, but actually assume it
  638. and do _not_ test for the server capability, as it was written in this document.
  639. There are now two choices: Adjust this document to the (good) reality or consider all clients broken.
  640. Summary: We consider this API document wrong and therefore fix it, thus increasing API version
  641. patch-level from 1.1.0 to 1.1.1
  642. * Add API-section "Subdirectories / Hierarchical Structure" that explains the session directory.
  643. This behaviour was already the case for nsm-legacy-gui and nsmd 1.5.0 was patched to adhere to this
  644. behaviour more strictly as well, removing false session entries in 3rd party clients such as Agordejo.
  645. === Changes in API Version 1.1.2
  646. * nsmd now follows the XDG Base Directory Specifications for it's session root and lock files. This
  647. if of no consequence to clients but required documentation nevertheless, which was described as
  648. "background information" in the chapters for lock files and daemon disovery.
  649. * nsmd now gracefully handles read-only `session.nsm` files. This theoretically enables read-only
  650. sessions and session-templates. It is included in the patch-level because this was marked as a
  651. long-standing `FIXME` in the code by the original author. Or in other words: just a bug fix.