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.
- package/README.md +7 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/src/EMIDIAccess.js +68 -0
- package/dist/src/EMIDIAccess.js.map +1 -0
- package/dist/src/EMIDIInput.js +226 -0
- package/dist/src/EMIDIInput.js.map +1 -0
- package/dist/src/EMIDIOutput.js +225 -0
- package/dist/src/EMIDIOutput.js.map +1 -0
- package/dist/src/EMIDIPort.js +213 -0
- package/dist/src/EMIDIPort.js.map +1 -0
- package/dist/src/MIDIErrors.js +4 -0
- package/dist/src/MIDIErrors.js.map +1 -0
- package/dist/src/Parsing.js +2 -0
- package/dist/src/Parsing.js.map +1 -0
- package/dist/src/StreamMaker.js +1 -0
- package/dist/src/StreamMaker.js.map +1 -0
- package/dist/src/Util.js +4 -0
- package/dist/src/Util.js.map +1 -0
- package/dist/src/index.js +9 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/internal/EMIDIAccess.js +409 -0
- package/dist/src/internal/EMIDIAccess.js.map +1 -0
- package/dist/src/internal/EMIDIInput.js +69 -0
- package/dist/src/internal/EMIDIInput.js.map +1 -0
- package/dist/src/internal/EMIDIOutput.js +120 -0
- package/dist/src/internal/EMIDIOutput.js.map +1 -0
- package/dist/src/internal/EMIDIPort.js +125 -0
- package/dist/src/internal/EMIDIPort.js.map +1 -0
- package/dist/src/internal/MIDIPortMethodCalls/acquireReleasePortConnection/acquireReleasePortConnectionByPort.js +27 -0
- package/dist/src/internal/MIDIPortMethodCalls/acquireReleasePortConnection/acquireReleasePortConnectionByPort.js.map +1 -0
- package/dist/src/internal/MIDIPortMethodCalls/acquireReleasePortConnection/acquireReleasePortConnectionByPortIdAndAccess.js +19 -0
- package/dist/src/internal/MIDIPortMethodCalls/acquireReleasePortConnection/acquireReleasePortConnectionByPortIdAndAccess.js.map +1 -0
- package/dist/src/internal/MIDIPortMethodCalls/acquireReleasePortConnection/acquireReleasePortConnectionByPortIdInContext.js +16 -0
- package/dist/src/internal/MIDIPortMethodCalls/acquireReleasePortConnection/acquireReleasePortConnectionByPortIdInContext.js.map +1 -0
- package/dist/src/internal/MIDIPortMethodCalls/actOnPort.js +18 -0
- package/dist/src/internal/MIDIPortMethodCalls/actOnPort.js.map +1 -0
- package/dist/src/internal/MIDIPortMethodCalls/closePortConnection/closePortConnectionByPort.js +27 -0
- package/dist/src/internal/MIDIPortMethodCalls/closePortConnection/closePortConnectionByPort.js.map +1 -0
- package/dist/src/internal/MIDIPortMethodCalls/closePortConnection/closePortConnectionByPortIdAndAccess.js +18 -0
- package/dist/src/internal/MIDIPortMethodCalls/closePortConnection/closePortConnectionByPortIdAndAccess.js.map +1 -0
- package/dist/src/internal/MIDIPortMethodCalls/closePortConnection/closePortConnectionByPortIdInContext.js +16 -0
- package/dist/src/internal/MIDIPortMethodCalls/closePortConnection/closePortConnectionByPortIdInContext.js.map +1 -0
- package/dist/src/internal/MIDIPortMethodCalls/makeMIDIPortMethodCallerFactory.js +21 -0
- package/dist/src/internal/MIDIPortMethodCalls/makeMIDIPortMethodCallerFactory.js.map +1 -0
- package/dist/src/internal/MIDIPortMethodCalls/openPortConnection/openPortConnectionByPort.js +30 -0
- package/dist/src/internal/MIDIPortMethodCalls/openPortConnection/openPortConnectionByPort.js.map +1 -0
- package/dist/src/internal/MIDIPortMethodCalls/openPortConnection/openPortConnectionByPortIdAndAccess.js +18 -0
- package/dist/src/internal/MIDIPortMethodCalls/openPortConnection/openPortConnectionByPortIdAndAccess.js.map +1 -0
- package/dist/src/internal/MIDIPortMethodCalls/openPortConnection/openPortConnectionByPortIdInContext.js +16 -0
- package/dist/src/internal/MIDIPortMethodCalls/openPortConnection/openPortConnectionByPortIdInContext.js.map +1 -0
- package/dist/src/internal/StreamMaker.js +101 -0
- package/dist/src/internal/StreamMaker.js.map +1 -0
- package/dist/src/internal/errors.js +161 -0
- package/dist/src/internal/errors.js.map +1 -0
- package/dist/src/internal/getPortByPortId/getPortByPortIdAndAccess.js +53 -0
- package/dist/src/internal/getPortByPortId/getPortByPortIdAndAccess.js.map +1 -0
- package/dist/src/internal/getPortByPortId/getPortByPortIdInContext.js +18 -0
- package/dist/src/internal/getPortByPortId/getPortByPortIdInContext.js.map +1 -0
- package/dist/src/internal/makePortStateChangesStream/makePortStateChangesStreamByPort.js +52 -0
- package/dist/src/internal/makePortStateChangesStream/makePortStateChangesStreamByPort.js.map +1 -0
- package/dist/src/internal/makePortStateChangesStream/makePortStateChangesStreamByPortIdAndAccess.js +13 -0
- package/dist/src/internal/makePortStateChangesStream/makePortStateChangesStreamByPortIdAndAccess.js.map +1 -0
- package/dist/src/internal/makePortStateChangesStream/makePortStateChangesStreamByPortIdInContext.js +18 -0
- package/dist/src/internal/makePortStateChangesStream/makePortStateChangesStreamByPortIdInContext.js.map +1 -0
- package/dist/src/internal/mutablePropertyTools/doesMutablePortPropertyHaveSpecificValue/doesMutablePortPropertyHaveSpecificValueByPort.js +66 -0
- package/dist/src/internal/mutablePropertyTools/doesMutablePortPropertyHaveSpecificValue/doesMutablePortPropertyHaveSpecificValueByPort.js.map +1 -0
- package/dist/src/internal/mutablePropertyTools/doesMutablePortPropertyHaveSpecificValue/doesMutablePortPropertyHaveSpecificValueByPortIdAndAccess.js +61 -0
- package/dist/src/internal/mutablePropertyTools/doesMutablePortPropertyHaveSpecificValue/doesMutablePortPropertyHaveSpecificValueByPortIdAndAccess.js.map +1 -0
- package/dist/src/internal/mutablePropertyTools/doesMutablePortPropertyHaveSpecificValue/doesMutablePortPropertyHaveSpecificValueByPortIdInContext.js +61 -0
- package/dist/src/internal/mutablePropertyTools/doesMutablePortPropertyHaveSpecificValue/doesMutablePortPropertyHaveSpecificValueByPortIdInContext.js.map +1 -0
- package/dist/src/internal/mutablePropertyTools/getMutablePortProperty/getMutablePortPropertyByPort.js +42 -0
- package/dist/src/internal/mutablePropertyTools/getMutablePortProperty/getMutablePortPropertyByPort.js.map +1 -0
- package/dist/src/internal/mutablePropertyTools/getMutablePortProperty/getMutablePortPropertyByPortIdAndAccess.js +42 -0
- package/dist/src/internal/mutablePropertyTools/getMutablePortProperty/getMutablePortPropertyByPortIdAndAccess.js.map +1 -0
- package/dist/src/internal/mutablePropertyTools/getMutablePortProperty/getMutablePortPropertyByPortIdInContext.js +29 -0
- package/dist/src/internal/mutablePropertyTools/getMutablePortProperty/getMutablePortPropertyByPortIdInContext.js.map +1 -0
- package/dist/src/internal/mutablePropertyTools/getValueInRawPortFieldUnsafe.js +6 -0
- package/dist/src/internal/mutablePropertyTools/getValueInRawPortFieldUnsafe.js.map +1 -0
- package/dist/src/internal/mutablePropertyTools/matchMutablePortProperty/matchMutablePortPropertyByPort.js +46 -0
- package/dist/src/internal/mutablePropertyTools/matchMutablePortProperty/matchMutablePortPropertyByPort.js.map +1 -0
- package/dist/src/internal/mutablePropertyTools/matchMutablePortProperty/matchMutablePortPropertyByPortIdAndAccess.js +25 -0
- package/dist/src/internal/mutablePropertyTools/matchMutablePortProperty/matchMutablePortPropertyByPortIdAndAccess.js.map +1 -0
- package/dist/src/internal/mutablePropertyTools/matchMutablePortProperty/matchMutablePortPropertyByPortIdInContext.js +31 -0
- package/dist/src/internal/mutablePropertyTools/matchMutablePortProperty/matchMutablePortPropertyByPortIdInContext.js.map +1 -0
- package/dist/src/internal/parsing.js +117 -0
- package/dist/src/internal/parsing.js.map +1 -0
- package/dist/src/internal/util.js +59 -0
- package/dist/src/internal/util.js.map +1 -0
- package/dist-types/index.d.ts +2 -0
- package/dist-types/index.d.ts.map +1 -0
- package/dist-types/src/EMIDIAccess.d.ts +27 -0
- package/dist-types/src/EMIDIAccess.d.ts.map +1 -0
- package/dist-types/src/EMIDIInput.d.ts +26 -0
- package/dist-types/src/EMIDIInput.d.ts.map +1 -0
- package/dist-types/src/EMIDIOutput.d.ts +26 -0
- package/dist-types/src/EMIDIOutput.d.ts.map +1 -0
- package/dist-types/src/EMIDIPort.d.ts +26 -0
- package/dist-types/src/EMIDIPort.d.ts.map +1 -0
- package/dist-types/src/MIDIErrors.d.ts +2 -0
- package/dist-types/src/MIDIErrors.d.ts.map +1 -0
- package/dist-types/src/Parsing.d.ts +2 -0
- package/dist-types/src/Parsing.d.ts.map +1 -0
- package/dist-types/src/StreamMaker.d.ts +2 -0
- package/dist-types/src/StreamMaker.d.ts.map +1 -0
- package/dist-types/src/Util.d.ts +2 -0
- package/dist-types/src/Util.d.ts.map +1 -0
- package/dist-types/src/index.d.ts +9 -0
- package/dist-types/src/index.d.ts.map +1 -0
- package/dist-types/src/internal/EMIDIAccess.d.ts +339 -0
- package/dist-types/src/internal/EMIDIAccess.d.ts.map +1 -0
- package/dist-types/src/internal/EMIDIInput.d.ts +48 -0
- package/dist-types/src/internal/EMIDIInput.d.ts.map +1 -0
- package/dist-types/src/internal/EMIDIOutput.d.ts +93 -0
- package/dist-types/src/internal/EMIDIOutput.d.ts.map +1 -0
- package/dist-types/src/internal/EMIDIPort.d.ts +87 -0
- package/dist-types/src/internal/EMIDIPort.d.ts.map +1 -0
- package/dist-types/src/internal/MIDIPortMethodCalls/acquireReleasePortConnection/acquireReleasePortConnectionByPort.d.ts +16 -0
- package/dist-types/src/internal/MIDIPortMethodCalls/acquireReleasePortConnection/acquireReleasePortConnectionByPort.d.ts.map +1 -0
- package/dist-types/src/internal/MIDIPortMethodCalls/acquireReleasePortConnection/acquireReleasePortConnectionByPortIdAndAccess.d.ts +15 -0
- package/dist-types/src/internal/MIDIPortMethodCalls/acquireReleasePortConnection/acquireReleasePortConnectionByPortIdAndAccess.d.ts.map +1 -0
- package/dist-types/src/internal/MIDIPortMethodCalls/acquireReleasePortConnection/acquireReleasePortConnectionByPortIdInContext.d.ts +13 -0
- package/dist-types/src/internal/MIDIPortMethodCalls/acquireReleasePortConnection/acquireReleasePortConnectionByPortIdInContext.d.ts.map +1 -0
- package/dist-types/src/internal/MIDIPortMethodCalls/actOnPort.d.ts +11 -0
- package/dist-types/src/internal/MIDIPortMethodCalls/actOnPort.d.ts.map +1 -0
- package/dist-types/src/internal/MIDIPortMethodCalls/closePortConnection/closePortConnectionByPort.d.ts +23 -0
- package/dist-types/src/internal/MIDIPortMethodCalls/closePortConnection/closePortConnectionByPort.d.ts.map +1 -0
- package/dist-types/src/internal/MIDIPortMethodCalls/closePortConnection/closePortConnectionByPortIdAndAccess.d.ts +15 -0
- package/dist-types/src/internal/MIDIPortMethodCalls/closePortConnection/closePortConnectionByPortIdAndAccess.d.ts.map +1 -0
- package/dist-types/src/internal/MIDIPortMethodCalls/closePortConnection/closePortConnectionByPortIdInContext.d.ts +13 -0
- package/dist-types/src/internal/MIDIPortMethodCalls/closePortConnection/closePortConnectionByPortIdInContext.d.ts.map +1 -0
- package/dist-types/src/internal/MIDIPortMethodCalls/makeMIDIPortMethodCallerFactory.d.ts +15 -0
- package/dist-types/src/internal/MIDIPortMethodCalls/makeMIDIPortMethodCallerFactory.d.ts.map +1 -0
- package/dist-types/src/internal/MIDIPortMethodCalls/openPortConnection/openPortConnectionByPort.d.ts +21 -0
- package/dist-types/src/internal/MIDIPortMethodCalls/openPortConnection/openPortConnectionByPort.d.ts.map +1 -0
- package/dist-types/src/internal/MIDIPortMethodCalls/openPortConnection/openPortConnectionByPortIdAndAccess.d.ts +15 -0
- package/dist-types/src/internal/MIDIPortMethodCalls/openPortConnection/openPortConnectionByPortIdAndAccess.d.ts.map +1 -0
- package/dist-types/src/internal/MIDIPortMethodCalls/openPortConnection/openPortConnectionByPortIdInContext.d.ts +13 -0
- package/dist-types/src/internal/MIDIPortMethodCalls/openPortConnection/openPortConnectionByPortIdInContext.d.ts.map +1 -0
- package/dist-types/src/internal/StreamMaker.d.ts +202 -0
- package/dist-types/src/internal/StreamMaker.d.ts.map +1 -0
- package/dist-types/src/internal/errors.d.ts +260 -0
- package/dist-types/src/internal/errors.d.ts.map +1 -0
- package/dist-types/src/internal/getPortByPortId/getPortByPortIdAndAccess.d.ts +27 -0
- package/dist-types/src/internal/getPortByPortId/getPortByPortIdAndAccess.d.ts.map +1 -0
- package/dist-types/src/internal/getPortByPortId/getPortByPortIdInContext.d.ts +20 -0
- package/dist-types/src/internal/getPortByPortId/getPortByPortIdInContext.d.ts.map +1 -0
- package/dist-types/src/internal/makePortStateChangesStream/makePortStateChangesStreamByPort.d.ts +71 -0
- package/dist-types/src/internal/makePortStateChangesStream/makePortStateChangesStreamByPort.d.ts.map +1 -0
- package/dist-types/src/internal/makePortStateChangesStream/makePortStateChangesStreamByPortIdAndAccess.d.ts +4 -0
- package/dist-types/src/internal/makePortStateChangesStream/makePortStateChangesStreamByPortIdAndAccess.d.ts.map +1 -0
- package/dist-types/src/internal/makePortStateChangesStream/makePortStateChangesStreamByPortIdInContext.d.ts +20 -0
- package/dist-types/src/internal/makePortStateChangesStream/makePortStateChangesStreamByPortIdInContext.d.ts.map +1 -0
- package/dist-types/src/internal/mutablePropertyTools/doesMutablePortPropertyHaveSpecificValue/doesMutablePortPropertyHaveSpecificValueByPort.d.ts +62 -0
- package/dist-types/src/internal/mutablePropertyTools/doesMutablePortPropertyHaveSpecificValue/doesMutablePortPropertyHaveSpecificValueByPort.d.ts.map +1 -0
- package/dist-types/src/internal/mutablePropertyTools/doesMutablePortPropertyHaveSpecificValue/doesMutablePortPropertyHaveSpecificValueByPortIdAndAccess.d.ts +16 -0
- package/dist-types/src/internal/mutablePropertyTools/doesMutablePortPropertyHaveSpecificValue/doesMutablePortPropertyHaveSpecificValueByPortIdAndAccess.d.ts.map +1 -0
- package/dist-types/src/internal/mutablePropertyTools/doesMutablePortPropertyHaveSpecificValue/doesMutablePortPropertyHaveSpecificValueByPortIdInContext.d.ts +16 -0
- package/dist-types/src/internal/mutablePropertyTools/doesMutablePortPropertyHaveSpecificValue/doesMutablePortPropertyHaveSpecificValueByPortIdInContext.d.ts.map +1 -0
- package/dist-types/src/internal/mutablePropertyTools/getMutablePortProperty/getMutablePortPropertyByPort.d.ts +36 -0
- package/dist-types/src/internal/mutablePropertyTools/getMutablePortProperty/getMutablePortPropertyByPort.d.ts.map +1 -0
- package/dist-types/src/internal/mutablePropertyTools/getMutablePortProperty/getMutablePortPropertyByPortIdAndAccess.d.ts +22 -0
- package/dist-types/src/internal/mutablePropertyTools/getMutablePortProperty/getMutablePortPropertyByPortIdAndAccess.d.ts.map +1 -0
- package/dist-types/src/internal/mutablePropertyTools/getMutablePortProperty/getMutablePortPropertyByPortIdInContext.d.ts +17 -0
- package/dist-types/src/internal/mutablePropertyTools/getMutablePortProperty/getMutablePortPropertyByPortIdInContext.d.ts.map +1 -0
- package/dist-types/src/internal/mutablePropertyTools/getValueInRawPortFieldUnsafe.d.ts +7 -0
- package/dist-types/src/internal/mutablePropertyTools/getValueInRawPortFieldUnsafe.d.ts.map +1 -0
- package/dist-types/src/internal/mutablePropertyTools/matchMutablePortProperty/matchMutablePortPropertyByPort.d.ts +71 -0
- package/dist-types/src/internal/mutablePropertyTools/matchMutablePortProperty/matchMutablePortPropertyByPort.d.ts.map +1 -0
- package/dist-types/src/internal/mutablePropertyTools/matchMutablePortProperty/matchMutablePortPropertyByPortIdAndAccess.d.ts +7 -0
- package/dist-types/src/internal/mutablePropertyTools/matchMutablePortProperty/matchMutablePortPropertyByPortIdAndAccess.d.ts.map +1 -0
- package/dist-types/src/internal/mutablePropertyTools/matchMutablePortProperty/matchMutablePortPropertyByPortIdInContext.d.ts +28 -0
- package/dist-types/src/internal/mutablePropertyTools/matchMutablePortProperty/matchMutablePortPropertyByPortIdInContext.d.ts.map +1 -0
- package/dist-types/src/internal/parsing.d.ts +72 -0
- package/dist-types/src/internal/parsing.d.ts.map +1 -0
- package/dist-types/src/internal/util.d.ts +33 -0
- package/dist-types/src/internal/util.d.ts.map +1 -0
- package/index.ts +1 -0
- package/package.json +83 -0
- package/src/EMIDIAccess.ts +271 -0
- package/src/EMIDIInput.ts +270 -0
- package/src/EMIDIOutput.ts +269 -0
- package/src/EMIDIPort.ts +267 -0
- package/src/MIDIErrors.ts +13 -0
- package/src/Parsing.ts +12 -0
- package/src/StreamMaker.ts +12 -0
- package/src/Util.ts +19 -0
- package/src/index.ts +8 -0
- package/src/internal/EMIDIAccess.ts +893 -0
- package/src/internal/EMIDIInput.ts +114 -0
- package/src/internal/EMIDIOutput.ts +228 -0
- package/src/internal/EMIDIPort.ts +233 -0
- package/src/internal/MIDIPortMethodCalls/acquireReleasePortConnection/acquireReleasePortConnectionByPort.ts +43 -0
- package/src/internal/MIDIPortMethodCalls/acquireReleasePortConnection/acquireReleasePortConnectionByPortIdAndAccess.ts +39 -0
- package/src/internal/MIDIPortMethodCalls/acquireReleasePortConnection/acquireReleasePortConnectionByPortIdInContext.ts +27 -0
- package/src/internal/MIDIPortMethodCalls/actOnPort.ts +66 -0
- package/src/internal/MIDIPortMethodCalls/closePortConnection/closePortConnectionByPort.ts +38 -0
- package/src/internal/MIDIPortMethodCalls/closePortConnection/closePortConnectionByPortIdAndAccess.ts +38 -0
- package/src/internal/MIDIPortMethodCalls/closePortConnection/closePortConnectionByPortIdInContext.ts +27 -0
- package/src/internal/MIDIPortMethodCalls/makeMIDIPortMethodCallerFactory.ts +73 -0
- package/src/internal/MIDIPortMethodCalls/openPortConnection/openPortConnectionByPort.ts +44 -0
- package/src/internal/MIDIPortMethodCalls/openPortConnection/openPortConnectionByPortIdAndAccess.ts +38 -0
- package/src/internal/MIDIPortMethodCalls/openPortConnection/openPortConnectionByPortIdInContext.ts +27 -0
- package/src/internal/StreamMaker.ts +414 -0
- package/src/internal/errors.ts +220 -0
- package/src/internal/getPortByPortId/getPortByPortIdAndAccess.ts +116 -0
- package/src/internal/getPortByPortId/getPortByPortIdInContext.ts +26 -0
- package/src/internal/makePortStateChangesStream/makePortStateChangesStreamByPort.ts +148 -0
- package/src/internal/makePortStateChangesStream/makePortStateChangesStreamByPortIdAndAccess.ts +14 -0
- package/src/internal/makePortStateChangesStream/makePortStateChangesStreamByPortIdInContext.ts +51 -0
- package/src/internal/mutablePropertyTools/doesMutablePortPropertyHaveSpecificValue/doesMutablePortPropertyHaveSpecificValueByPort.ts +127 -0
- package/src/internal/mutablePropertyTools/doesMutablePortPropertyHaveSpecificValue/doesMutablePortPropertyHaveSpecificValueByPortIdAndAccess.ts +74 -0
- package/src/internal/mutablePropertyTools/doesMutablePortPropertyHaveSpecificValue/doesMutablePortPropertyHaveSpecificValueByPortIdInContext.ts +74 -0
- package/src/internal/mutablePropertyTools/getMutablePortProperty/getMutablePortPropertyByPort.ts +63 -0
- package/src/internal/mutablePropertyTools/getMutablePortProperty/getMutablePortPropertyByPortIdAndAccess.ts +110 -0
- package/src/internal/mutablePropertyTools/getMutablePortProperty/getMutablePortPropertyByPortIdInContext.ts +37 -0
- package/src/internal/mutablePropertyTools/getValueInRawPortFieldUnsafe.ts +12 -0
- package/src/internal/mutablePropertyTools/matchMutablePortProperty/matchMutablePortPropertyByPort.ts +183 -0
- package/src/internal/mutablePropertyTools/matchMutablePortProperty/matchMutablePortPropertyByPortIdAndAccess.ts +29 -0
- package/src/internal/mutablePropertyTools/matchMutablePortProperty/matchMutablePortPropertyByPortIdInContext.ts +86 -0
- package/src/internal/parsing.ts +219 -0
- package/src/internal/util.ts +152 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import * as Brand from 'effect/Brand'
|
|
2
|
+
import * as EMIDIPort from './EMIDIPort.ts'
|
|
3
|
+
import * as StreamMaker from './StreamMaker.ts'
|
|
4
|
+
import * as Util from './util.ts'
|
|
5
|
+
|
|
6
|
+
// TODO: implement scoping of midi access that will clean up all message queues
|
|
7
|
+
// and streams, and remove listeners
|
|
8
|
+
|
|
9
|
+
// TODO: implement scope inheritance
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Thin wrapper around {@linkcode MIDIInput} instance. Will be seen in all
|
|
13
|
+
* external code.
|
|
14
|
+
*/
|
|
15
|
+
export interface EMIDIInput extends EMIDIPort.EMIDIPort<'input'> {}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Thin wrapper around {@linkcode MIDIInput} instance giving access to the
|
|
19
|
+
* actual field storing it.
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
interface EMIDIInputImpl extends EMIDIPort.EMIDIPortImpl<MIDIInput, 'input'> {}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Validates the raw MIDI input port, and puts it into a field hidden from the
|
|
26
|
+
* client's code
|
|
27
|
+
*
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
const makeImpl = (rawInput: MIDIInput): EMIDIInputImpl =>
|
|
31
|
+
EMIDIPort.makeImpl(rawInput, 'input', globalThis.MIDIInput)
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Asserts an object to be valid EMIDIInput and casts it to internal
|
|
35
|
+
* implementation type
|
|
36
|
+
*
|
|
37
|
+
* @internal
|
|
38
|
+
*/
|
|
39
|
+
const assertImpl = (input: unknown) => {
|
|
40
|
+
if (!isImpl(input)) throw new Error('Failed to cast to EMIDIInputImpl')
|
|
41
|
+
return input
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Asserts an object to be valid EMIDIInput
|
|
46
|
+
*/
|
|
47
|
+
export const assert: (input: unknown) => EMIDIInput = assertImpl
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @internal
|
|
51
|
+
*/
|
|
52
|
+
const assumeImpl = (input: EMIDIInput) => input as EMIDIInputImpl
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
*
|
|
56
|
+
*
|
|
57
|
+
* @internal
|
|
58
|
+
*/
|
|
59
|
+
export const make: (rawInput: MIDIInput) => EMIDIInput = makeImpl
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
*
|
|
63
|
+
*
|
|
64
|
+
* @internal
|
|
65
|
+
*/
|
|
66
|
+
const isImpl: (input: unknown) => input is EMIDIInputImpl =
|
|
67
|
+
EMIDIPort.isImplOfSpecificType('input', globalThis.MIDIInput)
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
*
|
|
71
|
+
*
|
|
72
|
+
*/
|
|
73
|
+
export const is: (input: unknown) => input is EMIDIInput = isImpl
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* [MIDIMessageEvent MDN
|
|
77
|
+
* Reference](https://developer.mozilla.org/docs/Web/API/MIDIMessageEvent)
|
|
78
|
+
*
|
|
79
|
+
* MIDI spec says that synthetically built `MIDIMessageEvent`s can have `data`
|
|
80
|
+
* field equal to `null`, but when coming from the browser, they won't. The
|
|
81
|
+
* default behavior is to defect on `null`.
|
|
82
|
+
*/
|
|
83
|
+
export const makeMessagesStreamByPort =
|
|
84
|
+
StreamMaker.createStreamMakerFrom<MIDIInputEventMap>()(
|
|
85
|
+
is,
|
|
86
|
+
input => ({
|
|
87
|
+
tag: 'MIDIMessage',
|
|
88
|
+
eventListener: {
|
|
89
|
+
target: assumeImpl(input)._port,
|
|
90
|
+
type: 'midimessage',
|
|
91
|
+
},
|
|
92
|
+
spanAttributes: {
|
|
93
|
+
spanTargetName: 'MIDI port',
|
|
94
|
+
port: Util.getStaticMIDIPortInfo(input),
|
|
95
|
+
},
|
|
96
|
+
nullableFieldName: 'data',
|
|
97
|
+
}),
|
|
98
|
+
midiMessage => ({ midiMessage }),
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
*
|
|
103
|
+
*
|
|
104
|
+
*/
|
|
105
|
+
export type PolymorphicInput<E, R> = EMIDIPort.PolymorphicPort<E, R, 'input'>
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
*
|
|
109
|
+
*
|
|
110
|
+
*/
|
|
111
|
+
export type PolymorphicInputClean = EMIDIPort.PolymorphicPortClean<'input'>
|
|
112
|
+
|
|
113
|
+
export type Id = EMIDIPort.Id<'input'>
|
|
114
|
+
export const Id = Brand.nominal<Id>()
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
/** biome-ignore-all lint/style/useShorthandFunctionType: It's a nice way to
|
|
2
|
+
* preserve JSDoc comments attached to the function signature */
|
|
3
|
+
|
|
4
|
+
import * as Brand from 'effect/Brand'
|
|
5
|
+
import * as Effect from 'effect/Effect'
|
|
6
|
+
import * as EFunction from 'effect/Function'
|
|
7
|
+
import * as EMIDIPort from './EMIDIPort.ts'
|
|
8
|
+
import * as Errors from './errors.ts'
|
|
9
|
+
import * as Util from './util.ts'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Thin wrapper around {@linkcode MIDIOutput} instance. Will be seen in all
|
|
13
|
+
* external code.
|
|
14
|
+
*/
|
|
15
|
+
export interface EMIDIOutput extends EMIDIPort.EMIDIPort<'output'> {}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Thin wrapper around {@linkcode MIDIOutput} instance giving access to the
|
|
19
|
+
* actual field storing it.
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
interface EMIDIOutputImpl
|
|
23
|
+
extends EMIDIPort.EMIDIPortImpl<MIDIOutput, 'output'> {}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Validates the raw MIDI output port, and puts it into a field hidden from the
|
|
27
|
+
* client's code
|
|
28
|
+
*
|
|
29
|
+
* @internal
|
|
30
|
+
*/
|
|
31
|
+
const makeImpl = (rawOutput: MIDIOutput): EMIDIOutputImpl =>
|
|
32
|
+
EMIDIPort.makeImpl(rawOutput, 'output', globalThis.MIDIOutput)
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Asserts an object to be valid EMIDIOutput and casts it to
|
|
36
|
+
* internal implementation type
|
|
37
|
+
*
|
|
38
|
+
* @internal
|
|
39
|
+
*/
|
|
40
|
+
const assertImpl = (output: unknown) => {
|
|
41
|
+
if (!isImpl(output))
|
|
42
|
+
throw new Error('Assertion failed: Not a EMIDIOutputImpl')
|
|
43
|
+
return output
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Asserts an object to be valid EMIDIOutput
|
|
48
|
+
*/
|
|
49
|
+
export const assert: (output: unknown) => EMIDIOutput = assertImpl
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Casts
|
|
53
|
+
* @internal
|
|
54
|
+
*/
|
|
55
|
+
const assumeImpl = (output: EMIDIOutput) => output as EMIDIOutputImpl
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
*
|
|
59
|
+
* @internal
|
|
60
|
+
*/
|
|
61
|
+
export const make: (rawOutput: MIDIOutput) => EMIDIOutput = makeImpl
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
*
|
|
65
|
+
* @internal
|
|
66
|
+
*/
|
|
67
|
+
const isImpl = EMIDIPort.isImplOfSpecificType('output', globalThis.MIDIOutput)
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
*
|
|
71
|
+
*/
|
|
72
|
+
export const is: (output: unknown) => output is EMIDIOutput = isImpl
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
*
|
|
76
|
+
*
|
|
77
|
+
* @internal
|
|
78
|
+
*/
|
|
79
|
+
const resolve = <E = never, R = never>(
|
|
80
|
+
polymorphicPort: PolymorphicOutput<E, R>,
|
|
81
|
+
) => Util.fromPolymorphic(polymorphicPort, is)
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* If `midiMessage` is a System Exclusive message, and the `MIDIAccess` did not
|
|
85
|
+
* enable System Exclusive access, an `InvalidAccessError` exception will be
|
|
86
|
+
* thrown
|
|
87
|
+
*
|
|
88
|
+
* If the port is `"connected"` and the connection is `"closed"`, asynchronously
|
|
89
|
+
* tries to open the port. It's unclear in the spec if potential error of `open`
|
|
90
|
+
* call would result in an `InvalidAccessError` error coming from the `send`
|
|
91
|
+
* method itself.
|
|
92
|
+
*
|
|
93
|
+
* @returns An effect with the same port for easier chaining of operations
|
|
94
|
+
*/
|
|
95
|
+
export const send: DualSendMIDIMessageFromPort = EFunction.dual<
|
|
96
|
+
SendMIDIMessagePortLast,
|
|
97
|
+
SendMIDIMessagePortFirst
|
|
98
|
+
>(
|
|
99
|
+
Util.polymorphicCheckInDual(is),
|
|
100
|
+
Effect.fn('EMIDIOutput.send')(
|
|
101
|
+
function* (polymorphicOutput, midiMessage, timestamp) {
|
|
102
|
+
const output = yield* resolve(polymorphicOutput)
|
|
103
|
+
|
|
104
|
+
yield* Effect.annotateCurrentSpan({
|
|
105
|
+
midiMessage,
|
|
106
|
+
timestamp,
|
|
107
|
+
port: Util.getStaticMIDIPortInfo(output),
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
yield* Effect.try({
|
|
111
|
+
try: () => assumeImpl(output)._port.send(midiMessage, timestamp),
|
|
112
|
+
catch: Errors.remapErrorByName(
|
|
113
|
+
{
|
|
114
|
+
NotAllowedError: Errors.CantSendSysexMessagesError,
|
|
115
|
+
// InvalidAccessError is kept for compatibility reason
|
|
116
|
+
// (https://github.com/WebAudio/web-midi-api/pull/278):
|
|
117
|
+
InvalidAccessError: Errors.CantSendSysexMessagesError,
|
|
118
|
+
|
|
119
|
+
InvalidStateError: Errors.DisconnectedPortError,
|
|
120
|
+
TypeError: Errors.MalformedMidiMessageError,
|
|
121
|
+
},
|
|
122
|
+
'EMIDIOutput.send error handling absurd',
|
|
123
|
+
{ portId: output.id, midiMessage: [...midiMessage] },
|
|
124
|
+
),
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
return output as EMIDIOutput
|
|
128
|
+
},
|
|
129
|
+
),
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Clears any enqueued send data that has not yet been sent from the
|
|
134
|
+
* `MIDIOutput`'s queue. The browser will ensure the MIDI stream is left in a
|
|
135
|
+
* good state, and if the output port is in the middle of a sysex message, a
|
|
136
|
+
* sysex termination byte (`0xf7`) will be sent.
|
|
137
|
+
*
|
|
138
|
+
* @param polymorphicOutput An effectful output port
|
|
139
|
+
*
|
|
140
|
+
* @returns An effect with the same port for easier chaining of operations
|
|
141
|
+
* @experimental Supported only in Firefox. {@link https://caniuse.com/mdn-api_midioutput_clear|Can I use - MIDIOutput API: clear}
|
|
142
|
+
* @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}
|
|
143
|
+
*/
|
|
144
|
+
export const clear = Effect.fn('EMIDIOutput.clear')(function* <
|
|
145
|
+
E = never,
|
|
146
|
+
R = never,
|
|
147
|
+
>(polymorphicOutput: PolymorphicOutput<E, R>) {
|
|
148
|
+
const output = yield* resolve(polymorphicOutput)
|
|
149
|
+
|
|
150
|
+
yield* Effect.annotateCurrentSpan({
|
|
151
|
+
port: Util.getStaticMIDIPortInfo(output),
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
yield* Effect.try({
|
|
155
|
+
// @ts-expect-error even though `.clear` is in spec, the API is not
|
|
156
|
+
// supported in at least 2 major browsers, hence doesn't meet the condition
|
|
157
|
+
// to be included into TS's DOM types
|
|
158
|
+
try: () => assumeImpl(output)._port.clear(),
|
|
159
|
+
catch: Errors.remapErrorByName(
|
|
160
|
+
{
|
|
161
|
+
// TODO: test this
|
|
162
|
+
// most likely it would be something like `TypeError: Undefined is not a function`
|
|
163
|
+
TypeError: Errors.ClearingSendingQueueIsNotSupportedError,
|
|
164
|
+
NotSupportedError: Errors.ClearingSendingQueueIsNotSupportedError,
|
|
165
|
+
},
|
|
166
|
+
'EMIDIOutput.clear error handling absurd',
|
|
167
|
+
{ portId: output.id },
|
|
168
|
+
),
|
|
169
|
+
})
|
|
170
|
+
|
|
171
|
+
return output
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
*
|
|
176
|
+
*
|
|
177
|
+
*/
|
|
178
|
+
export type PolymorphicOutput<E, R> = EMIDIPort.PolymorphicPort<E, R, 'output'>
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
*
|
|
182
|
+
*
|
|
183
|
+
*/
|
|
184
|
+
export type PolymorphicOutputClean = EMIDIPort.PolymorphicPortClean<'output'>
|
|
185
|
+
|
|
186
|
+
export type SendFromPortArgs = [
|
|
187
|
+
midiMessage: Iterable<number>,
|
|
188
|
+
timestamp?: DOMHighResTimeStamp,
|
|
189
|
+
]
|
|
190
|
+
|
|
191
|
+
export interface DualSendMIDIMessageFromPort
|
|
192
|
+
extends SendMIDIMessagePortLast,
|
|
193
|
+
SendMIDIMessagePortFirst {}
|
|
194
|
+
|
|
195
|
+
export interface SendMIDIMessagePortLast {
|
|
196
|
+
/**
|
|
197
|
+
*
|
|
198
|
+
*/
|
|
199
|
+
(
|
|
200
|
+
...args: SendFromPortArgs
|
|
201
|
+
): {
|
|
202
|
+
/**
|
|
203
|
+
*
|
|
204
|
+
*/
|
|
205
|
+
<E = never, R = never>(
|
|
206
|
+
polymorphicOutput: PolymorphicOutput<E, R>,
|
|
207
|
+
): SentMessageEffectFromPort<E, R>
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export interface SendMIDIMessagePortFirst {
|
|
212
|
+
/**
|
|
213
|
+
*
|
|
214
|
+
*/
|
|
215
|
+
<E = never, R = never>(
|
|
216
|
+
polymorphicOutput: PolymorphicOutput<E, R>,
|
|
217
|
+
...args: SendFromPortArgs
|
|
218
|
+
): SentMessageEffectFromPort<E, R>
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
*
|
|
223
|
+
*/
|
|
224
|
+
export interface SentMessageEffectFromPort<E = never, R = never>
|
|
225
|
+
extends Util.SentMessageEffectFrom<EMIDIOutput, E, R> {}
|
|
226
|
+
|
|
227
|
+
export type Id = EMIDIPort.Id<'output'>
|
|
228
|
+
export const Id = Brand.nominal<Id>()
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
/** biome-ignore-all lint/style/useShorthandFunctionType: It's a nice way to
|
|
2
|
+
* preserve JSDoc comments attached to the function signature */
|
|
3
|
+
|
|
4
|
+
import * as Brand from 'effect/Brand'
|
|
5
|
+
import * as Equal from 'effect/Equal'
|
|
6
|
+
import * as Hash from 'effect/Hash'
|
|
7
|
+
import * as Inspectable from 'effect/Inspectable'
|
|
8
|
+
import * as Pipeable from 'effect/Pipeable'
|
|
9
|
+
import type * as Util from './util.ts'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Unique symbol used for distinguishing {@linkcode EMIDIPort} instances
|
|
13
|
+
* from other objects at both runtime and type-level
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
const TypeId: unique symbol = Symbol.for('effect-web-midi/EMIDIPort')
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Unique symbol used for distinguishing {@linkcode EMIDIPort} instances
|
|
20
|
+
* from other objects at both runtime and type-level
|
|
21
|
+
*/
|
|
22
|
+
export type TypeId = typeof TypeId
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Prototype of all {@linkcode EMIDIPort} instances
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
28
|
+
const CommonProto = {
|
|
29
|
+
_tag: 'EMIDIPort' as const,
|
|
30
|
+
|
|
31
|
+
[TypeId]: TypeId,
|
|
32
|
+
|
|
33
|
+
[Hash.symbol](this: EMIDIPortImpl) {
|
|
34
|
+
return Hash.string(this.id)
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
[Equal.symbol](this: EMIDIPortImpl, that: Equal.Equal) {
|
|
38
|
+
return 'id' in that && this.id === that.id
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
pipe() {
|
|
42
|
+
// biome-ignore lint/complexity/noArguments: Effect's tradition
|
|
43
|
+
return Pipeable.pipeArguments(this, arguments)
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
toString(this: EMIDIPortImpl) {
|
|
47
|
+
return Inspectable.format(this.toJSON())
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
toJSON(this: EMIDIPortImpl) {
|
|
51
|
+
return {
|
|
52
|
+
_id: 'EMIDIPort',
|
|
53
|
+
id: this.id,
|
|
54
|
+
name: this.name,
|
|
55
|
+
manufacturer: this.manufacturer,
|
|
56
|
+
version: this.version,
|
|
57
|
+
type: this.type,
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
[Inspectable.NodeInspectSymbol](this: EMIDIPortImpl) {
|
|
62
|
+
return this.toJSON()
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
get id() {
|
|
66
|
+
return BothId(assumeImpl(this)._port.id)
|
|
67
|
+
},
|
|
68
|
+
get name() {
|
|
69
|
+
return assumeImpl(this)._port.name
|
|
70
|
+
},
|
|
71
|
+
get manufacturer() {
|
|
72
|
+
return assumeImpl(this)._port.manufacturer
|
|
73
|
+
},
|
|
74
|
+
get version() {
|
|
75
|
+
return assumeImpl(this)._port.version
|
|
76
|
+
},
|
|
77
|
+
get type() {
|
|
78
|
+
return assumeImpl(this)._port.type
|
|
79
|
+
},
|
|
80
|
+
} satisfies EMIDIPort
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Thin wrapper around {@linkcode MIDIPort} instance. Will be seen in all
|
|
84
|
+
* external code.
|
|
85
|
+
*/
|
|
86
|
+
export interface EMIDIPort<TMIDIPortType extends MIDIPortType = MIDIPortType>
|
|
87
|
+
extends Equal.Equal,
|
|
88
|
+
Pipeable.Pipeable,
|
|
89
|
+
Inspectable.Inspectable,
|
|
90
|
+
Pick<MIDIPort, 'version' | 'name' | 'manufacturer'> {
|
|
91
|
+
/**
|
|
92
|
+
* The **`id`** read-only property of the MIDIPort interface returns the unique ID of the port.
|
|
93
|
+
*
|
|
94
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/MIDIPort/id)
|
|
95
|
+
*/
|
|
96
|
+
readonly id: Id<TMIDIPortType>
|
|
97
|
+
readonly [TypeId]: TypeId
|
|
98
|
+
readonly _tag: 'EMIDIPort'
|
|
99
|
+
readonly type: TMIDIPortType
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Thin wrapper around {@linkcode MIDIPort} instance giving access to the
|
|
104
|
+
* actual field storing it.
|
|
105
|
+
* @internal
|
|
106
|
+
*/
|
|
107
|
+
export interface EMIDIPortImpl<
|
|
108
|
+
TPort extends MIDIPort = MIDIPort,
|
|
109
|
+
TPortType extends MIDIPortType = MIDIPortType,
|
|
110
|
+
> extends EMIDIPort<TPortType> {
|
|
111
|
+
readonly _port: TPort
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
*
|
|
116
|
+
*
|
|
117
|
+
* @internal
|
|
118
|
+
*/
|
|
119
|
+
export const makeImpl = <
|
|
120
|
+
TPort extends MIDIPort,
|
|
121
|
+
TPortType extends MIDIPortType,
|
|
122
|
+
>(
|
|
123
|
+
port: NoInfer<TPort>,
|
|
124
|
+
type: TPortType,
|
|
125
|
+
ClassToAssertInheritance: new (...args: unknown[]) => TPort,
|
|
126
|
+
): EMIDIPortImpl<TPort, TPortType> => {
|
|
127
|
+
if (port.type !== type || !(port instanceof ClassToAssertInheritance))
|
|
128
|
+
throw new Error(`EMIDIPort constructor accepts only ${type} ports`)
|
|
129
|
+
|
|
130
|
+
const instance = Object.create(CommonProto)
|
|
131
|
+
instance._port = port
|
|
132
|
+
return instance
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Asserts an object to be valid EMIDIPort and casts it to internal
|
|
137
|
+
* implementation type
|
|
138
|
+
*
|
|
139
|
+
* @internal
|
|
140
|
+
*/
|
|
141
|
+
const assertImpl = (port: unknown) => {
|
|
142
|
+
if (!isGeneralImpl(port)) throw new Error('Failed to cast to EMIDIPort')
|
|
143
|
+
return port
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Asserts an object to be valid EMIDIPort
|
|
148
|
+
*/
|
|
149
|
+
export const assert: (port: unknown) => EMIDIPort = assertImpl
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* @internal
|
|
153
|
+
*/
|
|
154
|
+
export const assumeImpl = (port: EMIDIPort) => port as EMIDIPortImpl
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
*
|
|
158
|
+
*
|
|
159
|
+
* @internal
|
|
160
|
+
*/
|
|
161
|
+
const isGeneralImpl = (port: unknown): port is EMIDIPortImpl =>
|
|
162
|
+
typeof port === 'object' &&
|
|
163
|
+
port !== null &&
|
|
164
|
+
Object.getPrototypeOf(port) === CommonProto &&
|
|
165
|
+
TypeId in port &&
|
|
166
|
+
'type' in port &&
|
|
167
|
+
'_port' in port &&
|
|
168
|
+
typeof port._port === 'object' &&
|
|
169
|
+
port._port instanceof MIDIPort
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
*
|
|
173
|
+
*
|
|
174
|
+
*/
|
|
175
|
+
export type PolymorphicPort<
|
|
176
|
+
EPort,
|
|
177
|
+
RPort,
|
|
178
|
+
TMIDIPortType extends MIDIPortType = MIDIPortType,
|
|
179
|
+
> = Util.PolymorphicEffect<EMIDIPort<TMIDIPortType>, EPort, RPort>
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
*
|
|
183
|
+
*
|
|
184
|
+
*/
|
|
185
|
+
export type PolymorphicPortClean<
|
|
186
|
+
TMIDIPortType extends MIDIPortType = MIDIPortType,
|
|
187
|
+
> = Util.PolymorphicEffect<EMIDIPort<TMIDIPortType>, never, never>
|
|
188
|
+
|
|
189
|
+
export type ExtractTypeFromPort<TPort extends EMIDIPort> =
|
|
190
|
+
TPort extends EMIDIPort<infer TPortType> ? TPortType : never
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
*
|
|
194
|
+
*
|
|
195
|
+
* @internal
|
|
196
|
+
*/
|
|
197
|
+
export const isImplOfSpecificType =
|
|
198
|
+
<const TPortType extends MIDIPortType, TPort extends MIDIPort>(
|
|
199
|
+
type: TPortType,
|
|
200
|
+
ClassToAssertInheritance: new (...args: unknown[]) => TPort,
|
|
201
|
+
) =>
|
|
202
|
+
(port: unknown): port is EMIDIPortImpl<TPort, TPortType> => {
|
|
203
|
+
if (!ClassToAssertInheritance)
|
|
204
|
+
throw new Error(
|
|
205
|
+
'Called in a context where ClassToAssertInheritance is falsy, probably on a platform where MIDI APIs are not supported, like node.js or bun',
|
|
206
|
+
)
|
|
207
|
+
|
|
208
|
+
return (
|
|
209
|
+
isGeneralImpl(port) &&
|
|
210
|
+
port.type === type &&
|
|
211
|
+
port._port instanceof ClassToAssertInheritance
|
|
212
|
+
)
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
*
|
|
217
|
+
*
|
|
218
|
+
*/
|
|
219
|
+
export const is: (port: unknown) => port is EMIDIPort = isGeneralImpl
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Unique identifier of the MIDI port.
|
|
223
|
+
*
|
|
224
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/MIDIPort/id)
|
|
225
|
+
*/
|
|
226
|
+
export type Id<TPortType extends MIDIPortType> =
|
|
227
|
+
// for distribution
|
|
228
|
+
TPortType extends MIDIPortType
|
|
229
|
+
? string & Brand.Brand<'MIDIPortId'> & Brand.Brand<TPortType>
|
|
230
|
+
: never
|
|
231
|
+
|
|
232
|
+
export type BothId = Id<MIDIPortType>
|
|
233
|
+
export const BothId = Brand.nominal<BothId>()
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import * as Effect from 'effect/Effect'
|
|
2
|
+
import type * as Scope from 'effect/Scope'
|
|
3
|
+
import * as EMIDIInput from '../../EMIDIInput.ts'
|
|
4
|
+
import * as EMIDIOutput from '../../EMIDIOutput.ts'
|
|
5
|
+
import * as EMIDIPort from '../../EMIDIPort.ts'
|
|
6
|
+
import type { UnavailablePortError } from '../../errors.ts'
|
|
7
|
+
import * as C from '../closePortConnection/closePortConnectionByPort.ts'
|
|
8
|
+
import type { TouchPort } from '../makeMIDIPortMethodCallerFactory.ts'
|
|
9
|
+
import * as O from '../openPortConnection/openPortConnectionByPort.ts'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
const makeConnectionAcquirerReleaser =
|
|
15
|
+
<THighLevelPortType extends MIDIPortType>(
|
|
16
|
+
is: (port: unknown) => port is EMIDIPort.EMIDIPort<THighLevelPortType>,
|
|
17
|
+
): TouchPort<UnavailablePortError, Scope.Scope, THighLevelPortType> =>
|
|
18
|
+
/**
|
|
19
|
+
* @returns An effect with the same port for easier chaining of operations
|
|
20
|
+
*/
|
|
21
|
+
port =>
|
|
22
|
+
Effect.acquireRelease(
|
|
23
|
+
O.makePortConnectionOpener(is)(port),
|
|
24
|
+
C.makePortConnectionCloser(is),
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
*
|
|
29
|
+
*/
|
|
30
|
+
export const acquireReleasePortConnectionByPort =
|
|
31
|
+
makeConnectionAcquirerReleaser(EMIDIPort.is)
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
*
|
|
35
|
+
*/
|
|
36
|
+
export const acquireReleaseInputConnectionByPort =
|
|
37
|
+
makeConnectionAcquirerReleaser(EMIDIInput.is)
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
*
|
|
41
|
+
*/
|
|
42
|
+
export const acquireReleaseOutputConnectionByPort =
|
|
43
|
+
makeConnectionAcquirerReleaser(EMIDIOutput.is)
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// TODO: acquireReleasePortConnectionByPortIdAndAccess.ts
|
|
2
|
+
/** biome-ignore-all lint/style/useShorthandFunctionType: It's a nice way to
|
|
3
|
+
* preserve JSDoc comments attached to the function signature */
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
getInputByPortIdAndAccess,
|
|
7
|
+
getOutputByPortIdAndAccess,
|
|
8
|
+
getPortByPortIdAndAccess,
|
|
9
|
+
} from '../../getPortByPortId/getPortByPortIdAndAccess.ts'
|
|
10
|
+
import { actOnPort } from '../actOnPort.ts'
|
|
11
|
+
import {
|
|
12
|
+
acquireReleaseInputConnectionByPort,
|
|
13
|
+
acquireReleaseOutputConnectionByPort,
|
|
14
|
+
acquireReleasePortConnectionByPort,
|
|
15
|
+
} from './acquireReleasePortConnectionByPort.ts'
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
20
|
+
export const acquireReleasePortConnectionByPortIdAndAccess = actOnPort(
|
|
21
|
+
getPortByPortIdAndAccess,
|
|
22
|
+
acquireReleasePortConnectionByPort,
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
*
|
|
27
|
+
*/
|
|
28
|
+
export const acquireReleaseInputConnectionByPortIdAndAccess = actOnPort(
|
|
29
|
+
getInputByPortIdAndAccess,
|
|
30
|
+
acquireReleaseInputConnectionByPort,
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
*
|
|
35
|
+
*/
|
|
36
|
+
export const acquireReleaseOutputConnectionByPortIdAndAccess = actOnPort(
|
|
37
|
+
getOutputByPortIdAndAccess,
|
|
38
|
+
acquireReleaseOutputConnectionByPort,
|
|
39
|
+
)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { flow } from 'effect/Function'
|
|
2
|
+
import * as Get from '../../getPortByPortId/getPortByPortIdInContext.ts'
|
|
3
|
+
import * as Acquire from './acquireReleasePortConnectionByPort.ts'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
export const acquireReleasePortConnectionByPortIdInContext = flow(
|
|
9
|
+
Get.getPortByPortIdInContext,
|
|
10
|
+
Acquire.acquireReleasePortConnectionByPort,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
*
|
|
15
|
+
*/
|
|
16
|
+
export const acquireReleaseInputConnectionByPortIdInContext = flow(
|
|
17
|
+
Get.getInputByPortIdInContext,
|
|
18
|
+
Acquire.acquireReleaseInputConnectionByPort,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
*
|
|
23
|
+
*/
|
|
24
|
+
export const acquireReleaseOutputConnectionByPortIdInContext = flow(
|
|
25
|
+
Get.getOutputByPortIdInContext,
|
|
26
|
+
Acquire.acquireReleaseOutputConnectionByPort,
|
|
27
|
+
)
|