import { TheoryNote } from "../note/TheoryNote"; import { TheoryCheck } from "../../util/TheoryCheck"; import { TheoryINote } from "../note/interface/TheoryINote"; import { TheoryBeats, IBeats } from "../beats/TheoryBeats"; export class TheoryData { private _note: TheoryNote; private _beats: TheoryBeats; private _musicData: { [measure: number]: { [staff: string]: TheoryINote[] } }; private _beatsData: IBeats; private static _instance: TheoryData; private constructor(note_: TheoryNote, beats_: TheoryBeats) { this._note = note_; this._beats = beats_; } // 获得 YYMData, 全局唯一的YYMData 的 实例对象 public static getInstance(note_: TheoryNote, beats_: TheoryBeats) { this._instance = new TheoryData(note_, beats_); return this._instance; } // 把 noteList 顺序从 musicXML 的顺序按照 abc 的顺序去排序 public getFinalJsonData() { this._musicData = {}; let measureRecorder: number[] = []; // 用来记录生成了多少个小节 let noteListXMLOrder = this._note.noteListXMLOrder; for (let i = 0; i < noteListXMLOrder.length; i++) { let note: TheoryINote = noteListXMLOrder[i]; let noteMeasureIndex = note.measureIndex; let noteStaff = note.staff; // 如果遇到的新的 voice 那么就要立马生成那个对应的对象 if (!measureRecorder.includes(note.measureIndex)) { this._musicData["m" + noteMeasureIndex] = {}; this._musicData["m" + noteMeasureIndex]["s1"] = []; this._musicData["m" + noteMeasureIndex]["s2"] = []; measureRecorder.push(noteMeasureIndex); } this._musicData[`m${noteMeasureIndex}`][`s${noteStaff}`].push(note); } return this._musicData; } public getFinalBeatsData() { this._beatsData = this._beats.getBeatDataObject(); return this._beatsData; } }