Forráskód Böngészése

feat: 支持fine标记渲染和播放逻辑

TIANYONG 2 hónapja
szülő
commit
03f89dcb04
4 módosított fájl, 32 hozzáadás és 4 törlés
  1. 1 1
      osmd-extended
  2. 29 1
      src/helpers/formateMusic.ts
  3. 1 1
      src/state.ts
  4. 1 1
      src/view/music-score/index.tsx

+ 1 - 1
osmd-extended

@@ -1 +1 @@
-Subproject commit 43dc4f3b6489924056a28b1c1c5a40771d150378
+Subproject commit 07fa2b7e680fd4be6fcc4c586030484c7fa6f8dd

+ 29 - 1
src/helpers/formateMusic.ts

@@ -787,6 +787,32 @@ export const formatXML = (xml: string, xmlUrl?: string): string => {
 };
 
 
+/** 处理fine标记播放逻辑 */
+export const filterNoteByFine = (notes: any[]) => {
+	let filterNotes: any[] = [];
+	for (let idx = 0; idx < notes.length; idx++) {
+		const note = notes[idx]?.note;
+		const nextNote = notes[idx+1]?.note
+		const isFine = note.sourceMeasure.lastRepetitionInstructions?.findIndex((repeat: any) => repeat.type == 6) >= 0;
+		if (isFine) {
+			// 判断当前的fine音符是否是最后一遍循环
+			const rightIds = notes.slice(idx).map((right: any) => right.note?.NoteToGraphicalNoteObjectId)
+			let isLast = 0;
+			rightIds.forEach((num: any) => num === note.NoteToGraphicalNoteObjectId && (isLast+=1) )
+			// console.log(isLast,'last',rightIds,note.NoteToGraphicalNoteObjectId)
+			if (note?.sourceMeasure?.MeasureNumberXML !== nextNote?.sourceMeasure?.MeasureNumberXML && isLast == 1) {
+				filterNotes.push(notes[idx])
+				break;
+			} else {
+				filterNotes.push(notes[idx])
+			}
+		} else {
+			filterNotes.push(notes[idx])
+		}
+	}
+	return filterNotes
+}
+
 /** 获取所有音符的时值,以及格式化音符 */
 export const formateTimes = (osmd: OpenSheetMusicDisplay) => {
 	const customNoteRealValue = customData.customNoteRealValue;
@@ -852,7 +878,7 @@ export const formateTimes = (osmd: OpenSheetMusicDisplay) => {
 
 	let preNoteMeasureNumber: any = null; // 上一个小节的number值
 
-	const _notes = [] as any[];
+	let _notes = [] as any[];
 	if (state.gradualTimes) {
 		console.log("后台设置的渐慢小节时间", state.gradual, state.gradualTimes);
 	}
@@ -985,6 +1011,8 @@ export const formateTimes = (osmd: OpenSheetMusicDisplay) => {
 	}
 	// 是否是变速的曲子
 	const hasVaryingSpeed = _notes.some((item: any) => item.measuresTempoInBPM !== _notes[0].measuresTempoInBPM)
+	// 循环时,遇到fine标记,最后一遍,需要立即结束
+	_notes = filterNoteByFine(_notes)
 	console.log('变速曲子',hasVaryingSpeed, _notes)
 	let noteIds: any = [];
 	// let voicesBBox: any = null;

+ 1 - 1
src/state.ts

@@ -1425,7 +1425,7 @@ function xmlToTracks(xmlString: string) {
   const partNames = Array.from(xmlParse.getElementsByTagName('part-name'));
   return partNames.reduce((arr: string[], item) => {
     const textContent = item?.textContent?.trim()
-    if (textContent != "COMMON" && textContent != "common" && textContent) {
+    if (textContent?.trim()?.toLocaleLowerCase() !== "common" && textContent) {
       arr.push(textContent)
     }
     return arr

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

@@ -210,7 +210,7 @@ export default defineComponent({
 			const activeMeasureIndex = state.times[state.activeNoteIndex]?.measureListIndex || -1;
 			for (const [first, last] of state.gradual) {
 				if (first && last) {
-					console.log('小节',first.measureIndex,last.measureIndex,activeMeasureIndex)
+					// console.log('小节',first.measureIndex,last.measureIndex,activeMeasureIndex)
 					result = first.measureIndex <= activeMeasureIndex && activeMeasureIndex < last.measureIndex;
 					if (result) {
 						break;