Browse Source

因为管乐迷的速度问题,使用管乐迷的音符计算方式

skyblued 2 years ago
parent
commit
2d9fa31ae4
2 changed files with 74 additions and 69 deletions
  1. 73 5
      src/pages/detail/helpers.ts
  2. 1 64
      src/pages/detail/runtime.ts

+ 73 - 5
src/pages/detail/helpers.ts

@@ -22,6 +22,71 @@ export const retain = (time: number) => {
   return Math.ceil(time * 1000000) / 1000000
 }
 
+export function formatBeatUnit(beatUnit: string) {
+  let multiple = 4
+  switch (beatUnit) {
+    case '1024th':
+      // bpm = bpm;
+      multiple = 1024
+      break
+    case '512th':
+      // divisionsFromNote = (noteDuration / 4) * 512;
+      multiple = 512
+      break
+    case '256th':
+      // divisionsFromNote = (noteDuration / 4) * 256;
+      multiple = 256
+      break
+    case '128th':
+      // divisionsFromNote = (noteDuration / 4) * 128;
+      multiple = 128
+      break
+    case '64th':
+      // divisionsFromNote = (noteDuration / 4) * 64;
+      multiple = 64
+      break
+    case '32nd':
+      // divisionsFromNote = (noteDuration / 4) * 32;
+      multiple = 32
+      break
+    case '16th':
+      // divisionsFromNote = (noteDuration / 4) * 16;
+      multiple = 16
+      break
+    case 'eighth':
+      // divisionsFromNote = (noteDuration / 4) * 8;
+      multiple = 8
+      break
+    case 'quarter':
+      multiple = 4
+      break
+    case 'half':
+      // divisionsFromNote = (noteDuration / 4) * 2;
+      multiple = 2
+      break
+    case 'whole':
+      // divisionsFromNote = (noteDuration / 4);
+      multiple = 1
+      break
+    case 'breve':
+      // divisionsFromNote = (noteDuration / 4) / 2;
+      multiple = 0.5
+      break
+    case 'long':
+      // divisionsFromNote = (noteDuration / 4) / 4;
+      multiple = 0.25
+      break
+    case 'maxima':
+      // divisionsFromNote = (noteDuration / 4) / 8;
+      multiple = 0.125
+      break
+    default:
+      break
+  }
+
+  return multiple
+}
+
 export const formatLyricsEntries = (note: any) => {
   const voiceEntries = note.parentStaffEntry?.voiceEntries || []
   const lyricsEntries: string[] = []
@@ -220,10 +285,13 @@ export const getAllNodes = (osmd: any) => {
             fixtime += getFixTime(beatSpeed)
           }
           // console.log({fixtime, relativeTime})
-          let noteLength =
-            (numerator === 0 && note.isRestFlag ? vRealValue : (wholeValue + numerator) / denominator) *
-            vDenominator *
-            (60 / beatSpeed)
+          // 酷乐秀计算音符时值方法
+          // let noteLength =
+          // (numerator === 0 && note.isRestFlag ? vRealValue : (wholeValue + numerator) / denominator) *
+          // vDenominator *
+          // (60 / beatSpeed)
+          //管乐迷计算时值方法
+          let noteLength = Math.min(vRealValue, noteRealValue) * formatBeatUnit(beatUnit) * (60 / beatSpeed)
           const measureLength = vRealValue * vDenominator * (60 / beatSpeed)
           // 单独处理个别的声部
           if (['Piano'].includes(state.activeDetail?.code)) {
@@ -271,7 +339,7 @@ export const getAllNodes = (osmd: any) => {
           usetime += noteLength
           relaMeasureLength += noteLength
           let relaEndtime = noteLength + relativeTime
-          console.log({noteLength,relativeTime ,relaEndtime, endtime: relaEndtime + fixtime})
+          // console.log({noteLength,relativeTime ,relaEndtime, endtime: relaEndtime + fixtime})
           const fixedKey = note.ParentVoiceEntry.ParentVoice.Parent.SubInstruments[0].fixedKey || 0
           // const svgElelent = activeVerticalMeasureList[0]?.vfVoices['1']?.tickables[si]
           const svgElelent = activeVerticalMeasureList[0]?.vfVoices['1']?.tickables[staveNoteIndex]

+ 1 - 64
src/pages/detail/runtime.ts

@@ -14,6 +14,7 @@ import {
   setStepIndex,
   getSlursNote,
   getVoicePartInfo,
+  formatBeatUnit,
 } from './helpers'
 import SectionHint from '/src/helpers/section-hint'
 import { browser, formatTime, getPlatform, getRequestHostname } from '/src/helpers/utils'
@@ -50,70 +51,6 @@ export const getFixtimeRelaVal = () => {
 }
 
 
-export function formatBeatUnit(beatUnit: string) {
-  let multiple = 4
-  switch (beatUnit) {
-    case '1024th':
-      // bpm = bpm;
-      multiple = 1024
-      break
-    case '512th':
-      // divisionsFromNote = (noteDuration / 4) * 512;
-      multiple = 512
-      break
-    case '256th':
-      // divisionsFromNote = (noteDuration / 4) * 256;
-      multiple = 256
-      break
-    case '128th':
-      // divisionsFromNote = (noteDuration / 4) * 128;
-      multiple = 128
-      break
-    case '64th':
-      // divisionsFromNote = (noteDuration / 4) * 64;
-      multiple = 64
-      break
-    case '32nd':
-      // divisionsFromNote = (noteDuration / 4) * 32;
-      multiple = 32
-      break
-    case '16th':
-      // divisionsFromNote = (noteDuration / 4) * 16;
-      multiple = 16
-      break
-    case 'eighth':
-      // divisionsFromNote = (noteDuration / 4) * 8;
-      multiple = 8
-      break
-    case 'quarter':
-      multiple = 4
-      break
-    case 'half':
-      // divisionsFromNote = (noteDuration / 4) * 2;
-      multiple = 2
-      break
-    case 'whole':
-      // divisionsFromNote = (noteDuration / 4);
-      multiple = 1
-      break
-    case 'breve':
-      // divisionsFromNote = (noteDuration / 4) / 2;
-      multiple = 0.5
-      break
-    case 'long':
-      // divisionsFromNote = (noteDuration / 4) / 4;
-      multiple = 0.25
-      break
-    case 'maxima':
-      // divisionsFromNote = (noteDuration / 4) / 8;
-      multiple = 0.125
-      break
-    default:
-      break
-  }
-
-  return multiple
-}
 export const getFixTime = (speed: number) => {
   const duration: any = getDuration(state.osmd)
   let numerator = duration.numerator || 0