Browse Source

feat: 速度逻辑

TIANYONG 3 months ago
parent
commit
9d324e83a5

+ 18 - 0
src/pages/detail/helpers.ts

@@ -130,6 +130,24 @@ const speedInfo: { [key in string]: number } = {
   'poco accel.': 0.8,
 }
 
+export const unitObj = {
+  "1/1": 1 / 1,
+  "1/2": 1 / 2,
+  "1/4": 1 / 4,
+  "1/8": 1 / 8,
+  "1/16": 1 / 16,
+  "1/2.": (1 / 2) * 1.5,
+  "1/4.": (1 / 4) * 1.5,
+  "1/8.": (1 / 8) * 1.5
+} as Record<string, any>
+
+/**
+* 速度转换,几分音符的速度转为几分音符的速度
+*/
+export const speedBeatTo = (speedBeat: { unit: string; speed: number }, unit: string) => {
+  return (unitObj[speedBeat.unit] * speedBeat.speed) / unitObj[unit]
+}
+
 /** 按照dorico的渐快渐慢生成对应的速度 */
 export const createSpeedInfo = (gradualChange: GradualChange | undefined, speed: number) => {
   if (gradualChange && speedInfo[gradualChange.startWord?.toLocaleLowerCase()]) {

+ 2 - 0
src/pages/detail/state.ts

@@ -94,6 +94,8 @@ const state = reactive({
   isDaYaCategory: false,
   /** 选段评测,开始播放的音符的时值 */
   firstNoteTime: 0,
+  /** 谱面的速度节拍 */
+  speedBeatUnit: "1/4",
 })
 
 export const isRhythmicExercises = (musicName?: string) => {

+ 2 - 0
src/subpages/colexiu/index.d.ts

@@ -64,6 +64,8 @@ export type MusicSheelDetail = {
   playSpeed?: number
   /** 曲谱类型 */
   musicSheetType?: string
+  /** 速度类型 */
+  speedBeatUnit?: string
 }
 
 export type ShaeetStatusType = 'loading' | 'error' | 'success'

+ 4 - 1
src/subpages/colexiu/index.tsx

@@ -4,7 +4,7 @@ import store from 'store'
 import runtime, * as RuntimeUtils from '/src/pages/detail/runtime'
 import { typeById, ITypeContentItem } from '/src/constant/fingering-colexiu'
 import detailState from '/src/pages/detail/state'
-import { getAllNodes, getDuration } from '/src/pages/detail/helpers'
+import { getAllNodes, getDuration, speedBeatTo } from '/src/pages/detail/helpers'
 import SettingState from '/src/pages/detail/setting-state'
 import {
   useMidi,
@@ -206,6 +206,9 @@ export default defineComponent({
 
       detailState.activeSpeed = detail.value.playSpeed || bpm || 100
       detailState.baseSpeed = detail.value.playSpeed || bpm || 100
+      // 这里把后台设置的速度 转换为1/4拍的速度 
+      detailState.baseSpeed = speedBeatTo({unit: detail.value.speedBeatUnit || "1/4",speed: parseFloat(detail.value.playSpeed) || 0}, `1/4`);
+      console.log('速度',detailState.baseSpeed)
       detailState.code = detail.value?.code || ''
       detailState.activeDetail.originalSpeed = detailState.baseSpeed
 

+ 1 - 1
vite.config.js

@@ -5,7 +5,7 @@ import glsl from 'vite-plugin-glsl'
 const vueJsx = require('@vitejs/plugin-vue-jsx')
 const legacy = require('@vitejs/plugin-legacy')
 
-const proxyUrl = 'https://test.lexiaoya.cn/' // test 环境
+const proxyUrl = 'https://dev.lexiaoya.cn/' // test 环境
 // const proxyUrl = 'http://192.168.3.70:8989/' // test 环境
 // const proxyUrl = 'https://online.colexiu.com/' // online 环境