Sfoglia il codice sorgente

feat: 曲目:摇篮曲的倚音位置特殊处理

TIANYONG 1 anno fa
parent
commit
d8385821cf
3 ha cambiato i file con 64 aggiunte e 2 eliminazioni
  1. 34 0
      src/helpers/customMusicScore.ts
  2. 14 0
      src/helpers/formateMusic.ts
  3. 16 2
      src/state.ts

+ 34 - 0
src/helpers/customMusicScore.ts

@@ -180,6 +180,40 @@ export const resetFormate = () => {
 		const staveSection: SVGAElement[] = Array.from(staffline.querySelectorAll(".vf-measure .vf-staveSection"));
 		const paths: SVGAElement[] = Array.from(staffline.querySelectorAll(".vf-measure > .vf-stave path"));
 		const dotModifiers: SVGAElement[] = Array.from(staffline.querySelectorAll(".vf-measure .vf-stopDot"));
+		/**
+		 * TODO:曲目:摇篮曲(节奏练习)-倚音位置 特殊处理
+		 */
+		const specialIds = ['1788850864767643649','1788502467554750466'];
+		if (specialIds.includes(state.cbsExamSongId)) {
+			const lastCurve = Array.from(document.getElementsByClassName('vf-curve'))?.last();
+			if (lastCurve) {
+				lastCurve.style.display = 'none';
+			}
+			if (state.musicRenderType === 'staff') {
+				const transNoteDom = document.getElementById('vf-auto2182')?.getElementsByClassName('vf-modifiers')?.[0];
+				const transBeamDom = document.getElementById('auto3167')?.parentNode?.getElementsByClassName('vf-beams')?.[0];
+				if (transNoteDom) {
+					transNoteDom.style.transform = 'translateX(-0.5rem)';
+				}
+				if (transBeamDom) {
+					transBeamDom.style.transform = 'translateX(-0.5rem)';
+				}
+			} else {
+				const signatureDom = document.getElementById('auto2784');
+				const needTransLateDom = document.getElementById('vf-auto2178')?.getElementsByClassName('vf-modifier')?.[0];
+				const arrowDom = document.getElementById('vf-auto2178-lines');
+				if (signatureDom) {
+					signatureDom.style.display = 'none';
+				}
+				if (needTransLateDom) {
+					needTransLateDom.style.transform = 'translateX(-0.65rem)';
+				}
+				if (arrowDom) {
+					arrowDom.style.transform = 'translateX(-0.65rem)';
+				}
+			}
+
+		}
 
 		// 获取第一个线谱的y轴坐标
 		const firstLinePathY = paths[0]?.getBBox().y || 0

+ 14 - 0
src/helpers/formateMusic.ts

@@ -383,6 +383,7 @@ export const onlyVisible = (xml: string, partIndex: number): string => {
 	// console.log(visiblePartInfo, partIndex)
 	// 根据后台已选择的分轨筛选出能切换的声轨
 	state.partListNames = partListNames;
+	// console.log('分轨名称',state.partListNames)
 	if (visiblePartInfo) {
 		const id = visiblePartInfo.getAttribute("id");
 		Array.from(parts).forEach((part: any) => {
@@ -1164,6 +1165,7 @@ export const formateTimes = (osmd: OpenSheetMusicDisplay) => {
 			}
 			// console.log(note.sourceMeasure.MeasureNumberXML, note.sourceMeasure.verticalSourceStaffEntryContainers.length)
 			// console.log('👀看看endtime', nodeDetail.duration, relaEndtime, fixtime, i)
+			// console.log('音符时间',nodeDetail.i,nodeDetail.time)
 			tickables = tickables.filter((tickable: any) => tickable.attrs?.type !== "GhostNote")
 			const maxNum = (state.isCombineRender && note.maxNoteNum) ? note.maxNoteNum : tickables.length;
 			nodeDetail.noteLength = maxNum || 1;
@@ -1277,6 +1279,7 @@ const customizationXml = (xmlParse: any) => {
 	const credits: any = Array.from(xmlParse.querySelectorAll('credit'));
 	const creators: any = Array.from(xmlParse.querySelectorAll('creator'));
 	const graces: any = Array.from(xmlParse.querySelectorAll('grace'));
+	const measures: any[] = Array.from(xmlParse.getElementsByTagName("measure"));
 	if (credits && credits.length) {
 		for (const credit of credits) {
 			if (credit.getElementsByTagName("credit-type")?.[0]?.textContent === 'lyricist') {
@@ -1300,6 +1303,17 @@ const customizationXml = (xmlParse: any) => {
 			// console.log(grace,'倚音')
 		}
 	}
+	// 妙极客xml部分小节没有音符,只有Segno,该小节不需要渲染,表示的是反复标记
+	for (const measure of measures) {
+		const hasNote = measure.getElementsByTagName("note").length;
+		const hasSegno = measure.getElementsByTagName("segno").length;
+		const sounds = Array.from(measure.getElementsByTagName("sound"));
+		const hasSoundSegno = sounds.some((item: any) => item.getAttribute('segno') === 'segno' );
+		if (!hasNote && hasSegno && hasSoundSegno) {
+			const parent = measure.parentNode;
+			parent.removeChild(measure);
+		}
+	}
 }
 
 // 计算evxml的起始播放时间

+ 16 - 2
src/state.ts

@@ -549,7 +549,7 @@ const handlePlaying = () => {
   state.playProgress = (currentTime / duration) * 100;
   let item = getNote(currentTime);
   // console.log(11111,currentTime,duration,state.playSource, item)
-  // console.log(item.i,item.noteId,item.measureSpeed)
+  // console.log(item?.i,item?.noteId,item?.measureSpeed,'播放')
   // 练习模式下,实时刷新小节速度
   if (item && state.modeType === "practise" && state.playState === "play" && item.measureSpeed && item.measureSpeed !== state.playIngSpeed) {
     const ratio = state.speed / state.originSpeed
@@ -821,8 +821,22 @@ export const getNote = (currentTime: number) => {
   }
   let _item = null as any;
   for (let i = state.activeNoteIndex; i < len; i++) {
-    const item = times[i];
+    let item = times[i];
     const prevItem = times[i - 1];
+    // if (state.isEvxml) {
+    //   let diffArr: any[] = [];
+    //   times.forEach((note: any, noteIdx: number) => {
+    //     if (currentTime >= note.time && currentTime <= times[noteIdx+1].time) {
+    //       let diffTime = times[noteIdx+1].time - currentTime;
+    //       diffArr.push({
+    //         diffTime,
+    //         idx: noteIdx
+    //       })
+    //     }
+    //   })
+    //   diffArr.sort((a, b) => a.diffTime - b.diffTime);
+    //   item = diffArr.length ? times[diffArr[0].idx] : item;
+    // }
     if (currentTime >= item.time) {
       if (!prevItem || item.time != prevItem.time) {
         _item = item;