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.

517 lines
18KB

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