effect-web-midi 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (222) hide show
  1. package/README.md +7 -0
  2. package/dist/index.js +2 -0
  3. package/dist/index.js.map +1 -0
  4. package/dist/src/EMIDIAccess.js +68 -0
  5. package/dist/src/EMIDIAccess.js.map +1 -0
  6. package/dist/src/EMIDIInput.js +226 -0
  7. package/dist/src/EMIDIInput.js.map +1 -0
  8. package/dist/src/EMIDIOutput.js +225 -0
  9. package/dist/src/EMIDIOutput.js.map +1 -0
  10. package/dist/src/EMIDIPort.js +213 -0
  11. package/dist/src/EMIDIPort.js.map +1 -0
  12. package/dist/src/MIDIErrors.js +4 -0
  13. package/dist/src/MIDIErrors.js.map +1 -0
  14. package/dist/src/Parsing.js +2 -0
  15. package/dist/src/Parsing.js.map +1 -0
  16. package/dist/src/StreamMaker.js +1 -0
  17. package/dist/src/StreamMaker.js.map +1 -0
  18. package/dist/src/Util.js +4 -0
  19. package/dist/src/Util.js.map +1 -0
  20. package/dist/src/index.js +9 -0
  21. package/dist/src/index.js.map +1 -0
  22. package/dist/src/internal/EMIDIAccess.js +409 -0
  23. package/dist/src/internal/EMIDIAccess.js.map +1 -0
  24. package/dist/src/internal/EMIDIInput.js +69 -0
  25. package/dist/src/internal/EMIDIInput.js.map +1 -0
  26. package/dist/src/internal/EMIDIOutput.js +120 -0
  27. package/dist/src/internal/EMIDIOutput.js.map +1 -0
  28. package/dist/src/internal/EMIDIPort.js +125 -0
  29. package/dist/src/internal/EMIDIPort.js.map +1 -0
  30. package/dist/src/internal/MIDIPortMethodCalls/acquireReleasePortConnection/acquireReleasePortConnectionByPort.js +27 -0
  31. package/dist/src/internal/MIDIPortMethodCalls/acquireReleasePortConnection/acquireReleasePortConnectionByPort.js.map +1 -0
  32. package/dist/src/internal/MIDIPortMethodCalls/acquireReleasePortConnection/acquireReleasePortConnectionByPortIdAndAccess.js +19 -0
  33. package/dist/src/internal/MIDIPortMethodCalls/acquireReleasePortConnection/acquireReleasePortConnectionByPortIdAndAccess.js.map +1 -0
  34. package/dist/src/internal/MIDIPortMethodCalls/acquireReleasePortConnection/acquireReleasePortConnectionByPortIdInContext.js +16 -0
  35. package/dist/src/internal/MIDIPortMethodCalls/acquireReleasePortConnection/acquireReleasePortConnectionByPortIdInContext.js.map +1 -0
  36. package/dist/src/internal/MIDIPortMethodCalls/actOnPort.js +18 -0
  37. package/dist/src/internal/MIDIPortMethodCalls/actOnPort.js.map +1 -0
  38. package/dist/src/internal/MIDIPortMethodCalls/closePortConnection/closePortConnectionByPort.js +27 -0
  39. package/dist/src/internal/MIDIPortMethodCalls/closePortConnection/closePortConnectionByPort.js.map +1 -0
  40. package/dist/src/internal/MIDIPortMethodCalls/closePortConnection/closePortConnectionByPortIdAndAccess.js +18 -0
  41. package/dist/src/internal/MIDIPortMethodCalls/closePortConnection/closePortConnectionByPortIdAndAccess.js.map +1 -0
  42. package/dist/src/internal/MIDIPortMethodCalls/closePortConnection/closePortConnectionByPortIdInContext.js +16 -0
  43. package/dist/src/internal/MIDIPortMethodCalls/closePortConnection/closePortConnectionByPortIdInContext.js.map +1 -0
  44. package/dist/src/internal/MIDIPortMethodCalls/makeMIDIPortMethodCallerFactory.js +21 -0
  45. package/dist/src/internal/MIDIPortMethodCalls/makeMIDIPortMethodCallerFactory.js.map +1 -0
  46. package/dist/src/internal/MIDIPortMethodCalls/openPortConnection/openPortConnectionByPort.js +30 -0
  47. package/dist/src/internal/MIDIPortMethodCalls/openPortConnection/openPortConnectionByPort.js.map +1 -0
  48. package/dist/src/internal/MIDIPortMethodCalls/openPortConnection/openPortConnectionByPortIdAndAccess.js +18 -0
  49. package/dist/src/internal/MIDIPortMethodCalls/openPortConnection/openPortConnectionByPortIdAndAccess.js.map +1 -0
  50. package/dist/src/internal/MIDIPortMethodCalls/openPortConnection/openPortConnectionByPortIdInContext.js +16 -0
  51. package/dist/src/internal/MIDIPortMethodCalls/openPortConnection/openPortConnectionByPortIdInContext.js.map +1 -0
  52. package/dist/src/internal/StreamMaker.js +101 -0
  53. package/dist/src/internal/StreamMaker.js.map +1 -0
  54. package/dist/src/internal/errors.js +161 -0
  55. package/dist/src/internal/errors.js.map +1 -0
  56. package/dist/src/internal/getPortByPortId/getPortByPortIdAndAccess.js +53 -0
  57. package/dist/src/internal/getPortByPortId/getPortByPortIdAndAccess.js.map +1 -0
  58. package/dist/src/internal/getPortByPortId/getPortByPortIdInContext.js +18 -0
  59. package/dist/src/internal/getPortByPortId/getPortByPortIdInContext.js.map +1 -0
  60. package/dist/src/internal/makePortStateChangesStream/makePortStateChangesStreamByPort.js +52 -0
  61. package/dist/src/internal/makePortStateChangesStream/makePortStateChangesStreamByPort.js.map +1 -0
  62. package/dist/src/internal/makePortStateChangesStream/makePortStateChangesStreamByPortIdAndAccess.js +13 -0
  63. package/dist/src/internal/makePortStateChangesStream/makePortStateChangesStreamByPortIdAndAccess.js.map +1 -0
  64. package/dist/src/internal/makePortStateChangesStream/makePortStateChangesStreamByPortIdInContext.js +18 -0
  65. package/dist/src/internal/makePortStateChangesStream/makePortStateChangesStreamByPortIdInContext.js.map +1 -0
  66. package/dist/src/internal/mutablePropertyTools/doesMutablePortPropertyHaveSpecificValue/doesMutablePortPropertyHaveSpecificValueByPort.js +66 -0
  67. package/dist/src/internal/mutablePropertyTools/doesMutablePortPropertyHaveSpecificValue/doesMutablePortPropertyHaveSpecificValueByPort.js.map +1 -0
  68. package/dist/src/internal/mutablePropertyTools/doesMutablePortPropertyHaveSpecificValue/doesMutablePortPropertyHaveSpecificValueByPortIdAndAccess.js +61 -0
  69. package/dist/src/internal/mutablePropertyTools/doesMutablePortPropertyHaveSpecificValue/doesMutablePortPropertyHaveSpecificValueByPortIdAndAccess.js.map +1 -0
  70. package/dist/src/internal/mutablePropertyTools/doesMutablePortPropertyHaveSpecificValue/doesMutablePortPropertyHaveSpecificValueByPortIdInContext.js +61 -0
  71. package/dist/src/internal/mutablePropertyTools/doesMutablePortPropertyHaveSpecificValue/doesMutablePortPropertyHaveSpecificValueByPortIdInContext.js.map +1 -0
  72. package/dist/src/internal/mutablePropertyTools/getMutablePortProperty/getMutablePortPropertyByPort.js +42 -0
  73. package/dist/src/internal/mutablePropertyTools/getMutablePortProperty/getMutablePortPropertyByPort.js.map +1 -0
  74. package/dist/src/internal/mutablePropertyTools/getMutablePortProperty/getMutablePortPropertyByPortIdAndAccess.js +42 -0
  75. package/dist/src/internal/mutablePropertyTools/getMutablePortProperty/getMutablePortPropertyByPortIdAndAccess.js.map +1 -0
  76. package/dist/src/internal/mutablePropertyTools/getMutablePortProperty/getMutablePortPropertyByPortIdInContext.js +29 -0
  77. package/dist/src/internal/mutablePropertyTools/getMutablePortProperty/getMutablePortPropertyByPortIdInContext.js.map +1 -0
  78. package/dist/src/internal/mutablePropertyTools/getValueInRawPortFieldUnsafe.js +6 -0
  79. package/dist/src/internal/mutablePropertyTools/getValueInRawPortFieldUnsafe.js.map +1 -0
  80. package/dist/src/internal/mutablePropertyTools/matchMutablePortProperty/matchMutablePortPropertyByPort.js +46 -0
  81. package/dist/src/internal/mutablePropertyTools/matchMutablePortProperty/matchMutablePortPropertyByPort.js.map +1 -0
  82. package/dist/src/internal/mutablePropertyTools/matchMutablePortProperty/matchMutablePortPropertyByPortIdAndAccess.js +25 -0
  83. package/dist/src/internal/mutablePropertyTools/matchMutablePortProperty/matchMutablePortPropertyByPortIdAndAccess.js.map +1 -0
  84. package/dist/src/internal/mutablePropertyTools/matchMutablePortProperty/matchMutablePortPropertyByPortIdInContext.js +31 -0
  85. package/dist/src/internal/mutablePropertyTools/matchMutablePortProperty/matchMutablePortPropertyByPortIdInContext.js.map +1 -0
  86. package/dist/src/internal/parsing.js +117 -0
  87. package/dist/src/internal/parsing.js.map +1 -0
  88. package/dist/src/internal/util.js +59 -0
  89. package/dist/src/internal/util.js.map +1 -0
  90. package/dist-types/index.d.ts +2 -0
  91. package/dist-types/index.d.ts.map +1 -0
  92. package/dist-types/src/EMIDIAccess.d.ts +27 -0
  93. package/dist-types/src/EMIDIAccess.d.ts.map +1 -0
  94. package/dist-types/src/EMIDIInput.d.ts +26 -0
  95. package/dist-types/src/EMIDIInput.d.ts.map +1 -0
  96. package/dist-types/src/EMIDIOutput.d.ts +26 -0
  97. package/dist-types/src/EMIDIOutput.d.ts.map +1 -0
  98. package/dist-types/src/EMIDIPort.d.ts +26 -0
  99. package/dist-types/src/EMIDIPort.d.ts.map +1 -0
  100. package/dist-types/src/MIDIErrors.d.ts +2 -0
  101. package/dist-types/src/MIDIErrors.d.ts.map +1 -0
  102. package/dist-types/src/Parsing.d.ts +2 -0
  103. package/dist-types/src/Parsing.d.ts.map +1 -0
  104. package/dist-types/src/StreamMaker.d.ts +2 -0
  105. package/dist-types/src/StreamMaker.d.ts.map +1 -0
  106. package/dist-types/src/Util.d.ts +2 -0
  107. package/dist-types/src/Util.d.ts.map +1 -0
  108. package/dist-types/src/index.d.ts +9 -0
  109. package/dist-types/src/index.d.ts.map +1 -0
  110. package/dist-types/src/internal/EMIDIAccess.d.ts +339 -0
  111. package/dist-types/src/internal/EMIDIAccess.d.ts.map +1 -0
  112. package/dist-types/src/internal/EMIDIInput.d.ts +48 -0
  113. package/dist-types/src/internal/EMIDIInput.d.ts.map +1 -0
  114. package/dist-types/src/internal/EMIDIOutput.d.ts +93 -0
  115. package/dist-types/src/internal/EMIDIOutput.d.ts.map +1 -0
  116. package/dist-types/src/internal/EMIDIPort.d.ts +87 -0
  117. package/dist-types/src/internal/EMIDIPort.d.ts.map +1 -0
  118. package/dist-types/src/internal/MIDIPortMethodCalls/acquireReleasePortConnection/acquireReleasePortConnectionByPort.d.ts +16 -0
  119. package/dist-types/src/internal/MIDIPortMethodCalls/acquireReleasePortConnection/acquireReleasePortConnectionByPort.d.ts.map +1 -0
  120. package/dist-types/src/internal/MIDIPortMethodCalls/acquireReleasePortConnection/acquireReleasePortConnectionByPortIdAndAccess.d.ts +15 -0
  121. package/dist-types/src/internal/MIDIPortMethodCalls/acquireReleasePortConnection/acquireReleasePortConnectionByPortIdAndAccess.d.ts.map +1 -0
  122. package/dist-types/src/internal/MIDIPortMethodCalls/acquireReleasePortConnection/acquireReleasePortConnectionByPortIdInContext.d.ts +13 -0
  123. package/dist-types/src/internal/MIDIPortMethodCalls/acquireReleasePortConnection/acquireReleasePortConnectionByPortIdInContext.d.ts.map +1 -0
  124. package/dist-types/src/internal/MIDIPortMethodCalls/actOnPort.d.ts +11 -0
  125. package/dist-types/src/internal/MIDIPortMethodCalls/actOnPort.d.ts.map +1 -0
  126. package/dist-types/src/internal/MIDIPortMethodCalls/closePortConnection/closePortConnectionByPort.d.ts +23 -0
  127. package/dist-types/src/internal/MIDIPortMethodCalls/closePortConnection/closePortConnectionByPort.d.ts.map +1 -0
  128. package/dist-types/src/internal/MIDIPortMethodCalls/closePortConnection/closePortConnectionByPortIdAndAccess.d.ts +15 -0
  129. package/dist-types/src/internal/MIDIPortMethodCalls/closePortConnection/closePortConnectionByPortIdAndAccess.d.ts.map +1 -0
  130. package/dist-types/src/internal/MIDIPortMethodCalls/closePortConnection/closePortConnectionByPortIdInContext.d.ts +13 -0
  131. package/dist-types/src/internal/MIDIPortMethodCalls/closePortConnection/closePortConnectionByPortIdInContext.d.ts.map +1 -0
  132. package/dist-types/src/internal/MIDIPortMethodCalls/makeMIDIPortMethodCallerFactory.d.ts +15 -0
  133. package/dist-types/src/internal/MIDIPortMethodCalls/makeMIDIPortMethodCallerFactory.d.ts.map +1 -0
  134. package/dist-types/src/internal/MIDIPortMethodCalls/openPortConnection/openPortConnectionByPort.d.ts +21 -0
  135. package/dist-types/src/internal/MIDIPortMethodCalls/openPortConnection/openPortConnectionByPort.d.ts.map +1 -0
  136. package/dist-types/src/internal/MIDIPortMethodCalls/openPortConnection/openPortConnectionByPortIdAndAccess.d.ts +15 -0
  137. package/dist-types/src/internal/MIDIPortMethodCalls/openPortConnection/openPortConnectionByPortIdAndAccess.d.ts.map +1 -0
  138. package/dist-types/src/internal/MIDIPortMethodCalls/openPortConnection/openPortConnectionByPortIdInContext.d.ts +13 -0
  139. package/dist-types/src/internal/MIDIPortMethodCalls/openPortConnection/openPortConnectionByPortIdInContext.d.ts.map +1 -0
  140. package/dist-types/src/internal/StreamMaker.d.ts +202 -0
  141. package/dist-types/src/internal/StreamMaker.d.ts.map +1 -0
  142. package/dist-types/src/internal/errors.d.ts +260 -0
  143. package/dist-types/src/internal/errors.d.ts.map +1 -0
  144. package/dist-types/src/internal/getPortByPortId/getPortByPortIdAndAccess.d.ts +27 -0
  145. package/dist-types/src/internal/getPortByPortId/getPortByPortIdAndAccess.d.ts.map +1 -0
  146. package/dist-types/src/internal/getPortByPortId/getPortByPortIdInContext.d.ts +20 -0
  147. package/dist-types/src/internal/getPortByPortId/getPortByPortIdInContext.d.ts.map +1 -0
  148. package/dist-types/src/internal/makePortStateChangesStream/makePortStateChangesStreamByPort.d.ts +71 -0
  149. package/dist-types/src/internal/makePortStateChangesStream/makePortStateChangesStreamByPort.d.ts.map +1 -0
  150. package/dist-types/src/internal/makePortStateChangesStream/makePortStateChangesStreamByPortIdAndAccess.d.ts +4 -0
  151. package/dist-types/src/internal/makePortStateChangesStream/makePortStateChangesStreamByPortIdAndAccess.d.ts.map +1 -0
  152. package/dist-types/src/internal/makePortStateChangesStream/makePortStateChangesStreamByPortIdInContext.d.ts +20 -0
  153. package/dist-types/src/internal/makePortStateChangesStream/makePortStateChangesStreamByPortIdInContext.d.ts.map +1 -0
  154. package/dist-types/src/internal/mutablePropertyTools/doesMutablePortPropertyHaveSpecificValue/doesMutablePortPropertyHaveSpecificValueByPort.d.ts +62 -0
  155. package/dist-types/src/internal/mutablePropertyTools/doesMutablePortPropertyHaveSpecificValue/doesMutablePortPropertyHaveSpecificValueByPort.d.ts.map +1 -0
  156. package/dist-types/src/internal/mutablePropertyTools/doesMutablePortPropertyHaveSpecificValue/doesMutablePortPropertyHaveSpecificValueByPortIdAndAccess.d.ts +16 -0
  157. package/dist-types/src/internal/mutablePropertyTools/doesMutablePortPropertyHaveSpecificValue/doesMutablePortPropertyHaveSpecificValueByPortIdAndAccess.d.ts.map +1 -0
  158. package/dist-types/src/internal/mutablePropertyTools/doesMutablePortPropertyHaveSpecificValue/doesMutablePortPropertyHaveSpecificValueByPortIdInContext.d.ts +16 -0
  159. package/dist-types/src/internal/mutablePropertyTools/doesMutablePortPropertyHaveSpecificValue/doesMutablePortPropertyHaveSpecificValueByPortIdInContext.d.ts.map +1 -0
  160. package/dist-types/src/internal/mutablePropertyTools/getMutablePortProperty/getMutablePortPropertyByPort.d.ts +36 -0
  161. package/dist-types/src/internal/mutablePropertyTools/getMutablePortProperty/getMutablePortPropertyByPort.d.ts.map +1 -0
  162. package/dist-types/src/internal/mutablePropertyTools/getMutablePortProperty/getMutablePortPropertyByPortIdAndAccess.d.ts +22 -0
  163. package/dist-types/src/internal/mutablePropertyTools/getMutablePortProperty/getMutablePortPropertyByPortIdAndAccess.d.ts.map +1 -0
  164. package/dist-types/src/internal/mutablePropertyTools/getMutablePortProperty/getMutablePortPropertyByPortIdInContext.d.ts +17 -0
  165. package/dist-types/src/internal/mutablePropertyTools/getMutablePortProperty/getMutablePortPropertyByPortIdInContext.d.ts.map +1 -0
  166. package/dist-types/src/internal/mutablePropertyTools/getValueInRawPortFieldUnsafe.d.ts +7 -0
  167. package/dist-types/src/internal/mutablePropertyTools/getValueInRawPortFieldUnsafe.d.ts.map +1 -0
  168. package/dist-types/src/internal/mutablePropertyTools/matchMutablePortProperty/matchMutablePortPropertyByPort.d.ts +71 -0
  169. package/dist-types/src/internal/mutablePropertyTools/matchMutablePortProperty/matchMutablePortPropertyByPort.d.ts.map +1 -0
  170. package/dist-types/src/internal/mutablePropertyTools/matchMutablePortProperty/matchMutablePortPropertyByPortIdAndAccess.d.ts +7 -0
  171. package/dist-types/src/internal/mutablePropertyTools/matchMutablePortProperty/matchMutablePortPropertyByPortIdAndAccess.d.ts.map +1 -0
  172. package/dist-types/src/internal/mutablePropertyTools/matchMutablePortProperty/matchMutablePortPropertyByPortIdInContext.d.ts +28 -0
  173. package/dist-types/src/internal/mutablePropertyTools/matchMutablePortProperty/matchMutablePortPropertyByPortIdInContext.d.ts.map +1 -0
  174. package/dist-types/src/internal/parsing.d.ts +72 -0
  175. package/dist-types/src/internal/parsing.d.ts.map +1 -0
  176. package/dist-types/src/internal/util.d.ts +33 -0
  177. package/dist-types/src/internal/util.d.ts.map +1 -0
  178. package/index.ts +1 -0
  179. package/package.json +83 -0
  180. package/src/EMIDIAccess.ts +271 -0
  181. package/src/EMIDIInput.ts +270 -0
  182. package/src/EMIDIOutput.ts +269 -0
  183. package/src/EMIDIPort.ts +267 -0
  184. package/src/MIDIErrors.ts +13 -0
  185. package/src/Parsing.ts +12 -0
  186. package/src/StreamMaker.ts +12 -0
  187. package/src/Util.ts +19 -0
  188. package/src/index.ts +8 -0
  189. package/src/internal/EMIDIAccess.ts +893 -0
  190. package/src/internal/EMIDIInput.ts +114 -0
  191. package/src/internal/EMIDIOutput.ts +228 -0
  192. package/src/internal/EMIDIPort.ts +233 -0
  193. package/src/internal/MIDIPortMethodCalls/acquireReleasePortConnection/acquireReleasePortConnectionByPort.ts +43 -0
  194. package/src/internal/MIDIPortMethodCalls/acquireReleasePortConnection/acquireReleasePortConnectionByPortIdAndAccess.ts +39 -0
  195. package/src/internal/MIDIPortMethodCalls/acquireReleasePortConnection/acquireReleasePortConnectionByPortIdInContext.ts +27 -0
  196. package/src/internal/MIDIPortMethodCalls/actOnPort.ts +66 -0
  197. package/src/internal/MIDIPortMethodCalls/closePortConnection/closePortConnectionByPort.ts +38 -0
  198. package/src/internal/MIDIPortMethodCalls/closePortConnection/closePortConnectionByPortIdAndAccess.ts +38 -0
  199. package/src/internal/MIDIPortMethodCalls/closePortConnection/closePortConnectionByPortIdInContext.ts +27 -0
  200. package/src/internal/MIDIPortMethodCalls/makeMIDIPortMethodCallerFactory.ts +73 -0
  201. package/src/internal/MIDIPortMethodCalls/openPortConnection/openPortConnectionByPort.ts +44 -0
  202. package/src/internal/MIDIPortMethodCalls/openPortConnection/openPortConnectionByPortIdAndAccess.ts +38 -0
  203. package/src/internal/MIDIPortMethodCalls/openPortConnection/openPortConnectionByPortIdInContext.ts +27 -0
  204. package/src/internal/StreamMaker.ts +414 -0
  205. package/src/internal/errors.ts +220 -0
  206. package/src/internal/getPortByPortId/getPortByPortIdAndAccess.ts +116 -0
  207. package/src/internal/getPortByPortId/getPortByPortIdInContext.ts +26 -0
  208. package/src/internal/makePortStateChangesStream/makePortStateChangesStreamByPort.ts +148 -0
  209. package/src/internal/makePortStateChangesStream/makePortStateChangesStreamByPortIdAndAccess.ts +14 -0
  210. package/src/internal/makePortStateChangesStream/makePortStateChangesStreamByPortIdInContext.ts +51 -0
  211. package/src/internal/mutablePropertyTools/doesMutablePortPropertyHaveSpecificValue/doesMutablePortPropertyHaveSpecificValueByPort.ts +127 -0
  212. package/src/internal/mutablePropertyTools/doesMutablePortPropertyHaveSpecificValue/doesMutablePortPropertyHaveSpecificValueByPortIdAndAccess.ts +74 -0
  213. package/src/internal/mutablePropertyTools/doesMutablePortPropertyHaveSpecificValue/doesMutablePortPropertyHaveSpecificValueByPortIdInContext.ts +74 -0
  214. package/src/internal/mutablePropertyTools/getMutablePortProperty/getMutablePortPropertyByPort.ts +63 -0
  215. package/src/internal/mutablePropertyTools/getMutablePortProperty/getMutablePortPropertyByPortIdAndAccess.ts +110 -0
  216. package/src/internal/mutablePropertyTools/getMutablePortProperty/getMutablePortPropertyByPortIdInContext.ts +37 -0
  217. package/src/internal/mutablePropertyTools/getValueInRawPortFieldUnsafe.ts +12 -0
  218. package/src/internal/mutablePropertyTools/matchMutablePortProperty/matchMutablePortPropertyByPort.ts +183 -0
  219. package/src/internal/mutablePropertyTools/matchMutablePortProperty/matchMutablePortPropertyByPortIdAndAccess.ts +29 -0
  220. package/src/internal/mutablePropertyTools/matchMutablePortProperty/matchMutablePortPropertyByPortIdInContext.ts +86 -0
  221. package/src/internal/parsing.ts +219 -0
  222. package/src/internal/util.ts +152 -0
@@ -0,0 +1,409 @@
1
+ /** biome-ignore-all lint/style/useShorthandFunctionType: It's a nice way to
2
+ * preserve JSDoc comments attached to the function signature */
3
+ import * as EArray from 'effect/Array';
4
+ import * as Context from 'effect/Context';
5
+ import * as Effect from 'effect/Effect';
6
+ import * as Equal from 'effect/Equal';
7
+ import * as EFunction from 'effect/Function';
8
+ import * as Hash from 'effect/Hash';
9
+ import * as Inspectable from 'effect/Inspectable';
10
+ import * as Iterable from 'effect/Iterable';
11
+ import * as Layer from 'effect/Layer';
12
+ import * as Option from 'effect/Option';
13
+ import * as Order from 'effect/Order';
14
+ import * as Pipeable from 'effect/Pipeable';
15
+ import * as Record from 'effect/Record';
16
+ import * as Ref from 'effect/Ref';
17
+ import * as SortedMap from 'effect/SortedMap';
18
+ import * as Unify from 'effect/Unify';
19
+ import * as EMIDIInput from "./EMIDIInput.js";
20
+ import * as EMIDIOutput from "./EMIDIOutput.js";
21
+ import * as Errors from "./errors.js";
22
+ import * as GetPort from "./getPortByPortId/getPortByPortIdInContext.js";
23
+ import { isOutputConnectionOpenByPort } from "./mutablePropertyTools/doesMutablePortPropertyHaveSpecificValue/doesMutablePortPropertyHaveSpecificValueByPort.js";
24
+ import { getOutputDeviceStateByPort } from "./mutablePropertyTools/getMutablePortProperty/getMutablePortPropertyByPort.js";
25
+ import * as StreamMaker from "./StreamMaker.js";
26
+ import * as Util from "./util.js";
27
+ // TODO: add stream of messages sent from this device to target midi device
28
+ // TODO: fat service APIs, where all the methods are attached to instance and
29
+ // where you don't have to constantly write the prefix
30
+ // TODO: implement scoping of midi access that will clean up all message queues
31
+ // and streams, and remove listeners
32
+ // TODO: implement scope inheritance
33
+ // TODO: make a Ref with a port map that would be automatically updated by
34
+ // listening to the stream of connection events?
35
+ // TODO: add a stream to listen for all messages of all currently
36
+ // connected inputs, all present inputs, specific input
37
+ // TODO: add sinks that will accept command streams to redirect midi commands
38
+ // from something into an actual API
39
+ // TODO: add effect to wait until connected by port ID
40
+ // TODO: reflect sysex and software flags in type-system
41
+ // TODO: make matchers that support returning effects from the callback instead of plain values
42
+ /**
43
+ * Unique symbol used for distinguishing {@linkcode EMIDIAccessInstance}
44
+ * instances from other objects at both runtime and type-level
45
+ * @internal
46
+ */
47
+ const TypeId = Symbol.for('effect-web-midi/EMIDIAccessInstance');
48
+ /**
49
+ * A tag that allows to provide
50
+ * {@linkcode EMIDIAccessInstance|access instance} once with e.g.
51
+ * {@linkcode layer}, {@linkcode layerSystemExclusiveSupported}, etc. and reuse
52
+ * it anywhere, instead of repeatedly {@linkcode request}ing it.
53
+ *
54
+ * The downside of using DI might be that in different places of the app it
55
+ * would be harder to maintain tight MIDI permission scopes.
56
+ *
57
+ * @example
58
+ * ```ts
59
+ * import { EMIDIAccess } from 'effect-web-midi'
60
+ * import * as Effect from 'effect/Effect'
61
+ *
62
+ * const program = Effect.gen(function* () {
63
+ * // ^ Effect.Effect<
64
+ * // void,
65
+ * // | AbortError
66
+ * // | UnderlyingSystemError
67
+ * // | MIDIAccessNotAllowedError
68
+ * // | MIDIAccessNotSupportedError
69
+ * // never
70
+ * // >
71
+ *
72
+ * const access = yield* EMIDIAccess.EMIDIAccess
73
+ * // ^ EMIDIAccessInstance
74
+ *
75
+ * console.log(access.sysexEnabled)
76
+ * // ^ true
77
+ * }).pipe(Effect.provide(EMIDIAccess.layerSystemExclusiveSupported))
78
+ * ```
79
+ *
80
+ * @see `navigator.requestMIDIAccess` {@link https://www.w3.org/TR/webmidi/#dom-navigator-requestmidiaccess|Web MIDI spec}, {@link https://developer.mozilla.org/en-US/docs/Web/API/Navigator/requestMIDIAccess|MDN reference}
81
+ */
82
+ export class EMIDIAccess extends Context.Tag('effect-web-midi/EMIDIAccess')() {
83
+ }
84
+ /**
85
+ * Prototype of all {@linkcode EMIDIAccessInstance} instances
86
+ * @internal
87
+ */
88
+ const Proto = {
89
+ _tag: 'EMIDIAccess',
90
+ [TypeId]: TypeId,
91
+ [Hash.symbol]() {
92
+ return Hash.structure(this._config);
93
+ },
94
+ [Equal.symbol](that) {
95
+ return this === that;
96
+ },
97
+ pipe() {
98
+ // biome-ignore lint/complexity/noArguments: Effect's tradition
99
+ return Pipeable.pipeArguments(this, arguments);
100
+ },
101
+ toString() {
102
+ return Inspectable.format(this.toJSON());
103
+ },
104
+ toJSON() {
105
+ return { _id: 'EMIDIAccess', config: this._config };
106
+ },
107
+ [Inspectable.NodeInspectSymbol]() {
108
+ return this.toJSON();
109
+ },
110
+ get sysexEnabled() {
111
+ return assumeImpl(this)._access.sysexEnabled;
112
+ },
113
+ get softwareSynthEnabled() {
114
+ return !!assumeImpl(this)._config.software;
115
+ },
116
+ };
117
+ /**
118
+ *
119
+ *
120
+ * @internal
121
+ */
122
+ const makeImpl = (rawAccess, config) => {
123
+ const instance = Object.create(Proto);
124
+ instance._access = rawAccess;
125
+ // TODO: set individual software and sysex flags instead
126
+ instance._config = config ?? {};
127
+ return instance;
128
+ };
129
+ /**
130
+ * Asserts an object to be valid `EMIDIAccess` and casts it to internal
131
+ * implementation type
132
+ *
133
+ * @internal
134
+ */
135
+ const assertImpl = (access) => {
136
+ if (!isImpl(access))
137
+ throw new Error('Failed to cast to EMIDIAccess');
138
+ return access;
139
+ };
140
+ /**
141
+ * Asserts an object to be valid `EMIDIAccess`
142
+ *
143
+ * @internal
144
+ */
145
+ export const assert = assertImpl;
146
+ /**
147
+ * @internal
148
+ */
149
+ export const assumeImpl = (access) => access;
150
+ /**
151
+ *
152
+ *
153
+ * @internal
154
+ */
155
+ const make = makeImpl;
156
+ /**
157
+ *
158
+ *
159
+ * @internal
160
+ */
161
+ const isImpl = (access) => typeof access === 'object' &&
162
+ access !== null &&
163
+ Object.getPrototypeOf(access) === Proto &&
164
+ TypeId in access &&
165
+ '_access' in access &&
166
+ typeof access._access === 'object' &&
167
+ '_config' in access &&
168
+ typeof access._config === 'object' &&
169
+ access._config !== null &&
170
+ access._access instanceof MIDIAccess;
171
+ /**
172
+ *
173
+ *
174
+ */
175
+ export const is = isImpl;
176
+ /**
177
+ *
178
+ * @internal
179
+ */
180
+ export const resolve = (polymorphicAccess) => Util.fromPolymorphic(polymorphicAccess, is);
181
+ /**
182
+ *
183
+ * @internal
184
+ */
185
+ const getPortEntriesFromRawAccess = (key, make) => (rawAccess) => Iterable.map(rawAccess[key], ([id, raw]) => [id, make(raw)]);
186
+ /**
187
+ *
188
+ * @internal
189
+ */
190
+ const getInputEntriesFromRaw = getPortEntriesFromRawAccess('inputs', EMIDIInput.make);
191
+ /**
192
+ *
193
+ * @internal
194
+ */
195
+ const getOutputEntriesFromRaw = getPortEntriesFromRawAccess('outputs', EMIDIOutput.make);
196
+ /**
197
+ *
198
+ * @internal
199
+ */
200
+ const getAllPortsEntriesFromRaw = (rawAccess) => Iterable.appendAll(getInputEntriesFromRaw(rawAccess), getOutputEntriesFromRaw(rawAccess));
201
+ /**
202
+ *
203
+ * @param accessor
204
+ * @returns
205
+ * @internal
206
+ */
207
+ const decorateToTakePolymorphicAccessAndReturnRecord = (accessor) => (polymorphicAccess) => Effect.map(resolve(polymorphicAccess), EFunction.flow(assumeImpl, e => e._access, accessor, Record.fromEntries));
208
+ /**
209
+ * Because `MIDIInputMap` can potentially be a mutable object, meaning new
210
+ * devices can be added or removed at runtime, it is effectful.
211
+ *
212
+ * The **`inputs`** read-only property of the MIDIAccess interface provides
213
+ * access to any available MIDI input ports.
214
+ *
215
+ * [MDN
216
+ * Reference](https://developer.mozilla.org/docs/Web/API/MIDIAccess/inputs)
217
+ */
218
+ export const getInputsRecord = decorateToTakePolymorphicAccessAndReturnRecord(getInputEntriesFromRaw);
219
+ /**
220
+ * Because `MIDIOutputMap` can potentially be a mutable object, meaning new
221
+ * devices can be added or removed at runtime, it is effectful.
222
+ *
223
+ * The **`outputs`** read-only property of the MIDIAccess interface provides
224
+ * access to any available MIDI output ports.
225
+ *
226
+ * [MDN
227
+ * Reference](https://developer.mozilla.org/docs/Web/API/MIDIAccess/outputs)
228
+ */
229
+ export const getOutputsRecord = decorateToTakePolymorphicAccessAndReturnRecord(getOutputEntriesFromRaw);
230
+ /**
231
+ *
232
+ *
233
+ */
234
+ export const getAllPortsRecord = decorateToTakePolymorphicAccessAndReturnRecord(getAllPortsEntriesFromRaw);
235
+ /**
236
+ *
237
+ *
238
+ */
239
+ export const InputsRecord = getInputsRecord(EMIDIAccess);
240
+ /**
241
+ *
242
+ *
243
+ */
244
+ export const OutputsRecord = getOutputsRecord(EMIDIAccess);
245
+ /**
246
+ *
247
+ *
248
+ */
249
+ export const AllPortsRecord = getAllPortsRecord(EMIDIAccess);
250
+ /**
251
+ * [MIDIConnectionEvent MDN
252
+ * Reference](https://developer.mozilla.org/docs/Web/API/MIDIConnectionEvent)
253
+ */
254
+ export const makeAllPortsStateChangesStream = StreamMaker.createStreamMakerFrom()(is, access => ({
255
+ tag: 'MIDIPortStateChange',
256
+ eventListener: {
257
+ target: assumeImpl(access)._access,
258
+ type: 'statechange',
259
+ },
260
+ spanAttributes: {
261
+ spanTargetName: 'MIDI access handle',
262
+ requestedAccessConfig: assumeImpl(access)._config,
263
+ },
264
+ nullableFieldName: 'port',
265
+ }), rawPort => ({
266
+ newState: rawPort
267
+ ? {
268
+ ofDevice: rawPort.state,
269
+ ofConnection: rawPort.connection,
270
+ }
271
+ : null,
272
+ port: rawPort instanceof globalThis.MIDIInput
273
+ ? EMIDIInput.make(rawPort)
274
+ : rawPort instanceof globalThis.MIDIOutput
275
+ ? EMIDIOutput.make(rawPort)
276
+ : null,
277
+ }));
278
+ /**
279
+ * beware that it's not possible to ensure the messages will either be all
280
+ * delivered, or all not delivered, as in ACID transactions. There's not even a
281
+ * mechanism to remove a specific message (not all) from the sending queue
282
+ */
283
+ export const send = EFunction.dual(Util.polymorphicCheckInDual(is), Effect.fn('EMIDIAccess.send')(function* (polymorphicAccess, target, midiMessage, timestamp) {
284
+ const access = yield* resolve(polymorphicAccess);
285
+ const outputs = yield* getOutputsRecord(access);
286
+ if (target === 'all existing outputs at effect execution')
287
+ return yield* EFunction.pipe(Record.values(outputs), Effect.forEach(EMIDIOutput.send(midiMessage, timestamp)), Effect.as(access));
288
+ if (target === 'all open connections at effect execution')
289
+ return yield* EFunction.pipe(Record.values(outputs),
290
+ // TODO: maybe also do something about pending?
291
+ Effect.filter(isOutputConnectionOpenByPort), Effect.flatMap(Effect.forEach(EMIDIOutput.send(midiMessage, timestamp))), Effect.as(access));
292
+ // TODO: maybe since deviceState returns always connected devices we can
293
+ // simplify this check by applying intersections and comparing lengths
294
+ const portsIdsToSend = EArray.ensure(target);
295
+ const deviceStatusesEffect = portsIdsToSend.map(id => EFunction.pipe(Record.get(outputs, id), Option.match({
296
+ onNone: () => Effect.succeed('disconnected'),
297
+ onSome: EFunction.flow(getOutputDeviceStateByPort),
298
+ }), effect => Unify.unify(effect), Effect.map(state => ({ id, state }))));
299
+ const disconnectedDevice = EArray.findFirst(yield* Effect.all(deviceStatusesEffect), _ => _.state === 'disconnected');
300
+ if (Option.isSome(disconnectedDevice))
301
+ return yield* new Errors.DisconnectedPortError({
302
+ portId: disconnectedDevice.value.id,
303
+ cause: new DOMException(
304
+ // TODO: make an experiment and paste the error text here
305
+ 'TODO: imitate there an error thats thrown when the port is disconnected', 'InvalidStateError'),
306
+ });
307
+ const sendToSome = (predicate) => Effect.all(Record.reduce(outputs, [],
308
+ // TODO: investigate what the fuck is going on, why the fuck can't I
309
+ // make it a simple expression without either nesting it in
310
+ // curly-braced function body or adding manual type-annotation
311
+ (acc, port, id) => predicate(id)
312
+ ? [
313
+ ...acc,
314
+ EMIDIOutput.send(port, midiMessage, timestamp),
315
+ ]
316
+ : acc));
317
+ yield* sendToSome(id => portsIdsToSend.includes(id));
318
+ return access;
319
+ }));
320
+ /**
321
+ * @param options Passing a value of a `boolean` type is equivalent to setting
322
+ * `options.capture` property
323
+ */
324
+ export const makeMessagesStreamByInputId = (id, options) => EMIDIInput.makeMessagesStreamByPort(GetPort.getInputByPortIdInContext(id), options);
325
+ // TODO: makeMessagesStreamByInputIdAndAccess
326
+ export const makeMessagesStreamByInputIdAndAccess = () => {
327
+ throw new Error('not implemented');
328
+ };
329
+ /**
330
+ *
331
+ */
332
+ export const sendToPortById = (id, ...args) => Effect.asVoid(EMIDIOutput.send(GetPort.getOutputByPortIdInContext(id), ...args));
333
+ /**
334
+ *
335
+ */
336
+ export const clearPortById = EFunction.flow(GetPort.getOutputByPortIdInContext, EMIDIOutput.clear, Effect.asVoid);
337
+ /**
338
+ * @param options Passing a value of a `boolean` type is equivalent to setting
339
+ * `options.capture` property
340
+ */
341
+ export const makeAllPortsStateChangesStreamInContext = (options) => makeAllPortsStateChangesStream(EMIDIAccess, options);
342
+ /**
343
+ *
344
+ *
345
+ */
346
+ export const sendInContext = (...args) => Effect.asVoid(send(EMIDIAccess, ...args));
347
+ /**
348
+ * @param options
349
+ *
350
+ * @returns An Effect representing a request for access to MIDI devices on a
351
+ * user's system. Available only in secure contexts.
352
+ */
353
+ export const request = Effect.fn('EMIDIAccess.request')(function* (options) {
354
+ yield* Effect.annotateCurrentSpan({ options });
355
+ const rawAccess = yield* Effect.tryPromise({
356
+ try: () => navigator.requestMIDIAccess(options),
357
+ catch: Errors.remapErrorByName({
358
+ AbortError: Errors.AbortError,
359
+ InvalidStateError: Errors.UnderlyingSystemError,
360
+ NotAllowedError: Errors.MIDIAccessNotAllowedError,
361
+ // SecurityError is kept for compatibility reason
362
+ // (https://github.com/WebAudio/web-midi-api/pull/267):
363
+ SecurityError: Errors.MIDIAccessNotAllowedError,
364
+ NotSupportedError: Errors.MIDIAccessNotSupportedError,
365
+ // For case when navigator doesn't exist
366
+ ReferenceError: Errors.MIDIAccessNotSupportedError,
367
+ // For case when navigator.requestMIDIAccess is undefined
368
+ TypeError: Errors.MIDIAccessNotSupportedError,
369
+ }, 'EMIDIAccess.request error handling absurd', { whileAskingForPermissions: options ?? {} }),
370
+ });
371
+ // TODO: finish this
372
+ const ref = yield* Ref.make(SortedMap.empty(Order.string));
373
+ // return make(rawAccess, options, ref)
374
+ return make(rawAccess, options);
375
+ });
376
+ // TODO: clear all outputs
377
+ /**
378
+ *
379
+ * **Errors:**
380
+ *
381
+ * - {@linkcode Errors.AbortError} Argument x must be non-zero
382
+ * - {@linkcode Errors.UnderlyingSystemError} Argument x must be non-zero
383
+ * - {@linkcode Errors.MIDIAccessNotSupportedError} Argument x must be non-zero
384
+ * - {@linkcode Errors.MIDIAccessNotAllowedError} Argument x must be non-zero
385
+ *
386
+ * @param config
387
+ * @returns
388
+ */
389
+ export const layer = (config) => Layer.effect(EMIDIAccess, request(config));
390
+ /**
391
+ *
392
+ */
393
+ export const layerMostRestricted = layer();
394
+ /**
395
+ *
396
+ */
397
+ export const layerSystemExclusiveSupported = layer({ sysex: true });
398
+ /**
399
+ *
400
+ */
401
+ export const layerSoftwareSynthSupported = layer({ software: true });
402
+ /**
403
+ *
404
+ */
405
+ export const layerSystemExclusiveAndSoftwareSynthSupported = layer({
406
+ software: true,
407
+ sysex: true,
408
+ });
409
+ //# sourceMappingURL=EMIDIAccess.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EMIDIAccess.js","sourceRoot":"","sources":["../../../src/internal/EMIDIAccess.ts"],"names":[],"mappings":"AAAA;gEACgE;AAEhE,OAAO,KAAK,MAAM,MAAM,cAAc,CAAA;AACtC,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,SAAS,MAAM,iBAAiB,CAAA;AAC5C,OAAO,KAAK,IAAI,MAAM,aAAa,CAAA;AACnC,OAAO,KAAK,WAAW,MAAM,oBAAoB,CAAA;AACjD,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAC3C,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,MAAM,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;YAClD,yDAAyD;YACzD,SAAS,EAAE,MAAM,CAAC,2BAA2B;SAC9C,EACD,2CAA2C,EAC3C,EAAE,yBAAyB,EAAE,OAAO,IAAI,EAAE,EAAE,CAC7C;KACF,CAAC,CAAA;IAEF,oBAAoB;IAEpB,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,GAAG,CAAC,IAAI,CACzB,SAAS,CAAC,KAAK,CAAiC,KAAK,CAAC,MAAM,CAAC,CAC9D,CAAA;IAED,uCAAuC;IACvC,OAAO,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;AACjC,CAAC,CAAC,CAAA;AAEF,0BAA0B;AAE1B;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,MAAiC,EAAE,EAAE,CACzD,KAAK,CAAC,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAA;AAE5C;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,EAAE,CAAA;AAE1C;;GAEG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;AAEnE;;GAEG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,KAAK,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAA;AAEpE;;GAEG;AACH,MAAM,CAAC,MAAM,6CAA6C,GAAG,KAAK,CAAC;IACjE,QAAQ,EAAE,IAAI;IACd,KAAK,EAAE,IAAI;CACZ,CAAC,CAAA"}
@@ -0,0 +1,69 @@
1
+ import * as Brand from 'effect/Brand';
2
+ import * as EMIDIPort from "./EMIDIPort.js";
3
+ import * as StreamMaker from "./StreamMaker.js";
4
+ import * as Util from "./util.js";
5
+ /**
6
+ * Validates the raw MIDI input port, and puts it into a field hidden from the
7
+ * client's code
8
+ *
9
+ * @internal
10
+ */
11
+ const makeImpl = (rawInput) => EMIDIPort.makeImpl(rawInput, 'input', globalThis.MIDIInput);
12
+ /**
13
+ * Asserts an object to be valid EMIDIInput and casts it to internal
14
+ * implementation type
15
+ *
16
+ * @internal
17
+ */
18
+ const assertImpl = (input) => {
19
+ if (!isImpl(input))
20
+ throw new Error('Failed to cast to EMIDIInputImpl');
21
+ return input;
22
+ };
23
+ /**
24
+ * Asserts an object to be valid EMIDIInput
25
+ */
26
+ export const assert = assertImpl;
27
+ /**
28
+ * @internal
29
+ */
30
+ const assumeImpl = (input) => input;
31
+ /**
32
+ *
33
+ *
34
+ * @internal
35
+ */
36
+ export const make = makeImpl;
37
+ /**
38
+ *
39
+ *
40
+ * @internal
41
+ */
42
+ const isImpl = EMIDIPort.isImplOfSpecificType('input', globalThis.MIDIInput);
43
+ /**
44
+ *
45
+ *
46
+ */
47
+ export const is = isImpl;
48
+ /**
49
+ * [MIDIMessageEvent MDN
50
+ * Reference](https://developer.mozilla.org/docs/Web/API/MIDIMessageEvent)
51
+ *
52
+ * MIDI spec says that synthetically built `MIDIMessageEvent`s can have `data`
53
+ * field equal to `null`, but when coming from the browser, they won't. The
54
+ * default behavior is to defect on `null`.
55
+ */
56
+ export const makeMessagesStreamByPort = StreamMaker.createStreamMakerFrom()(is, input => ({
57
+ tag: 'MIDIMessage',
58
+ eventListener: {
59
+ target: assumeImpl(input)._port,
60
+ type: 'midimessage',
61
+ },
62
+ spanAttributes: {
63
+ spanTargetName: 'MIDI port',
64
+ port: Util.getStaticMIDIPortInfo(input),
65
+ },
66
+ nullableFieldName: 'data',
67
+ }), midiMessage => ({ midiMessage }));
68
+ export const Id = Brand.nominal();
69
+ //# sourceMappingURL=EMIDIInput.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EMIDIInput.js","sourceRoot":"","sources":["../../../src/internal/EMIDIInput.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAA;AAC3C,OAAO,KAAK,WAAW,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EAAE,WAAW,EAAE,CAAC,CACjC,CAAA;AAeH,MAAM,CAAC,MAAM,EAAE,GAAG,KAAK,CAAC,OAAO,EAAM,CAAA"}
@@ -0,0 +1,120 @@
1
+ /** biome-ignore-all lint/style/useShorthandFunctionType: It's a nice way to
2
+ * preserve JSDoc comments attached to the function signature */
3
+ import * as Brand from 'effect/Brand';
4
+ import * as Effect from 'effect/Effect';
5
+ import * as EFunction from 'effect/Function';
6
+ import * as EMIDIPort from "./EMIDIPort.js";
7
+ import * as Errors from "./errors.js";
8
+ import * as Util from "./util.js";
9
+ /**
10
+ * Validates the raw MIDI output port, and puts it into a field hidden from the
11
+ * client's code
12
+ *
13
+ * @internal
14
+ */
15
+ const makeImpl = (rawOutput) => EMIDIPort.makeImpl(rawOutput, 'output', globalThis.MIDIOutput);
16
+ /**
17
+ * Asserts an object to be valid EMIDIOutput and casts it to
18
+ * internal implementation type
19
+ *
20
+ * @internal
21
+ */
22
+ const assertImpl = (output) => {
23
+ if (!isImpl(output))
24
+ throw new Error('Assertion failed: Not a EMIDIOutputImpl');
25
+ return output;
26
+ };
27
+ /**
28
+ * Asserts an object to be valid EMIDIOutput
29
+ */
30
+ export const assert = assertImpl;
31
+ /**
32
+ * Casts
33
+ * @internal
34
+ */
35
+ const assumeImpl = (output) => output;
36
+ /**
37
+ *
38
+ * @internal
39
+ */
40
+ export const make = makeImpl;
41
+ /**
42
+ *
43
+ * @internal
44
+ */
45
+ const isImpl = EMIDIPort.isImplOfSpecificType('output', globalThis.MIDIOutput);
46
+ /**
47
+ *
48
+ */
49
+ export const is = isImpl;
50
+ /**
51
+ *
52
+ *
53
+ * @internal
54
+ */
55
+ const resolve = (polymorphicPort) => Util.fromPolymorphic(polymorphicPort, is);
56
+ /**
57
+ * If `midiMessage` is a System Exclusive message, and the `MIDIAccess` did not
58
+ * enable System Exclusive access, an `InvalidAccessError` exception will be
59
+ * thrown
60
+ *
61
+ * If the port is `"connected"` and the connection is `"closed"`, asynchronously
62
+ * tries to open the port. It's unclear in the spec if potential error of `open`
63
+ * call would result in an `InvalidAccessError` error coming from the `send`
64
+ * method itself.
65
+ *
66
+ * @returns An effect with the same port for easier chaining of operations
67
+ */
68
+ export const send = EFunction.dual(Util.polymorphicCheckInDual(is), Effect.fn('EMIDIOutput.send')(function* (polymorphicOutput, midiMessage, timestamp) {
69
+ const output = yield* resolve(polymorphicOutput);
70
+ yield* Effect.annotateCurrentSpan({
71
+ midiMessage,
72
+ timestamp,
73
+ port: Util.getStaticMIDIPortInfo(output),
74
+ });
75
+ yield* Effect.try({
76
+ try: () => assumeImpl(output)._port.send(midiMessage, timestamp),
77
+ catch: Errors.remapErrorByName({
78
+ NotAllowedError: Errors.CantSendSysexMessagesError,
79
+ // InvalidAccessError is kept for compatibility reason
80
+ // (https://github.com/WebAudio/web-midi-api/pull/278):
81
+ InvalidAccessError: Errors.CantSendSysexMessagesError,
82
+ InvalidStateError: Errors.DisconnectedPortError,
83
+ TypeError: Errors.MalformedMidiMessageError,
84
+ }, 'EMIDIOutput.send error handling absurd', { portId: output.id, midiMessage: [...midiMessage] }),
85
+ });
86
+ return output;
87
+ }));
88
+ /**
89
+ * Clears any enqueued send data that has not yet been sent from the
90
+ * `MIDIOutput`'s queue. The browser will ensure the MIDI stream is left in a
91
+ * good state, and if the output port is in the middle of a sysex message, a
92
+ * sysex termination byte (`0xf7`) will be sent.
93
+ *
94
+ * @param polymorphicOutput An effectful output port
95
+ *
96
+ * @returns An effect with the same port for easier chaining of operations
97
+ * @experimental Supported only in Firefox. {@link https://caniuse.com/mdn-api_midioutput_clear|Can I use - MIDIOutput API: clear}
98
+ * @see {@link https://www.w3.org/TR/webmidi/#dom-midioutput-clear|Web MIDI spec}, {@link https://developer.mozilla.org/en-US/docs/Web/API/MIDIOutput/clear|MDN reference}
99
+ */
100
+ export const clear = Effect.fn('EMIDIOutput.clear')(function* (polymorphicOutput) {
101
+ const output = yield* resolve(polymorphicOutput);
102
+ yield* Effect.annotateCurrentSpan({
103
+ port: Util.getStaticMIDIPortInfo(output),
104
+ });
105
+ yield* Effect.try({
106
+ // @ts-expect-error even though `.clear` is in spec, the API is not
107
+ // supported in at least 2 major browsers, hence doesn't meet the condition
108
+ // to be included into TS's DOM types
109
+ try: () => assumeImpl(output)._port.clear(),
110
+ catch: Errors.remapErrorByName({
111
+ // TODO: test this
112
+ // most likely it would be something like `TypeError: Undefined is not a function`
113
+ TypeError: Errors.ClearingSendingQueueIsNotSupportedError,
114
+ NotSupportedError: Errors.ClearingSendingQueueIsNotSupportedError,
115
+ }, 'EMIDIOutput.clear error handling absurd', { portId: output.id }),
116
+ });
117
+ return output;
118
+ });
119
+ export const Id = Brand.nominal();
120
+ //# sourceMappingURL=EMIDIOutput.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EMIDIOutput.js","sourceRoot":"","sources":["../../../src/internal/EMIDIOutput.ts"],"names":[],"mappings":"AAAA;gEACgE;AAEhE,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,SAAS,MAAM,iBAAiB,CAAA;AAC5C,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAA;AAC3C,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACrC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AAgBjC;;;;;GAKG;AACH,MAAM,QAAQ,GAAG,CAAC,SAAqB,EAAmB,EAAE,CAC1D,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,QAAQ,EAAE,UAAU,CAAC,UAAU,CAAC,CAAA;AAEhE;;;;;GAKG;AACH,MAAM,UAAU,GAAG,CAAC,MAAe,EAAE,EAAE;IACrC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAA;IAC5D,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,MAAM,GAAq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