Browse Source

单声轨包含两个声部计算节拍器时长问题修复

TIANYONG 2 months ago
parent
commit
f8e857580b
4 changed files with 18 additions and 5 deletions
  1. 1 1
      src/helpers/calcSpeed.ts
  2. 14 2
      src/helpers/formateMusic.ts
  3. 1 0
      src/state.ts
  4. 2 2
      vite.config.ts

+ 1 - 1
src/helpers/calcSpeed.ts

@@ -116,7 +116,7 @@ export type GradualItem = {
  * @param xml 始终按照第一分谱进行减慢速度的计算
  */
 export const getGradualLengthByXml = (xml: string) => {
-	const firstPartXml = onlyVisible(xml, 0)
+	const firstPartXml = onlyVisible(xml, 0, 'calc')
 	const xmlParse = new DOMParser().parseFromString(firstPartXml, "text/xml");
 	const measures = Array.from(xmlParse.querySelectorAll("measure"));
 	const notes = Array.from(xmlParse.querySelectorAll("note"));

+ 14 - 2
src/helpers/formateMusic.ts

@@ -362,7 +362,7 @@ export const isRepeatWord = (text: string): boolean => {
 	return false;
 };
 
-export const onlyVisible = (xml: string, partIndex: number): string => {
+export const onlyVisible = (xml: string, partIndex: number, resourceType?: string): string => {
 	if (!xml) return "";
 	// console.log('原始xml')
 	const detailId = state.examSongId + "";
@@ -500,6 +500,17 @@ export const onlyVisible = (xml: string, partIndex: number): string => {
 
 			// 最后一个小节的结束线元素不在最后 调整
 			if (part && part.getAttribute("id") === id) {
+				if (!resourceType) {
+					const backups = Array.from(part.getElementsByTagName('backup')) || []
+					for (let backup of backups) {
+						// @ts-ignore
+						if (backup && backup?.getElementsByTagName('duration')?.length) {
+							state.isSingleMutliTrack = true;
+							break;
+						}
+					}
+					state.isSingleMutliTrack = part.getElementsByTagName('backup').length > 0 ? true : false;
+				}
 				const barlines = part.getElementsByTagName("barline");
 				const lastParent = barlines[barlines.length - 1]?.parentElement;
 				if (lastParent?.lastElementChild?.tagName !== "barline") {
@@ -1514,8 +1525,9 @@ 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,nodeDetail.endtime)
+
 			tickables = tickables.filter((tickable: any) => tickable.attrs?.type !== "GhostNote")
-			let maxNum = (state.isCombineRender && note.maxNoteNum) ? note.maxNoteNum : tickables.length;
+			let maxNum = (state.isCombineRender && note.maxNoteNum) || state.isSingleMutliTrack ? note.maxNoteNum : tickables.length;
 			// 妙极客的曲子,一个休止小节内可能有多个休止符,此时maxNum是0,需要针对这种情况作处理
 			if (note.isRestFlag && maxNum === 0) {
 				maxNum = note.maxNoteNum;

+ 1 - 0
src/state.ts

@@ -592,6 +592,7 @@ const state = reactive({
   isAutoRePlay: false,
   /** 右上角速度图标,根据当前小节的速度是几分音符的动态变化 */
   speedIcon: 'speed3', // 默认取1/4拍的图片
+  isSingleMutliTrack: false, // 是否是单声轨多声部的声轨
 });
 const browserInfo = browser();
 let offset_duration = 0;

+ 2 - 2
vite.config.ts

@@ -76,8 +76,8 @@ export default defineConfig({
         // 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://test.kt.colexiu.com",
+        target: "https://test.resource.colexiu.com", // 内容平台开发环境,内容平台开发,需在url链接上加上isCbs=true
+        // target: "https://test.kt.colexiu.com",
         // target: "https://mec.colexiu.com",
         changeOrigin: true,
         rewrite: (path) => path.replace(/^\/instrument/, ""),