@jamesrock/rockjs 1.36.0 → 1.37.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/index.js +46 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -412,6 +412,18 @@ export class DisplayObject {
|
|
|
412
412
|
return this;
|
|
413
413
|
|
|
414
414
|
};
|
|
415
|
+
on(event, handler, passive = true) {
|
|
416
|
+
|
|
417
|
+
this.node.addEventListener(event, handler, {passive});
|
|
418
|
+
return this;
|
|
419
|
+
|
|
420
|
+
};
|
|
421
|
+
once(event, handler, passive = true) {
|
|
422
|
+
|
|
423
|
+
this.node.addEventListener(event, handler, {passive, once: true});
|
|
424
|
+
return this;
|
|
425
|
+
|
|
426
|
+
};
|
|
415
427
|
dispatchEvent(event) {
|
|
416
428
|
|
|
417
429
|
this.node.dispatchEvent(new Event(event));
|
|
@@ -892,7 +904,7 @@ export class SoundManager {
|
|
|
892
904
|
|
|
893
905
|
if(!this.buffers[sound]) {
|
|
894
906
|
console.log(`SoundManager: '${sound}' not loaded!`);
|
|
895
|
-
return;
|
|
907
|
+
return this;
|
|
896
908
|
};
|
|
897
909
|
|
|
898
910
|
const source = this.context.createBufferSource();
|
|
@@ -907,6 +919,8 @@ export class SoundManager {
|
|
|
907
919
|
|
|
908
920
|
source.start();
|
|
909
921
|
|
|
922
|
+
return this;
|
|
923
|
+
|
|
910
924
|
};
|
|
911
925
|
volume(sound, value) {
|
|
912
926
|
|
|
@@ -933,6 +947,37 @@ export class SoundManager {
|
|
|
933
947
|
};
|
|
934
948
|
};
|
|
935
949
|
|
|
950
|
+
export class Tempo {
|
|
951
|
+
constructor() {
|
|
952
|
+
|
|
953
|
+
this.taps = [];
|
|
954
|
+
|
|
955
|
+
};
|
|
956
|
+
tap(base = 120) {
|
|
957
|
+
|
|
958
|
+
const now = performance.now();
|
|
959
|
+
this.taps.push(now);
|
|
960
|
+
|
|
961
|
+
if(this.taps.length > 1 && now - this.taps[this.taps.length - 2] > 2000) {
|
|
962
|
+
taps = [now];
|
|
963
|
+
return base;
|
|
964
|
+
};
|
|
965
|
+
|
|
966
|
+
if(this.taps.length < 2) return base;
|
|
967
|
+
if(this.taps.length > 10) this.taps.shift();
|
|
968
|
+
|
|
969
|
+
const intervals = [];
|
|
970
|
+
for(let i = 1; i < this.taps.length; i++) {
|
|
971
|
+
intervals.push(this.taps[i] - this.taps[i - 1]);
|
|
972
|
+
};
|
|
973
|
+
|
|
974
|
+
const averageInterval = intervals.reduce((a, b) => a + b) / intervals.length;
|
|
975
|
+
|
|
976
|
+
return floorTo(60000 / averageInterval);
|
|
977
|
+
|
|
978
|
+
};
|
|
979
|
+
};
|
|
980
|
+
|
|
936
981
|
// temporary alias
|
|
937
982
|
export const createNode = makeNode;
|
|
938
983
|
export const createSVGNode = makeSVGNode;
|