@mulsense/xnew 0.1.6 → 0.1.7
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/types/audio/audio.d.ts +16 -10
- package/dist/types/audio/loader.d.ts +16 -0
- package/dist/types/audio/synthesizer.d.ts +10 -24
- package/dist/types/basics/Controller.d.ts +18 -16
- package/dist/types/basics/Drag.d.ts +6 -0
- package/dist/types/basics/KeyEvent.d.ts +2 -0
- package/dist/types/basics/KeyboardEvent.d.ts +2 -0
- package/dist/types/basics/PointerEvent.d.ts +2 -0
- package/dist/types/basics/Screen.d.ts +0 -4
- package/dist/types/basics/Tab.d.ts +2 -2
- package/dist/types/basics/UserEvent.d.ts +1 -1
- package/dist/types/core/unit.d.ts +7 -7
- package/dist/types/index.d.ts +10 -7
- package/dist/xnew.d.ts +58 -60
- package/dist/xnew.js +341 -296
- package/dist/xnew.mjs +341 -296
- package/package.json +1 -1
package/dist/xnew.js
CHANGED
|
@@ -223,7 +223,7 @@
|
|
|
223
223
|
}
|
|
224
224
|
|
|
225
225
|
//----------------------------------------------------------------------------------------------------
|
|
226
|
-
//
|
|
226
|
+
// defines
|
|
227
227
|
//----------------------------------------------------------------------------------------------------
|
|
228
228
|
const SYSTEM_EVENTS = ['start', 'update', 'stop', 'finalize'];
|
|
229
229
|
class UnitPromise {
|
|
@@ -798,61 +798,58 @@
|
|
|
798
798
|
Unit.current._.captures.push({ checker, execute: Unit.wrap(Unit.current, (unit) => execute(unit)) });
|
|
799
799
|
};
|
|
800
800
|
|
|
801
|
-
function
|
|
802
|
-
const
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
801
|
+
function PointerEvent(unit) {
|
|
802
|
+
const internal = xnew$1();
|
|
803
|
+
internal.on('pointerdown', (event) => unit.emit('-pointerdown', { event, position: getPosition(unit.element, event) }));
|
|
804
|
+
internal.on('pointermove', (event) => unit.emit('-pointermove', { event, position: getPosition(unit.element, event) }));
|
|
805
|
+
internal.on('pointerup', (event) => unit.emit('-pointerup', { event, position: getPosition(unit.element, event) }));
|
|
806
|
+
internal.on('wheel', (event) => unit.emit('-wheel', { event, delta: { x: event.wheelDeltaX, y: event.wheelDeltaY } }));
|
|
807
|
+
internal.on('mouseover', (event) => unit.emit('-mouseover', { event, position: getPosition(unit.element, event) }));
|
|
808
|
+
internal.on('mouseout', (event) => unit.emit('-mouseout', { event, position: getPosition(unit.element, event) }));
|
|
807
809
|
const drag = xnew$1(DragEvent);
|
|
808
|
-
drag.on('-dragstart', (...args) =>
|
|
809
|
-
drag.on('-dragmove', (...args) =>
|
|
810
|
-
drag.on('-dragend', (...args) =>
|
|
811
|
-
drag.on('-dragcancel', (...args) =>
|
|
810
|
+
drag.on('-dragstart', (...args) => unit.emit('-dragstart', ...args));
|
|
811
|
+
drag.on('-dragmove', (...args) => unit.emit('-dragmove', ...args));
|
|
812
|
+
drag.on('-dragend', (...args) => unit.emit('-dragend', ...args));
|
|
813
|
+
drag.on('-dragcancel', (...args) => unit.emit('-dragcancel', ...args));
|
|
812
814
|
const gesture = xnew$1(GestureEvent);
|
|
813
|
-
gesture.on('-gesturestart', (...args) =>
|
|
814
|
-
gesture.on('-gesturemove', (...args) =>
|
|
815
|
-
gesture.on('-gestureend', (...args) =>
|
|
816
|
-
gesture.on('-gesturecancel', (...args) =>
|
|
817
|
-
const keyborad = xnew$1(Keyboard);
|
|
818
|
-
keyborad.on('-keydown', (...args) => self.emit('-keydown', ...args));
|
|
819
|
-
keyborad.on('-keyup', (...args) => self.emit('-keyup', ...args));
|
|
820
|
-
keyborad.on('-arrowkeydown', (...args) => self.emit('-arrowkeydown', ...args));
|
|
821
|
-
keyborad.on('-arrowkeyup', (...args) => self.emit('-arrowkeyup', ...args));
|
|
815
|
+
gesture.on('-gesturestart', (...args) => unit.emit('-gesturestart', ...args));
|
|
816
|
+
gesture.on('-gesturemove', (...args) => unit.emit('-gesturemove', ...args));
|
|
817
|
+
gesture.on('-gestureend', (...args) => unit.emit('-gestureend', ...args));
|
|
818
|
+
gesture.on('-gesturecancel', (...args) => unit.emit('-gesturecancel', ...args));
|
|
822
819
|
}
|
|
823
|
-
function DragEvent(
|
|
820
|
+
function DragEvent(unit) {
|
|
824
821
|
xnew$1().on('pointerdown', (event) => {
|
|
825
822
|
const id = event.pointerId;
|
|
826
|
-
const position = getPosition(
|
|
823
|
+
const position = getPosition(unit.element, event);
|
|
827
824
|
let previous = position;
|
|
828
825
|
xnew$1(() => {
|
|
829
826
|
xnew$1.listener(window).on('pointermove', (event) => {
|
|
830
827
|
if (event.pointerId === id) {
|
|
831
|
-
const position = getPosition(
|
|
828
|
+
const position = getPosition(unit.element, event);
|
|
832
829
|
const delta = { x: position.x - previous.x, y: position.y - previous.y };
|
|
833
|
-
|
|
830
|
+
unit.emit('-dragmove', { event, position, delta });
|
|
834
831
|
previous = position;
|
|
835
832
|
}
|
|
836
833
|
});
|
|
837
834
|
xnew$1.listener(window).on('pointerup', (event) => {
|
|
838
835
|
if (event.pointerId === id) {
|
|
839
|
-
const position = getPosition(
|
|
840
|
-
|
|
836
|
+
const position = getPosition(unit.element, event);
|
|
837
|
+
unit.emit('-dragend', { event, position, });
|
|
841
838
|
xnew$1.listener(window).off();
|
|
842
839
|
}
|
|
843
840
|
});
|
|
844
841
|
xnew$1.listener(window).on('pointercancel', (event) => {
|
|
845
842
|
if (event.pointerId === id) {
|
|
846
|
-
const position = getPosition(
|
|
847
|
-
|
|
843
|
+
const position = getPosition(unit.element, event);
|
|
844
|
+
unit.emit('-dragcancel', { event, position, });
|
|
848
845
|
xnew$1.listener(window).off();
|
|
849
846
|
}
|
|
850
847
|
});
|
|
851
848
|
});
|
|
852
|
-
|
|
849
|
+
unit.emit('-dragstart', { event, position });
|
|
853
850
|
});
|
|
854
851
|
}
|
|
855
|
-
function GestureEvent(
|
|
852
|
+
function GestureEvent(unit) {
|
|
856
853
|
const drag = xnew$1(DragEvent);
|
|
857
854
|
let isActive = false;
|
|
858
855
|
const map = new Map();
|
|
@@ -860,7 +857,7 @@
|
|
|
860
857
|
map.set(event.pointerId, Object.assign({}, position));
|
|
861
858
|
isActive = map.size === 2 ? true : false;
|
|
862
859
|
if (isActive === true) {
|
|
863
|
-
|
|
860
|
+
unit.emit('-gesturestart', {});
|
|
864
861
|
}
|
|
865
862
|
});
|
|
866
863
|
drag.on('-dragmove', ({ event, position, delta }) => {
|
|
@@ -886,20 +883,20 @@
|
|
|
886
883
|
// rotate = sign > 0.0 ? +angle : -angle;
|
|
887
884
|
// }
|
|
888
885
|
// }
|
|
889
|
-
|
|
886
|
+
unit.emit('-gesturemove', { event, position, delta, scale });
|
|
890
887
|
}
|
|
891
888
|
map.set(event.pointerId, position);
|
|
892
889
|
});
|
|
893
890
|
drag.on('-dragend', ({ event }) => {
|
|
894
891
|
if (isActive === true) {
|
|
895
|
-
|
|
892
|
+
unit.emit('-gestureend', {});
|
|
896
893
|
}
|
|
897
894
|
isActive = false;
|
|
898
895
|
map.delete(event.pointerId);
|
|
899
896
|
});
|
|
900
897
|
drag.on('-dragcancel', ({ event }) => {
|
|
901
898
|
if (isActive === true) {
|
|
902
|
-
|
|
899
|
+
unit.emit('-gesturecancel', { event });
|
|
903
900
|
}
|
|
904
901
|
isActive = false;
|
|
905
902
|
map.delete(event.pointerId);
|
|
@@ -912,21 +909,26 @@
|
|
|
912
909
|
return others;
|
|
913
910
|
}
|
|
914
911
|
}
|
|
915
|
-
function
|
|
912
|
+
function getPosition(element, event) {
|
|
913
|
+
const rect = element.getBoundingClientRect();
|
|
914
|
+
return { x: event.clientX - rect.left, y: event.clientY - rect.top };
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
function KeyboardEvent(unit) {
|
|
916
918
|
const state = {};
|
|
917
919
|
xnew$1.listener(window).on('keydown', (event) => {
|
|
918
920
|
state[event.code] = 1;
|
|
919
|
-
|
|
921
|
+
unit.emit('-keydown', { event, type: '-keydown', code: event.code });
|
|
920
922
|
});
|
|
921
923
|
xnew$1.listener(window).on('keyup', (event) => {
|
|
922
924
|
state[event.code] = 0;
|
|
923
|
-
|
|
925
|
+
unit.emit('-keyup', { event, type: '-keyup', code: event.code });
|
|
924
926
|
});
|
|
925
927
|
xnew$1.listener(window).on('keydown', (event) => {
|
|
926
|
-
|
|
928
|
+
unit.emit('-arrowkeydown', { event, type: '-arrowkeydown', code: event.code, vector: getVector() });
|
|
927
929
|
});
|
|
928
930
|
xnew$1.listener(window).on('keyup', (event) => {
|
|
929
|
-
|
|
931
|
+
unit.emit('-arrowkeyup', { event, type: '-arrowkeyup', code: event.code, vector: getVector() });
|
|
930
932
|
});
|
|
931
933
|
function getVector() {
|
|
932
934
|
return {
|
|
@@ -935,16 +937,12 @@
|
|
|
935
937
|
};
|
|
936
938
|
}
|
|
937
939
|
}
|
|
938
|
-
function getPosition(element, event) {
|
|
939
|
-
const rect = element.getBoundingClientRect();
|
|
940
|
-
return { x: event.clientX - rect.left, y: event.clientY - rect.top };
|
|
941
|
-
}
|
|
942
940
|
|
|
943
941
|
function Screen(screen, { width = 640, height = 480, fit = 'contain' } = {}) {
|
|
944
942
|
const size = { width, height };
|
|
945
943
|
const wrapper = xnew$1.nest('<div style="position: relative; width: 100%; height: 100%; overflow: hidden;">');
|
|
946
944
|
const absolute = xnew$1.nest('<div style="position: absolute; margin: auto;">');
|
|
947
|
-
const canvas = xnew$1
|
|
945
|
+
const canvas = xnew$1(`<canvas width="${width}" height="${height}" style="width: 100%; height: 100%; vertical-align: bottom; user-select: none; user-drag: none;">`);
|
|
948
946
|
xnew$1(wrapper, ResizeEvent).on('-resize', resize);
|
|
949
947
|
resize();
|
|
950
948
|
function resize() {
|
|
@@ -975,18 +973,15 @@
|
|
|
975
973
|
}
|
|
976
974
|
return {
|
|
977
975
|
get canvas() {
|
|
978
|
-
return canvas;
|
|
976
|
+
return canvas.element;
|
|
979
977
|
},
|
|
980
978
|
resize(width, height) {
|
|
981
979
|
size.width = width;
|
|
982
980
|
size.height = height;
|
|
983
|
-
canvas.setAttribute('width', width + 'px');
|
|
984
|
-
canvas.setAttribute('height', height + 'px');
|
|
981
|
+
canvas.element.setAttribute('width', width + 'px');
|
|
982
|
+
canvas.element.setAttribute('height', height + 'px');
|
|
985
983
|
resize();
|
|
986
984
|
},
|
|
987
|
-
get scale() {
|
|
988
|
-
return { x: size.width / canvas.clientWidth, y: size.height / canvas.clientHeight };
|
|
989
|
-
}
|
|
990
985
|
};
|
|
991
986
|
}
|
|
992
987
|
|
|
@@ -1039,14 +1034,14 @@
|
|
|
1039
1034
|
};
|
|
1040
1035
|
}
|
|
1041
1036
|
|
|
1042
|
-
function TabFrame(frame, {
|
|
1037
|
+
function TabFrame(frame, { select } = {}) {
|
|
1043
1038
|
const internal = xnew$1((internal) => {
|
|
1044
1039
|
const buttons = new Map();
|
|
1045
1040
|
const contents = new Map();
|
|
1046
1041
|
return { frame, buttons, contents };
|
|
1047
1042
|
});
|
|
1048
1043
|
xnew$1.context('xnew.tabframe', internal);
|
|
1049
|
-
xnew$1.timeout(() => internal.emit('-select', { key:
|
|
1044
|
+
xnew$1.timeout(() => internal.emit('-select', { key: select !== null && select !== void 0 ? select : [...internal.buttons.keys()][0] }));
|
|
1050
1045
|
}
|
|
1051
1046
|
function TabButton(button, { key } = {}) {
|
|
1052
1047
|
const internal = xnew$1.context('xnew.tabframe');
|
|
@@ -1183,18 +1178,30 @@
|
|
|
1183
1178
|
function DragTarget(target, {} = {}) {
|
|
1184
1179
|
const { frame, absolute } = xnew$1.context('xnew.dragframe');
|
|
1185
1180
|
xnew$1.nest('<div>');
|
|
1186
|
-
const
|
|
1181
|
+
const pointer = xnew$1(absolute.parentElement, PointerEvent);
|
|
1187
1182
|
const current = { x: 0, y: 0 };
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1183
|
+
const offset = { x: 0, y: 0 };
|
|
1184
|
+
let dragged = false;
|
|
1185
|
+
pointer.on('-dragstart', ({ event, position }) => {
|
|
1186
|
+
if (target.element.contains(event.target) === false)
|
|
1187
|
+
return;
|
|
1188
|
+
dragged = true;
|
|
1189
|
+
offset.x = position.x - parseFloat(absolute.style.left || '0');
|
|
1190
|
+
offset.y = position.y - parseFloat(absolute.style.top || '0');
|
|
1191
|
+
current.x = position.x - offset.x;
|
|
1192
|
+
current.y = position.y - offset.y;
|
|
1191
1193
|
});
|
|
1192
|
-
|
|
1194
|
+
pointer.on('-dragmove', ({ event, delta }) => {
|
|
1195
|
+
if (dragged !== true)
|
|
1196
|
+
return;
|
|
1193
1197
|
current.x += delta.x;
|
|
1194
1198
|
current.y += delta.y;
|
|
1195
1199
|
absolute.style.left = `${current.x}px`;
|
|
1196
1200
|
absolute.style.top = `${current.y}px`;
|
|
1197
1201
|
});
|
|
1202
|
+
pointer.on('-dragcancel -dragend', ({ event }) => {
|
|
1203
|
+
dragged = false;
|
|
1204
|
+
});
|
|
1198
1205
|
}
|
|
1199
1206
|
|
|
1200
1207
|
//----------------------------------------------------------------------------------------------------
|
|
@@ -1203,184 +1210,264 @@
|
|
|
1203
1210
|
function SVGTemplate(self, { fill = null, fillOpacity = 0.8, stroke = null, strokeOpacity = 0.8, strokeWidth = 2, strokeLinejoin = 'round' }) {
|
|
1204
1211
|
xnew$1.nest(`<svg
|
|
1205
1212
|
viewBox="0 0 100 100"
|
|
1206
|
-
style="position: absolute; width: 100%; height: 100%;
|
|
1213
|
+
style="position: absolute; width: 100%; height: 100%; pointer-select: none;
|
|
1207
1214
|
${fill ? `fill: ${fill}; fill-opacity: ${fillOpacity};` : ''}
|
|
1208
1215
|
${stroke ? `stroke: ${stroke}; stroke-opacity: ${strokeOpacity}; stroke-width: ${strokeWidth}; stroke-linejoin: ${strokeLinejoin};` : ''}
|
|
1209
1216
|
">`);
|
|
1210
1217
|
}
|
|
1211
|
-
function
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
xnew$1('<polygon points="50 93 40 83 60 83">');
|
|
1218
|
-
xnew$1('<polygon points=" 7 50 18 40 18 60">');
|
|
1219
|
-
xnew$1('<polygon points="93 50 83 40 83 60">');
|
|
1220
|
-
});
|
|
1221
|
-
const target = xnew$1((self) => {
|
|
1222
|
-
xnew$1.extend(SVGTemplate, { fill, fillOpacity, stroke, strokeOpacity, strokeWidth, strokeLinejoin });
|
|
1223
|
-
xnew$1('<circle cx="50" cy="50" r="23">');
|
|
1224
|
-
});
|
|
1225
|
-
const user = xnew$1(UserEvent);
|
|
1226
|
-
user.on('-dragstart', ({ event, position }) => {
|
|
1227
|
-
const vector = getVector(position);
|
|
1228
|
-
target.element.style.filter = 'brightness(90%)';
|
|
1229
|
-
target.element.style.left = vector.x * size / 4 + 'px';
|
|
1230
|
-
target.element.style.top = vector.y * size / 4 + 'px';
|
|
1231
|
-
self.emit('-down', { vector });
|
|
1232
|
-
});
|
|
1233
|
-
user.on('-dragmove', ({ event, position }) => {
|
|
1234
|
-
const vector = getVector(position);
|
|
1235
|
-
target.element.style.filter = 'brightness(90%)';
|
|
1236
|
-
target.element.style.left = vector.x * size / 4 + 'px';
|
|
1237
|
-
target.element.style.top = vector.y * size / 4 + 'px';
|
|
1238
|
-
self.emit('-move', { vector });
|
|
1239
|
-
});
|
|
1240
|
-
user.on('-dragend', ({ event }) => {
|
|
1241
|
-
const vector = { x: 0, y: 0 };
|
|
1242
|
-
target.element.style.filter = '';
|
|
1243
|
-
target.element.style.left = vector.x * size / 4 + 'px';
|
|
1244
|
-
target.element.style.top = vector.y * size / 4 + 'px';
|
|
1245
|
-
self.emit('-up', { vector });
|
|
1246
|
-
});
|
|
1247
|
-
function getVector(position) {
|
|
1248
|
-
const x = position.x - size / 2;
|
|
1249
|
-
const y = position.y - size / 2;
|
|
1250
|
-
const d = Math.min(1.0, Math.sqrt(x * x + y * y) / (size / 4));
|
|
1251
|
-
const a = (y !== 0 || x !== 0) ? Math.atan2(y, x) : 0;
|
|
1252
|
-
return { x: Math.cos(a) * d, y: Math.sin(a) * d };
|
|
1218
|
+
function AnalogStick(self, { size, fill = '#FFF', fillOpacity = 0.8, stroke = '#000', strokeOpacity = 0.8, strokeWidth = 2, strokeLinejoin = 'round' } = {}) {
|
|
1219
|
+
xnew$1.nest(`<div style="position: relative; width: 100%; height: 100%;">`);
|
|
1220
|
+
let internal;
|
|
1221
|
+
let newsize;
|
|
1222
|
+
if (size) {
|
|
1223
|
+
newsize = size;
|
|
1253
1224
|
}
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
'<polygon points="50 50 35 35 35 5 37 3 63 3 65 5 65 35">',
|
|
1260
|
-
'<polygon points="50 50 35 65 35 95 37 97 63 97 65 95 65 65">',
|
|
1261
|
-
'<polygon points="50 50 35 35 5 35 3 37 3 63 5 65 35 65">',
|
|
1262
|
-
'<polygon points="50 50 65 35 95 35 97 37 97 63 95 65 65 65">'
|
|
1263
|
-
];
|
|
1264
|
-
const targets = polygons.map((polygon) => {
|
|
1265
|
-
return xnew$1((self) => {
|
|
1266
|
-
xnew$1.extend(SVGTemplate, { fill, fillOpacity });
|
|
1267
|
-
xnew$1(polygon);
|
|
1225
|
+
else {
|
|
1226
|
+
newsize = Math.min(self.element.clientWidth, self.element.clientHeight);
|
|
1227
|
+
xnew$1(self.element, ResizeEvent).on('-resize', () => {
|
|
1228
|
+
newsize = Math.min(self.element.clientWidth, self.element.clientHeight);
|
|
1229
|
+
internal === null || internal === void 0 ? void 0 : internal.reboot();
|
|
1268
1230
|
});
|
|
1269
|
-
});
|
|
1270
|
-
xnew$1((self) => {
|
|
1271
|
-
xnew$1.extend(SVGTemplate, { fill: 'none', stroke, strokeOpacity, strokeWidth, strokeLinejoin });
|
|
1272
|
-
xnew$1('<polyline points="35 35 35 5 37 3 63 3 65 5 65 35">');
|
|
1273
|
-
xnew$1('<polyline points="35 65 35 95 37 97 63 97 65 95 65 65">');
|
|
1274
|
-
xnew$1('<polyline points="35 35 5 35 3 37 3 63 5 65 35 65">');
|
|
1275
|
-
xnew$1('<polyline points="65 35 95 35 97 37 97 63 95 65 65 65">');
|
|
1276
|
-
xnew$1('<polygon points="50 11 42 20 58 20">');
|
|
1277
|
-
xnew$1('<polygon points="50 89 42 80 58 80">');
|
|
1278
|
-
xnew$1('<polygon points="11 50 20 42 20 58">');
|
|
1279
|
-
xnew$1('<polygon points="89 50 80 42 80 58">');
|
|
1280
|
-
});
|
|
1281
|
-
const user = xnew$1(UserEvent);
|
|
1282
|
-
user.on('-dragstart', ({ event, position }) => {
|
|
1283
|
-
const vector = getVector(position);
|
|
1284
|
-
targets[0].element.style.filter = (vector.y < 0) ? 'brightness(90%)' : '';
|
|
1285
|
-
targets[1].element.style.filter = (vector.y > 0) ? 'brightness(90%)' : '';
|
|
1286
|
-
targets[2].element.style.filter = (vector.x < 0) ? 'brightness(90%)' : '';
|
|
1287
|
-
targets[3].element.style.filter = (vector.x > 0) ? 'brightness(90%)' : '';
|
|
1288
|
-
self.emit('-down', { vector });
|
|
1289
|
-
});
|
|
1290
|
-
user.on('-dragmove', ({ event, position }) => {
|
|
1291
|
-
const vector = getVector(position);
|
|
1292
|
-
targets[0].element.style.filter = (vector.y < 0) ? 'brightness(90%)' : '';
|
|
1293
|
-
targets[1].element.style.filter = (vector.y > 0) ? 'brightness(90%)' : '';
|
|
1294
|
-
targets[2].element.style.filter = (vector.x < 0) ? 'brightness(90%)' : '';
|
|
1295
|
-
targets[3].element.style.filter = (vector.x > 0) ? 'brightness(90%)' : '';
|
|
1296
|
-
self.emit('-move', { vector });
|
|
1297
|
-
});
|
|
1298
|
-
user.on('-dragend', ({ event }) => {
|
|
1299
|
-
const vector = { x: 0, y: 0 };
|
|
1300
|
-
targets[0].element.style.filter = '';
|
|
1301
|
-
targets[1].element.style.filter = '';
|
|
1302
|
-
targets[2].element.style.filter = '';
|
|
1303
|
-
targets[3].element.style.filter = '';
|
|
1304
|
-
self.emit('-up', { vector });
|
|
1305
|
-
});
|
|
1306
|
-
function getVector(position) {
|
|
1307
|
-
const x = position.x - size / 2;
|
|
1308
|
-
const y = position.y - size / 2;
|
|
1309
|
-
const a = (y !== 0 || x !== 0) ? Math.atan2(y, x) : 0;
|
|
1310
|
-
const d = Math.min(1.0, Math.sqrt(x * x + y * y) / (size / 4));
|
|
1311
|
-
const vector = { x: Math.cos(a) * d, y: Math.sin(a) * d };
|
|
1312
|
-
vector.x = Math.abs(vector.x) > 0.5 ? Math.sign(vector.x) : 0;
|
|
1313
|
-
vector.y = Math.abs(vector.y) > 0.5 ? Math.sign(vector.y) : 0;
|
|
1314
|
-
return vector;
|
|
1315
1231
|
}
|
|
1232
|
+
internal = xnew$1(() => {
|
|
1233
|
+
xnew$1.nest(`<div style="position: absolute; width: ${newsize}px; height: ${newsize}px; margin: auto; inset: 0; cursor: pointer; pointer-select: none; pointer-events: auto; overflow: hidden;">`);
|
|
1234
|
+
xnew$1((self) => {
|
|
1235
|
+
xnew$1.extend(SVGTemplate, { fill, fillOpacity, stroke, strokeOpacity, strokeWidth, strokeLinejoin });
|
|
1236
|
+
xnew$1('<polygon points="50 7 40 18 60 18">');
|
|
1237
|
+
xnew$1('<polygon points="50 93 40 83 60 83">');
|
|
1238
|
+
xnew$1('<polygon points=" 7 50 18 40 18 60">');
|
|
1239
|
+
xnew$1('<polygon points="93 50 83 40 83 60">');
|
|
1240
|
+
});
|
|
1241
|
+
const target = xnew$1((self) => {
|
|
1242
|
+
xnew$1.extend(SVGTemplate, { fill, fillOpacity, stroke, strokeOpacity, strokeWidth, strokeLinejoin });
|
|
1243
|
+
xnew$1('<circle cx="50" cy="50" r="23">');
|
|
1244
|
+
});
|
|
1245
|
+
const pointer = xnew$1(PointerEvent);
|
|
1246
|
+
pointer.on('-dragstart', ({ event, position }) => {
|
|
1247
|
+
const vector = getVector(position);
|
|
1248
|
+
target.element.style.filter = 'brightness(90%)';
|
|
1249
|
+
target.element.style.left = vector.x * newsize / 4 + 'px';
|
|
1250
|
+
target.element.style.top = vector.y * newsize / 4 + 'px';
|
|
1251
|
+
self.emit('-down', { vector });
|
|
1252
|
+
});
|
|
1253
|
+
pointer.on('-dragmove', ({ event, position }) => {
|
|
1254
|
+
const vector = getVector(position);
|
|
1255
|
+
target.element.style.filter = 'brightness(90%)';
|
|
1256
|
+
target.element.style.left = vector.x * newsize / 4 + 'px';
|
|
1257
|
+
target.element.style.top = vector.y * newsize / 4 + 'px';
|
|
1258
|
+
self.emit('-move', { vector });
|
|
1259
|
+
});
|
|
1260
|
+
pointer.on('-dragend', ({ event }) => {
|
|
1261
|
+
const vector = { x: 0, y: 0 };
|
|
1262
|
+
target.element.style.filter = '';
|
|
1263
|
+
target.element.style.left = vector.x * newsize / 4 + 'px';
|
|
1264
|
+
target.element.style.top = vector.y * newsize / 4 + 'px';
|
|
1265
|
+
self.emit('-up', { vector });
|
|
1266
|
+
});
|
|
1267
|
+
function getVector(position) {
|
|
1268
|
+
const x = position.x - newsize / 2;
|
|
1269
|
+
const y = position.y - newsize / 2;
|
|
1270
|
+
const d = Math.min(1.0, Math.sqrt(x * x + y * y) / (newsize / 4));
|
|
1271
|
+
const a = (y !== 0 || x !== 0) ? Math.atan2(y, x) : 0;
|
|
1272
|
+
return { x: Math.cos(a) * d, y: Math.sin(a) * d };
|
|
1273
|
+
}
|
|
1274
|
+
});
|
|
1316
1275
|
}
|
|
1317
|
-
function
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1276
|
+
function DirectionalPad(self, { size, diagonal = true, fill = '#FFF', fillOpacity = 0.8, stroke = '#000', strokeOpacity = 0.8, strokeWidth = 2, strokeLinejoin = 'round' } = {}) {
|
|
1277
|
+
xnew$1.nest(`<div style="position: relative; width: 100%; height: 100%;">`);
|
|
1278
|
+
let internal;
|
|
1279
|
+
let newsize;
|
|
1280
|
+
if (size) {
|
|
1281
|
+
newsize = size;
|
|
1282
|
+
}
|
|
1283
|
+
else {
|
|
1284
|
+
newsize = Math.min(self.element.clientWidth, self.element.clientHeight);
|
|
1285
|
+
xnew$1(self.element, ResizeEvent).on('-resize', () => {
|
|
1286
|
+
newsize = Math.min(self.element.clientWidth, self.element.clientHeight);
|
|
1287
|
+
internal === null || internal === void 0 ? void 0 : internal.reboot();
|
|
1288
|
+
});
|
|
1289
|
+
}
|
|
1290
|
+
internal = xnew$1(() => {
|
|
1291
|
+
xnew$1.nest(`<div style="position: absolute; width: ${newsize}px; height: ${newsize}px; margin: auto; inset: 0; cursor: pointer; pointer-select: none; pointer-events: auto; overflow: hidden;">`);
|
|
1292
|
+
const polygons = [
|
|
1293
|
+
'<polygon points="50 50 35 35 35 5 37 3 63 3 65 5 65 35">',
|
|
1294
|
+
'<polygon points="50 50 35 65 35 95 37 97 63 97 65 95 65 65">',
|
|
1295
|
+
'<polygon points="50 50 35 35 5 35 3 37 3 63 5 65 35 65">',
|
|
1296
|
+
'<polygon points="50 50 65 35 95 35 97 37 97 63 95 65 65 65">'
|
|
1297
|
+
];
|
|
1298
|
+
const targets = polygons.map((polygon) => {
|
|
1299
|
+
return xnew$1((self) => {
|
|
1300
|
+
xnew$1.extend(SVGTemplate, { fill, fillOpacity });
|
|
1301
|
+
xnew$1(polygon);
|
|
1302
|
+
});
|
|
1303
|
+
});
|
|
1304
|
+
xnew$1((self) => {
|
|
1305
|
+
xnew$1.extend(SVGTemplate, { fill: 'none', stroke, strokeOpacity, strokeWidth, strokeLinejoin });
|
|
1306
|
+
xnew$1('<polyline points="35 35 35 5 37 3 63 3 65 5 65 35">');
|
|
1307
|
+
xnew$1('<polyline points="35 65 35 95 37 97 63 97 65 95 65 65">');
|
|
1308
|
+
xnew$1('<polyline points="35 35 5 35 3 37 3 63 5 65 35 65">');
|
|
1309
|
+
xnew$1('<polyline points="65 35 95 35 97 37 97 63 95 65 65 65">');
|
|
1310
|
+
xnew$1('<polygon points="50 11 42 20 58 20">');
|
|
1311
|
+
xnew$1('<polygon points="50 89 42 80 58 80">');
|
|
1312
|
+
xnew$1('<polygon points="11 50 20 42 20 58">');
|
|
1313
|
+
xnew$1('<polygon points="89 50 80 42 80 58">');
|
|
1314
|
+
});
|
|
1315
|
+
const pointer = xnew$1(PointerEvent);
|
|
1316
|
+
pointer.on('-dragstart', ({ event, position }) => {
|
|
1317
|
+
const vector = getVector(position);
|
|
1318
|
+
targets[0].element.style.filter = (vector.y < 0) ? 'brightness(90%)' : '';
|
|
1319
|
+
targets[1].element.style.filter = (vector.y > 0) ? 'brightness(90%)' : '';
|
|
1320
|
+
targets[2].element.style.filter = (vector.x < 0) ? 'brightness(90%)' : '';
|
|
1321
|
+
targets[3].element.style.filter = (vector.x > 0) ? 'brightness(90%)' : '';
|
|
1322
|
+
self.emit('-down', { vector });
|
|
1323
|
+
});
|
|
1324
|
+
pointer.on('-dragmove', ({ event, position }) => {
|
|
1325
|
+
const vector = getVector(position);
|
|
1326
|
+
targets[0].element.style.filter = (vector.y < 0) ? 'brightness(90%)' : '';
|
|
1327
|
+
targets[1].element.style.filter = (vector.y > 0) ? 'brightness(90%)' : '';
|
|
1328
|
+
targets[2].element.style.filter = (vector.x < 0) ? 'brightness(90%)' : '';
|
|
1329
|
+
targets[3].element.style.filter = (vector.x > 0) ? 'brightness(90%)' : '';
|
|
1330
|
+
self.emit('-move', { vector });
|
|
1331
|
+
});
|
|
1332
|
+
pointer.on('-dragend', ({ event }) => {
|
|
1333
|
+
const vector = { x: 0, y: 0 };
|
|
1334
|
+
targets[0].element.style.filter = '';
|
|
1335
|
+
targets[1].element.style.filter = '';
|
|
1336
|
+
targets[2].element.style.filter = '';
|
|
1337
|
+
targets[3].element.style.filter = '';
|
|
1338
|
+
self.emit('-up', { vector });
|
|
1339
|
+
});
|
|
1340
|
+
function getVector(position) {
|
|
1341
|
+
const x = position.x - newsize / 2;
|
|
1342
|
+
const y = position.y - newsize / 2;
|
|
1343
|
+
const a = (y !== 0 || x !== 0) ? Math.atan2(y, x) : 0;
|
|
1344
|
+
const d = Math.min(1.0, Math.sqrt(x * x + y * y) / (newsize / 4));
|
|
1345
|
+
const vector = { x: Math.cos(a) * d, y: Math.sin(a) * d };
|
|
1346
|
+
if (diagonal === true) {
|
|
1347
|
+
vector.x = Math.abs(vector.x) > 0.5 ? Math.sign(vector.x) : 0;
|
|
1348
|
+
vector.y = Math.abs(vector.y) > 0.5 ? Math.sign(vector.y) : 0;
|
|
1349
|
+
}
|
|
1350
|
+
else if (Math.abs(vector.x) > Math.abs(vector.y)) {
|
|
1351
|
+
vector.x = Math.abs(vector.x) > 0.5 ? Math.sign(vector.x) : 0;
|
|
1352
|
+
vector.y = 0;
|
|
1353
|
+
}
|
|
1354
|
+
else {
|
|
1355
|
+
vector.x = 0;
|
|
1356
|
+
vector.y = Math.abs(vector.y) > 0.5 ? Math.sign(vector.y) : 0;
|
|
1357
|
+
}
|
|
1358
|
+
return vector;
|
|
1359
|
+
}
|
|
1323
1360
|
});
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1361
|
+
}
|
|
1362
|
+
|
|
1363
|
+
const context = new AudioContext();
|
|
1364
|
+
const master = context.createGain();
|
|
1365
|
+
master.gain.value = 1.0;
|
|
1366
|
+
master.connect(context.destination);
|
|
1367
|
+
function connect(params) {
|
|
1368
|
+
const nodes = {};
|
|
1369
|
+
Object.keys(params).forEach((key) => {
|
|
1370
|
+
const [type, props, ...to] = params[key];
|
|
1371
|
+
nodes[key] = context[`create${type}`]();
|
|
1372
|
+
const node = nodes[key];
|
|
1373
|
+
Object.keys(props).forEach((name) => {
|
|
1374
|
+
var _a;
|
|
1375
|
+
if (((_a = node[name]) === null || _a === void 0 ? void 0 : _a.value) !== undefined) {
|
|
1376
|
+
node[name].value = props[name];
|
|
1377
|
+
}
|
|
1378
|
+
else {
|
|
1379
|
+
node[name] = props[name];
|
|
1380
|
+
}
|
|
1381
|
+
});
|
|
1328
1382
|
});
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1383
|
+
Object.keys(params).forEach((key) => {
|
|
1384
|
+
const [type, props, ...to] = params[key];
|
|
1385
|
+
to.forEach((to) => {
|
|
1386
|
+
let dest = null;
|
|
1387
|
+
if (to.indexOf('.') > 0) {
|
|
1388
|
+
dest = nodes[to.split('.')[0]][to.split('.')[1]];
|
|
1389
|
+
}
|
|
1390
|
+
else if (nodes[to]) {
|
|
1391
|
+
dest = nodes[to];
|
|
1392
|
+
}
|
|
1393
|
+
else if (to === 'master') {
|
|
1394
|
+
dest = master;
|
|
1395
|
+
}
|
|
1396
|
+
nodes[key].connect(dest);
|
|
1397
|
+
});
|
|
1332
1398
|
});
|
|
1399
|
+
return nodes;
|
|
1333
1400
|
}
|
|
1334
1401
|
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1402
|
+
const store = new Map();
|
|
1403
|
+
function load(path) {
|
|
1404
|
+
return new AudioFile(path);
|
|
1405
|
+
}
|
|
1406
|
+
class AudioFile {
|
|
1407
|
+
constructor(path) {
|
|
1408
|
+
this.data = {};
|
|
1409
|
+
if (store.has(path)) {
|
|
1410
|
+
this.data = store.get(path);
|
|
1343
1411
|
}
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
nodes[key][name].value = props[name];
|
|
1356
|
-
}
|
|
1357
|
-
else {
|
|
1358
|
-
nodes[key][name] = props[name];
|
|
1359
|
-
}
|
|
1360
|
-
});
|
|
1361
|
-
});
|
|
1362
|
-
Object.keys(params).forEach((key) => {
|
|
1363
|
-
const [type, props, ...to] = params[key];
|
|
1364
|
-
to.forEach((to) => {
|
|
1365
|
-
let dest = null;
|
|
1366
|
-
if (to.indexOf('.') > 0) {
|
|
1367
|
-
dest = nodes[to.split('.')[0]][to.split('.')[1]];
|
|
1368
|
-
}
|
|
1369
|
-
else if (nodes[to]) {
|
|
1370
|
-
dest = nodes[to];
|
|
1371
|
-
}
|
|
1372
|
-
else if (to === 'master') {
|
|
1373
|
-
dest = Audio.master;
|
|
1374
|
-
}
|
|
1375
|
-
nodes[key].connect(dest);
|
|
1412
|
+
else {
|
|
1413
|
+
this.data.buffer = null;
|
|
1414
|
+
this.data.promise = fetch(path)
|
|
1415
|
+
.then((response) => response.arrayBuffer())
|
|
1416
|
+
.then((response) => context.decodeAudioData(response))
|
|
1417
|
+
.then((response) => {
|
|
1418
|
+
this.data.buffer = response;
|
|
1419
|
+
this.nodes.source.buffer = this.data.buffer;
|
|
1420
|
+
})
|
|
1421
|
+
.catch(() => {
|
|
1422
|
+
console.warn(`"${path}" could not be loaded.`);
|
|
1376
1423
|
});
|
|
1424
|
+
store.set(path, this.data);
|
|
1425
|
+
}
|
|
1426
|
+
this.startTime = null;
|
|
1427
|
+
this.nodes = connect({
|
|
1428
|
+
source: ['BufferSource', {}, 'volume'],
|
|
1429
|
+
volume: ['Gain', { gain: 1.0 }, 'master'],
|
|
1377
1430
|
});
|
|
1378
|
-
|
|
1431
|
+
}
|
|
1432
|
+
isReady() {
|
|
1433
|
+
return this.data.buffer ? true : false;
|
|
1434
|
+
}
|
|
1435
|
+
get promise() {
|
|
1436
|
+
return this.data.promise;
|
|
1437
|
+
}
|
|
1438
|
+
set volume(value) {
|
|
1439
|
+
this.nodes.volume.gain.value = value;
|
|
1440
|
+
}
|
|
1441
|
+
get volume() {
|
|
1442
|
+
return this.nodes.volume.gain.value;
|
|
1443
|
+
}
|
|
1444
|
+
set loop(value) {
|
|
1445
|
+
this.nodes.source.loop = value;
|
|
1446
|
+
}
|
|
1447
|
+
get loop() {
|
|
1448
|
+
return this.nodes.source.loop;
|
|
1449
|
+
}
|
|
1450
|
+
play(offset = 0) {
|
|
1451
|
+
if (this.startTime !== null)
|
|
1452
|
+
return;
|
|
1453
|
+
if (this.isReady()) {
|
|
1454
|
+
this.startTime = context.currentTime;
|
|
1455
|
+
this.nodes.source.playbackRate.value = 1;
|
|
1456
|
+
this.nodes.source.start(context.currentTime, offset / 1000);
|
|
1457
|
+
}
|
|
1458
|
+
else {
|
|
1459
|
+
this.promise.then(() => this.play());
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
pause() {
|
|
1463
|
+
if (this.startTime === null)
|
|
1464
|
+
return;
|
|
1465
|
+
this.nodes.source.stop(context.currentTime);
|
|
1466
|
+
const elapsed = (context.currentTime - this.startTime) % this.data.buffer.duration * 1000;
|
|
1467
|
+
this.startTime = null;
|
|
1468
|
+
return elapsed;
|
|
1379
1469
|
}
|
|
1380
1470
|
}
|
|
1381
|
-
Audio.context = null;
|
|
1382
|
-
Audio.master = null;
|
|
1383
|
-
Audio.initialize();
|
|
1384
1471
|
|
|
1385
1472
|
function synthesizer(props, effects) {
|
|
1386
1473
|
return new Synthesizer(props, effects);
|
|
@@ -1404,30 +1491,20 @@
|
|
|
1404
1491
|
window.removeEventListener('mousedown', initialize, true);
|
|
1405
1492
|
}
|
|
1406
1493
|
}
|
|
1407
|
-
constructor({ oscillator = null, filter = null, amp = null } = {}, { bmp = null, reverb = null
|
|
1494
|
+
constructor({ oscillator = null, filter = null, amp = null } = {}, { bmp = null, reverb = null } = {}) {
|
|
1408
1495
|
this.oscillator = isObject(oscillator) ? oscillator : {};
|
|
1409
1496
|
this.oscillator.type = setType(this.oscillator.type, ['sine', 'triangle', 'square', 'sawtooth']);
|
|
1410
1497
|
this.oscillator.envelope = setEnvelope(this.oscillator.envelope, -36, +36);
|
|
1411
1498
|
this.oscillator.LFO = setLFO(this.oscillator.LFO, 36);
|
|
1412
1499
|
this.filter = isObject(filter) ? filter : {};
|
|
1413
1500
|
this.filter.type = setType(this.filter.type, ['lowpass', 'highpass', 'bandpass']);
|
|
1414
|
-
this.filter.Q = isNumber(this.filter.Q) ? clamp(this.filter.Q, 0, 32) : 0;
|
|
1415
|
-
// cutoffはundefinedを使う
|
|
1416
1501
|
this.filter.cutoff = isNumber(this.filter.cutoff) ? clamp(this.filter.cutoff, 4, 8192) : undefined;
|
|
1417
|
-
this.filter.envelope = setEnvelope(this.filter.envelope, -36, +36);
|
|
1418
|
-
this.filter.LFO = setLFO(this.filter.LFO, 36);
|
|
1419
1502
|
this.amp = isObject(amp) ? amp : {};
|
|
1420
1503
|
this.amp.envelope = setEnvelope(this.amp.envelope, 0, 1);
|
|
1421
|
-
this.amp.LFO = setLFO(this.amp.LFO, 36);
|
|
1422
1504
|
this.bmp = isNumber(bmp) ? clamp(bmp, 60, 240) : 120;
|
|
1423
|
-
this.options = { bmp: this.bmp };
|
|
1424
1505
|
this.reverb = isObject(reverb) ? reverb : {};
|
|
1425
1506
|
this.reverb.time = isNumber(this.reverb.time) ? clamp(this.reverb.time, 0, 2000) : 0.0;
|
|
1426
1507
|
this.reverb.mix = isNumber(this.reverb.mix) ? clamp(this.reverb.mix, 0, 1.0) : 0.0;
|
|
1427
|
-
this.delay = isObject(delay) ? delay : {};
|
|
1428
|
-
this.delay.time = isNumber(this.delay.time) ? clamp(this.delay.time, 0, 2000) : 0.0;
|
|
1429
|
-
this.delay.feedback = isNumber(this.delay.feedback) ? clamp(this.delay.feedback, 0.0, 0.9) : 0.0;
|
|
1430
|
-
this.delay.mix = isNumber(this.delay.mix) ? clamp(this.delay.mix, 0.0, 1.0) : 0.0;
|
|
1431
1508
|
function setType(type, list, value = 0) {
|
|
1432
1509
|
return list.includes(type) ? type : list[value];
|
|
1433
1510
|
}
|
|
@@ -1463,46 +1540,43 @@
|
|
|
1463
1540
|
}
|
|
1464
1541
|
press(frequency, duration = null, wait = 0.0) {
|
|
1465
1542
|
frequency = typeof frequency === 'string' ? Synthesizer.keymap[frequency] : frequency;
|
|
1466
|
-
duration = typeof duration === 'string' ? (Synthesizer.notemap[duration] * 60 / this.
|
|
1467
|
-
const start =
|
|
1543
|
+
duration = typeof duration === 'string' ? (Synthesizer.notemap[duration] * 60 / this.bmp) : (duration !== null ? (duration / 1000) : duration);
|
|
1544
|
+
const start = context.currentTime + wait / 1000;
|
|
1468
1545
|
let stop = null;
|
|
1469
|
-
const
|
|
1546
|
+
const nodes = {};
|
|
1547
|
+
nodes.oscillator = context.createOscillator();
|
|
1548
|
+
nodes.amp = context.createGain();
|
|
1549
|
+
nodes.amp.gain.value = 0.0;
|
|
1550
|
+
nodes.target = context.createGain();
|
|
1551
|
+
nodes.target.gain.value = 1.0;
|
|
1552
|
+
nodes.amp.connect(nodes.target);
|
|
1553
|
+
nodes.target.connect(master);
|
|
1470
1554
|
if (this.filter.type && this.filter.cutoff) {
|
|
1471
|
-
|
|
1472
|
-
|
|
1555
|
+
nodes.filter = context.createBiquadFilter();
|
|
1556
|
+
nodes.oscillator.connect(nodes.filter);
|
|
1557
|
+
nodes.filter.connect(nodes.amp);
|
|
1473
1558
|
}
|
|
1474
1559
|
else {
|
|
1475
|
-
|
|
1560
|
+
nodes.oscillator.connect(nodes.amp);
|
|
1476
1561
|
}
|
|
1477
|
-
params.amp = ['Gain', { gain: 0.0 }, 'target'];
|
|
1478
|
-
params.target = ['Gain', { gain: 1.0 }, 'master'];
|
|
1479
1562
|
if (this.reverb.time > 0.0 && this.reverb.mix > 0.0) {
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
params.delayDepth = ['Gain', { gain: 1.0 }, 'master'];
|
|
1488
|
-
params.delayFeedback = ['Gain', { gain: this.delay.feedback }, 'delay'];
|
|
1563
|
+
nodes.convolver = context.createConvolver();
|
|
1564
|
+
nodes.convolver.buffer = impulseResponse({ time: this.reverb.time });
|
|
1565
|
+
nodes.convolverDepth = context.createGain();
|
|
1566
|
+
nodes.convolverDepth.gain.value = 1.0;
|
|
1567
|
+
nodes.amp.connect(nodes.convolver);
|
|
1568
|
+
nodes.convolver.connect(nodes.convolverDepth);
|
|
1569
|
+
nodes.convolverDepth.connect(master);
|
|
1489
1570
|
}
|
|
1490
1571
|
if (this.oscillator.LFO) {
|
|
1491
|
-
|
|
1492
|
-
|
|
1572
|
+
nodes.oscillatorLFO = context.createOscillator();
|
|
1573
|
+
nodes.oscillatorLFODepth = context.createGain();
|
|
1574
|
+
nodes.oscillatorLFO.connect(nodes.oscillatorLFODepth);
|
|
1575
|
+
nodes.oscillatorLFODepth.connect(nodes.oscillator.frequency);
|
|
1493
1576
|
}
|
|
1494
|
-
if (this.filter.LFO) {
|
|
1495
|
-
params.filterLFO = ['Oscillator', {}, 'filterLFODepth'];
|
|
1496
|
-
params.filterLFODepth = ['Gain', {}, 'filter.frequency'];
|
|
1497
|
-
}
|
|
1498
|
-
if (this.amp.LFO) {
|
|
1499
|
-
params.ampLFO = ['Oscillator', {}, 'ampLFODepth'];
|
|
1500
|
-
params.ampLFODepth = ['Gain', {}, 'amp.gain'];
|
|
1501
|
-
}
|
|
1502
|
-
const nodes = Audio.connect(params);
|
|
1503
1577
|
nodes.oscillator.type = this.oscillator.type;
|
|
1504
1578
|
nodes.oscillator.frequency.value = clamp(frequency, 10.0, 5000.0);
|
|
1505
|
-
if (this.filter.type && this.filter.cutoff) {
|
|
1579
|
+
if (this.filter.type && this.filter.cutoff && nodes.filter) {
|
|
1506
1580
|
nodes.filter.type = this.filter.type;
|
|
1507
1581
|
nodes.filter.frequency.value = this.filter.cutoff;
|
|
1508
1582
|
}
|
|
@@ -1510,39 +1584,17 @@
|
|
|
1510
1584
|
nodes.target.gain.value *= (1.0 - this.reverb.mix);
|
|
1511
1585
|
nodes.convolverDepth.gain.value *= this.reverb.mix;
|
|
1512
1586
|
}
|
|
1513
|
-
if (this.delay.time > 0.0 && this.delay.mix > 0.0) {
|
|
1514
|
-
console.log(this.delay.time / 1000);
|
|
1515
|
-
nodes.delay.delayTime.value = this.delay.time / 1000;
|
|
1516
|
-
nodes.target.gain.value *= (1.0 - this.delay.mix);
|
|
1517
|
-
nodes.delayDepth.gain.value *= this.delay.mix;
|
|
1518
|
-
}
|
|
1519
1587
|
{
|
|
1520
|
-
if (this.oscillator.LFO) {
|
|
1588
|
+
if (this.oscillator.LFO && nodes.oscillatorLFO && nodes.oscillatorLFODepth) {
|
|
1521
1589
|
nodes.oscillatorLFODepth.gain.value = frequency * (Math.pow(2.0, this.oscillator.LFO.amount / 12.0) - 1.0);
|
|
1522
1590
|
nodes.oscillatorLFO.type = this.oscillator.LFO.type;
|
|
1523
1591
|
nodes.oscillatorLFO.frequency.value = this.oscillator.LFO.rate;
|
|
1524
1592
|
nodes.oscillatorLFO.start(start);
|
|
1525
1593
|
}
|
|
1526
|
-
if (this.filter.LFO) {
|
|
1527
|
-
nodes.filterLFODepth.gain.value = frequency * (Math.pow(2.0, this.filter.LFO.amount / 12.0) - 1.0);
|
|
1528
|
-
nodes.filterLFO.type = this.filter.LFO.type;
|
|
1529
|
-
nodes.filterLFO.frequency.value = this.filter.LFO.rate;
|
|
1530
|
-
nodes.filterLFO.start(start);
|
|
1531
|
-
}
|
|
1532
|
-
if (this.amp.LFO) {
|
|
1533
|
-
nodes.ampLFODepth.gain.value = this.amp.LFO.amount;
|
|
1534
|
-
nodes.ampLFO.type = this.amp.LFO.type;
|
|
1535
|
-
nodes.ampLFO.frequency.value = this.amp.LFO.rate;
|
|
1536
|
-
nodes.ampLFO.start(start);
|
|
1537
|
-
}
|
|
1538
1594
|
if (this.oscillator.envelope) {
|
|
1539
1595
|
const amount = frequency * (Math.pow(2.0, this.oscillator.envelope.amount / 12.0) - 1.0);
|
|
1540
1596
|
startEnvelope(nodes.oscillator.frequency, frequency, amount, this.oscillator.envelope.ADSR);
|
|
1541
1597
|
}
|
|
1542
|
-
if (this.filter.envelope) {
|
|
1543
|
-
const amount = this.filter.cutoff * (Math.pow(2.0, this.filter.envelope.amount / 12.0) - 1.0);
|
|
1544
|
-
startEnvelope(nodes.filter.frequency, this.filter.cutoff, amount, this.filter.envelope.ADSR);
|
|
1545
|
-
}
|
|
1546
1598
|
if (this.amp.envelope) {
|
|
1547
1599
|
startEnvelope(nodes.amp.gain, 0.0, this.amp.envelope.amount, this.amp.envelope.ADSR);
|
|
1548
1600
|
}
|
|
@@ -1552,7 +1604,7 @@
|
|
|
1552
1604
|
release.call(this);
|
|
1553
1605
|
}
|
|
1554
1606
|
function release() {
|
|
1555
|
-
duration = duration !== null && duration !== void 0 ? duration : (
|
|
1607
|
+
duration = duration !== null && duration !== void 0 ? duration : (context.currentTime - start);
|
|
1556
1608
|
if (this.amp.envelope) {
|
|
1557
1609
|
const ADSR = this.amp.envelope.ADSR;
|
|
1558
1610
|
const adsr = [ADSR[0] / 1000, ADSR[1] / 1000, ADSR[2], ADSR[3] / 1000];
|
|
@@ -1562,20 +1614,13 @@
|
|
|
1562
1614
|
else {
|
|
1563
1615
|
stop = start + duration;
|
|
1564
1616
|
}
|
|
1565
|
-
if (
|
|
1617
|
+
if (nodes.oscillatorLFO) {
|
|
1566
1618
|
nodes.oscillatorLFO.stop(stop);
|
|
1567
1619
|
}
|
|
1568
|
-
if (this.amp.LFO) {
|
|
1569
|
-
nodes.ampLFO.stop(stop);
|
|
1570
|
-
}
|
|
1571
1620
|
if (this.oscillator.envelope) {
|
|
1572
1621
|
const amount = frequency * (Math.pow(2.0, this.oscillator.envelope.amount / 12.0) - 1.0);
|
|
1573
1622
|
stopEnvelope(nodes.oscillator.frequency, frequency, amount, this.oscillator.envelope.ADSR);
|
|
1574
1623
|
}
|
|
1575
|
-
if (this.filter.envelope) {
|
|
1576
|
-
const amount = this.filter.cutoff * (Math.pow(2.0, this.filter.envelope.amount / 12.0) - 1.0);
|
|
1577
|
-
stopEnvelope(nodes.filter.frequency, this.filter.cutoff, amount, this.filter.envelope.ADSR);
|
|
1578
|
-
}
|
|
1579
1624
|
if (this.amp.envelope) {
|
|
1580
1625
|
stopEnvelope(nodes.amp.gain, 0.0, this.amp.envelope.amount, this.amp.envelope.ADSR);
|
|
1581
1626
|
}
|
|
@@ -1621,8 +1666,8 @@
|
|
|
1621
1666
|
};
|
|
1622
1667
|
Synthesizer.initialize();
|
|
1623
1668
|
function impulseResponse({ time, decay = 2.0 }) {
|
|
1624
|
-
const length =
|
|
1625
|
-
const impulse =
|
|
1669
|
+
const length = context.sampleRate * time / 1000;
|
|
1670
|
+
const impulse = context.createBuffer(2, length, context.sampleRate);
|
|
1626
1671
|
const ch0 = impulse.getChannelData(0);
|
|
1627
1672
|
const ch1 = impulse.getChannelData(1);
|
|
1628
1673
|
for (let i = 0; i < length; i++) {
|
|
@@ -1634,8 +1679,9 @@
|
|
|
1634
1679
|
|
|
1635
1680
|
const basics = {
|
|
1636
1681
|
Screen,
|
|
1637
|
-
|
|
1682
|
+
PointerEvent,
|
|
1638
1683
|
ResizeEvent,
|
|
1684
|
+
KeyboardEvent,
|
|
1639
1685
|
ModalFrame,
|
|
1640
1686
|
ModalContent,
|
|
1641
1687
|
AccordionFrame,
|
|
@@ -1648,12 +1694,11 @@
|
|
|
1648
1694
|
InputFrame,
|
|
1649
1695
|
DragFrame,
|
|
1650
1696
|
DragTarget,
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
TouchButton,
|
|
1697
|
+
AnalogStick,
|
|
1698
|
+
DirectionalPad,
|
|
1654
1699
|
};
|
|
1655
1700
|
const audio = {
|
|
1656
|
-
synthesizer
|
|
1701
|
+
synthesizer, load
|
|
1657
1702
|
};
|
|
1658
1703
|
const xnew = Object.assign(xnew$1, {
|
|
1659
1704
|
basics,
|