Browse Source

解决连续休止小节没有打时间,并且需要忽略的问题

黄琪勇 10 months ago
parent
commit
09f02f1e50
1 changed files with 21 additions and 1 deletions
  1. 21 1
      src/helpers/formateMusic.ts

+ 21 - 1
src/helpers/formateMusic.ts

@@ -1260,7 +1260,27 @@ export const formateTimes = (osmd: OpenSheetMusicDisplay) => {
 			 */
 			if (state.isEvxml && note.isRestFlag && note?.noteTimeInfo?.length === 0 && state.xmlHasTimes ) {
 				const idx = _notes.findIndex(item=>item.note === note);
-				const allowRange = Math.abs(_notes[idx+1]?.note?.noteTimeInfo?.[0]?.begin*1000 - _notes[idx-1]?.note?.noteTimeInfo?.[0]?.end*1000) < 10;
+				let nextNoteTimes = _notes[idx+1]?.note?.noteTimeInfo?.[0]?.begin*1000 
+				let preNoteTImes = _notes[idx-1]?.note?.noteTimeInfo?.[0]?.end*1000
+				// 当下一个音符也没有时间的时候,再往下一个找
+				if(!nextNoteTimes && nextNoteTimes!==0){
+					let nextIndex = idx + 2
+					while(!nextNoteTimes && nextIndex<_notes.length){
+						nextNoteTimes = _notes[nextIndex]?.note?.noteTimeInfo?.[0]?.begin*1000
+						nextIndex ++
+					}
+					// 当最后音符就是没有打时间的休止小节,可能nextNoteTimes时间找不到,目前没有处理
+				}
+				if(!preNoteTImes && preNoteTImes!==0){
+					let preIndex = idx - 2
+					while(!preNoteTImes && preIndex>-1){
+						preNoteTImes = _notes[preIndex]?.note?.noteTimeInfo?.[0]?.end*1000
+						preIndex --
+					}
+					// 当没有找到preNoteTImes的时候 赋值为0 (当第一个音符就是没有打时间的休止小节会出现这种情况)
+					preNoteTImes || (preNoteTImes = 0)
+				}
+				const allowRange = Math.abs(nextNoteTimes - preNoteTImes)< 10;
 				if (allowRange) {
 					note.maxNoteNum = note.maxNoteNum - 1;
 					// 唱名时间补齐,当删除这个音符的时候,上个音符的持续时间要加上这个音符的时间