|
@@ -15,6 +15,7 @@ import {
|
|
|
} from "/osmd-extended/src";
|
|
|
import { GradualChange, speedInfo } from "./calcSpeed";
|
|
|
import { beatUnitTo, speedBeatTo } from "/src/helpers/beatConfig"
|
|
|
+import { xmlDocRef } from "/src/view/music-score"
|
|
|
|
|
|
const browserInfo = browser();
|
|
|
dayjs.extend(duration);
|
|
@@ -250,13 +251,16 @@ export type CustomInfo = {
|
|
|
};
|
|
|
|
|
|
/** 从xml中获取自定义信息,并删除多余的字符串 */
|
|
|
-export const getCustomInfo = (xml: string): CustomInfo => {
|
|
|
+export const getCustomInfo = (xml: string, resourceType?: string): CustomInfo => {
|
|
|
const data = {
|
|
|
showSpeed: true,
|
|
|
parsedXML: xml,
|
|
|
};
|
|
|
- const xmlParse = new DOMParser().parseFromString(xml, "text/xml");
|
|
|
- const words: any = xmlParse.getElementsByTagName("words");
|
|
|
+ //console.time('解析xml 耗时3')
|
|
|
+ // const xmlParse = new DOMParser().parseFromString(xml, "text/xml");
|
|
|
+ const xmlParse = xmlDocRef.value && resourceType === 'init' ? xmlDocRef.value : new DOMParser().parseFromString(xml, "text/xml");
|
|
|
+ //console.timeEnd('解析xml 耗时3')
|
|
|
+ const words: any = xmlParse?.getElementsByTagName("words");
|
|
|
for (const word of words) {
|
|
|
if (word && word.textContent?.trim() === "隐藏速度") {
|
|
|
data.showSpeed = false;
|
|
@@ -365,7 +369,10 @@ export const onlyVisible = (xml: string, partIndex: number, resourceType?: strin
|
|
|
if (!xml) return "";
|
|
|
// console.log('原始xml')
|
|
|
const detailId = state.cbsExamSongId + "";
|
|
|
- const xmlParse = new DOMParser().parseFromString(xml, "text/xml");
|
|
|
+ //console.time('解析xml 耗时4')
|
|
|
+ // const xmlParse = new DOMParser().parseFromString(xml, "text/xml");
|
|
|
+ const xmlParse = xmlDocRef.value && !resourceType ? xmlDocRef.value : new DOMParser().parseFromString(xml, "text/xml");
|
|
|
+ //console.timeEnd('解析xml 耗时4')
|
|
|
const partList = xmlParse.getElementsByTagName("part-list")?.[0]?.getElementsByTagName("score-part") || [];
|
|
|
const partListNames = Array.from(partList).map((item) => item.getElementsByTagName("part-name")?.[0]?.textContent?.trim() || "");
|
|
|
const parts: any = xmlParse.getElementsByTagName("part");
|
|
@@ -535,7 +542,9 @@ export const onlyVisible2 = (xml: string): string => {
|
|
|
if (!xml) return "";
|
|
|
// console.log('原始xml')
|
|
|
//const detailId = state.cbsExamSongId + "";
|
|
|
+ console.time('解析xml 耗时5')
|
|
|
const xmlParse = new DOMParser().parseFromString(xml, "text/xml");
|
|
|
+ console.timeEnd('解析xml 耗时5')
|
|
|
const partList = xmlParse.getElementsByTagName("part-list")?.[0]?.getElementsByTagName("score-part") || [];
|
|
|
//const partListNames = Array.from(partList).map((item) => item.getElementsByTagName("part-name")?.[0]?.textContent?.trim() || "");
|
|
|
//state.partListNames = partListNames;
|
|
@@ -628,7 +637,9 @@ export const formatZoom = (num = 1) => {
|
|
|
/** 妙极客多分轨的曲子,可能没有part-name标签,需要手动加上该标签 */
|
|
|
export const xmlAddPartName = (xml: string) => {
|
|
|
if (!xml) return "";
|
|
|
+ console.time('解析xml 耗时')
|
|
|
const xmlParse = new DOMParser().parseFromString(xml, "text/xml");
|
|
|
+ console.timeEnd('解析xml 耗时')
|
|
|
const scoreParts = Array.from(xmlParse.getElementsByTagName("score-part"));
|
|
|
for (const scorePart of scoreParts) {
|
|
|
if (scorePart.getElementsByTagName("part-name").length === 0) {
|
|
@@ -642,15 +653,19 @@ export const xmlAddPartName = (xml: string) => {
|
|
|
scorePart.getElementsByTagName("part-name")[0].textContent = scorePart.getAttribute("id") || "";
|
|
|
}
|
|
|
}
|
|
|
+ xmlDocRef.value = xmlParse;
|
|
|
return new XMLSerializer().serializeToString(xmlParse);
|
|
|
}
|
|
|
|
|
|
/** 格式化曲谱
|
|
|
* 1.全休止符的小节,没有音符默认加个全休止符
|
|
|
*/
|
|
|
-export const formatXML = (xml: string, xmlUrl?: string): string => {
|
|
|
+export const formatXML = (xml: string, xmlUrl?: string, resourceType?: string): string => {
|
|
|
if (!xml) return "";
|
|
|
- const xmlParse = new DOMParser().parseFromString(xml, "text/xml");
|
|
|
+ //console.time('解析xml 耗时7')
|
|
|
+ // const xmlParse = new DOMParser().parseFromString(xml, "text/xml");
|
|
|
+ const xmlParse = xmlDocRef.value && resourceType === 'init' ? xmlDocRef.value : new DOMParser().parseFromString(xml, "text/xml");
|
|
|
+ //console.timeEnd('解析xml 耗时7')
|
|
|
|
|
|
// 声调
|
|
|
const fifths = xmlParse.getElementsByTagName("fifths");
|
|
@@ -741,6 +756,7 @@ export const formatXML = (xml: string, xmlUrl?: string): string => {
|
|
|
// 前面小节的拍子
|
|
|
let preBeats: number = 4;
|
|
|
let preBeatType: number = 4;
|
|
|
+ let baseDivisions: number = 256;
|
|
|
// 小节中如果没有节点默认为休止符
|
|
|
for (const measure of measures) {
|
|
|
if (beats === -1 && measure.getElementsByTagName("beats").length) {
|
|
@@ -757,7 +773,8 @@ export const formatXML = (xml: string, xmlUrl?: string): string => {
|
|
|
const currentBeatType = measure.getElementsByTagName("beat-type").length ? measure.getElementsByTagName("beat-type")[0]?.textContent : preBeatType;
|
|
|
preBeats = Number(currentBeats);
|
|
|
preBeatType = Number(currentBeatType);
|
|
|
- const divisions = parseInt(measure.getElementsByTagName("divisions")[0]?.textContent || "256");
|
|
|
+ const divisions = parseInt(measure.getElementsByTagName("divisions")[0]?.textContent || String(baseDivisions));
|
|
|
+ baseDivisions = divisions
|
|
|
// 如果note节点里面有space节点,并且没有duration节点,代表这是一个空白节点,需要删除
|
|
|
if (measure.getElementsByTagName("note").length && state.isEvxml) {
|
|
|
const noteList = Array.from(measure.getElementsByTagName("note")) || [];
|
|
@@ -1392,6 +1409,7 @@ export const formateTimes = (osmd: OpenSheetMusicDisplay) => {
|
|
|
isStaccato: note.voiceEntry.isStaccato(),
|
|
|
isRestFlag: note.isRestFlag,
|
|
|
noteId: note.NoteToGraphicalNoteObjectId,
|
|
|
+ // noteId: note.NoteToGraphicalNoteObjectId || `restNote${note.sourceMeasure.MeasureNumberXML}`,
|
|
|
measureListIndex: note.sourceMeasure.measureListIndex,
|
|
|
MeasureNumberXML: note.sourceMeasure.MeasureNumberXML, // 当前的小节数,(从1开始)
|
|
|
_noteLength: _noteLength,
|