@grame/faustwasm 0.2.3 → 0.3.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/assets/standalone/faustwasm/index.d.ts +41 -0
- package/assets/standalone/faustwasm/index.js +538 -15
- package/assets/standalone/faustwasm/index.js.map +3 -3
- package/assets/standalone/index.js +17 -11
- package/dist/cjs/index.d.ts +41 -0
- package/dist/cjs/index.js +537 -15
- package/dist/cjs/index.js.map +3 -3
- package/dist/cjs-bundle/index.d.ts +41 -0
- package/dist/cjs-bundle/index.js +537 -15
- package/dist/cjs-bundle/index.js.map +3 -3
- package/dist/esm/index.d.ts +41 -0
- package/dist/esm/index.js +538 -15
- package/dist/esm/index.js.map +3 -3
- package/dist/esm-bundle/index.d.ts +41 -0
- package/dist/esm-bundle/index.js +537 -15
- package/dist/esm-bundle/index.js.map +3 -3
- package/package.json +1 -1
- package/src/FaustAudioWorkletNode.ts +73 -0
- package/src/FaustAudioWorkletProcessor.ts +33 -4
- package/src/FaustDspGenerator.ts +14 -2
- package/src/FaustOfflineProcessor.ts +10 -0
- package/src/FaustScriptProcessorNode.ts +61 -1
- package/src/FaustSensors.ts +370 -0
- package/src/FaustWebAudioDsp.ts +109 -10
- package/test/faustlive-wasm/faustwasm/index.d.ts +41 -0
- package/test/faustlive-wasm/faustwasm/index.js +538 -15
- package/test/faustlive-wasm/faustwasm/index.js.map +3 -3
- package/test/faustlive-wasm/index.js +2 -0
- package/test/osc.dsp +4 -2
- package/LIB.dsp +0 -1
package/dist/esm-bundle/index.js
CHANGED
|
@@ -30,6 +30,24 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
30
30
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
31
31
|
mod
|
|
32
32
|
));
|
|
33
|
+
var __accessCheck = (obj, member, msg) => {
|
|
34
|
+
if (!member.has(obj))
|
|
35
|
+
throw TypeError("Cannot " + msg);
|
|
36
|
+
};
|
|
37
|
+
var __privateGet = (obj, member, getter) => {
|
|
38
|
+
__accessCheck(obj, member, "read from private field");
|
|
39
|
+
return getter ? getter.call(obj) : member.get(obj);
|
|
40
|
+
};
|
|
41
|
+
var __privateAdd = (obj, member, value) => {
|
|
42
|
+
if (member.has(obj))
|
|
43
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
44
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
45
|
+
};
|
|
46
|
+
var __privateSet = (obj, member, value, setter) => {
|
|
47
|
+
__accessCheck(obj, member, "write to private field");
|
|
48
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
49
|
+
return value;
|
|
50
|
+
};
|
|
33
51
|
var __toBinary = /* @__PURE__ */ (() => {
|
|
34
52
|
var table = new Uint8Array(128);
|
|
35
53
|
for (var i = 0; i < 64; i++)
|
|
@@ -6121,18 +6139,30 @@ var getFaustAudioWorkletProcessor = (dependencies, faustData, register = true) =
|
|
|
6121
6139
|
handleMessageAux(e) {
|
|
6122
6140
|
const msg = e.data;
|
|
6123
6141
|
switch (msg.type) {
|
|
6124
|
-
case "
|
|
6142
|
+
case "acc": {
|
|
6143
|
+
this.propagateAcc(msg.data);
|
|
6144
|
+
break;
|
|
6145
|
+
}
|
|
6146
|
+
case "gyr": {
|
|
6147
|
+
this.propagateGyr(msg.data);
|
|
6148
|
+
break;
|
|
6149
|
+
}
|
|
6150
|
+
case "midi": {
|
|
6125
6151
|
this.midiMessage(msg.data);
|
|
6126
6152
|
break;
|
|
6127
|
-
|
|
6153
|
+
}
|
|
6154
|
+
case "ctrlChange": {
|
|
6128
6155
|
this.ctrlChange(msg.data[0], msg.data[1], msg.data[2]);
|
|
6129
6156
|
break;
|
|
6130
|
-
|
|
6157
|
+
}
|
|
6158
|
+
case "pitchWheel": {
|
|
6131
6159
|
this.pitchWheel(msg.data[0], msg.data[1]);
|
|
6132
6160
|
break;
|
|
6133
|
-
|
|
6161
|
+
}
|
|
6162
|
+
case "param": {
|
|
6134
6163
|
this.setParamValue(msg.data.path, msg.data.value);
|
|
6135
6164
|
break;
|
|
6165
|
+
}
|
|
6136
6166
|
case "setPlotHandler": {
|
|
6137
6167
|
if (msg.data) {
|
|
6138
6168
|
this.fDSPCode.setPlotHandler((output, index, events) => this.port.postMessage({ type: "plot", value: output, index, events }));
|
|
@@ -6171,6 +6201,12 @@ var getFaustAudioWorkletProcessor = (dependencies, faustData, register = true) =
|
|
|
6171
6201
|
pitchWheel(channel, wheel) {
|
|
6172
6202
|
this.fDSPCode.pitchWheel(channel, wheel);
|
|
6173
6203
|
}
|
|
6204
|
+
propagateAcc(accelerationIncludingGravity) {
|
|
6205
|
+
this.fDSPCode.propagateAcc(accelerationIncludingGravity);
|
|
6206
|
+
}
|
|
6207
|
+
propagateGyr(event) {
|
|
6208
|
+
this.fDSPCode.propagateGyr(event);
|
|
6209
|
+
}
|
|
6174
6210
|
}
|
|
6175
6211
|
class FaustMonoAudioWorkletProcessor extends FaustAudioWorkletProcessor {
|
|
6176
6212
|
constructor(options) {
|
|
@@ -7486,6 +7522,270 @@ var FaustWasmInstantiator = class {
|
|
|
7486
7522
|
};
|
|
7487
7523
|
var FaustWasmInstantiator_default = FaustWasmInstantiator;
|
|
7488
7524
|
|
|
7525
|
+
// src/FaustSensors.ts
|
|
7526
|
+
var FaustSensors = class _FaustSensors {
|
|
7527
|
+
/**
|
|
7528
|
+
* Function to convert a number to an axis type
|
|
7529
|
+
*
|
|
7530
|
+
* @param value number
|
|
7531
|
+
* @returns axis type
|
|
7532
|
+
*/
|
|
7533
|
+
static convertToAxis(value) {
|
|
7534
|
+
switch (value) {
|
|
7535
|
+
case 0:
|
|
7536
|
+
return 0 /* x */;
|
|
7537
|
+
case 1:
|
|
7538
|
+
return 1 /* y */;
|
|
7539
|
+
case 2:
|
|
7540
|
+
return 2 /* z */;
|
|
7541
|
+
default:
|
|
7542
|
+
console.error("Error: Axis not found value: " + value);
|
|
7543
|
+
return 0 /* x */;
|
|
7544
|
+
}
|
|
7545
|
+
}
|
|
7546
|
+
/**
|
|
7547
|
+
* Function to convert a number to a curve type
|
|
7548
|
+
*
|
|
7549
|
+
* @param value number
|
|
7550
|
+
* @returns curve type
|
|
7551
|
+
*/
|
|
7552
|
+
static convertToCurve(value) {
|
|
7553
|
+
switch (value) {
|
|
7554
|
+
case 0:
|
|
7555
|
+
return 0 /* Up */;
|
|
7556
|
+
case 1:
|
|
7557
|
+
return 1 /* Down */;
|
|
7558
|
+
case 2:
|
|
7559
|
+
return 2 /* UpDown */;
|
|
7560
|
+
case 3:
|
|
7561
|
+
return 3 /* DownUp */;
|
|
7562
|
+
default:
|
|
7563
|
+
console.error("Error: Curve not found value: " + value);
|
|
7564
|
+
return 0 /* Up */;
|
|
7565
|
+
}
|
|
7566
|
+
}
|
|
7567
|
+
static get Range() {
|
|
7568
|
+
if (!this._Range) {
|
|
7569
|
+
this._Range = class {
|
|
7570
|
+
constructor(x, y) {
|
|
7571
|
+
this.fLo = Math.min(x, y);
|
|
7572
|
+
this.fHi = Math.max(x, y);
|
|
7573
|
+
}
|
|
7574
|
+
clip(x) {
|
|
7575
|
+
if (x < this.fLo)
|
|
7576
|
+
return this.fLo;
|
|
7577
|
+
if (x > this.fHi)
|
|
7578
|
+
return this.fHi;
|
|
7579
|
+
return x;
|
|
7580
|
+
}
|
|
7581
|
+
};
|
|
7582
|
+
}
|
|
7583
|
+
return this._Range;
|
|
7584
|
+
}
|
|
7585
|
+
/**
|
|
7586
|
+
* Interpolator class
|
|
7587
|
+
*/
|
|
7588
|
+
static get Interpolator() {
|
|
7589
|
+
if (!this._Interpolator) {
|
|
7590
|
+
this._Interpolator = class {
|
|
7591
|
+
constructor(lo, hi, v1, v2) {
|
|
7592
|
+
this.fRange = new _FaustSensors.Range(lo, hi);
|
|
7593
|
+
if (hi !== lo) {
|
|
7594
|
+
this.fCoef = (v2 - v1) / (hi - lo);
|
|
7595
|
+
this.fOffset = v1 - lo * this.fCoef;
|
|
7596
|
+
} else {
|
|
7597
|
+
this.fCoef = 0;
|
|
7598
|
+
this.fOffset = (v1 + v2) / 2;
|
|
7599
|
+
}
|
|
7600
|
+
}
|
|
7601
|
+
returnMappedValue(v) {
|
|
7602
|
+
var x = this.fRange.clip(v);
|
|
7603
|
+
return this.fOffset + x * this.fCoef;
|
|
7604
|
+
}
|
|
7605
|
+
getLowHigh(amin, amax) {
|
|
7606
|
+
return { amin: this.fRange.fLo, amax: this.fRange.fHi };
|
|
7607
|
+
}
|
|
7608
|
+
};
|
|
7609
|
+
}
|
|
7610
|
+
return this._Interpolator;
|
|
7611
|
+
}
|
|
7612
|
+
/**
|
|
7613
|
+
* Interpolator3pt class, combine two interpolators
|
|
7614
|
+
*/
|
|
7615
|
+
static get Interpolator3pt() {
|
|
7616
|
+
if (!this._Interpolator3pt) {
|
|
7617
|
+
this._Interpolator3pt = class {
|
|
7618
|
+
constructor(lo, mid, hi, v1, vMid, v2) {
|
|
7619
|
+
this.fSegment1 = new _FaustSensors.Interpolator(lo, mid, v1, vMid);
|
|
7620
|
+
this.fSegment2 = new _FaustSensors.Interpolator(mid, hi, vMid, v2);
|
|
7621
|
+
this.fMid = mid;
|
|
7622
|
+
}
|
|
7623
|
+
returnMappedValue(x) {
|
|
7624
|
+
return x < this.fMid ? this.fSegment1.returnMappedValue(x) : this.fSegment2.returnMappedValue(x);
|
|
7625
|
+
}
|
|
7626
|
+
getMappingValues(amin, amid, amax) {
|
|
7627
|
+
var lowHighSegment1 = this.fSegment1.getLowHigh(amin, amid);
|
|
7628
|
+
var lowHighSegment2 = this.fSegment2.getLowHigh(amid, amax);
|
|
7629
|
+
return { amin: lowHighSegment1.amin, amid: lowHighSegment2.amin, amax: lowHighSegment2.amax };
|
|
7630
|
+
}
|
|
7631
|
+
};
|
|
7632
|
+
}
|
|
7633
|
+
return this._Interpolator3pt;
|
|
7634
|
+
}
|
|
7635
|
+
/**
|
|
7636
|
+
* UpConverter class, convert accelerometer value to Faust value
|
|
7637
|
+
*/
|
|
7638
|
+
static get UpConverter() {
|
|
7639
|
+
if (!this._UpConverter) {
|
|
7640
|
+
this._UpConverter = class {
|
|
7641
|
+
constructor(amin, amid, amax, fmin, fmid, fmax) {
|
|
7642
|
+
this.fActive = true;
|
|
7643
|
+
this.fA2F = new _FaustSensors.Interpolator3pt(amin, amid, amax, fmin, fmid, fmax);
|
|
7644
|
+
this.fF2A = new _FaustSensors.Interpolator3pt(fmin, fmid, fmax, amin, amid, amax);
|
|
7645
|
+
}
|
|
7646
|
+
uiToFaust(x) {
|
|
7647
|
+
return this.fA2F.returnMappedValue(x);
|
|
7648
|
+
}
|
|
7649
|
+
faustToUi(x) {
|
|
7650
|
+
return this.fF2A.returnMappedValue(x);
|
|
7651
|
+
}
|
|
7652
|
+
setMappingValues(amin, amid, amax, min, init, max) {
|
|
7653
|
+
this.fA2F = new _FaustSensors.Interpolator3pt(amin, amid, amax, min, init, max);
|
|
7654
|
+
this.fF2A = new _FaustSensors.Interpolator3pt(min, init, max, amin, amid, amax);
|
|
7655
|
+
}
|
|
7656
|
+
getMappingValues(amin, amid, amax) {
|
|
7657
|
+
return this.fA2F.getMappingValues(amin, amid, amax);
|
|
7658
|
+
}
|
|
7659
|
+
setActive(onOff) {
|
|
7660
|
+
this.fActive = onOff;
|
|
7661
|
+
}
|
|
7662
|
+
getActive() {
|
|
7663
|
+
return this.fActive;
|
|
7664
|
+
}
|
|
7665
|
+
};
|
|
7666
|
+
}
|
|
7667
|
+
return this._UpConverter;
|
|
7668
|
+
}
|
|
7669
|
+
/**
|
|
7670
|
+
* DownConverter class, convert accelerometer value to Faust value
|
|
7671
|
+
*/
|
|
7672
|
+
static get DownConverter() {
|
|
7673
|
+
if (!this._DownConverter) {
|
|
7674
|
+
this._DownConverter = class {
|
|
7675
|
+
constructor(amin, amid, amax, fmin, fmid, fmax) {
|
|
7676
|
+
this.fActive = true;
|
|
7677
|
+
this.fA2F = new _FaustSensors.Interpolator3pt(amin, amid, amax, fmax, fmid, fmin);
|
|
7678
|
+
this.fF2A = new _FaustSensors.Interpolator3pt(fmin, fmid, fmax, amax, amid, amin);
|
|
7679
|
+
}
|
|
7680
|
+
uiToFaust(x) {
|
|
7681
|
+
return this.fA2F.returnMappedValue(x);
|
|
7682
|
+
}
|
|
7683
|
+
faustToUi(x) {
|
|
7684
|
+
return this.fF2A.returnMappedValue(x);
|
|
7685
|
+
}
|
|
7686
|
+
setMappingValues(amin, amid, amax, min, init, max) {
|
|
7687
|
+
this.fA2F = new _FaustSensors.Interpolator3pt(amin, amid, amax, max, init, min);
|
|
7688
|
+
this.fF2A = new _FaustSensors.Interpolator3pt(min, init, max, amax, amid, amin);
|
|
7689
|
+
}
|
|
7690
|
+
getMappingValues(amin, amid, amax) {
|
|
7691
|
+
return this.fA2F.getMappingValues(amin, amid, amax);
|
|
7692
|
+
}
|
|
7693
|
+
setActive(onOff) {
|
|
7694
|
+
this.fActive = onOff;
|
|
7695
|
+
}
|
|
7696
|
+
getActive() {
|
|
7697
|
+
return this.fActive;
|
|
7698
|
+
}
|
|
7699
|
+
};
|
|
7700
|
+
}
|
|
7701
|
+
return this._DownConverter;
|
|
7702
|
+
}
|
|
7703
|
+
/**
|
|
7704
|
+
* UpDownConverter class, convert accelerometer value to Faust value
|
|
7705
|
+
*/
|
|
7706
|
+
static get UpDownConverter() {
|
|
7707
|
+
if (!this._UpDownConverter) {
|
|
7708
|
+
this._UpDownConverter = class {
|
|
7709
|
+
constructor(amin, amid, amax, fmin, fmid, fmax) {
|
|
7710
|
+
this.fActive = true;
|
|
7711
|
+
this.fA2F = new _FaustSensors.Interpolator3pt(amin, amid, amax, fmin, fmax, fmin);
|
|
7712
|
+
this.fF2A = new _FaustSensors.Interpolator(fmin, fmax, amin, amax);
|
|
7713
|
+
}
|
|
7714
|
+
uiToFaust(x) {
|
|
7715
|
+
return this.fA2F.returnMappedValue(x);
|
|
7716
|
+
}
|
|
7717
|
+
faustToUi(x) {
|
|
7718
|
+
return this.fF2A.returnMappedValue(x);
|
|
7719
|
+
}
|
|
7720
|
+
setMappingValues(amin, amid, amax, min, init, max) {
|
|
7721
|
+
this.fA2F = new _FaustSensors.Interpolator3pt(amin, amid, amax, min, max, min);
|
|
7722
|
+
this.fF2A = new _FaustSensors.Interpolator(min, max, amin, amax);
|
|
7723
|
+
}
|
|
7724
|
+
getMappingValues(amin, amid, amax) {
|
|
7725
|
+
return this.fA2F.getMappingValues(amin, amid, amax);
|
|
7726
|
+
}
|
|
7727
|
+
setActive(onOff) {
|
|
7728
|
+
this.fActive = onOff;
|
|
7729
|
+
}
|
|
7730
|
+
getActive() {
|
|
7731
|
+
return this.fActive;
|
|
7732
|
+
}
|
|
7733
|
+
};
|
|
7734
|
+
}
|
|
7735
|
+
return this._UpDownConverter;
|
|
7736
|
+
}
|
|
7737
|
+
static get DownUpConverter() {
|
|
7738
|
+
if (!this._DownUpConverter) {
|
|
7739
|
+
this._DownUpConverter = class {
|
|
7740
|
+
constructor(amin, amid, amax, fmin, fmid, fmax) {
|
|
7741
|
+
this.fActive = true;
|
|
7742
|
+
this.fA2F = new _FaustSensors.Interpolator3pt(amin, amid, amax, fmax, fmin, fmax);
|
|
7743
|
+
this.fF2A = new _FaustSensors.Interpolator(fmin, fmax, amin, amax);
|
|
7744
|
+
}
|
|
7745
|
+
uiToFaust(x) {
|
|
7746
|
+
return this.fA2F.returnMappedValue(x);
|
|
7747
|
+
}
|
|
7748
|
+
faustToUi(x) {
|
|
7749
|
+
return this.fF2A.returnMappedValue(x);
|
|
7750
|
+
}
|
|
7751
|
+
setMappingValues(amin, amid, amax, min, init, max) {
|
|
7752
|
+
this.fA2F = new _FaustSensors.Interpolator3pt(amin, amid, amax, max, min, max);
|
|
7753
|
+
this.fF2A = new _FaustSensors.Interpolator(min, max, amin, amax);
|
|
7754
|
+
}
|
|
7755
|
+
getMappingValues(amin, amid, amax) {
|
|
7756
|
+
return this.fA2F.getMappingValues(amin, amid, amax);
|
|
7757
|
+
}
|
|
7758
|
+
setActive(onOff) {
|
|
7759
|
+
this.fActive = onOff;
|
|
7760
|
+
}
|
|
7761
|
+
getActive() {
|
|
7762
|
+
return this.fActive;
|
|
7763
|
+
}
|
|
7764
|
+
};
|
|
7765
|
+
}
|
|
7766
|
+
return this._DownUpConverter;
|
|
7767
|
+
}
|
|
7768
|
+
/**
|
|
7769
|
+
* Public function to build the accelerometer handler
|
|
7770
|
+
*
|
|
7771
|
+
* @returns `UpdatableValueConverter` built for the given curve
|
|
7772
|
+
*/
|
|
7773
|
+
static buildHandler(curve, amin, amid, amax, min, init, max) {
|
|
7774
|
+
switch (curve) {
|
|
7775
|
+
case 0 /* Up */:
|
|
7776
|
+
return new _FaustSensors.UpConverter(amin, amid, amax, min, init, max);
|
|
7777
|
+
case 1 /* Down */:
|
|
7778
|
+
return new _FaustSensors.DownConverter(amin, amid, amax, min, init, max);
|
|
7779
|
+
case 2 /* UpDown */:
|
|
7780
|
+
return new _FaustSensors.UpDownConverter(amin, amid, amax, min, init, max);
|
|
7781
|
+
case 3 /* DownUp */:
|
|
7782
|
+
return new _FaustSensors.DownUpConverter(amin, amid, amax, min, init, max);
|
|
7783
|
+
default:
|
|
7784
|
+
return new _FaustSensors.UpConverter(amin, amid, amax, min, init, max);
|
|
7785
|
+
}
|
|
7786
|
+
}
|
|
7787
|
+
};
|
|
7788
|
+
|
|
7489
7789
|
// src/FaustWebAudioDsp.ts
|
|
7490
7790
|
var WasmAllocator = class {
|
|
7491
7791
|
constructor(memory, offset) {
|
|
@@ -7738,17 +8038,25 @@ var FaustBaseWebAudioDsp = class _FaustBaseWebAudioDsp {
|
|
|
7738
8038
|
if (!item.meta)
|
|
7739
8039
|
return;
|
|
7740
8040
|
item.meta.forEach((meta) => {
|
|
7741
|
-
const { midi } = meta;
|
|
7742
|
-
if (
|
|
7743
|
-
|
|
7744
|
-
|
|
7745
|
-
|
|
7746
|
-
|
|
7747
|
-
|
|
7748
|
-
|
|
7749
|
-
|
|
7750
|
-
|
|
7751
|
-
|
|
8041
|
+
const { midi, acc, gyr } = meta;
|
|
8042
|
+
if (midi) {
|
|
8043
|
+
const strMidi = midi.trim();
|
|
8044
|
+
if (strMidi === "pitchwheel") {
|
|
8045
|
+
this.fPitchwheelLabel.push({ path: item.address, min: item.min, max: item.max });
|
|
8046
|
+
} else {
|
|
8047
|
+
const matched = strMidi.match(/^ctrl\s(\d+)/);
|
|
8048
|
+
if (matched) {
|
|
8049
|
+
this.fCtrlLabel[parseInt(matched[1])].push({ path: item.address, min: item.min, max: item.max });
|
|
8050
|
+
}
|
|
8051
|
+
}
|
|
8052
|
+
}
|
|
8053
|
+
if (acc) {
|
|
8054
|
+
const numAcc = acc.trim().split(" ").map(Number);
|
|
8055
|
+
this.setupAccHandler(item.address, FaustSensors.convertToAxis(numAcc[0]), FaustSensors.convertToCurve(numAcc[1]), numAcc[2], numAcc[3], numAcc[4], item.min, item.init, item.max);
|
|
8056
|
+
}
|
|
8057
|
+
if (gyr) {
|
|
8058
|
+
const numAcc = gyr.trim().split(" ").map(Number);
|
|
8059
|
+
this.setupGyrHandler(item.address, FaustSensors.convertToAxis(numAcc[0]), FaustSensors.convertToCurve(numAcc[1]), numAcc[2], numAcc[3], numAcc[4], item.min, item.init, item.max);
|
|
7752
8060
|
}
|
|
7753
8061
|
});
|
|
7754
8062
|
} else if (item.type === "soundfile") {
|
|
@@ -7763,6 +8071,8 @@ var FaustBaseWebAudioDsp = class _FaustBaseWebAudioDsp {
|
|
|
7763
8071
|
this.fPtrSize = sampleSize;
|
|
7764
8072
|
this.fSampleSize = sampleSize;
|
|
7765
8073
|
this.fSoundfileBuffers = soundfiles;
|
|
8074
|
+
this.fAcc = { x: [], y: [], z: [] };
|
|
8075
|
+
this.fGyr = { x: [], y: [], z: [] };
|
|
7766
8076
|
}
|
|
7767
8077
|
// Tools
|
|
7768
8078
|
static remap(v, mn0, mx0, mn1, mx1) {
|
|
@@ -7792,6 +8102,60 @@ var FaustBaseWebAudioDsp = class _FaustBaseWebAudioDsp {
|
|
|
7792
8102
|
let trimmed = input.replace(/^\{|\}$/g, "");
|
|
7793
8103
|
return trimmed.split(";").map((str) => str.length <= 2 ? "" : str.substring(1, str.length - 1));
|
|
7794
8104
|
}
|
|
8105
|
+
get hasAccInput() {
|
|
8106
|
+
return this.fAcc.x.length + this.fAcc.y.length + this.fAcc.z.length > 0;
|
|
8107
|
+
}
|
|
8108
|
+
propagateAcc(accelerationIncludingGravity) {
|
|
8109
|
+
const { x, y, z } = accelerationIncludingGravity;
|
|
8110
|
+
if (x !== null)
|
|
8111
|
+
this.fAcc.x.forEach((handler) => handler(x));
|
|
8112
|
+
if (y !== null)
|
|
8113
|
+
this.fAcc.y.forEach((handler) => handler(y));
|
|
8114
|
+
if (z !== null)
|
|
8115
|
+
this.fAcc.z.forEach((handler) => handler(z));
|
|
8116
|
+
}
|
|
8117
|
+
get hasGyrInput() {
|
|
8118
|
+
return this.fGyr.x.length + this.fGyr.y.length + this.fGyr.z.length > 0;
|
|
8119
|
+
}
|
|
8120
|
+
propagateGyr(event) {
|
|
8121
|
+
const { alpha, beta, gamma } = event;
|
|
8122
|
+
if (alpha !== null)
|
|
8123
|
+
this.fGyr.x.forEach((handler) => handler(alpha));
|
|
8124
|
+
if (beta !== null)
|
|
8125
|
+
this.fGyr.y.forEach((handler) => handler(beta));
|
|
8126
|
+
if (gamma !== null)
|
|
8127
|
+
this.fGyr.z.forEach((handler) => handler(gamma));
|
|
8128
|
+
}
|
|
8129
|
+
/** Build the accelerometer handler */
|
|
8130
|
+
setupAccHandler(path, axis, curve, amin, amid, amax, min, init, max) {
|
|
8131
|
+
const handler = FaustSensors.buildHandler(curve, amin, amid, amax, min, init, max);
|
|
8132
|
+
switch (axis) {
|
|
8133
|
+
case 0 /* x */:
|
|
8134
|
+
this.fAcc.x.push((val) => this.setParamValue(path, handler.uiToFaust(val)));
|
|
8135
|
+
break;
|
|
8136
|
+
case 1 /* y */:
|
|
8137
|
+
this.fAcc.y.push((val) => this.setParamValue(path, handler.uiToFaust(val)));
|
|
8138
|
+
break;
|
|
8139
|
+
case 2 /* z */:
|
|
8140
|
+
this.fAcc.z.push((val) => this.setParamValue(path, handler.uiToFaust(val)));
|
|
8141
|
+
break;
|
|
8142
|
+
}
|
|
8143
|
+
}
|
|
8144
|
+
/** Build the gyroscope handler */
|
|
8145
|
+
setupGyrHandler(path, axis, curve, amin, amid, amax, min, init, max) {
|
|
8146
|
+
const handler = FaustSensors.buildHandler(curve, amin, amid, amax, min, init, max);
|
|
8147
|
+
switch (axis) {
|
|
8148
|
+
case 0 /* x */:
|
|
8149
|
+
this.fGyr.x.push((val) => this.setParamValue(path, handler.uiToFaust(val)));
|
|
8150
|
+
break;
|
|
8151
|
+
case 1 /* y */:
|
|
8152
|
+
this.fGyr.y.push((val) => this.setParamValue(path, handler.uiToFaust(val)));
|
|
8153
|
+
break;
|
|
8154
|
+
case 2 /* z */:
|
|
8155
|
+
this.fGyr.z.push((val) => this.setParamValue(path, handler.uiToFaust(val)));
|
|
8156
|
+
break;
|
|
8157
|
+
}
|
|
8158
|
+
}
|
|
7795
8159
|
static extractUrlsFromMeta(dspMeta) {
|
|
7796
8160
|
const soundfilesEntry = dspMeta.meta.find((entry) => entry.soundfiles !== void 0);
|
|
7797
8161
|
if (soundfilesEntry) {
|
|
@@ -8605,6 +8969,18 @@ var FaustOfflineProcessor = class {
|
|
|
8605
8969
|
destroy() {
|
|
8606
8970
|
this.fDSPCode.destroy();
|
|
8607
8971
|
}
|
|
8972
|
+
get hasAccInput() {
|
|
8973
|
+
return this.fDSPCode.hasAccInput;
|
|
8974
|
+
}
|
|
8975
|
+
propagateAcc(accelerationIncludingGravity) {
|
|
8976
|
+
this.fDSPCode.propagateAcc(accelerationIncludingGravity);
|
|
8977
|
+
}
|
|
8978
|
+
get hasGyrInput() {
|
|
8979
|
+
return this.fDSPCode.hasGyrInput;
|
|
8980
|
+
}
|
|
8981
|
+
propagateGyr(event) {
|
|
8982
|
+
this.fDSPCode.propagateGyr(event);
|
|
8983
|
+
}
|
|
8608
8984
|
/**
|
|
8609
8985
|
* Render frames in an array.
|
|
8610
8986
|
*
|
|
@@ -9224,6 +9600,7 @@ var SoundfileReader = class {
|
|
|
9224
9600
|
var SoundfileReader_default = SoundfileReader;
|
|
9225
9601
|
|
|
9226
9602
|
// src/FaustAudioWorkletNode.ts
|
|
9603
|
+
var _hasAccInput, _hasGyrInput;
|
|
9227
9604
|
var FaustAudioWorkletNode = class extends (globalThis.AudioWorkletNode || null) {
|
|
9228
9605
|
constructor(context, name, factory, options, nodeOptions = {}) {
|
|
9229
9606
|
const JSONObj = JSON.parse(factory.json);
|
|
@@ -9237,6 +9614,8 @@ var FaustAudioWorkletNode = class extends (globalThis.AudioWorkletNode || null)
|
|
|
9237
9614
|
processorOptions: options,
|
|
9238
9615
|
...nodeOptions
|
|
9239
9616
|
});
|
|
9617
|
+
__privateAdd(this, _hasAccInput, false);
|
|
9618
|
+
__privateAdd(this, _hasGyrInput, false);
|
|
9240
9619
|
this.fJSONDsp = JSONObj;
|
|
9241
9620
|
this.fJSON = factory.json;
|
|
9242
9621
|
this.fOutputHandler = null;
|
|
@@ -9248,6 +9627,15 @@ var FaustAudioWorkletNode = class extends (globalThis.AudioWorkletNode || null)
|
|
|
9248
9627
|
if (item.type === "vslider" || item.type === "hslider" || item.type === "button" || item.type === "checkbox" || item.type === "nentry") {
|
|
9249
9628
|
this.fInputsItems.push(item.address);
|
|
9250
9629
|
this.fDescriptor.push(item);
|
|
9630
|
+
if (!item.meta)
|
|
9631
|
+
return;
|
|
9632
|
+
item.meta.forEach((meta) => {
|
|
9633
|
+
const { midi, acc, gyr } = meta;
|
|
9634
|
+
if (acc)
|
|
9635
|
+
__privateSet(this, _hasAccInput, true);
|
|
9636
|
+
if (gyr)
|
|
9637
|
+
__privateSet(this, _hasGyrInput, true);
|
|
9638
|
+
});
|
|
9251
9639
|
}
|
|
9252
9640
|
};
|
|
9253
9641
|
FaustBaseWebAudioDsp.parseUI(this.fJSONDsp.ui, this.fUICallback);
|
|
@@ -9260,6 +9648,54 @@ var FaustAudioWorkletNode = class extends (globalThis.AudioWorkletNode || null)
|
|
|
9260
9648
|
};
|
|
9261
9649
|
}
|
|
9262
9650
|
// Public API
|
|
9651
|
+
/** Setup accelerometer and gyroscope handlers */
|
|
9652
|
+
async listenMotion() {
|
|
9653
|
+
if (this.hasAccInput) {
|
|
9654
|
+
const handleDeviceMotion = ({ accelerationIncludingGravity }) => {
|
|
9655
|
+
if (!accelerationIncludingGravity)
|
|
9656
|
+
return;
|
|
9657
|
+
const { x, y, z } = accelerationIncludingGravity;
|
|
9658
|
+
this.propagateAcc({ x, y, z });
|
|
9659
|
+
};
|
|
9660
|
+
if (window.DeviceMotionEvent) {
|
|
9661
|
+
if (typeof window.DeviceMotionEvent.requestPermission === "function") {
|
|
9662
|
+
try {
|
|
9663
|
+
const response = await window.DeviceMotionEvent.requestPermission();
|
|
9664
|
+
if (response !== "granted")
|
|
9665
|
+
throw new Error("Unable to access the accelerometer.");
|
|
9666
|
+
window.addEventListener("devicemotion", handleDeviceMotion, true);
|
|
9667
|
+
} catch (error) {
|
|
9668
|
+
console.error(error);
|
|
9669
|
+
}
|
|
9670
|
+
} else {
|
|
9671
|
+
window.addEventListener("devicemotion", handleDeviceMotion, true);
|
|
9672
|
+
}
|
|
9673
|
+
} else {
|
|
9674
|
+
console.log("Cannot set the accelerometer handler.");
|
|
9675
|
+
}
|
|
9676
|
+
}
|
|
9677
|
+
if (this.hasGyrInput) {
|
|
9678
|
+
const handleDeviceOrientation = ({ alpha, beta, gamma }) => {
|
|
9679
|
+
this.propagateGyr({ alpha, beta, gamma });
|
|
9680
|
+
};
|
|
9681
|
+
if (window.DeviceMotionEvent) {
|
|
9682
|
+
if (typeof window.DeviceOrientationEvent.requestPermission === "function") {
|
|
9683
|
+
try {
|
|
9684
|
+
const response = await window.DeviceOrientationEvent.requestPermission();
|
|
9685
|
+
if (response !== "granted")
|
|
9686
|
+
throw new Error("Unable to access the gyroscope.");
|
|
9687
|
+
window.addEventListener("deviceorientation", handleDeviceOrientation, true);
|
|
9688
|
+
} catch (error) {
|
|
9689
|
+
console.error(error);
|
|
9690
|
+
}
|
|
9691
|
+
} else {
|
|
9692
|
+
window.addEventListener("deviceorientation", handleDeviceOrientation, true);
|
|
9693
|
+
}
|
|
9694
|
+
} else {
|
|
9695
|
+
console.log("Cannot set the gyroscope handler.");
|
|
9696
|
+
}
|
|
9697
|
+
}
|
|
9698
|
+
}
|
|
9263
9699
|
setOutputParamHandler(handler) {
|
|
9264
9700
|
this.fOutputHandler = handler;
|
|
9265
9701
|
}
|
|
@@ -9318,6 +9754,24 @@ var FaustAudioWorkletNode = class extends (globalThis.AudioWorkletNode || null)
|
|
|
9318
9754
|
const e = { type: "pitchWheel", data: [channel, wheel] };
|
|
9319
9755
|
this.port.postMessage(e);
|
|
9320
9756
|
}
|
|
9757
|
+
get hasAccInput() {
|
|
9758
|
+
return __privateGet(this, _hasAccInput);
|
|
9759
|
+
}
|
|
9760
|
+
propagateAcc(accelerationIncludingGravity) {
|
|
9761
|
+
if (!accelerationIncludingGravity)
|
|
9762
|
+
return;
|
|
9763
|
+
const e = { type: "acc", data: accelerationIncludingGravity };
|
|
9764
|
+
this.port.postMessage(e);
|
|
9765
|
+
}
|
|
9766
|
+
get hasGyrInput() {
|
|
9767
|
+
return __privateGet(this, _hasGyrInput);
|
|
9768
|
+
}
|
|
9769
|
+
propagateGyr(event) {
|
|
9770
|
+
if (!event)
|
|
9771
|
+
return;
|
|
9772
|
+
const e = { type: "gyr", data: event };
|
|
9773
|
+
this.port.postMessage(e);
|
|
9774
|
+
}
|
|
9321
9775
|
setParamValue(path, value) {
|
|
9322
9776
|
const e = { type: "param", data: { path, value } };
|
|
9323
9777
|
this.port.postMessage(e);
|
|
@@ -9355,6 +9809,8 @@ var FaustAudioWorkletNode = class extends (globalThis.AudioWorkletNode || null)
|
|
|
9355
9809
|
this.port.close();
|
|
9356
9810
|
}
|
|
9357
9811
|
};
|
|
9812
|
+
_hasAccInput = new WeakMap();
|
|
9813
|
+
_hasGyrInput = new WeakMap();
|
|
9358
9814
|
var FaustMonoAudioWorkletNode = class extends FaustAudioWorkletNode {
|
|
9359
9815
|
constructor(context, name, factory, sampleSize, nodeOptions = {}) {
|
|
9360
9816
|
super(context, name, factory, { name, factory, sampleSize }, nodeOptions);
|
|
@@ -9450,6 +9906,54 @@ var FaustScriptProcessorNode = class extends (globalThis.ScriptProcessorNode ||
|
|
|
9450
9906
|
this.start();
|
|
9451
9907
|
}
|
|
9452
9908
|
// Public API
|
|
9909
|
+
/** Setup accelerometer and gyroscope handlers */
|
|
9910
|
+
async listenMotion() {
|
|
9911
|
+
if (this.hasAccInput) {
|
|
9912
|
+
const handleDeviceMotion = ({ accelerationIncludingGravity }) => {
|
|
9913
|
+
if (!accelerationIncludingGravity)
|
|
9914
|
+
return;
|
|
9915
|
+
const { x, y, z } = accelerationIncludingGravity;
|
|
9916
|
+
this.propagateAcc({ x, y, z });
|
|
9917
|
+
};
|
|
9918
|
+
if (window.DeviceMotionEvent) {
|
|
9919
|
+
if (typeof window.DeviceMotionEvent.requestPermission === "function") {
|
|
9920
|
+
try {
|
|
9921
|
+
const response = await window.DeviceMotionEvent.requestPermission();
|
|
9922
|
+
if (response !== "granted")
|
|
9923
|
+
throw new Error("Unable to access the accelerometer.");
|
|
9924
|
+
window.addEventListener("devicemotion", handleDeviceMotion, true);
|
|
9925
|
+
} catch (error) {
|
|
9926
|
+
console.error(error);
|
|
9927
|
+
}
|
|
9928
|
+
} else {
|
|
9929
|
+
window.addEventListener("devicemotion", handleDeviceMotion, true);
|
|
9930
|
+
}
|
|
9931
|
+
} else {
|
|
9932
|
+
console.log("Cannot set the accelerometer handler.");
|
|
9933
|
+
}
|
|
9934
|
+
}
|
|
9935
|
+
if (this.hasGyrInput) {
|
|
9936
|
+
const handleDeviceOrientation = ({ alpha, beta, gamma }) => {
|
|
9937
|
+
this.propagateGyr({ alpha, beta, gamma });
|
|
9938
|
+
};
|
|
9939
|
+
if (window.DeviceMotionEvent) {
|
|
9940
|
+
if (typeof window.DeviceOrientationEvent.requestPermission === "function") {
|
|
9941
|
+
try {
|
|
9942
|
+
const response = await window.DeviceOrientationEvent.requestPermission();
|
|
9943
|
+
if (response !== "granted")
|
|
9944
|
+
throw new Error("Unable to access the gyroscope.");
|
|
9945
|
+
window.addEventListener("deviceorientation", handleDeviceOrientation, true);
|
|
9946
|
+
} catch (error) {
|
|
9947
|
+
console.error(error);
|
|
9948
|
+
}
|
|
9949
|
+
} else {
|
|
9950
|
+
window.addEventListener("deviceorientation", handleDeviceOrientation, true);
|
|
9951
|
+
}
|
|
9952
|
+
} else {
|
|
9953
|
+
console.log("Cannot set the gyroscope handler.");
|
|
9954
|
+
}
|
|
9955
|
+
}
|
|
9956
|
+
}
|
|
9453
9957
|
compute(input, output) {
|
|
9454
9958
|
return this.fDSPCode.compute(input, output);
|
|
9455
9959
|
}
|
|
@@ -9518,6 +10022,18 @@ var FaustScriptProcessorNode = class extends (globalThis.ScriptProcessorNode ||
|
|
|
9518
10022
|
destroy() {
|
|
9519
10023
|
this.fDSPCode.destroy();
|
|
9520
10024
|
}
|
|
10025
|
+
get hasAccInput() {
|
|
10026
|
+
return this.fDSPCode.hasAccInput;
|
|
10027
|
+
}
|
|
10028
|
+
propagateAcc(accelerationIncludingGravity) {
|
|
10029
|
+
this.fDSPCode.propagateAcc(accelerationIncludingGravity);
|
|
10030
|
+
}
|
|
10031
|
+
get hasGyrInput() {
|
|
10032
|
+
return this.fDSPCode.hasGyrInput;
|
|
10033
|
+
}
|
|
10034
|
+
propagateGyr(event) {
|
|
10035
|
+
this.fDSPCode.propagateGyr(event);
|
|
10036
|
+
}
|
|
9521
10037
|
};
|
|
9522
10038
|
var FaustMonoScriptProcessorNode = class extends FaustScriptProcessorNode {
|
|
9523
10039
|
};
|
|
@@ -9601,6 +10117,8 @@ var ${Soundfile.name} = ${Soundfile.toString()}
|
|
|
9601
10117
|
var Soundfile = ${Soundfile.name};
|
|
9602
10118
|
var ${WasmAllocator.name} = ${WasmAllocator.toString()}
|
|
9603
10119
|
var WasmAllocator = ${WasmAllocator.name};
|
|
10120
|
+
var ${FaustSensors.name} = ${FaustSensors.toString()}
|
|
10121
|
+
var FaustSensors = ${FaustSensors.name};
|
|
9604
10122
|
// Put them in dependencies
|
|
9605
10123
|
const dependencies = {
|
|
9606
10124
|
FaustBaseWebAudioDsp,
|
|
@@ -9653,6 +10171,8 @@ var ${Soundfile.name} = ${Soundfile.toString()}
|
|
|
9653
10171
|
var Soundfile = ${Soundfile.name};
|
|
9654
10172
|
var ${WasmAllocator.name} = ${WasmAllocator.toString()}
|
|
9655
10173
|
var WasmAllocator = ${WasmAllocator.name};
|
|
10174
|
+
var ${FaustSensors.name} = ${FaustSensors.toString()}
|
|
10175
|
+
var FaustSensors = ${FaustSensors.name};
|
|
9656
10176
|
var FFTUtils = ${fftUtils.toString()}
|
|
9657
10177
|
// Put them in dependencies
|
|
9658
10178
|
const dependencies = {
|
|
@@ -9880,6 +10400,8 @@ var ${Soundfile.name} = ${Soundfile.toString()}
|
|
|
9880
10400
|
var Soundfile = ${Soundfile.name};
|
|
9881
10401
|
var ${WasmAllocator.name} = ${WasmAllocator.toString()}
|
|
9882
10402
|
var WasmAllocator = ${WasmAllocator.name};
|
|
10403
|
+
var ${FaustSensors.name} = ${FaustSensors.toString()}
|
|
10404
|
+
var FaustSensors = ${FaustSensors.name};
|
|
9883
10405
|
// Put them in dependencies
|
|
9884
10406
|
const dependencies = {
|
|
9885
10407
|
FaustBaseWebAudioDsp,
|