ソースを参照

feat: 谱面编辑渐强渐弱线优化

TIANYONG 3 ヶ月 前
コミット
6f9949c3c0
2 ファイル変更24 行追加4 行削除
  1. 1 1
      osmd-extended
  2. 23 3
      src/view/plugins/move-music-score/index.tsx

+ 1 - 1
osmd-extended

@@ -1 +1 @@
-Subproject commit 46bdba03a3654e74d0ad2bd61e993a2467d0f80e
+Subproject commit 2692703cac7823ace1b04e8923c5eb4648d2b72e

+ 23 - 3
src/view/plugins/move-music-score/index.tsx

@@ -219,6 +219,12 @@ export const filterMoveData = async () => {
 				};
 				if (n.type === "vf-lineGroup") {
 					item.dx = n.dx;
+					// 需要获取当前渐强渐弱线所对应的小节的宽度,算出相对当前宽度的比例,用于不同设备回显用
+					const measureNum = document.getElementById(n.id)?.getAttribute('data-mnum');
+					const measureWidth = measureNum ? document.querySelector(`g[data-num='${measureNum}']`)?.getBoundingClientRect()?.width : 0;
+					if (measureWidth) {
+						item.dxRate = n.dx / measureWidth;
+					}
 				}
 				if (n.id.includes('text')) {
 					// let copyDom = document.querySelector("#" + n.id)!.cloneNode(true) as SVGSVGElement
@@ -405,6 +411,7 @@ const resetMoveNote = () => {
 		moveData.modelList[i].isMove = false;
 		moveData.modelList[i].isDelete = false;
 		moveData.modelList[i].dx = 0;
+		moveData.modelList[i].dxRate = 0;
 		renderSvgItem(moveData.modelList[i]);
 		if (moveData.modelList[i].type === "vf-lineGroup") {
 			renderLineGroup(moveData.modelList[i]);
@@ -476,10 +483,23 @@ function renderLineGroup(lineGroup: any) {
 				dx2 = dx2[0] && !isNaN(Number(dx2[0])) ? Number(dx2[0]) : 0;
 
 				if (dx1 && dx2) {
+					// 根据dxRate比例转换dx
+					let targetDx = lineGroup.dx;
+					if (lineGroup.dxRate) {
+						// 需要获取当前渐强渐弱线所对应的小节的宽度,算出相对当前宽度的比例,用于不同设备回显用
+						const measureNum = document.getElementById(lineGroup.id)?.getAttribute('data-mnum');
+						const measureWidth = measureNum ? document.querySelector(`g[data-num='${measureNum}']`)?.getBoundingClientRect()?.width : 0;
+						targetDx = measureWidth ? measureWidth * lineGroup.dxRate : lineGroup.dx;
+					}
+					// targetDx = targetDx * state.zoom;
+					// console.log('targetDx',targetDx)
+					if (storeData.isApp) {
+						targetDx = targetDx * state.zoom;
+					}
 					if (dx1 < dx2) {
-						d = d.replace(dx2, lineGroup.d2 + lineGroup.dx + "");
+						d = d.replace(dx2, lineGroup.d2 + targetDx + "");
 					} else {
-						d = d.replace(dx1, lineGroup.d2 + lineGroup.dx + "");
+						d = d.replace(dx1, lineGroup.d2 + targetDx + "");
 					}
 					path.setAttribute("d", d);
 				}
@@ -688,4 +708,4 @@ export default defineComponent({
 			</div>
 		);
 	},
-});
+});