Browse Source

fix: 妙极客曲子部分bug修复

TIANYONG 10 months ago
parent
commit
e08e305db0

+ 37 - 0
src/helpers/formateMusic.ts

@@ -17,6 +17,11 @@ const browserInfo = browser();
 dayjs.extend(duration);
 
 /**
+ * 需要隐藏的中文速度文本
+ */
+const hideSpeedWords: string[] = ["中速"];
+
+/**
  * 获取节拍器的时间
  * @param speed 速度
  * @param firstMeasure 曲谱第一个小节
@@ -624,6 +629,7 @@ export const formatXML = (xml: string, xmlUrl?: string): string => {
 	// 解析处理evxml
 	if (state.isEvxml) {
 		analyzeEvxml(xmlParse, xmlUrl);
+		customizationXml(xmlParse);
 	}
 	// const words: any = xmlParse.getElementsByTagName("words");
 	// for (const word of words) {
@@ -660,6 +666,15 @@ export const formatXML = (xml: string, xmlUrl?: string): string => {
 				}
 			});
 		}
+		// 如果有特殊中文速度文本,需要删除
+		if (measure.getElementsByTagName("words").length && state.isEvxml) {
+			const wordList = Array.from(measure.getElementsByTagName("words")) || [];
+			wordList.forEach((word: any) => {
+				if(hideSpeedWords.includes(word?.textContent) && word?.parentNode?.parentNode) {
+					measure.removeChild(word.parentNode.parentNode);
+				}
+			})
+		}
 		if (measure.getElementsByTagName("note").length === 0) {
 			const forwardTimeElement = measure.getElementsByTagName("forward")[0]?.getElementsByTagName("duration")[0];
 			if (forwardTimeElement) {
@@ -1254,6 +1269,28 @@ export const verifyCanRepeat = (startNum: number, endNum: number) => {
 	}
 }
 
+// 处理妙极客xml谱面
+const customizationXml = (xmlParse: any) => {
+	const credits: any = Array.from(xmlParse.querySelectorAll('credit'));
+	const creators: any = Array.from(xmlParse.querySelectorAll('creator'));
+	if (credits && credits.length) {
+		for (const credit of credits) {
+			if (credit.getElementsByTagName("credit-type")?.[0]?.textContent === 'lyricist') {
+				const creditWord = credit.getElementsByTagName("credit-words")
+				creditWord?.[0].setAttribute('justify', 'right')
+			}
+		}
+	}
+	if (creators && creators.length) {
+		for (const creator of creators) {
+			if (creator.getAttribute('type') === 'lyricist') {
+				// creator.textContent = '测试一下1';
+			}
+			
+		}
+	}
+}
+
 // 计算evxml的起始播放时间
 const analyzeEvxml = (xmlParse: any, xmlUrl?: string) => {
 	// xml拍号数

+ 0 - 1
src/page-instrument/view-detail/index.tsx

@@ -375,7 +375,6 @@ export default defineComponent({
       detailData.fingerPreView = false;
       detailData.fingerPreViewGuide = false;
     };
-    console.log(1111222,state.zoom)
     return () => (
       <div
         class={[styles.detail, state.setting.eyeProtection && "eyeProtection", (state.platform === IPlatform.PC && state.zoom > 0.8) && styles.PC, state.isPreView && styles.preViewDetail, state.isSingleLine && styles.singleLineDetail]}

+ 7 - 0
src/state.ts

@@ -1253,6 +1253,11 @@ export const followBeatPaly = () => {
 
 // 音符添加bbox
 export const addNoteBBox = (list: any[]) => {
+  const musicContainer = document.getElementById("musicAndSelection")?.getBoundingClientRect() || {
+		x: 0,
+		y: 0,
+	};
+	const parentLeft = musicContainer.x || 0;
   let voicesBBox: any = null;
   for (let i = 0; i < list.length; i++) {
     const note = list[i];
@@ -1264,7 +1269,9 @@ export const addNoteBBox = (list: any[]) => {
     if (svgElement?.attrs.id) {
       // @ts-ignore
       bbox = document.getElementById(`vf-${svgElement?.attrs?.id}`)?.getBBox();
+      const noteBbox = document.getElementById(`vf-${svgElement?.attrs?.id}`)?.getBoundingClientRect?.() || { x: 0, width: 0 };
       bbox = {
+        left: noteBbox.x - parentLeft - noteBbox.width / 4, // 用于简谱模式,跳动音符时,设置光标的位置(五线谱:osmd自动设置光标位置,简谱:需要手动设置光标位置)
         x: bbox?.x * state.zoom,
         y: bbox?.y * state.zoom,
         width: bbox?.width * state.zoom,

+ 3 - 3
src/view/music-score/index.tsx

@@ -101,7 +101,8 @@ export default defineComponent({
 				autoResize: false,
 				followCursor: false,
 				drawPartNames: props.showPartNames, // 是否渲染声轨名称
-				drawComposer: false, // 渲染作者
+				// drawLyricist: false, // 渲染作曲家
+				// drawComposer: false, // 渲染作词家
 				defaultColorMusic: props.musicColor, // 颜色
 				renderSingleHorizontalStaffline: state.isSingleLine ? true : false,
 				autoGenerateMultipleRestMeasuresFromRestMeasures: state.isSingleLine ? false : true, // 连续休止小节是否合并显示
@@ -109,7 +110,6 @@ export default defineComponent({
 				// pageFormat: 'A4_P',
 				// autoBeam: true,
 				// drawMetronomeMarks: false,
-				// drawLyricist: false,
 				// ...this.opotions,
 				
 			});
@@ -137,7 +137,7 @@ export default defineComponent({
 			await osmd.load(musicData.score);
 			osmd.zoom = state.zoom;
 			osmd.render();
-			// console.log("🚀 ~ osmd:", osmd)
+			console.log("🚀 ~ osmd:", osmd)
 			emit("rendered", osmd);
 			resetFormate();
 			resetGivenFormate();

+ 2 - 2
vite.config.ts

@@ -75,8 +75,8 @@ export default defineConfig({
       "^/instrument/.*": {
         // target: "https://kt.colexiu.com",
         // target: "https://test.lexiaoya.cn",
-        target: "https://kt.colexiu.com",
-        // target: "https://test.resource.colexiu.com", // 内容平台开发环境,内容平台开发,需在url链接上加上isCbs=true
+        // target: "https://kt.colexiu.com",
+        target: "https://test.resource.colexiu.com", // 内容平台开发环境,内容平台开发,需在url链接上加上isCbs=true
         // target: "https://dev.resource.colexiu.com",
         // target: "https://test.kt.colexiu.com",
         // target: "https://mec.colexiu.com",