Преглед на файлове

feat: 多个声轨合并显示问题修改

TIANYONG преди 6 месеца
родител
ревизия
922fe44e0a
променени са 2 файла, в които са добавени 9 реда и са изтрити 2 реда
  1. 2 1
      src/helpers/formateMusic.ts
  2. 7 1
      src/state.ts

+ 2 - 1
src/helpers/formateMusic.ts

@@ -862,6 +862,7 @@ export const formateTimes = (osmd: OpenSheetMusicDisplay) => {
 	let repeatIdx = 0; // 循环的次数
 	// 当多选声部的时候 ,取选择的第一个声部
 	const firstTrackName = state.combinePartIndexs.length>1 ? state.partListNames[state.combinePartIndexs[0]] : state.canSelectTracks[0] || "";
+	const currentTrackIndex = state.isCombineRender && state.combinePartIndexs.length > 1 ? state.combinePartIndexs[0] : 0;
 	while (!iterator.EndReached) {
 		// console.log({ ...iterator });
 		/** 多声轨合并显示,当前音符的时值取所有声轨中的最小值 */
@@ -1041,7 +1042,7 @@ export const formateTimes = (osmd: OpenSheetMusicDisplay) => {
 				note.sourceMeasure.verticalMeasureList = note.sourceMeasure?.verticalMeasureList.filter((item: any) => state.canSelectTracks.includes(item?.parentStaff?.parentInstrument.Name))
 			}
 
-			activeVerticalMeasureList = [note.sourceMeasure?.verticalMeasureList?.[0]] || [];
+			activeVerticalMeasureList = [note.sourceMeasure?.verticalMeasureList?.[currentTrackIndex]] || [];
 			// 某些情况下,合并显示的妙极客曲子,note.sourceMeasure?.verticalMeasureList可能为空数组
 			if (state.isCombineRender && state.isEvxml && note.sourceMeasure?.verticalMeasureList.length === 0) {
 				activeVerticalMeasureList = osmd.GraphicSheet.MeasureList.find((item: any) => item[0]?.MeasureNumber === note.sourceMeasure.MeasureNumberXML) || [];

+ 7 - 1
src/state.ts

@@ -1392,7 +1392,7 @@ const getMusicInfo = async (res: any) => {
   let partIndexs = query["part-index"] ? query["part-index"].split(",") : ["-1"] // -1为partIndex没有值的时候
   partIndexs = partIndexs.map((indexStr:string) => {
     return parseInt(indexStr)
-  })
+  }).sort();
   let partIndex = partIndexs[0]
   // 当partIndexs 大于1个的时候,代表用户自己选择了多个声部,用总谱渲染的逻辑
   if(partIndexs.length > 1){
@@ -1413,6 +1413,12 @@ const getMusicInfo = async (res: any) => {
   xmlString = xmlAddPartName(xmlString);
   downloadXmlStr.value = xmlString //给musice-score 赋值xmlString 以免加载2次
   const tracks = xmlToTracks(xmlString) //获取声轨列表
+  // 如果是多个分轨合并显示的,需要记录下所选分轨的第一个分轨的名字,渲染计算音符位置的时候需要根据第一个分轨找到对应音符的位置
+  if (state.combinePartIndexs.length) {
+    (window as any).DYFirstTrackName = tracks[state.combinePartIndexs[0]] || '';
+  } else {
+    (window as any).DYFirstTrackName = '';
+  }
   // 设置音源  track 为当前的声轨 index为当前的
   const { track, index, musicalInstrumentId } = state.isSimplePage ? { track:tracks[0], index:0, musicalInstrumentId: '' } : initMusicSource(res.data, tracks, partIndex, workRecordInstrumentId)
   // 这里返回的track可能和实际的对不上,所以重新筛选一下