Browse Source

系统节拍器 速度不准的问题

黄琪勇 1 month ago
parent
commit
8242cdf9c9
2 changed files with 6 additions and 4 deletions
  1. 1 1
      src/page-instrument/view-detail/index.tsx
  2. 5 3
      src/view/tick/index.tsx

+ 1 - 1
src/page-instrument/view-detail/index.tsx

@@ -299,7 +299,7 @@ export default defineComponent({
        * 设置节拍器,跟练需要播放系统节拍器,所以不需要判断needTick状态
        */
       // if (state.needTick) {
-      handleInitTick(osmd?.Sheet?.SheetPlaybackSetting?.Rhythm?.Numerator || 4);
+      handleInitTick(osmd?.Sheet?.SheetPlaybackSetting?.Rhythm?.Numerator || 4, osmd?.Sheet?.SheetPlaybackSetting?.Rhythm?.denominator);
       // }
       // api_cloudLoading();
       // state.playBtnDirection = query.imagePos === 'left' ? 'left' : 'right';

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

@@ -10,6 +10,7 @@ import tockWav from "/src/assets/tock.mp3";
 
 const tickData = reactive({
 	len: 0,
+	denominator: undefined as undefined | number,
 	reduceLen: 0,
 	tickEnd: false,
 	/** 节拍器时间 */
@@ -95,9 +96,11 @@ const createAudio = (src: string): Promise<HTMLAudioElement | null> => {
 
 /** 设置节拍器
  * @param beat 节拍数
+ * @param denominator 节拍器分母
  */
-export const handleInitTick = (beat: number) => {
+export const handleInitTick = (beat: number, denominator?: number) => {
 	tickData.len = beat;
+	tickData.denominator = denominator;
 	// 节拍器的个数除以2 直到小于等于4为止 
 	while (beat > 4 && beat % 2 === 0) {
         beat = beat / 2;
@@ -111,8 +114,7 @@ export const handleStartTick = async () => {
 	tickData.show = true;
 	tickData.tickEnd = false;
 	tickData.index = 0;
-	// tickData.beatLengthInMilliseconds = (60 / state.speed) * 1000;
-	tickData.beatLengthInMilliseconds = (state.times[0].xmlMp3BeatFixTime * 1000) / tickData.len || (60 / state.speed) * 1000;
+	tickData.beatLengthInMilliseconds = tickData.denominator ? 4 / tickData.denominator * (60 / state.speed) * 1000 : (60 / state.speed) * 1000;
 	for(let i = 0; i <= useLen.value; i++){
 		// 提前结束, 直接放回false
 		if (tickData.tickEnd) return false;