Browse Source

feat: 计速度取整逻辑修改

TIANYONG 1 week ago
parent
commit
6d8131020f
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"
@@ -598,6 +598,10 @@ export const skipNotePlay = async (itemIndex: number, isStart = false) => {
     // 非选段模式,点击音符,动态设置右下角的速度
     if (item.measureSpeed && state.section.length < 2) {
       state.speed = state.basePlayRate * 10000 * item.measureSpeed / 10000
+      // 如果是接近整数的小数,则取整
+      if ( checkDecimal(state.speed) ) {
+        state.speed = Math.round(state.speed)
+      }
       // console.log('速度',3,state.speed)
     }
     setAudioCurrentTime(itemTime, itemIndex);

+ 5 - 0
src/utils/index.ts

@@ -186,4 +186,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());
 }