|
@@ -185,10 +185,10 @@ interface IRenderMeasuresOption {
|
|
|
showTitle?: boolean;
|
|
|
showCreator?: boolean;
|
|
|
}
|
|
|
-/**
|
|
|
+/**
|
|
|
* 生成小节
|
|
|
* @param abc
|
|
|
- *
|
|
|
+ *
|
|
|
* @returns
|
|
|
*/
|
|
|
export const renderMeasures = (abc: IAbc, option?: IRenderMeasuresOption) => {
|
|
@@ -196,7 +196,7 @@ export const renderMeasures = (abc: IAbc, option?: IRenderMeasuresOption) => {
|
|
|
let wrap = 1;
|
|
|
let text = `X:1\n`;
|
|
|
|
|
|
- if (option?.showTitle){
|
|
|
+ if (option?.showTitle) {
|
|
|
abc.title && (text += abc.title + "\n");
|
|
|
}
|
|
|
if (option?.showCreator) {
|
|
@@ -211,43 +211,43 @@ export const renderMeasures = (abc: IAbc, option?: IRenderMeasuresOption) => {
|
|
|
const measures = abc.measures;
|
|
|
for (let i = 0; i < measures.length; i++) {
|
|
|
const measure = measures[i];
|
|
|
- text += measure.repeat ?? '';// 重复
|
|
|
- text += measure.meter ?? '';// 拍号
|
|
|
+ text += measure.repeat ?? ""; // 重复
|
|
|
+ text += measure.meter ?? ""; // 拍号
|
|
|
for (let j = 0; j < measure.notes.length; j++) {
|
|
|
const note = measure.notes[j];
|
|
|
const playStr = note.play?.join("") ?? "";
|
|
|
|
|
|
- text += note.clef ?? ''; // 谱号
|
|
|
- text += note.key ?? ''; // 调号
|
|
|
- text += note.speed ?? ''; // 速度
|
|
|
- text += note.slus ?? ''; // 3连音
|
|
|
+ text += note.clef ?? ""; // 谱号
|
|
|
+ text += note.key ?? ""; // 调号
|
|
|
+ text += note.speed ?? ""; // 速度
|
|
|
+ text += note.slus ?? ""; // 3连音
|
|
|
if (note.tie?.includes("(")) {
|
|
|
// 连音线 前
|
|
|
- text += note.tie ?? '';
|
|
|
+ text += note.tie ?? "";
|
|
|
}
|
|
|
- if (!option?.hiddenIndex){
|
|
|
+ if (!option?.hiddenIndex) {
|
|
|
text += `"<${i + "." + j}"`; // 音符 id
|
|
|
}
|
|
|
- text += playStr ?? ''; // 演奏技法
|
|
|
- text += note.dynamics ?? ''; // 力度符号
|
|
|
- text += note.accidental ?? ''; // 临时升降记号
|
|
|
- text += note.content ?? ''; // 音符
|
|
|
+ text += playStr ?? ""; // 演奏技法
|
|
|
+ text += note.dynamics ?? ""; // 力度符号
|
|
|
+ text += note.accidental ?? ""; // 临时升降记号
|
|
|
+ text += note.content ?? ""; // 音符
|
|
|
// 音符时值
|
|
|
- text += note.noteType ?? '';
|
|
|
- text += note.dot ?? ''; // 点
|
|
|
+ text += note.noteType ?? "";
|
|
|
+ text += note.dot ?? ""; // 点
|
|
|
|
|
|
- text += note.tieline ?? ''; // 延音
|
|
|
+ text += note.tieline ?? ""; // 延音
|
|
|
if (note.tie?.includes(")")) {
|
|
|
// 连音线 后
|
|
|
- text += note.tie ?? '';
|
|
|
+ text += note.tie ?? "";
|
|
|
}
|
|
|
- text += note.segno ?? ''; // 分割
|
|
|
+ text += note.segno ?? ""; // 分割
|
|
|
}
|
|
|
let _i = i + 1;
|
|
|
if (!option?.hiddenIndex) {
|
|
|
- text += `"<${_i}"`
|
|
|
+ text += `"<${_i}"`;
|
|
|
}
|
|
|
- text += measure.barline ?? '';
|
|
|
+ text += measure.barline ?? "";
|
|
|
if (wrap % 4 === 0) {
|
|
|
text += "\n";
|
|
|
}
|
|
@@ -294,7 +294,23 @@ export const moveNoteKey = (note: string, moveData: { step: number; move: number
|
|
|
return note;
|
|
|
};
|
|
|
|
|
|
-export const formateAbc = (visualObj: TuneObject) => {
|
|
|
+const formateGetData = {
|
|
|
+ getNoteType: (duration: number) => {
|
|
|
+ const type = 0.25 / duration;
|
|
|
+ console.log(type);
|
|
|
+ const noteType = [
|
|
|
+ { name: 0.25, value: "4" },
|
|
|
+ { name: 0.5, value: "2" },
|
|
|
+ { name: 1, value: "" },
|
|
|
+ { name: 2, value: "/" },
|
|
|
+ { name: 4, value: "//" },
|
|
|
+ { name: 8, value: "///" },
|
|
|
+ ];
|
|
|
+ return noteType.find((n) => n.name === type)?.value || "";
|
|
|
+ },
|
|
|
+};
|
|
|
+
|
|
|
+export const formateAbc = (visualObj: TuneObject, option: any) => {
|
|
|
const abc = {
|
|
|
celf: "K:treble",
|
|
|
minUnit: "L:1/4",
|
|
@@ -302,9 +318,10 @@ export const formateAbc = (visualObj: TuneObject) => {
|
|
|
speed: "Q:1/4=60",
|
|
|
key: "K:C",
|
|
|
visualTranspose: 0,
|
|
|
- subjectCode: "acoustic_grand_piano",
|
|
|
+ subjectCode: option.subjectCode ?? "acoustic_grand_piano",
|
|
|
};
|
|
|
const list = [];
|
|
|
+ let notes = [];
|
|
|
let measureIndex = 0;
|
|
|
for (let i = 0; i < visualObj.lines.length; i++) {
|
|
|
const line = visualObj.lines[i];
|
|
@@ -323,15 +340,59 @@ export const formateAbc = (visualObj: TuneObject) => {
|
|
|
}
|
|
|
}
|
|
|
if (staff.voices) {
|
|
|
+ let measure = {
|
|
|
+ notes: [] as INote[],
|
|
|
+ barline: "|",
|
|
|
+ repeat: "",
|
|
|
+ measureNumber: measureIndex,
|
|
|
+ celf: "",
|
|
|
+ key: "",
|
|
|
+ meter: "",
|
|
|
+ };
|
|
|
for (let k = 0; k < staff.voices.length; k++) {
|
|
|
const voice = staff.voices[k];
|
|
|
for (let l = 0; l < voice.length; l++) {
|
|
|
const element = voice[l];
|
|
|
if (element.el_type === "bar") {
|
|
|
measureIndex++;
|
|
|
+ list.push(measure);
|
|
|
+ notes = [];
|
|
|
+ measure = {
|
|
|
+ notes: [] as INote[],
|
|
|
+ barline: "|",
|
|
|
+ repeat: "",
|
|
|
+ measureNumber: measureIndex,
|
|
|
+ celf: "",
|
|
|
+ key: "",
|
|
|
+ meter: "",
|
|
|
+ };
|
|
|
}
|
|
|
if (element.el_type === "note") {
|
|
|
- list.push(element);
|
|
|
+ // const abcEle = visualObj.getElementFromChar(element.startChar);
|
|
|
+ console.log("🚀 ~ abcEle:", element);
|
|
|
+ let content = ''
|
|
|
+ if (element.rest) {
|
|
|
+ content = 'z';
|
|
|
+ } else {
|
|
|
+ content = element.pitches?.[0]?.name ?? "";
|
|
|
+ }
|
|
|
+ console.log(content)
|
|
|
+ const note = createNote({
|
|
|
+ clef: "", //// 谱号
|
|
|
+ key: "", // 调号
|
|
|
+ speed: "", // 速度
|
|
|
+ slus: "", // 3连音
|
|
|
+ tie: "", // 连音线 前,连音线 后
|
|
|
+ content: content, // 音符
|
|
|
+ noteType: formateGetData.getNoteType(element.duration), // 音符时值
|
|
|
+ play: [],
|
|
|
+ dynamics: "", // 力度符号
|
|
|
+ accidental: "", // 临时升降记号
|
|
|
+ dot: "", //附点
|
|
|
+ tieline: "", // 延音线
|
|
|
+ segno: "", // 分割
|
|
|
+ });
|
|
|
+ measure.notes.push(note);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -339,5 +400,9 @@ export const formateAbc = (visualObj: TuneObject) => {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- console.log(measureIndex);
|
|
|
+ console.log(measureIndex, list);
|
|
|
+ return {
|
|
|
+ ...abc,
|
|
|
+ measures: list,
|
|
|
+ };
|
|
|
};
|