Browse Source

feat: 带有rit的xml,小节数从0开始时,异常处理

TIANYONG 2 weeks ago
parent
commit
6e882875bd
3 changed files with 4 additions and 1 deletions
  1. 1 0
      src/helpers/formateMusic.ts
  2. 1 1
      src/helpers/metronome.ts
  3. 2 0
      src/state.ts

+ 1 - 0
src/helpers/formateMusic.ts

@@ -660,6 +660,7 @@ export const formatXML = (xml: string, xmlUrl?: string): string => {
 	}
 
 	const measures = Array.from(xmlParse.getElementsByTagName("measure"));
+	state.firstMeasureNumber = measures[0] ? Number(measures[0].getAttribute('number') || 1) : 1;
 	const minutes: any = xmlParse.getElementsByTagName("per-minute");
 	let speeds: any = []
 	for (const minute of minutes) {

+ 1 - 1
src/helpers/metronome.ts

@@ -320,7 +320,7 @@ class Metronome {
 			// console.log("🚀 ~ note?.noteElement?.sourceMeasure", note?.noteElement?.sourceMeasure)
 			// console.log("🚀 ~ measureNumberXML", measureNumberXML, note)
 			// console.log("🚀 ~ measureNumberXML", note)
-			const measureListIndex = measureNumberXML - 1;
+			const measureListIndex = state.firstMeasureNumber == 0 ? measureNumberXML : measureNumberXML - 1;
 			// 当渐快渐慢的时候  不播节拍器
 			if(isWithinRange(state.gradual, measureListIndex)){
 				xmlNumber = measureNumberXML;

+ 2 - 0
src/state.ts

@@ -608,6 +608,8 @@ const state = reactive({
   hasFollowResult: false,  
   /** 右上角速度图标,根据当前小节的速度是几分音符的动态变化 */
   speedIcon: 'speed3', // 默认取1/4拍的图片
+  /** xml的第一个measure标签的number */
+  firstMeasureNumber: 1,
   /** 曲目点播价格 */
   musicPrice: 0,
   /** 专辑id */