Browse Source

系统节拍器 也按节拍响

黄琪勇 5 tháng trước cách đây
mục cha
commit
ccdc8943d3
2 tập tin đã thay đổi với 4 bổ sung4 xóa
  1. 1 1
      osmd-extended
  2. 3 3
      src/view/tick/index.tsx

+ 1 - 1
osmd-extended

@@ -1 +1 @@
-Subproject commit 8a653186333a6f49d85b61d348e9009ba2803a07
+Subproject commit 03fa7c2e5b7ad0445360e69636a441ec4f8ea97a

+ 3 - 3
src/view/tick/index.tsx

@@ -70,7 +70,7 @@ const handlePlay = (i: number, source: any | null) => {
 		} else {
 			_time=setTimeout(() => {
 				tickPlayCb(i, resolve, source);
-			}, tickData.beatLengthInMilliseconds[i-1]*1000/state.basePlayRate);
+			}, Math.abs(tickData.beatLengthInMilliseconds[i-1])*1000/state.basePlayRate);
 		}
 	});
 };
@@ -99,7 +99,7 @@ const createAudio = (src: string): Promise<HTMLAudioElement | null> => {
 export const handleInitTick = () => {
 	const beatLen = metronomeData.firstBeatTypeArr.length * (state.repeatedBeats ? 2 : 1)
 	const beatLengthInMilliseconds = metronomeData.firstBeatTypeArr.map(item=>{
-		return Math.abs(item)*state.times[0].measureLength
+		return item*state.times[0].measureLength
 	})
 	tickData.beatLengthInMilliseconds = [...beatLengthInMilliseconds,...(state.repeatedBeats ? beatLengthInMilliseconds : [])]
 	tickData.len = beatLen;
@@ -120,7 +120,7 @@ export const handleStartTick = async () => {
 		// 提前结束, 直接放回false
 		if (tickData.tickEnd) return false;
 		// Audio 标签播放音频
-		const source = i === 0 ? audioData.tick : i === useLen.value ? null : audioData.tock;
+		const source = tickData.beatLengthInMilliseconds[i] < 0 ? audioData.tick : i === useLen.value ? null : audioData.tock;
 		await handlePlay(i, source)
 	}
 	tickData.show = false;