Browse Source

feat: 节拍指针位置修改

TIANYONG 8 months ago
parent
commit
d0690d671a
2 changed files with 23 additions and 2 deletions
  1. 1 1
      osmd-extended
  2. 22 1
      src/helpers/metronome.ts

+ 1 - 1
osmd-extended

@@ -1 +1 @@
-Subproject commit 8a653186333a6f49d85b61d348e9009ba2803a07
+Subproject commit 03fa7c2e5b7ad0445360e69636a441ec4f8ea97a

+ 22 - 1
src/helpers/metronome.ts

@@ -413,6 +413,10 @@ class Metronome {
 					metronomeData.firstBeatTypeArr = beatTypeArr
 				}
 				metroMeasure[i] = [] as number[];
+				// 根据有几个拍子,划分成几份
+				const widthStep = 100 / beatTypeArr.length;
+				// 当前拍子的组合数(2+3+2,3+2)中的数字
+				let beatNum = 0;
 				for (let j = 0; j < beatTypeArr.length; j++) {
 					// 累加
 					const beatMuit = Array(j).fill("").reduce((num:number,v:any,i:number) => {
@@ -420,13 +424,30 @@ class Metronome {
 					}, 0) || 0
 					const time = measure.time * beatMuit + measure.start;
 					metroList.push(time);
+					let left = "";
+					// 当前拍子数对应的节拍位置索引
+					let currentIdx = 0;
+					if (j == 0) {
+						currentIdx = 0
+					} else {
+						beatNum += Number(measure.CompoundTempo.split('+')[j]);
+						currentIdx = beatNum
+					}
+					if (measure.stepList[currentIdx]) {
+						left = measure.stepList[currentIdx] + "px";
+					} else {
+						const preLeft = measure.stepList[j - 1];
+						left = !preLeft ? `${widthStep*(j+1)}%` : preLeft.toString().indexOf("%") > -1 ? `${preLeft} + ${widthStep*(j+1)}%` : `${preLeft}px + ${widthStep*(j+1)}%`;
+						measure.stepList[j] = left;
+					}					
 					metroMeasure[i].push({
 						isTick: beatTypeArr[j] < 0,
 						index: j,
 						time,
-						left: 0,
+						left: left?.indexOf("%") > -1 ? `calc(${left})` : left,
 						measureNumberXML: measure.measureNumberXML,
 						isRestFlag: measure.isRestFlag,
+						stepList: measure.stepList
 					});
 				}
 			}