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.

493 lines
17KB

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