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.

570 lines
20KB

  1. ! title Non Session Management API
  2. ! author Jonathan Moore Liles #(email,male@tuxfamily.org)
  3. ! date August 1, 2010
  4. ! revision Version 1.1
  5. ! extra #(image,logo,icon.png)
  6. -- Table Of Contents
  7. : Non Session Management API
  8. The Non Session Management API is used by the various components of
  9. the Non audio production suite to allow any number of independent
  10. programs to be managed together as part of a logical session (i.e. a
  11. song). Thus, operations such as loading and saving are synchronized.
  12. The API comprises a simple Open Sound Control (OSC) based protocol,
  13. along with some behavioral guidelines, which can easily be
  14. implemented by various applications.
  15. The Non project contains an program called `nsmd` which is an
  16. implementation of the server side of the NSM API. `nsmd` is
  17. controlled by the `non-session-manager` GUI. However, the same
  18. server-side API can also be implemented by other session managers
  19. (such as LADISH), although consistency and robustness will likely
  20. suffer if non-NSM compliant clients are allowed to participate in a
  21. session.
  22. The only dependency for client implementations `liblo` (the OSC
  23. library), which several Linux audio applications already link to or
  24. plan to link to in the future.
  25. The aim of this project is to thoroughly define the behavior
  26. required of clients. This is an area where other attempts at session
  27. management (LASH and JACK-Session) have failed. Often the difficulty
  28. with these systems has been not in implementing support for them,
  29. but in attempting to interpret the confusing, ambiguous, or
  30. ill-conceived API documentation. For these reasons and more all
  31. previous attempts at Linux audio session management protocols are
  32. considered harmful.
  33. You *WILL* see some unambiguous and emphatic language in this
  34. document. For the good of the user, these rules are meant to be
  35. followed and are non-negotiable. If an application does not conform
  36. to this specification it should be considered broken. Consistency
  37. across applications under session management is very important for a
  38. good user experience.
  39. :: Client Behavior Under Session Management
  40. Most graphical applications make available to the user a common set
  41. of file operations, typically presented under a File or Project
  42. menu.
  43. These are: New, Open, Save, Save As, Close and Quit or Exit.
  44. The following sub-sections describe how these options should behave when
  45. the application is part of an NSM session. These rules only apply
  46. when session management is active (that is, after the `announce`
  47. handshake described in the #(ref,Non Session Management API::NSM OSC Protocol) section).
  48. In order to provide a consistent and predictable user experience, it
  49. is critically important for applications to adhere to these
  50. guidelines.
  51. ::: New
  52. This option may empty\/reset the current file or project (possibly
  53. after user confirmation). *UNDER NO CIRCUMSTANCES* should it allow
  54. the user to create a new project\/file in another location.
  55. ::: Open
  56. This option *MUST* be disabled.
  57. The application may, however, elect to implement an option called
  58. 'Import into Session', creates a copy of a file\/project which is
  59. then saved at the session path provided by NSM.
  60. ::: Save
  61. This option should behave as normal, saving the current
  62. file\/project as established by the NSM `open` message.
  63. *UNDER NO CIRCUMSTANCES* should this option present the user with a
  64. choice of where to save the file.
  65. ::: Save As
  66. This option *MUST* be disabled.
  67. The application may, however, elect to implement an option called
  68. 'Export from Session', which creates a copy of the current
  69. file\/project which is then saved in a user-specified location
  70. outside of the session path provided by NSM.
  71. ::: Close (as distinguished from Quit or Exit)
  72. This option *MUST* be disabled unless its meaning is to disconnect
  73. the application from session management.
  74. ::: Quit or Exit
  75. This option may behave as normal (possibly asking the user to
  76. confirm exiting).
  77. :: NSM OSC Protocol
  78. All message parameters are *REQUIRED*. All messages *MUST* be sent
  79. from the same socket as the `announce` message, using the
  80. `lo\_send\_from` method of liblo or its equivalent, as the server uses
  81. the return addresses to distinguish between clients.
  82. Clients *MUST* create thier OSC servers using the same protocol
  83. (UDP,TCP) as found in `NSM\_URL`. liblo is lacking a robust TCP
  84. implementation at the time of writing, but in the future it may be
  85. useful.
  86. ::: Establishing a Connection
  87. :::: Announce
  88. At launch, the client *MUST* check the environment for the value of
  89. `NSM\_URL`. If present, the client *MUST* send the following message
  90. to the provided address as soon as it is ready to respond to the
  91. `\/nsm\/client\/open` event:
  92. > /nsm/server/announce s:application_name s:capabilities s:executable_name i:api_version_major i:api_version_minor i:pid
  93. If `NSM\_URL` is undefined, invalid, or unreachable, then the client
  94. should proceed assuming that session management is unavailable.
  95. `api\_version\_major` and `api\_version\_minor` must be the two
  96. parts of the version number of the NSM API as defined by this
  97. document.
  98. Note that if the application intends to register JACK clients,
  99. `application\_name` *MUST* be the same as the name that would
  100. normally be passed to `jack\_client\_open`. For example, Non-Mixer
  101. sends "Non-Mixer" as its `application\_name`. Applications *MUST
  102. NOT* register their JACK clients until receiving an `open` message;
  103. the `open` message will provide a unique client name prefix suitable
  104. for passing to JACK. This is probably the most complex requirement
  105. of the NSM API, but it isn't difficult to implement, especially if
  106. the application simply wishes to delay its initialization process
  107. breifly while awaiting the `announce` reply and
  108. subsequent `open` message.
  109. `capabilities` *MUST* be a string containing a colon separated list
  110. of the special capabilities the client
  111. possesses. e.g. `:dirty:switch:progress:`
  112. // Available Client Capabilities
  113. [[ Name, Description
  114. [[ switch, client is capable of responding to multiple `open` messages without restarting
  115. [[ dirty, client knows when it has unsaved changes
  116. [[ progress, client can send progress updates during time-consuming operations
  117. [[ message, client can send textual status updates
  118. [[ optional-gui, client has an optional GUI
  119. :::: Response
  120. The server will respond to the client's `announce` message with the
  121. following message:
  122. > /reply "/nsm/server/announce" s:message s:name_of_session_manager s:capabilities
  123. `message` is a welcome message.
  124. The value of `name\_of\_session\_manager` will depend on the
  125. implementation of the NSM server. It might say "Non Session
  126. Manager", or it might say "LADISH". This is for display to the user.
  127. `capabilities` will be a string containing a colon separated list of
  128. special server capabilities.
  129. Presently, the server `capabilities` are:
  130. // Available Server Capabilities
  131. [[ Name, Description
  132. [[ server_control, client-to-server control
  133. [[ broadcast, server responds to /nsm/server/broadcast message
  134. [[ optional-gui, server responds to optional-gui messages--if this capability is not present then clients with optional-guis MUST always keep them visible
  135. A client should not consider itself to be under session management
  136. until it receives this response. For example, the Non applications
  137. activate their "SM" blinkers at this time.
  138. If there is an error, a reply of the following form will be sent to
  139. the client:
  140. > /error "/nsm/server/announce" i:error_code s:error_message
  141. The following table defines possible values of `error\_code`:
  142. // Response codes
  143. [[ Code, Meaning
  144. [[ ERR_GENERAL, General Error
  145. [[ ERR_INCOMPATIBLE_API, Incompatible API version
  146. [[ ERR_BLACKLISTED, Client has been blacklisted.
  147. ::: Server to Client Control Messages
  148. Compliant clients *MUST* accept the client control messages
  149. described in this section. All client control messages *REQUIRE* a
  150. response. Responses *MUST* be delivered back to the sender (NSM)
  151. from the same socket used by the client in its `announce` message
  152. (by using `lo\_send\_from`) *AFTER* the action has been completed or
  153. if an error is encountered. The required response is described in
  154. the subsection for each message.
  155. If there is an error and the action cannot be completed, then
  156. `error\_code` *MUST* be set to a valid error code (see #(ref,Non Session Management API::NSM OSC Protocol::Error Code Definitions))
  157. and `message` to a string describing the problem (suitable
  158. for display to the user).
  159. The reply can take one of the following two forms, where `path` *MUST* be
  160. the path of the message being replied to (e.g. "/nsm\/client\/save"):
  161. > /reply s:path s:message
  162. > /error s:path i:error_code s:message
  163. :::: Quit
  164. There is no message for this. Clients will receive the Unix SIGTERM
  165. signal and *MUST* close cleanly *IMMEDIATELY*, without displaying
  166. any kind of dialog to the user and regardless of whether or not
  167. unsaved changes would be lost. When a session is closed the
  168. application will receive this signal soon after having responded to
  169. a `save` message.
  170. :::: Open
  171. > /nsm/client/open s:path_to_instance_specific_project s:display_name s:client_id
  172. `path\_to\_instance_specific\_project` is a path name assigned to
  173. the client for storing its project data.
  174. The client may append to the path, creating a sub-directory,
  175. e.g. '/song.foo' or simply append the client's native file extension
  176. (e.g. '.non' or '.XML'). The same transformation *MUST* be applied
  177. to the name when opening an existing project, as NSM will only
  178. provide the instance specific part of the path.
  179. If a project exists at the path, the client *MUST* immediately open
  180. it.
  181. If a project does not exist at the path, then the client *MUST*
  182. immediately create and open a new one at the specified path or, for
  183. clients which hold all their state in memory, store the path for
  184. later use when responding to the `save` message.
  185. No file or directory will be created at the specified path by the
  186. server. It is up to the client to create what it needs.
  187. For clients which *HAVE NOT* specified the `:switch:` capability,
  188. the `open` message will only be delivered once, immediately
  189. following the `announce` response.
  190. For clients which *HAVE* specified the `:switch:` capability, the
  191. client *MUST* immediately switch to the specified project or create
  192. a new one if it doesn't exist.
  193. Clients which are incapable of switching projects or are prone to
  194. crashing upon switching *MUST NOT* include `:switch:` in their
  195. capability string.
  196. If the user the is allowed to run two or more instances of the
  197. application simultaneously (that is to say, there is no technical
  198. limitation preventing them from doing so, even if it doesn't make
  199. sense to the author), then such an application *MUST PRE-PEND* the
  200. provided `client\_id` string to any names it registers with common
  201. subsystems (e.g. JACK client names). This ensures that multiple
  202. instances of the same application can be restored in any order
  203. without scrambling the JACK connections or causing other
  204. conflicts. The provided `client\_id` will be a concatenation of the
  205. value of `application\_name` sent by the client in its `announce`
  206. message and a unique identifier. Therefore, applications which
  207. create single JACK clients can use the value of `client\_id` directly
  208. as their JACK client name. Applications which register multiple JACK
  209. clients (e.g. Non-Mixer) *MUST PRE-PEND* `client\_id` value to the
  210. client names they register with JACK and the application determined
  211. part *MUST* be unique for that (JACK) client.
  212. For example, a suitable JACK client name would be:
  213. > $CLIENT_ID/track-1
  214. Note that this means that the application *MUST NOT* register with
  215. JACK (or any other subsystem requiring unique names) until it
  216. receives an `open` message from NSM. Likewise, applications with the
  217. `:switch:` capability should close their JACK clients and re-create
  218. them with using the new `client\_id`. Re-registering is necessary
  219. because the JACK API does currently support renaming existing
  220. clients, although this is a sorely needed addition.
  221. A response is *REQUIRED* as soon as the open operation has been
  222. completed. Ongoing progress may be indicated by sending messages to
  223. `\/nsm\/client\/progress`.
  224. ::::: Response
  225. The client *MUST* respond to the 'open' message with:
  226. > /reply "/nsm/client/open" s:message
  227. Or
  228. > /error "/nsm/client/open" i:error_code s:message
  229. // Response Codes
  230. [[ Code, Meaning
  231. [[ ERR, General Error
  232. [[ ERR_BAD_PROJECT, An existing project file was found to be corrupt
  233. [[ ERR_CREATE_FAILED, A new project could not be created
  234. [[ ERR_UNSAVED_CHANGES, Unsaved changes would be lost
  235. [[ ERR_NOT_NOW, Operation cannot be completed at this time
  236. :::: Save
  237. > /nsm/client/save
  238. This message will only be delivered after a previous `open` message,
  239. and may be sent any number of times within the course of a session
  240. (including zero, if the user aborts the session).
  241. If able to, the client *MUST* immediately save the current
  242. application specific project data to the project path previously
  243. established in the 'open' message. *UNDER NO CIRCUMSTANCES* should a
  244. dialog be displayed to the user (giving a choice of where to save,
  245. etc.)
  246. However, if the client is incapable of saving at the specific moment
  247. without disturbing the user (e.g. a JACK client that can't save
  248. while the transport is rolling without causing massive XRUNS), then
  249. the client may respond to "/error" with ERR_NOT_NOW and a string
  250. explaining exactly why the save could not be completed (so that, in
  251. this example, the user knows that they have to stop the transport in
  252. order to save).
  253. ::::: Response
  254. The client *MUST* respond to the 'save' message with:
  255. > /reply "/nsm/client/save" s:message
  256. Or
  257. > /error "/nsm/client/save" i:error_code s:message
  258. // Response Codes
  259. [[ Code, Meaning
  260. [[ ERR, General Error
  261. [[ ERR_SAVE_FAILED, Project could not be saved
  262. [[ ERR_NOT_NOW, Operation cannot be completed at this time
  263. ::: Server to Client Informational Messages
  264. :::: Session is Loaded
  265. Accepting this message is optional. The intent is to signal to
  266. clients which may have some interdependence (say, peer to peer OSC
  267. connections) that the session is fully loaded and all their peers
  268. are available.
  269. > /nsm/client/session_is_loaded
  270. This message does not require a response.
  271. :::: Show Optional Gui
  272. If the client has specified the `optional-gui` capability, then it
  273. may receive this message from the server when the user wishes to
  274. change the visibility state of the GUI. It doesn't matter if the
  275. optional GUI is integrated with the program or if it is a separate
  276. program \(as is the case with SooperLooper\). When the GUI is
  277. hidden, there should be no window mapped and if the GUI is a
  278. separate program, it should be killed.
  279. > /nsm/client/show_optional_gui
  280. > /nsm/client/hide_optional_gui
  281. No response is message is required.
  282. ::: Client to Server Informational Messages
  283. These are optional messages which a client can send to the NSM
  284. server to inform it about the client's status. The client should not
  285. expect any reply to these messages. If a client intends to send a
  286. message described in this section, then it *MUST* add the
  287. appropriate value to its `capabilities` string when composing the
  288. `announce` message.
  289. :::: Optional GUI
  290. If the client has specified the `optional-gui` capability, then it
  291. *MUST* send this message whenever the state of visibility of the
  292. optional GUI has changed. It also *MUST* send this message after
  293. it's announce message to indicate the initial visibility state of
  294. the optional GUI.
  295. > /nsm/client/gui_is_hidden
  296. > /nsm/client/gui_is_shown
  297. No response will be delivered.
  298. :::: Progress
  299. > /nsm/client/progress f:progress
  300. For potentially time-consuming operations, such as `save` and
  301. `open`, progress updates may be indicated throughout the duration by
  302. sending a floating point value between 0.0 and 1.0, 1.0 indicating
  303. completion, to the NSM server.
  304. The server will not send a response to these messages, but will
  305. relay the information to the user.
  306. Note that even when using the `progress` feature, the final
  307. response to the `save` or `open` message is still *REQUIRED*.
  308. Clients which intend to send `progress` messages should include
  309. `:progress:` in their `announce` capability string.
  310. :::: Dirtiness
  311. > /nsm/client/is_dirty
  312. > /nsm/client/is_clean
  313. Some clients may be able to inform the server when they have unsaved
  314. changes pending. Such clients may optionally send `is\_dirty` and `is\_clean`
  315. messages.
  316. Clients which have this capability should include `:dirty:` in their
  317. `announce` capability string.
  318. :::: Status Messages
  319. > /nsm/client/message i:priority s:message
  320. Clients may send miscellaneous status updates to the server for
  321. possible display to the user. This may simply be chatter that is
  322. normally written to the console. `priority` should be a number from
  323. 0 to 3, 3 being the most important.
  324. Clients which have this capability should include `:message:` in their
  325. `announce` capability string.
  326. ::: Error Code Definitions
  327. // Error Code Definitions
  328. [[ Symbolic Name, Integer Value
  329. [[ ERR_GENERAL, -1
  330. [[ ERR_INCOMPATIBLE_API, -2
  331. [[ ERR_BLACKLISTED, -3
  332. [[ ERR_LAUNCH_FAILED, -4
  333. [[ ERR_NO_SUCH_FILE, -5
  334. [[ ERR_NO_SESSION_OPEN, -6
  335. [[ ERR_UNSAVED_CHANGES, -7
  336. [[ ERR_NOT_NOW, -8
  337. [[ ERR_BAD_PROJECT, -9
  338. [[ ERR_CREATE_FAILED, -10
  339. ::: Client to Server Control
  340. If the server publishes the `:server\_control:` capability, then
  341. clients can also initiate action by the server. For example, a
  342. client might implement a 'Save All' option which sends a
  343. `\/nsm\/server\/save` message to the server, rather than requiring
  344. the user to switch to the session management interface to effect the
  345. save.
  346. ::: Server Control API
  347. The session manager not only manages clients via OSC, but it is
  348. itself controlled via OSC messages. The server responds to the
  349. following messages.
  350. All of the following messages will be responded to, at the sender's
  351. address, with one of the two following messages:
  352. > /reply s:path s:message
  353. > /error s:path i:error_code s:message
  354. The first parameter of the reply is the path to the message being
  355. replied to. The `\/error` reply includes an integer error code
  356. (non-zero indicates error). `message` will be a description of the
  357. error.
  358. The possible errors are:
  359. // Responses
  360. [[ Code, Meaning
  361. [[ ERR_GENERAL, General Error
  362. [[ ERR_LAUNCH_FAILED, Launch failed
  363. [[ ERR_NO_SUCH_FILE, No such file
  364. [[ ERR_NO_SESSION, No session is open
  365. [[ ERR_UNSAVED_CHANGES, Unsaved changes would be lost
  366. = /nsm/server/add s:path_to_executable
  367. Adds a client to the current session.
  368. = /nsm/server/save
  369. Saves the current session.
  370. = /nsm/server/load s:project_name
  371. Saves the current session and loads a new session.
  372. = /nsm/server/new s:project_name
  373. Saves the current session and creates a new session.
  374. = /nsm/server/duplicate s:new_project
  375. Saves and closes the current session, makes a copy, and opens it.
  376. = /nsm/server/close
  377. Saves and closes the current session.
  378. = /nsm/server/abort
  379. Closes the current session *WITHOUT SAVING*
  380. = /nsm/server/quit
  381. Saves and closes the current session and terminates the server.
  382. = /nsm/server/list
  383. Lists available projects. One `\/reply` message will be sent for each existing project.
  384. :::: Client to Client Communication
  385. If the server includes `:broadcast:` in its capability string, then
  386. clients may send broadcast messages to each other through the NSM
  387. server.
  388. Clients may send messages to the server at the path
  389. `\/nsm\/server\/broadcast`.
  390. The format of this message is as follows:
  391. > /nsm/server/broadcast s:path [arguments...]
  392. The message will then be relayed to all clients in the session at
  393. the path `path` (with the arguments shifted by one).
  394. For example the message:
  395. > /nsm/server/broadcast /tempomap/update "0,120,4/4:12351234,240,4/4"
  396. Would broadcast the following message to all clients in the session
  397. (except for the sender), some of which might respond to the message
  398. by updating their own tempo maps.
  399. > /tempomap/update "0,120,4/4:12351234,240,4/4"
  400. The Non programs use this feature to establish peer to peer OSC
  401. communication by symbolic names (client IDs) without having to
  402. remember the OSC URLs of peers across sessions.