@opendaw/studio-core 0.0.25 → 0.0.26
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/dist/AudioDevices.js +4 -4
- package/dist/AudioOfflineRenderer.d.ts.map +1 -1
- package/dist/AudioOfflineRenderer.js +2 -2
- package/dist/capture/CaptureAudio.d.ts.map +1 -1
- package/dist/capture/CaptureAudio.js +3 -3
- package/dist/capture/CaptureMidi.d.ts.map +1 -1
- package/dist/capture/CaptureMidi.js +5 -4
- package/dist/capture/Recording.d.ts.map +1 -1
- package/dist/capture/Recording.js +3 -3
- package/dist/index.d.ts +12 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -11
- package/dist/midi/MIDILearning.d.ts +26 -0
- package/dist/midi/MIDILearning.d.ts.map +1 -0
- package/dist/midi/MIDILearning.js +88 -0
- package/dist/midi/MIDIMessageSubscriber.d.ts +5 -0
- package/dist/midi/MIDIMessageSubscriber.d.ts.map +1 -0
- package/dist/midi/MIDIMessageSubscriber.js +40 -0
- package/dist/midi/MidiDevices.d.ts.map +1 -0
- package/dist/{MidiDevices.js → midi/MidiDevices.js} +6 -5
- package/dist/processors.js +3 -3
- package/dist/processors.js.map +4 -4
- package/dist/project/Project.d.ts +7 -0
- package/dist/project/Project.d.ts.map +1 -1
- package/dist/project/Project.js +11 -0
- package/dist/project/ProjectBundle.d.ts +1 -1
- package/dist/project/ProjectBundle.d.ts.map +1 -1
- package/dist/project/ProjectBundle.js +9 -11
- package/dist/project/ProjectProfile.js +3 -3
- package/dist/workers.js +2 -2
- package/dist/workers.js.map +4 -4
- package/package.json +14 -14
- package/dist/MidiDevices.d.ts.map +0 -1
- /package/dist/{MidiDevices.d.ts → midi/MidiDevices.d.ts} +0 -0
package/dist/AudioDevices.js
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
import { Promises } from "@opendaw/lib-runtime";
|
2
|
-
import { Arrays,
|
2
|
+
import { Arrays, Errors } from "@opendaw/lib-std";
|
3
3
|
import { ConstrainDOM } from "@opendaw/lib-dom";
|
4
4
|
export class AudioDevices {
|
5
5
|
static async requestPermission() {
|
6
6
|
const { status, value: stream } = await Promises.tryCatch(navigator.mediaDevices.getUserMedia({ audio: true }));
|
7
7
|
if (status === "rejected") {
|
8
|
-
return warn("Could not request permission.");
|
8
|
+
return Errors.warn("Could not request permission.");
|
9
9
|
}
|
10
10
|
stream.getTracks().forEach(track => track.stop());
|
11
11
|
await this.updateInputList();
|
@@ -13,7 +13,7 @@ export class AudioDevices {
|
|
13
13
|
static async requestStream(constraints) {
|
14
14
|
const { status, value: stream, error } = await Promises.tryCatch(navigator.mediaDevices.getUserMedia({ audio: constraints }));
|
15
15
|
if (status === "rejected") {
|
16
|
-
return warn(
|
16
|
+
return Errors.warn(Errors.isOverconstrained(error) ?
|
17
17
|
error.constraint === "deviceId"
|
18
18
|
? `Could not find device with id: '${ConstrainDOM.resolveString(constraints.deviceId)}'`
|
19
19
|
: error.constraint
|
@@ -26,7 +26,7 @@ export class AudioDevices {
|
|
26
26
|
this.#inputs = Arrays.empty();
|
27
27
|
const { status, value: devices } = await Promises.tryCatch(navigator.mediaDevices.enumerateDevices());
|
28
28
|
if (status === "rejected") {
|
29
|
-
return warn("Could not enumerate devices.");
|
29
|
+
return Errors.warn("Could not enumerate devices.");
|
30
30
|
}
|
31
31
|
this.#inputs = devices.filter(device => device.kind === "audioinput" && device.deviceId !== "" && device.groupId !== "");
|
32
32
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"AudioOfflineRenderer.d.ts","sourceRoot":"","sources":["../src/AudioOfflineRenderer.ts"],"names":[],"mappings":"AAAA,OAAO,
|
1
|
+
{"version":3,"file":"AudioOfflineRenderer.d.ts","sourceRoot":"","sources":["../src/AudioOfflineRenderer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiC,GAAG,EAAE,MAAM,EAAmC,MAAM,kBAAkB,CAAA;AAI9G,OAAO,EAAC,wBAAwB,EAAC,MAAM,0BAA0B,CAAA;AACjE,OAAO,EAAC,OAAO,EAAC,MAAM,mBAAmB,CAAA;AACzC,OAAO,EAAC,WAAW,EAAC,MAAM,uBAAuB,CAAA;AAIjD,yBAAiB,oBAAoB,CAAC;IAC3B,MAAM,KAAK,GAAU,QAAQ,OAAO,EACf,MAAM,WAAW,EACjB,wBAAwB,MAAM,CAAC,wBAAwB,CAAC,EACxD,aAAY,GAAY,KAAG,OAAO,CAAC,IAAI,CA4BlE,CAAA;CA6CJ"}
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import { DefaultObservableValue, panic, RuntimeNotifier, TimeSpan } from "@opendaw/lib-std";
|
1
|
+
import { DefaultObservableValue, Errors, panic, RuntimeNotifier, TimeSpan } from "@opendaw/lib-std";
|
2
2
|
import { PPQN } from "@opendaw/lib-dsp";
|
3
|
-
import { AnimationFrame,
|
3
|
+
import { AnimationFrame, Files } from "@opendaw/lib-dom";
|
4
4
|
import { Promises, Wait } from "@opendaw/lib-runtime";
|
5
5
|
import { ExportStemsConfiguration } from "@opendaw/studio-adapters";
|
6
6
|
import { encodeWavFloat } from "./Wav";
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"CaptureAudio.d.ts","sourceRoot":"","sources":["../../src/capture/CaptureAudio.ts"],"names":[],"mappings":"AAAA,OAAO,EAKH,uBAAuB,EACvB,MAAM,EAEN,UAAU,
|
1
|
+
{"version":3,"file":"CaptureAudio.d.ts","sourceRoot":"","sources":["../../src/capture/CaptureAudio.ts"],"names":[],"mappings":"AAAA,OAAO,EAKH,uBAAuB,EACvB,MAAM,EAEN,UAAU,EACb,MAAM,kBAAkB,CAAA;AAEzB,OAAO,EAAC,YAAY,EAAE,eAAe,EAAC,MAAM,uBAAuB,CAAA;AACnE,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAA;AACjC,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAA;AAI/C,qBAAa,YAAa,SAAQ,OAAO,CAAC,eAAe,CAAC;;gBAQ1C,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,YAAY,EAAE,eAAe,EAAE,eAAe;IA4BjG,IAAI,MAAM,IAAI,MAAM,CAAsB;IAE1C,IAAI,MAAM,IAAI,uBAAuB,CAAC,WAAW,CAAC,CAAsB;IAExE,IAAI,cAAc,IAAI,MAAM,CAAC,MAAM,CAAC,CAEnC;IAED,IAAI,KAAK,IAAI,MAAM,CAAsE;IAEzF,IAAI,WAAW,IAAI,MAAM,CAAC,MAAM,CAAC,CAA+D;IAEhG,IAAI,gBAAgB,IAAI,MAAM,CAAC,gBAAgB,CAAC,CAE/C;IAEK,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC;IAiBvC,cAAc,IAAI,UAAU;CA+D/B"}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { Errors, isDefined, isUndefined, MutableObservableOption, Option, RuntimeNotifier, Terminable } from "@opendaw/lib-std";
|
2
2
|
import { Promises } from "@opendaw/lib-runtime";
|
3
3
|
import { Capture } from "./Capture";
|
4
4
|
import { RecordAudio } from "./RecordAudio";
|
@@ -50,7 +50,7 @@ export class CaptureAudio extends Capture {
|
|
50
50
|
cancelText: "Cancel"
|
51
51
|
});
|
52
52
|
if (!approved) {
|
53
|
-
return
|
53
|
+
return Promise.reject("Recording cancelled");
|
54
54
|
}
|
55
55
|
}
|
56
56
|
return this.#streamGenerator();
|
@@ -110,7 +110,7 @@ export class CaptureAudio extends Capture {
|
|
110
110
|
}
|
111
111
|
else {
|
112
112
|
stream.getAudioTracks().forEach(track => track.stop());
|
113
|
-
return warn(`Could not find audio device with id: '${deviceId} in ${gotDeviceId}'`);
|
113
|
+
return Errors.warn(`Could not find audio device with id: '${deviceId} in ${gotDeviceId}'`);
|
114
114
|
}
|
115
115
|
});
|
116
116
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"CaptureMidi.d.ts","sourceRoot":"","sources":["../../src/capture/CaptureMidi.ts"],"names":[],"mappings":"AAAA,OAAO,
|
1
|
+
{"version":3,"file":"CaptureMidi.d.ts","sourceRoot":"","sources":["../../src/capture/CaptureMidi.ts"],"names":[],"mappings":"AAAA,OAAO,EAQH,QAAQ,EACR,MAAM,EACN,YAAY,EACZ,UAAU,EACb,MAAM,kBAAkB,CAAA;AAIzB,OAAO,EAAC,YAAY,EAAE,cAAc,EAAC,MAAM,uBAAuB,CAAA;AAClE,OAAO,EAAC,UAAU,EAAC,MAAM,0BAA0B,CAAA;AAEnD,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAA;AACjC,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAA;AAI/C,qBAAa,WAAY,SAAQ,OAAO,CAAC,cAAc,CAAC;;gBAOxC,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,YAAY,EAAE,cAAc,EAAE,cAAc;IA8B/F,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;IAEhC,cAAc,CAAC,QAAQ,EAAE,QAAQ,CAAC,UAAU,CAAC,GAAG,YAAY;IAE5D,IAAI,KAAK,IAAI,MAAM,CAgBlB;IAED,IAAI,WAAW,IAAI,MAAM,CAAC,MAAM,CAAC,CAIhC;IAEK,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC;IAuBvC,cAAc,IAAI,UAAU;CAgD/B"}
|
@@ -1,11 +1,12 @@
|
|
1
|
-
import { assert, isDefined, isUndefined, Notifier, Option, Terminable
|
1
|
+
import { assert, Errors, isDefined, isUndefined, Notifier, Option, Terminable } from "@opendaw/lib-std";
|
2
2
|
import { Events } from "@opendaw/lib-dom";
|
3
3
|
import { MidiData } from "@opendaw/lib-midi";
|
4
4
|
import { Promises } from "@opendaw/lib-runtime";
|
5
5
|
import { NoteSignal } from "@opendaw/studio-adapters";
|
6
|
-
import { MidiDevices } from "../MidiDevices";
|
6
|
+
import { MidiDevices } from "../midi/MidiDevices";
|
7
7
|
import { Capture } from "./Capture";
|
8
8
|
import { RecordMidi } from "./RecordMidi";
|
9
|
+
var warn = Errors.warn;
|
9
10
|
export class CaptureMidi extends Capture {
|
10
11
|
#streamGenerator;
|
11
12
|
#notifier = new Notifier();
|
@@ -66,12 +67,12 @@ export class CaptureMidi extends Capture {
|
|
66
67
|
await MidiDevices.requestPermission();
|
67
68
|
}
|
68
69
|
else {
|
69
|
-
return warn("MIDI not available");
|
70
|
+
return Errors.warn("MIDI not available");
|
70
71
|
}
|
71
72
|
}
|
72
73
|
const optInputs = MidiDevices.inputs();
|
73
74
|
if (optInputs.isEmpty()) {
|
74
|
-
return warn("MIDI not available");
|
75
|
+
return Errors.warn("MIDI not available");
|
75
76
|
}
|
76
77
|
const inputs = optInputs.unwrap();
|
77
78
|
if (inputs.length === 0) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Recording.d.ts","sourceRoot":"","sources":["../../src/capture/Recording.ts"],"names":[],"mappings":"AAAA,OAAO,
|
1
|
+
{"version":3,"file":"Recording.d.ts","sourceRoot":"","sources":["../../src/capture/Recording.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuC,UAAU,EAAa,MAAM,kBAAkB,CAAA;AAK7F,OAAO,EAAC,OAAO,EAAC,MAAM,oBAAoB,CAAA;AAE1C,qBAAa,SAAS;;IAClB,MAAM,KAAK,WAAW,IAAI,OAAO,CAA2B;WAE/C,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC;IA8D3E,OAAO;CACV"}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { asInstanceOf, assert, Option, Terminable, Terminator
|
1
|
+
import { asInstanceOf, assert, Errors, Option, Terminable, Terminator } from "@opendaw/lib-std";
|
2
2
|
import { Promises } from "@opendaw/lib-runtime";
|
3
3
|
import { AudioUnitBox } from "@opendaw/studio-boxes";
|
4
4
|
import { AudioUnitType } from "@opendaw/studio-enums";
|
@@ -17,12 +17,12 @@ export class Recording {
|
|
17
17
|
const captures = captureDevices.filterArmed();
|
18
18
|
if (captures.length === 0) {
|
19
19
|
this.#isRecording = false;
|
20
|
-
return warn("No track is armed for Recording");
|
20
|
+
return Errors.warn("No track is armed for Recording");
|
21
21
|
}
|
22
22
|
const { status, error } = await Promises.tryCatch(Promise.all(captures.map(capture => capture.prepareRecording())));
|
23
23
|
if (status === "rejected") {
|
24
24
|
this.#isRecording = false;
|
25
|
-
return warn(String(error));
|
25
|
+
return Errors.warn(String(error));
|
26
26
|
}
|
27
27
|
terminator.ownAll(...captures.map(capture => capture.startRecording()));
|
28
28
|
engine.startRecording(countIn);
|
package/dist/index.d.ts
CHANGED
@@ -1,13 +1,3 @@
|
|
1
|
-
export * from "./sync-log/Commit";
|
2
|
-
export * from "./sync-log/SyncLogReader";
|
3
|
-
export * from "./sync-log/SyncLogWriter";
|
4
|
-
export * from "./samples/SampleStorage";
|
5
|
-
export * from "./samples/MainThreadSampleLoader";
|
6
|
-
export * from "./samples/MainThreadSampleManager";
|
7
|
-
export * from "./samples/OpenSampleAPI";
|
8
|
-
export * from "./samples/SampleAPI";
|
9
|
-
export * from "./samples/SampleImporter";
|
10
|
-
export * from "./samples/SampleProvider";
|
11
1
|
export * from "./capture/Capture";
|
12
2
|
export * from "./capture/CaptureAudio";
|
13
3
|
export * from "./capture/CaptureMidi";
|
@@ -17,6 +7,8 @@ export * from "./dawproject/DawProject";
|
|
17
7
|
export * from "./dawproject/DawProjectExporter";
|
18
8
|
export * from "./dawproject/DawProjectImport";
|
19
9
|
export * from "./dawproject/DawProjectImport";
|
10
|
+
export * from "./midi/MidiDevices";
|
11
|
+
export * from "./midi/MIDILearning";
|
20
12
|
export * from "./project/Project";
|
21
13
|
export * from "./project/ProjectApi";
|
22
14
|
export * from "./project/ProjectBundle";
|
@@ -24,6 +16,16 @@ export * from "./project/ProjectEnv";
|
|
24
16
|
export * from "./project/ProjectMeta";
|
25
17
|
export * from "./project/ProjectPaths";
|
26
18
|
export * from "./project/ProjectProfile";
|
19
|
+
export * from "./samples/SampleStorage";
|
20
|
+
export * from "./samples/MainThreadSampleLoader";
|
21
|
+
export * from "./samples/MainThreadSampleManager";
|
22
|
+
export * from "./samples/OpenSampleAPI";
|
23
|
+
export * from "./samples/SampleAPI";
|
24
|
+
export * from "./samples/SampleImporter";
|
25
|
+
export * from "./samples/SampleProvider";
|
26
|
+
export * from "./sync-log/Commit";
|
27
|
+
export * from "./sync-log/SyncLogReader";
|
28
|
+
export * from "./sync-log/SyncLogWriter";
|
27
29
|
export * from "./AudioDevices";
|
28
30
|
export * from "./AudioOfflineRenderer";
|
29
31
|
export * from "./AudioUnitOrdering";
|
@@ -42,7 +44,6 @@ export * from "./InstrumentFactory";
|
|
42
44
|
export * from "./InstrumentOptions";
|
43
45
|
export * from "./InstrumentProduct";
|
44
46
|
export * from "./MeterWorklet";
|
45
|
-
export * from "./MidiDevices";
|
46
47
|
export * from "./Mixer";
|
47
48
|
export * from "./PeaksWriter";
|
48
49
|
export * from "./RenderQuantum";
|
package/dist/index.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,0BAA0B,CAAA;AACxC,cAAc,
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,wBAAwB,CAAA;AACtC,cAAc,uBAAuB,CAAA;AACrC,cAAc,0BAA0B,CAAA;AACxC,cAAc,qBAAqB,CAAA;AAEnC,cAAc,yBAAyB,CAAA;AACvC,cAAc,iCAAiC,CAAA;AAC/C,cAAc,+BAA+B,CAAA;AAC7C,cAAc,+BAA+B,CAAA;AAE7C,cAAc,oBAAoB,CAAA;AAClC,cAAc,qBAAqB,CAAA;AAEnC,cAAc,mBAAmB,CAAA;AACjC,cAAc,sBAAsB,CAAA;AACpC,cAAc,yBAAyB,CAAA;AACvC,cAAc,sBAAsB,CAAA;AACpC,cAAc,uBAAuB,CAAA;AACrC,cAAc,wBAAwB,CAAA;AACtC,cAAc,0BAA0B,CAAA;AAExC,cAAc,yBAAyB,CAAA;AACvC,cAAc,kCAAkC,CAAA;AAChD,cAAc,mCAAmC,CAAA;AACjD,cAAc,yBAAyB,CAAA;AACvC,cAAc,qBAAqB,CAAA;AACnC,cAAc,0BAA0B,CAAA;AACxC,cAAc,0BAA0B,CAAA;AAExC,cAAc,mBAAmB,CAAA;AACjC,cAAc,0BAA0B,CAAA;AACxC,cAAc,0BAA0B,CAAA;AAExC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,wBAAwB,CAAA;AACtC,cAAc,qBAAqB,CAAA;AACnC,cAAc,cAAc,CAAA;AAC5B,cAAc,UAAU,CAAA;AACxB,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,mBAAmB,CAAA;AACjC,cAAc,UAAU,CAAA;AACxB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,yBAAyB,CAAA;AACvC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,uBAAuB,CAAA;AACrC,cAAc,qBAAqB,CAAA;AACnC,cAAc,qBAAqB,CAAA;AACnC,cAAc,qBAAqB,CAAA;AACnC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,SAAS,CAAA;AACvB,cAAc,eAAe,CAAA;AAC7B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,OAAO,CAAA;AACrB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,iBAAiB,CAAA"}
|
package/dist/index.js
CHANGED
@@ -1,13 +1,3 @@
|
|
1
|
-
export * from "./sync-log/Commit";
|
2
|
-
export * from "./sync-log/SyncLogReader";
|
3
|
-
export * from "./sync-log/SyncLogWriter";
|
4
|
-
export * from "./samples/SampleStorage";
|
5
|
-
export * from "./samples/MainThreadSampleLoader";
|
6
|
-
export * from "./samples/MainThreadSampleManager";
|
7
|
-
export * from "./samples/OpenSampleAPI";
|
8
|
-
export * from "./samples/SampleAPI";
|
9
|
-
export * from "./samples/SampleImporter";
|
10
|
-
export * from "./samples/SampleProvider";
|
11
1
|
export * from "./capture/Capture";
|
12
2
|
export * from "./capture/CaptureAudio";
|
13
3
|
export * from "./capture/CaptureMidi";
|
@@ -17,6 +7,8 @@ export * from "./dawproject/DawProject";
|
|
17
7
|
export * from "./dawproject/DawProjectExporter";
|
18
8
|
export * from "./dawproject/DawProjectImport";
|
19
9
|
export * from "./dawproject/DawProjectImport";
|
10
|
+
export * from "./midi/MidiDevices";
|
11
|
+
export * from "./midi/MIDILearning";
|
20
12
|
export * from "./project/Project";
|
21
13
|
export * from "./project/ProjectApi";
|
22
14
|
export * from "./project/ProjectBundle";
|
@@ -24,6 +16,16 @@ export * from "./project/ProjectEnv";
|
|
24
16
|
export * from "./project/ProjectMeta";
|
25
17
|
export * from "./project/ProjectPaths";
|
26
18
|
export * from "./project/ProjectProfile";
|
19
|
+
export * from "./samples/SampleStorage";
|
20
|
+
export * from "./samples/MainThreadSampleLoader";
|
21
|
+
export * from "./samples/MainThreadSampleManager";
|
22
|
+
export * from "./samples/OpenSampleAPI";
|
23
|
+
export * from "./samples/SampleAPI";
|
24
|
+
export * from "./samples/SampleImporter";
|
25
|
+
export * from "./samples/SampleProvider";
|
26
|
+
export * from "./sync-log/Commit";
|
27
|
+
export * from "./sync-log/SyncLogReader";
|
28
|
+
export * from "./sync-log/SyncLogWriter";
|
27
29
|
export * from "./AudioDevices";
|
28
30
|
export * from "./AudioOfflineRenderer";
|
29
31
|
export * from "./AudioUnitOrdering";
|
@@ -42,7 +44,6 @@ export * from "./InstrumentFactory";
|
|
42
44
|
export * from "./InstrumentOptions";
|
43
45
|
export * from "./InstrumentProduct";
|
44
46
|
export * from "./MeterWorklet";
|
45
|
-
export * from "./MidiDevices";
|
46
47
|
export * from "./Mixer";
|
47
48
|
export * from "./PeaksWriter";
|
48
49
|
export * from "./RenderQuantum";
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import { byte, JSONValue, Provider, Terminable } from "@opendaw/lib-std";
|
2
|
+
import { Address, AddressJSON, PrimitiveField, PrimitiveValues } from "@opendaw/lib-box";
|
3
|
+
import { Pointers } from "@opendaw/studio-enums";
|
4
|
+
import { Project } from "../project/Project";
|
5
|
+
export type MIDIConnectionJSON = ({
|
6
|
+
type: "control";
|
7
|
+
controlId: byte;
|
8
|
+
}) & {
|
9
|
+
address: AddressJSON;
|
10
|
+
channel: byte;
|
11
|
+
} & JSONValue;
|
12
|
+
export interface MIDIConnection extends Terminable {
|
13
|
+
address: Address;
|
14
|
+
label: Provider<string>;
|
15
|
+
toJSON(): MIDIConnectionJSON;
|
16
|
+
}
|
17
|
+
export declare class MIDILearning implements Terminable {
|
18
|
+
#private;
|
19
|
+
constructor(project: Project);
|
20
|
+
hasMidiConnection(address: Address): boolean;
|
21
|
+
forgetMidiConnection(address: Address): void;
|
22
|
+
learnMIDIControls(field: PrimitiveField<PrimitiveValues, Pointers.MidiControl | Pointers>): Promise<void>;
|
23
|
+
toJSON(): ReadonlyArray<MIDIConnectionJSON>;
|
24
|
+
terminate(): void;
|
25
|
+
}
|
26
|
+
//# sourceMappingURL=MIDILearning.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"MIDILearning.d.ts","sourceRoot":"","sources":["../../src/midi/MIDILearning.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,IAAI,EAGJ,SAAS,EAET,QAAQ,EAGR,UAAU,EAEb,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAC,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,eAAe,EAAC,MAAM,kBAAkB,CAAA;AAEtF,OAAO,EAAC,QAAQ,EAAC,MAAM,uBAAuB,CAAA;AAE9C,OAAO,EAAC,OAAO,EAAC,MAAM,oBAAoB,CAAA;AAG1C,MAAM,MAAM,kBAAkB,GAAG,CAAC;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,SAAS,EAAE,IAAI,CAAA;CAAE,CAAC,GACjE;IAAE,OAAO,EAAE,WAAW,CAAC;IAAC,OAAO,EAAE,IAAI,CAAA;CAAE,GACvC,SAAS,CAAA;AAEf,MAAM,WAAW,cAAe,SAAQ,UAAU;IAC9C,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAA;IACvB,MAAM,IAAI,kBAAkB,CAAA;CAC/B;AAID,qBAAa,YAAa,YAAW,UAAU;;gBAM/B,OAAO,EAAE,OAAO;IAK5B,iBAAiB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO;IAC5C,oBAAoB,CAAC,OAAO,EAAE,OAAO;IAE/B,iBAAiB,CAAC,KAAK,EAAE,cAAc,CAAC,eAAe,EAAE,QAAQ,CAAC,WAAW,GAAG,QAAQ,CAAC;IAsB/F,MAAM,IAAI,aAAa,CAAC,kBAAkB,CAAC;IAI3C,SAAS,IAAI,IAAI;CAgDpB"}
|
@@ -0,0 +1,88 @@
|
|
1
|
+
import { Errors, isDefined, RuntimeNotifier, Terminator } from "@opendaw/lib-std";
|
2
|
+
import { Address } from "@opendaw/lib-box";
|
3
|
+
import { MidiData } from "@opendaw/lib-midi";
|
4
|
+
import { MidiDevices } from "./MidiDevices";
|
5
|
+
export class MIDILearning {
|
6
|
+
#terminator = new Terminator();
|
7
|
+
#project;
|
8
|
+
#connections;
|
9
|
+
constructor(project) {
|
10
|
+
this.#project = project;
|
11
|
+
this.#connections = Address.newSet(connection => connection.address);
|
12
|
+
}
|
13
|
+
hasMidiConnection(address) { return this.#connections.hasKey(address); }
|
14
|
+
forgetMidiConnection(address) { this.#connections.removeByKey(address).terminate(); }
|
15
|
+
async learnMIDIControls(field) {
|
16
|
+
if (!MidiDevices.canRequestMidiAccess()) {
|
17
|
+
return;
|
18
|
+
}
|
19
|
+
await MidiDevices.requestPermission();
|
20
|
+
const learnLifecycle = this.#terminator.spawn();
|
21
|
+
const abortController = new AbortController();
|
22
|
+
learnLifecycle.own(MidiDevices.subscribeMessageEvents((event) => {
|
23
|
+
const data = event.data;
|
24
|
+
if (data === null) {
|
25
|
+
return;
|
26
|
+
}
|
27
|
+
if (MidiData.isController(data)) {
|
28
|
+
learnLifecycle.terminate();
|
29
|
+
abortController.abort(Errors.AbortError);
|
30
|
+
return this.#startListeningControl(field, MidiData.readChannel(data), MidiData.readParam1(data), event);
|
31
|
+
}
|
32
|
+
}));
|
33
|
+
return RuntimeNotifier.info({
|
34
|
+
headline: "Learn Midi Keys...",
|
35
|
+
message: "Hit a key on your midi-device to learn a connection.",
|
36
|
+
okText: "Cancel",
|
37
|
+
abortSignal: abortController.signal
|
38
|
+
}).then(() => learnLifecycle.terminate(), Errors.CatchAbort);
|
39
|
+
}
|
40
|
+
toJSON() {
|
41
|
+
return this.#connections.values().map(connection => connection.toJSON());
|
42
|
+
}
|
43
|
+
terminate() {
|
44
|
+
this.#killAllConnections();
|
45
|
+
this.#terminator.terminate();
|
46
|
+
}
|
47
|
+
#startListeningControl(field, channel, controlId, event) {
|
48
|
+
console.debug(`startListeningControl channel: ${channel}, controlId: ${controlId}`);
|
49
|
+
const { observer, terminate } = this.#createMidiControlObserver(this.#project, this.#project.parameterFieldAdapters.get(field.address), controlId);
|
50
|
+
if (isDefined(event)) {
|
51
|
+
observer(event);
|
52
|
+
}
|
53
|
+
const subscription = MidiDevices.subscribeMessageEvents(observer, channel);
|
54
|
+
this.#connections.add({
|
55
|
+
address: field.address,
|
56
|
+
toJSON: () => ({
|
57
|
+
type: "control",
|
58
|
+
address: field.address.toJSON(),
|
59
|
+
channel,
|
60
|
+
controlId
|
61
|
+
}),
|
62
|
+
label: () => this.#project.parameterFieldAdapters.get(field.address).name,
|
63
|
+
terminate: () => {
|
64
|
+
terminate();
|
65
|
+
subscription.terminate();
|
66
|
+
}
|
67
|
+
});
|
68
|
+
}
|
69
|
+
#killAllConnections() {
|
70
|
+
this.#connections.forEach(({ terminate }) => terminate());
|
71
|
+
this.#connections.clear();
|
72
|
+
}
|
73
|
+
#createMidiControlObserver(project, adapter, controlId) {
|
74
|
+
const registration = adapter.registerMidiControl();
|
75
|
+
return {
|
76
|
+
observer: (event) => {
|
77
|
+
const data = event.data;
|
78
|
+
if (data === null) {
|
79
|
+
return;
|
80
|
+
}
|
81
|
+
if (MidiData.isController(data) && MidiData.readParam1(data) === controlId) {
|
82
|
+
project.editing.modify(() => adapter.setValue(adapter.valueMapping.y(MidiData.asValue(data))), false);
|
83
|
+
}
|
84
|
+
},
|
85
|
+
terminate: () => registration.terminate()
|
86
|
+
};
|
87
|
+
}
|
88
|
+
}
|
@@ -0,0 +1,5 @@
|
|
1
|
+
import { byte, Observer, Subscription } from "@opendaw/lib-std";
|
2
|
+
export declare class MIDIMessageSubscriber {
|
3
|
+
static subscribeMessageEvents(access: MIDIAccess, observer: Observer<MIDIMessageEvent>, channel?: byte): Subscription;
|
4
|
+
}
|
5
|
+
//# sourceMappingURL=MIDIMessageSubscriber.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"MIDIMessageSubscriber.d.ts","sourceRoot":"","sources":["../../src/midi/MIDIMessageSubscriber.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAqC,QAAQ,EAAE,YAAY,EAAC,MAAM,kBAAkB,CAAA;AAIhG,qBAAa,qBAAqB;IAC9B,MAAM,CAAC,sBAAsB,CAAC,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,CAAC,gBAAgB,CAAC,EAAE,OAAO,CAAC,EAAE,IAAI,GAAG,YAAY;CA+BxH"}
|
@@ -0,0 +1,40 @@
|
|
1
|
+
import { isDefined, isInstanceOf } from "@opendaw/lib-std";
|
2
|
+
import { Events } from "@opendaw/lib-dom";
|
3
|
+
import { MidiData } from "@opendaw/lib-midi";
|
4
|
+
export class MIDIMessageSubscriber {
|
5
|
+
static subscribeMessageEvents(access, observer, channel) {
|
6
|
+
const listen = (input) => isDefined(channel)
|
7
|
+
? Events.subscribe(input, "midimessage", (event) => {
|
8
|
+
if (event.data === null || MidiData.readChannel(event.data) !== channel) {
|
9
|
+
return;
|
10
|
+
}
|
11
|
+
observer(event);
|
12
|
+
}) : Events.subscribe(input, "midimessage", observer);
|
13
|
+
const connections = Array.from(access.inputs.values())
|
14
|
+
.map(input => ([input, listen(input)]));
|
15
|
+
const stateSubscription = Events.subscribe(access, "statechange", (event) => {
|
16
|
+
const port = event.port;
|
17
|
+
if (!isInstanceOf(port, MIDIInput)) {
|
18
|
+
return;
|
19
|
+
}
|
20
|
+
for (const [input, subscription] of connections) {
|
21
|
+
if (input === port) {
|
22
|
+
// Well, this is strange, but if you start listening to a midi-input initially,
|
23
|
+
// it will change its state to 'connected', so we clean up the first old subscriptions.
|
24
|
+
subscription.terminate();
|
25
|
+
break;
|
26
|
+
}
|
27
|
+
}
|
28
|
+
if (port.state === "connected") {
|
29
|
+
connections.push([port, listen(port)]);
|
30
|
+
}
|
31
|
+
});
|
32
|
+
return {
|
33
|
+
terminate: () => {
|
34
|
+
stateSubscription.terminate();
|
35
|
+
connections.forEach(([_, subscription]) => subscription.terminate());
|
36
|
+
connections.length = 0;
|
37
|
+
}
|
38
|
+
};
|
39
|
+
}
|
40
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"MidiDevices.d.ts","sourceRoot":"","sources":["../../src/midi/MidiDevices.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,IAAI,EAIJ,sBAAsB,EAEtB,gBAAgB,EAEhB,QAAQ,EACR,MAAM,EACN,YAAY,EAEf,MAAM,kBAAkB,CAAA;AAKzB,qBAAa,WAAW;;IACpB,MAAM,CAAC,oBAAoB,IAAI,OAAO;WAIzB,iBAAiB;IAiB9B,MAAM,CAAC,GAAG,IAAI,gBAAgB,CAAC,UAAU,CAAC;IAE1C,MAAM,CAAC,sBAAsB,CAAC,QAAQ,EAAE,QAAQ,CAAC,gBAAgB,CAAC,EAAE,OAAO,CAAC,EAAE,IAAI,GAAG,YAAY;IAWjG,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;IAIjD,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;IAInD,MAAM,CAAC,KAAK,IAAI,IAAI;IAkBpB,MAAM,CAAC,SAAS,IAAI,sBAAsB,CAAC,OAAO,CAAC;CAqCtD"}
|
@@ -7,18 +7,19 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
7
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
9
9
|
};
|
10
|
-
import { Lazy, MutableObservableOption, MutableObservableValue, Notifier, Terminator
|
10
|
+
import { Errors, Lazy, MutableObservableOption, MutableObservableValue, Notifier, Terminator } from "@opendaw/lib-std";
|
11
11
|
import { MidiData } from "@opendaw/lib-midi";
|
12
12
|
import { Promises } from "@opendaw/lib-runtime";
|
13
|
-
import { MIDIMessageSubscriber } from "
|
13
|
+
import { MIDIMessageSubscriber } from "./MIDIMessageSubscriber";
|
14
14
|
export class MidiDevices {
|
15
15
|
static canRequestMidiAccess() { return "requestMIDIAccess" in navigator; }
|
16
|
+
static #memoizedRequest = Promises.memoizeAsync(() => navigator.requestMIDIAccess({ sysex: false }));
|
16
17
|
static async requestPermission() {
|
17
18
|
if (this.canRequestMidiAccess()) {
|
18
|
-
const { status, value: midiAccess, error } = await Promises.tryCatch(
|
19
|
+
const { status, value: midiAccess, error } = await Promises.tryCatch(this.#memoizedRequest());
|
19
20
|
if (status === "rejected") {
|
20
21
|
console.warn(error);
|
21
|
-
return warn("Could not request MIDI");
|
22
|
+
return Errors.warn("Could not request MIDI");
|
22
23
|
}
|
23
24
|
const numberOfInputs = midiAccess.inputs.size;
|
24
25
|
const numberOfOutputs = midiAccess.outputs.size;
|
@@ -26,7 +27,7 @@ export class MidiDevices {
|
|
26
27
|
this.#midiAccess.wrap(midiAccess);
|
27
28
|
}
|
28
29
|
else {
|
29
|
-
return warn("This browser does not support MIDI");
|
30
|
+
return Errors.warn("This browser does not support MIDI");
|
30
31
|
}
|
31
32
|
}
|
32
33
|
static get() { return this.#midiAccess; }
|