Browse Source

feat: 计速度取整逻辑修改

TIANYONG 1 week ago
parent
commit
1e7ca8726c
2 changed files with 10 additions and 1 deletions
  1. 5 1
      src/state.ts
  2. 5 0
      src/utils/index.ts

+ 5 - 1
src/state.ts

@@ -8,7 +8,7 @@ import { IFingering, mappingVoicePart, subjectFingering, matchVoicePart } from "
 import { handleStartTick, closeTick } from "./view/tick";
 import { audioListStart, getAudioCurrentTime, getAudioDuration, setAudioCurrentTime, setAudioPlaybackRate, audioData } from "./view/audio-list";
 import { toggleFollow } from "./view/follow-practice";
-import { browser, setStorageSpeed, setGlobalData } from "./utils";
+import { browser, setStorageSpeed, setGlobalData, checkDecimal } from "./utils";
 import { api_cloudGetMediaStatus, api_createMusicPlayer, api_cloudChangeSpeed, api_cloudSuspend, api_cloudSetCurrentTime, api_cloudDestroy } from "./helpers/communication";
 import { verifyCanRepeat, getDuration, xmlAddPartName } from "./helpers/formateMusic";
 import { getMusicSheetDetail, getInstrumentCode } from "./utils/baseApi"
@@ -638,6 +638,10 @@ export const skipNotePlay = async (itemIndex: number, isStart = false, handType?
     if (item.measureSpeed && state.section.length < 2) {
       // console.log('速度3')
       state.speed = state.basePlayRate * 1000000 * item.measureSpeed / 1000000
+      // 如果是接近整数的小数,则取整
+      if ( checkDecimal(state.speed) ) {
+        state.speed = Math.round(state.speed)
+      }
     }
     setAudioCurrentTime(itemTime, itemIndex);
     // 一行谱,点击音符,或者播放完成,需要跳转音符位置

+ 5 - 0
src/utils/index.ts

@@ -157,4 +157,9 @@ export const debounce = (fn: Function, ms = 0) => {
 	  // @ts-ignore
 	  timeoutId = setTimeout(() => fn.apply(this, args), ms);
 	}
+}
+
+// 使用正则表达式匹配小数点后第一位数字是否是 0 或 9
+export const checkDecimal = (num: number | string) => {
+	return /^\d*\.(0|9)/.test(num.toString());
 }