Bladeren bron

feat: xml移调兼容处理

TIANYONG 1 jaar geleden
bovenliggende
commit
38bf7d79d7
3 gewijzigde bestanden met toevoegingen van 41 en 4 verwijderingen
  1. 1 1
      osmd-extended
  2. 38 1
      src/helpers/formateMusic.ts
  3. 2 2
      vite.config.ts

+ 1 - 1
osmd-extended

@@ -1 +1 @@
-Subproject commit 9d41c99bb92f1a836080f4a62e44211dbec45379
+Subproject commit 47b9fe957f556ddcf7904c6cc9952be34cad471f

+ 38 - 1
src/helpers/formateMusic.ts

@@ -596,7 +596,8 @@ export const formatXML = (xml: string): string => {
 	if (!xml) return "";
 	const xmlParse = new DOMParser().parseFromString(xml, "text/xml");
 	const measures = Array.from(xmlParse.getElementsByTagName("measure"));
-	const repeats: any = Array.from(xmlParse.querySelectorAll('repeat'))
+	const repeats: any = Array.from(xmlParse.querySelectorAll('repeat'));
+	compatibleXmlPitchVoice(xmlParse);
 	// 处理重复小节信息
 	parseXmlToRepeat(repeats)
 	// const words: any = xmlParse.getElementsByTagName("words");
@@ -1127,4 +1128,40 @@ export const verifyCanRepeat = (startNum: number, endNum: number) => {
 			canRepeat: false
 		}
 	}
+}
+
+/**
+ * 兼容处理xml声部移调
+ * 打谱软件可能会自动处理移调,这类型的xml就不用通过程序移调了
+ * 没有通过软件处理的移调xml,才需要通过程序处理
+ * 判读规则:只处理独奏的,不处理合奏的,
+ * <instrument-name></instrument-name>标签的值为:Tenor Recorder(竖笛)、Panpipes(排箫)、Ocarina(陶笛)、空的和solo,需要程序处理移调
+ */
+export const compatibleXmlPitchVoice = (xmlParse: any) => {
+	const partNames = Array.from(xmlParse.getElementsByTagName('part-name'));
+	const partListNames = partNames.map((item: any) => item[0]?.textContent?.trim().toLocaleUpperCase !== "COMMON");
+	if (partListNames.length == 1) {
+		const instrumentNames = Array.from(xmlParse.getElementsByTagName('instrument-name')) || [];
+		// @ts-ignore
+		const instrumentName = instrumentNames[0]?.textContent?.trim()?.toLocaleLowerCase() || ''
+		// console.log('ins名称',instrumentName)
+		// 是否需要程序处理移调
+		let xmlNeedAdjustVoice = false;
+		switch (state.musicalCodeId) {
+			case 37:
+			case 38:
+				xmlNeedAdjustVoice = !instrumentName || instrumentName.includes('solo') || instrumentName.includes('tenor recorder') ? true : false
+				break;
+			case 33:
+				xmlNeedAdjustVoice = !instrumentName || instrumentName.includes('solo') || instrumentName.includes('panpipes') ? true : false
+				break;
+			case 34:
+				xmlNeedAdjustVoice = !instrumentName || instrumentName.includes('solo') || instrumentName.includes('ocarina') ? true : false
+				break;
+			default:
+				xmlNeedAdjustVoice = !instrumentName || instrumentName.includes('solo') ? true : false
+				break;
+		}
+		(window as any).xmlNeedAdjustVoice = xmlNeedAdjustVoice
+	}
 }

+ 2 - 2
vite.config.ts

@@ -68,8 +68,8 @@ export default defineConfig({
 				// target: "https://test.lexiaoya.cn",
 				// target: "https://dev.kt.colexiu.com",
 				// target: "https://test.resource.colexiu.com", // 内容平台开发环境,内容平台开发,需在url链接上加上isCbs=true
-				// target: "https://test.resource.colexiu.com",
-				target: "https://test.kt.colexiu.com",
+				target: "https://test.resource.colexiu.com",
+				// target: "https://test.kt.colexiu.com",
 				changeOrigin: true,
 				rewrite: (path) => path.replace(/^\/instrument/, ""),
 			},