Browse Source

feat: 速度问题修改

TIANYONG 3 months ago
parent
commit
d985d77af3

+ 2 - 2
src/helpers/formateMusic.ts

@@ -883,7 +883,7 @@ export const formateTimes = (osmd: OpenSheetMusicDisplay) => {
 		if (state.isCombineRender) {
 			iterator.currentVoiceEntries = iterator.currentVoiceEntries.filter((item: any) => {
 				const trackName = state.isEvxml && state.evxmlAddPartName ? item.parentVoice.parent.IdString || '' : item.parentVoice.parent.Name || '';
-				return trackName === firstTrackName
+				return trackName?.trim() === firstTrackName
 			});
 		}
 		let minIndex = 0, elRealValue = 0
@@ -1060,7 +1060,7 @@ export const formateTimes = (osmd: OpenSheetMusicDisplay) => {
 			
 			// 合并展示某些分轨,需要把展示的分轨筛选出来
 			if (state.isCombineRender && note.sourceMeasure.verticalMeasureList.length) {
-				note.sourceMeasure.verticalMeasureList = note.sourceMeasure?.verticalMeasureList.filter((item: any) => state.canSelectTracks.includes(item?.parentStaff?.parentInstrument.Name))
+				note.sourceMeasure.verticalMeasureList = note.sourceMeasure?.verticalMeasureList.filter((item: any) => state.canSelectTracks.includes(item?.parentStaff?.parentInstrument.Name?.trim()))
 			}
 
 			activeVerticalMeasureList = [note.sourceMeasure?.verticalMeasureList?.[currentTrackIndex]] || [];

+ 24 - 24
src/helpers/svgToPng.ts

@@ -1,29 +1,29 @@
 // 将svg转成png
 export const getSvgPngToSize = (osmd: any) => {
-    if (osmd) {
-      if (osmd.Drawer.Backends.length > 0) {
-        var imgList = []
-        
-        for (var idx = 0, len = osmd.Drawer.Backends.length; idx < len; idx++) {
-          var backend = osmd.Drawer.Backends[idx]
-          var state = backend.ctx.state;
-          var width = backend.ctx.width / state.scale.x;
-          var height = backend.ctx.height / state.scale.y;
-          const textX = width - 120,textY = height - 50;
-          const textDom = `<g><text x="${textX}" y="${textY}" stroke-width="3" fill="#000000" stroke="none" stroke-dasharray="none" font-family="Times New Roman" font-size="36px" font-weight="bold" font-style="none">第${idx+1}页</text></g>`
-          backend.ctx.svg.innerHTML = backend.ctx.svg.innerHTML + textDom;
-          var cont = new XMLSerializer().serializeToString(
-            backend.ctx.svg
-          )
-          imgList.push({
-            img: cont,
-            width: width,
-            height: height,
-          })
-        }
-        return imgList
+  if (osmd) {
+    if (osmd.Drawer.Backends.length > 0) {
+      var imgList = []
+      
+      for (var idx = 0, len = osmd.Drawer.Backends.length; idx < len; idx++) {
+        var backend = osmd.Drawer.Backends[idx]
+        var state = backend.ctx.state;
+        var width = backend.ctx.width / state.scale.x;
+        var height = backend.ctx.height / state.scale.y;
+        const textX = width - 90,textY = height - 90;
+        const textDom = `<g><text x="${textX}" y="${textY}" stroke-width="3" fill="#000000" stroke="none" stroke-dasharray="none" font-family="Times New Roman" font-size="36px" font-weight="bold" font-style="none">${idx+1}/${len}</text></g>`
+        backend.ctx.svg.innerHTML = backend.ctx.svg.innerHTML + textDom;
+        var cont = new XMLSerializer().serializeToString(
+          backend.ctx.svg
+        )
+        imgList.push({
+          img: cont,
+          width: width,
+          height: height,
+        })
       }
-    } else {
-      console.log('没有OSMD')
+      return imgList
     }
+  } else {
+    console.log('没有OSMD')
+  }
 }

+ 8 - 5
src/page-instrument/header-top/speed/index.module.less

@@ -1,7 +1,10 @@
 .speedContainer{
     width: 334px;
     &.isHideBeat .content{
-        height: 172px;
+        height: 206px;
+        .speedSel{
+            padding-bottom: 0px !important;
+        }
     }
     .head{
         height: 42px;
@@ -25,7 +28,7 @@
     }
     .content{
         margin-top: -26px;
-        height: 230px;
+        height: 264px;
         background: #FFFFFF;
         border-radius: 16px;
         padding: 36px 16px 16px 16px;
@@ -122,8 +125,8 @@
                 }
             }
             .speedSel{
-                margin-top: 20px;
-                padding-bottom: 8px;
+                margin-top: 8px;
+                padding-bottom: 18px;
                 display: flex;
                 justify-content: space-between;
                 flex-wrap: wrap;
@@ -138,7 +141,7 @@
                     font-size: 13px;
                     color: rgba(0,0,0,0.6);
                     cursor: pointer;
-                    margin-bottom: 10px;
+                    margin-top: 10px;
                     margin-right: 3px;
                     &:active{
                         background: #B9F2DF;

+ 2 - 1
src/page-instrument/header-top/speed/index.tsx

@@ -39,7 +39,8 @@ export default defineComponent({
 				state.speed = speed.value
 				// handleSetSpeed(speed.value);
 				if (state.playState === 'paused') {
-					const currentItem: any = (state.sectionStatus && state.section.length === 2) ? state.sectionFirst || state.section[0] : state.times[state.activeNoteIndex];
+					// const currentItem: any = (state.sectionStatus && state.section.length === 2) ? state.sectionFirst || state.section[0] : state.times[state.activeNoteIndex];
+					const currentItem: any = state.times[state.activeNoteIndex];
 					state.basePlayRate = currentItem?.measureSpeed ? state.speed / currentItem.measureSpeed : state.speed / state.originSpeed;
 				}
 			}

+ 11 - 9
src/page-instrument/view-detail/index.tsx

@@ -316,15 +316,17 @@ export default defineComponent({
       // }
 
       // 管乐迷曲谱详情页,需要下载A4尺寸的图片
-      if (query.downPng === 'A4') {
-        const imgList = getSvgPngToSize(state.osmd)
-        console.log('A4', imgList)
-        window.parent.postMessage({
-          api: 'musicStaffRender',
-          loading: false,
-          osmdImg: imgList
-        }, '*');
-      }
+      setTimeout(() => {
+        if (query.downPng === 'A4' && state.partIndex != 999) {
+          const imgList = getSvgPngToSize(state.osmd)
+          console.log('A4', imgList)
+          window.parent.postMessage({
+            api: 'musicStaffRender',
+            loading: false,
+            osmdImg: imgList
+          }, '*');
+        }
+      }, 100);
 
       state.musicScoreBtnDirection = state.playBtnDirection;
       state.musicRendered = true;

+ 2 - 1
src/state.ts

@@ -1191,7 +1191,8 @@ export const handleSetSpeed = (speed: number) => {
   // setStorageSpeed(state.examSongId, speed);
   state.speed = speed;
   // 当前的音符
-  const currentItem: any = (state.sectionStatus && state.section.length === 2) ? state.section[0] : state.times[state.activeNoteIndex];
+  // const currentItem: any = (state.sectionStatus && state.section.length === 2) ? state.section[0] : state.times[state.activeNoteIndex];
+  const currentItem: any = state.times[state.activeNoteIndex];
   state.basePlayRate = currentItem?.measureSpeed ? state.speed / currentItem.measureSpeed : state.speed / state.originSpeed;
   const actualRate = state.originAudioPlayRate * state.basePlayRate;
   console.log('速度设置',speed,'小节计算的倍率',state.basePlayRate,'实际播放倍率',actualRate)

+ 2 - 1
src/view/music-score/index.tsx

@@ -169,10 +169,11 @@ export default defineComponent({
 				const canSelectTracks = state.combinePartIndexs.length > 1 ? state.combinePartIndexs.map(partIndex => { return state.partListNames[partIndex] }) : state.canSelectTracks
 				for (let i = 0; i < osmd.Sheet.Instruments.length; i++) {
 					const trackName = state.isEvxml && state.evxmlAddPartName ? osmd.Sheet.Instruments[i].idString || '' : osmd.Sheet.Instruments[i].Name || '';
-					osmd.Sheet.Instruments[i].Visible = canSelectTracks.includes(trackName)
+					osmd.Sheet.Instruments[i].Visible = canSelectTracks.includes(trackName.trim())
 				}
 			}
 			if (query.downPng === 'A4') {
+				osmd.EngravingRules.PageTopMargin = 5
 				osmd.setPageFormat('794x1100')
 				osmd.zoom = 0.3;
 			} else {