index.tsx 83 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750
  1. import { computed, defineComponent, nextTick, onMounted, onUnmounted, reactive, ref, watch } from "vue";
  2. import ABCJS, {
  3. AbcElem,
  4. AbcVisualParams,
  5. ClickListenerAnalysis,
  6. ClickListenerDrag,
  7. NoteTimingEvent,
  8. SynthObjectController,
  9. } from "abcjs";
  10. import "ABCJS/ABCJS-audio.css";
  11. import styles from "./index.module.less";
  12. import { showConfirmDialog, showToast } from "vant";
  13. import Keys from "../component/keys";
  14. import { Collapse, CollapseItem } from "@varlet/ui";
  15. import { IAbc, IMeasure, INote, INoteActive } from "../types";
  16. import {
  17. ABC_DATA,
  18. createMeasure,
  19. createNote,
  20. formateAbc,
  21. getKeyStep,
  22. moveNoteKey,
  23. renderMeasures,
  24. } from "./runtime";
  25. import TheIcon from "/src/components/The-icon";
  26. import { cloneDeep } from "lodash";
  27. import TheSpeed from "./component/the-speed";
  28. import { getImage } from "./images";
  29. import {
  30. NButton,
  31. NDropdown,
  32. NGi,
  33. NGrid,
  34. NIcon,
  35. NInput,
  36. NInputNumber,
  37. NModal,
  38. NPopover,
  39. NPopselect,
  40. NSelect,
  41. NSpace,
  42. NSpin,
  43. useDialog,
  44. useMessage,
  45. } from "naive-ui";
  46. import { LongArrowAltDown, LongArrowAltUp, GripLinesVertical } from "@vicons/fa";
  47. import { svg2canvas } from "/src/utils/svg2canvas";
  48. import { decodeUrl, downloadFile } from "/src/utils";
  49. import FileBtn, { IFileBtnType } from "./component/file-btn";
  50. import TheSetting from "./component/the-setting";
  51. import { useRoute } from "vue-router";
  52. import {
  53. api_musicSheetCreationDetail,
  54. api_musicSheetCreationSave,
  55. api_musicSheetCreationUpdate,
  56. api_xmlToAbc,
  57. } from "../api";
  58. import instrumentsNames from "/src/constant/instrmentsNames.json";
  59. import { ALL_NOTES, ALL_Pitches } from "./noteData";
  60. import { Close } from "@vicons/ionicons5";
  61. import { getQuery } from "/src/utils/queryString";
  62. import Metronome, { metronomeData } from "/src/helpers/metronome";
  63. import cleanDeep from "clean-deep";
  64. import { saveAs } from "file-saver";
  65. import qs from "query-string";
  66. import { useDocumentVisibility } from "@vueuse/core";
  67. import request from "/src/utils/request";
  68. import { api_uploadFile } from "/src/utils/uploadFile";
  69. import { bufferToWave } from "/src/helpers/parseABC";
  70. import UploadToResources from "../component/upload-to-resources";
  71. export const initMusic = (total: number): IMeasure[] => {
  72. return new Array(total).fill(0).map((item, index) => {
  73. return {
  74. measureNumber: index + 1,
  75. barline: "|",
  76. celf: "",
  77. key: "",
  78. repeat: "",
  79. meter: "",
  80. notes: [
  81. {
  82. accidental: "",
  83. clef: "",
  84. meter: "",
  85. content: "z",
  86. noteType: "4",
  87. play: [],
  88. key: "",
  89. speed: "",
  90. dynamics: "",
  91. dCode: "",
  92. tie: "",
  93. tCode: "",
  94. dot: "",
  95. slus: "",
  96. tieline: "",
  97. segno: "",
  98. },
  99. ],
  100. };
  101. });
  102. };
  103. function moveNote(note: string, step: number) {
  104. var x = ALL_Pitches.indexOf(note);
  105. if (x >= 0) {
  106. const _note = ALL_Pitches[x - step];
  107. return _note ? _note : note;
  108. }
  109. return note;
  110. }
  111. export default defineComponent({
  112. name: "Home",
  113. setup() {
  114. const dialog = useDialog();
  115. const route = useRoute();
  116. const message = useMessage();
  117. const popup = reactive({
  118. instrument: false,
  119. selectSubjectShow: false, // 声部弹窗
  120. moveKeyShow: false, // 移调弹窗
  121. speedShow: false, // 节拍弹窗
  122. accidentalsShow: false, // 临时升降记号弹窗
  123. clefShow: false, // 谱号弹窗
  124. keyShow: false, // 调号弹窗
  125. meterShow: false, // 拍号弹窗
  126. playShow: false, // 演奏技法弹窗
  127. dynamicsShow: false, // 力度标记弹窗
  128. barShow: false, // 小节弹窗
  129. mearseDeleteShow: false,
  130. staffShow: false, // 五线谱弹窗
  131. settingShow: false, // 设置弹窗
  132. selectMearesShow: false, // 选择小节弹窗
  133. });
  134. const data = reactive({
  135. uploadStatus: "",
  136. saveLoading: false,
  137. loading: true,
  138. drawCount: 0,
  139. isSave: true,
  140. musicId: Date.now().toString(),
  141. musicName: "", // 曲谱名称
  142. creator: "", // 创建者
  143. subjectId: "", // 声部
  144. speed: "",
  145. music: "",
  146. playState: false, // 播放状态
  147. active: null as unknown as INoteActive,
  148. select: {
  149. state: false,
  150. list: [] as any[],
  151. parmas: null as any,
  152. },
  153. isClickNote: false,
  154. /** 音符类型 */
  155. noteType: "",
  156. /** 选择小节范围 */
  157. selectMeasures: {
  158. state: false,
  159. x: 0,
  160. y: 0,
  161. start: 1,
  162. startNote: null as any,
  163. end: 0,
  164. endNote: null as any,
  165. max: 30,
  166. },
  167. slide: ["note", "meter", "dynamics"],
  168. morePlay: false, // 更多演奏技法
  169. addMearseType: "pre" as "pre" | "next" | "finish", // 添加小节类型
  170. addMearseNumber: 1, // 添加小节数量
  171. deleteMearseType: "ing" as "ing" | "finish", // 删除小节类型
  172. loadingAudioSrouce: false, // 加载音频资源
  173. /** 移调类型 */
  174. moveKeyType: "inset" as "inset" | "up" | "down", // 移调类型
  175. activePlayNote: null as any, // 当前演奏音符
  176. times: [] as any[], // 节拍器数据
  177. undoList: [] as any[], // 撤销列表
  178. redoList: [] as any[], // 重做列表
  179. uploadShow: false, // 上传弹窗
  180. item: {} as any, // 上传数据
  181. uploadClick: false, // 上传点击
  182. });
  183. const noteTypes = ABC_DATA.types.map((item) => item.value).filter(Boolean);
  184. const accidentals = ABC_DATA.accidentals.map((item) => item.value).filter(Boolean);
  185. const clefs = ABC_DATA.clef.map((item) => item.value).filter(Boolean);
  186. const playTypes = ABC_DATA.play.map((item) => item.value).filter(Boolean);
  187. const dynamics = ABC_DATA.dynamics
  188. .map((item) => item.value)
  189. .flat()
  190. .filter(Boolean);
  191. const barTypes = ABC_DATA.bar.map((item) => item.value).filter(Boolean);
  192. console.log("🚀 ~ noteTypes:", noteTypes, accidentals, clefs, playTypes, dynamics);
  193. /** 点击音符 */
  194. const clickListener = (
  195. abcElem: AbcElem,
  196. tuneNumber: number,
  197. classes: string,
  198. analysis: ClickListenerAnalysis,
  199. drag: ClickListenerDrag
  200. ) => {
  201. // console.log("🚀 ~ data.select.state:", data.select.state);
  202. let indexStr: any = abcElem.chord?.find((n) => n.position === "left")?.name || "";
  203. indexStr = indexStr.split(".").map((n: string) => Number(n));
  204. const active = {
  205. ...cloneDeep(abcElem),
  206. measureIndex: indexStr[0],
  207. noteIndex: indexStr[1],
  208. isFirstChecked: true,
  209. };
  210. // 选择范围模式
  211. if (data.select.state) {
  212. data.select.list.push(active);
  213. if (data.select.list.length === 1) {
  214. showToast("请先选择结束音符");
  215. }
  216. if (data.select.list.length === 2) {
  217. console.log(data.select.list);
  218. data.select.list = data.select.list.sort((a, b) => a.startChar - b.startChar);
  219. handleSelectNote();
  220. }
  221. return;
  222. }
  223. data.active = active;
  224. console.log(
  225. "🚀 ~ abcElem:",
  226. abcElem,
  227. data.music.substring(data.active.startChar, data.active.endChar)
  228. );
  229. if (data.active?.el_type === "note" && !popup.selectMearesShow) {
  230. const totalTime = (abcData.synthControl as any).visualObj.getTotalTime();
  231. if (totalTime) {
  232. const progress = (data.active as any).currentTrackMilliseconds / 1000 / totalTime;
  233. // console.log("🚀 ~ data.active:", progress);
  234. (abcData.synthControl as any).seek(progress);
  235. }
  236. }
  237. // if (abcElem.el_type === "tempo") {
  238. // abcData.visualObj.engraver.rangeHighlight(abcElem.startChar, abcElem.endChar);
  239. // }
  240. if (drag && drag.step) {
  241. handleChange({ type: "move", value: { action: "drag", step: drag.step } });
  242. return;
  243. }
  244. if (!abcElem?.midiPitches) return;
  245. ABCJS.synth.playEvent(abcElem.midiPitches, abcElem.midiGraceNotePitches, 1000);
  246. };
  247. const textAreaRef = ref();
  248. const abcData = reactive({
  249. visualObj: null as any,
  250. midiBuffer: null as unknown as ABCJS.MidiBuffer,
  251. abcOptions: {
  252. selectionColor: "#0f81ff",
  253. jazzchords: true,
  254. add_classes: true,
  255. clickListener: clickListener,
  256. responsive: "resize",
  257. dragging: true,
  258. selectTypes: ["note"],
  259. visualTranspose: 0,
  260. wrap: {
  261. minSpacing: 0.1,
  262. maxSpacing: 2.7,
  263. preferredMeasuresPerLine: 4,
  264. },
  265. staffwidth: 800,
  266. } as AbcVisualParams,
  267. synthControl: null as unknown as SynthObjectController,
  268. synthOptions: {
  269. program: 0,
  270. soundFontUrl: "https://oss.dayaedu.com/musicSheet/",
  271. // soundFontUrl: "https://paulrosen.github.io/midi-js-soundfonts/FluidR3_GM/", // 默认 FluidR3_GM
  272. // soundFontUrl: "https://paulrosen.github.io/midi-js-soundfonts/MusyngKite/", // Musyng Kite
  273. },
  274. abc: {
  275. celf: "K:treble",
  276. minUnit: "L:1/4",
  277. meter: "M:4/4",
  278. speed: "Q:1/4=60",
  279. key: "K:C",
  280. visualTranspose: 0,
  281. visualKey: "K:C",
  282. subjectCode: "acoustic_grand_piano",
  283. measures: initMusic(30),
  284. } as IAbc,
  285. });
  286. /** 添加音符 */
  287. const handleCreateNote = (measureIndex: number, noteIndex: number, options: INote) => {
  288. // console.log("🚀 ~ noteIndex:", noteIndex);
  289. const measure = abcData.abc.measures[measureIndex];
  290. if (measure) {
  291. measure.notes.splice(noteIndex + 1, 0, options);
  292. }
  293. };
  294. const hideCursor = () => {
  295. const cursor = document.querySelector("#paper svg .ABCJS-cursor");
  296. if (cursor) {
  297. cursor.setAttribute("x1", "0");
  298. cursor.setAttribute("x2", "0");
  299. cursor.setAttribute("y1", "0");
  300. cursor.setAttribute("y2", "0");
  301. }
  302. };
  303. const cursorControl = {
  304. onReady: function () {},
  305. onStart: function () {
  306. console.log("开始");
  307. data.playState = true;
  308. var svg = document.querySelector("#paper svg");
  309. let cursor = document.querySelector("#paper svg .ABCJS-cursor");
  310. if (!cursor) {
  311. cursor = document.createElementNS("http://www.w3.org/2000/svg", "line");
  312. cursor.setAttribute("class", "ABCJS-cursor");
  313. svg?.appendChild(cursor);
  314. }
  315. cursor.setAttributeNS(null, "x1", "0");
  316. cursor.setAttributeNS(null, "y1", "0");
  317. cursor.setAttributeNS(null, "x2", "0");
  318. cursor.setAttributeNS(null, "y2", "0");
  319. },
  320. onBeat: function (beatNumber: any, totalBeats: any, totalTime: any) {
  321. if (!data.playState) return;
  322. if (popup.selectMearesShow && data.selectMeasures.startNote && data.selectMeasures.endNote) {
  323. const end =
  324. totalBeats *
  325. (data.selectMeasures.endNote.milliseconds / (abcData.visualObj.getTotalTime() * 1000)) -
  326. 0.1;
  327. // console.log(beatNumber, start, end, progress);
  328. if (beatNumber >= end) {
  329. const progress =
  330. data.selectMeasures.startNote.milliseconds / (abcData.visualObj.getTotalTime() * 1000);
  331. (abcData.synthControl as any).seek(progress);
  332. return;
  333. }
  334. }
  335. // console.log("🚀 ~ beatNumber:", beatNumber, totalBeats, totalTime);
  336. const time = (beatNumber / totalBeats) * totalTime;
  337. metronomeData.metro.sound(time);
  338. },
  339. onEvent: (event: any) => {
  340. let ev = event as any;
  341. if (!data.playState) return;
  342. if (ev.measureStart && ev.left === null) return; // this was the second part of a tie across a measure line. Just ignore it.
  343. data.activePlayNote = { ...ev };
  344. var cursor = document.querySelector("#paper svg .ABCJS-cursor");
  345. if (cursor) {
  346. cursor.setAttribute("x1", ev.left + ev.width / 2);
  347. cursor.setAttribute("x2", ev.left + ev.width / 2);
  348. cursor.setAttribute("y1", ev.top);
  349. cursor.setAttribute("y2", ev.top + ev.height);
  350. }
  351. },
  352. onFinished: function () {
  353. console.log("finished");
  354. data.playState = false;
  355. var els = document.querySelectorAll("svg .highlight");
  356. for (var i = 0; i < els.length; i++) {
  357. els[i].classList.remove("highlight");
  358. }
  359. hideCursor();
  360. },
  361. };
  362. const staffNotes = ALL_NOTES();
  363. const loadMiniMp3 = async () => {
  364. data.loadingAudioSrouce = true;
  365. const midiBuffer = new ABCJS.synth.CreateSynth();
  366. const str = `X: 1\nM:4/4\nL:1/4\n${staffNotes}`;
  367. const visualObj = ABCJS.parseOnly(str);
  368. await midiBuffer.init({
  369. visualObj: visualObj[0],
  370. options: { ...abcData.synthOptions },
  371. });
  372. };
  373. const resetMidi = (useActive = false) => {
  374. const midiBuffer = new ABCJS.synth.CreateSynth();
  375. midiBuffer
  376. .init({
  377. visualObj: abcData.visualObj,
  378. options: { ...abcData.synthOptions },
  379. })
  380. .then(() => {
  381. abcData.synthControl
  382. .setTune(abcData.visualObj, useActive, {
  383. midiTranspose: abcData.abc.visualTranspose,
  384. program: abcData.synthOptions.program,
  385. })
  386. .then(function (response) {
  387. data.loadingAudioSrouce = false;
  388. // console.log("Audio successfully loaded.", {...abcData.synthControl});
  389. // console.log("🚀 ~ abcData.synthControl:", abcData.synthControl);
  390. })
  391. .catch((err) => {
  392. console.log(err);
  393. });
  394. });
  395. };
  396. const togglePlay = async (type: "play" | "pause" | "reset") => {
  397. if (type === "play") {
  398. if (popup.selectMearesShow) {
  399. if (
  400. data.selectMeasures.start > data.selectMeasures.end ||
  401. !data.selectMeasures.startNote ||
  402. !data.selectMeasures.endNote
  403. ) {
  404. data.selectMeasures.start = 0;
  405. data.selectMeasures.end = 0;
  406. data.selectMeasures.startNote = null;
  407. data.selectMeasures.endNote = null;
  408. message.warning("请输入正确的小节范围");
  409. data.selectMeasures.state = false;
  410. nextTick(() => {
  411. data.selectMeasures.state = true;
  412. });
  413. return;
  414. }
  415. if (!(abcData.synthControl as any).isLoaded) {
  416. (abcData.synthControl as any).runWhenReady(() => {
  417. const progress =
  418. data.selectMeasures.startNote.milliseconds / (abcData.visualObj.getTotalTime() * 1000);
  419. (abcData.synthControl as any).seek(progress);
  420. });
  421. } else {
  422. const progress =
  423. data.selectMeasures.startNote.milliseconds / (abcData.visualObj.getTotalTime() * 1000);
  424. (abcData.synthControl as any).seek(progress);
  425. }
  426. }
  427. abcData.synthControl.play();
  428. data.playState = true;
  429. } else if (type === "pause") {
  430. abcData.synthControl.play();
  431. // abcData.synthControl.pause();
  432. data.playState = false;
  433. hideCursor();
  434. const totalTime = (abcData.synthControl as any).visualObj.getTotalTime();
  435. if (totalTime && data.activePlayNote?.milliseconds !== undefined) {
  436. const progress = data.activePlayNote.milliseconds / 1000 / totalTime;
  437. nextTick(() => {
  438. (abcData.synthControl as any).seek(progress);
  439. });
  440. }
  441. } else {
  442. abcData.synthControl.restart();
  443. nextTick(() => {
  444. if (popup.selectMearesShow) {
  445. if (
  446. data.selectMeasures.start > data.selectMeasures.end ||
  447. !data.selectMeasures.startNote ||
  448. !data.selectMeasures.endNote
  449. ) {
  450. data.selectMeasures.start = 0;
  451. data.selectMeasures.end = 0;
  452. data.selectMeasures.startNote = null;
  453. data.selectMeasures.endNote = null;
  454. message.warning("请输入正确的小节范围");
  455. data.selectMeasures.state = false;
  456. nextTick(() => {
  457. data.selectMeasures.state = true;
  458. });
  459. return;
  460. }
  461. if (!(abcData.synthControl as any).isLoaded) {
  462. (abcData.synthControl as any).runWhenReady(() => {
  463. const progress =
  464. data.selectMeasures.startNote.milliseconds / (abcData.visualObj.getTotalTime() * 1000);
  465. (abcData.synthControl as any).seek(progress);
  466. });
  467. } else {
  468. const progress =
  469. data.selectMeasures.startNote.milliseconds / (abcData.visualObj.getTotalTime() * 1000);
  470. (abcData.synthControl as any).seek(progress);
  471. }
  472. }
  473. if (!data.playState) {
  474. abcData.synthControl.play();
  475. }
  476. });
  477. }
  478. // console.log("🚀 ~ abcData.synthControl:", abcData.synthControl.timer.noteTimings);
  479. };
  480. const renderSvg = () => {
  481. abcData.visualObj = ABCJS.renderAbc("paper", data.music, {
  482. ...abcData.abcOptions,
  483. visualTranspose: abcData.abc.visualTranspose,
  484. })[0];
  485. if (data.drawCount < 3) {
  486. console.log("🚀 ~ visualObj:", abcData.visualObj);
  487. }
  488. };
  489. const renderBoxRect = () => {
  490. const svg = document.querySelector("#paper svg");
  491. const padding = 4;
  492. let measureNumber = 0;
  493. for (let i = 0; i < abcData.visualObj.lines.length; i++) {
  494. const line = abcData.visualObj.lines[i];
  495. // console.log("🚀 ~ line:", line);
  496. for (let j = 0; j < line.staff.length; j++) {
  497. const staff = line.staff[j];
  498. const voices = [...staff.voices].flat();
  499. for (let l = 0; l < voices.length; l++) {
  500. const item = voices[l];
  501. if (item.el_type === "bar") {
  502. measureNumber++;
  503. }
  504. // console.log(item.el_type);
  505. if (["note", "keySignature", "clef", "timeSignature"].includes(item.el_type)) {
  506. const box = item.abselem.elemset?.[0]?.getBBox?.() || null;
  507. // console.log("🚀 ~ box:", item.abselem, box);
  508. if (box) {
  509. const rect = document.createElementNS("http://www.w3.org/2000/svg", "rect");
  510. rect.setAttributeNS(null, "x", box.x - padding + "");
  511. rect.setAttributeNS(null, "y", box.y - padding + "");
  512. rect.setAttributeNS(null, "width", box.width + padding * 2 + "");
  513. rect.setAttributeNS(null, "height", box.height + padding * 2 + "");
  514. rect.setAttributeNS(null, "fill", "rgba(0,0,0,0)");
  515. rect.setAttributeNS(null, "stroke", "rgba(0,0,0,0)");
  516. rect.setAttributeNS(null, "rx", "2");
  517. rect.classList.add("abcjs-note-hover");
  518. svg?.appendChild(rect);
  519. }
  520. }
  521. }
  522. }
  523. }
  524. console.log(measureNumber);
  525. data.selectMeasures.max = measureNumber;
  526. };
  527. let saveTimer: any = null;
  528. const autoSave = () => {
  529. saveTimer && clearTimeout(saveTimer);
  530. saveTimer = setTimeout(() => {
  531. handleSaveMusic(false);
  532. }, 15000);
  533. };
  534. /**
  535. * @param isProduct 是否是生成曲谱
  536. */
  537. const handleResetRender = () => {
  538. if (data.drawCount > 0) {
  539. abcData.synthControl.disable(true);
  540. if (data.playState) {
  541. data.playState = false;
  542. }
  543. data.isSave = false;
  544. }
  545. if (popup.selectMearesShow) {
  546. data.selectMeasures.startNote = null;
  547. data.selectMeasures.endNote = null;
  548. data.selectMeasures.start = 0;
  549. data.selectMeasures.end = 0;
  550. popup.selectMearesShow = false;
  551. data.selectMeasures.state = false;
  552. nextTick(() => {
  553. data.selectMeasures.state = true;
  554. });
  555. }
  556. return new Promise((resolve) => {
  557. nextTick(() => {
  558. data.music = renderMeasures(abcData.abc);
  559. renderSvg();
  560. resetMidi(data.drawCount > 0 ? true : false);
  561. renderBoxRect();
  562. try {
  563. productMetronomeData();
  564. } catch (error) {
  565. console.log("🚀 ~ error:", error);
  566. }
  567. resolve(1);
  568. if (data.drawCount > 0) {
  569. const host = location.host;
  570. if (host.includes("localhost") || host.includes("192")) return;
  571. autoSave();
  572. }
  573. textAreaRef.value && (textAreaRef.value.value = data.music);
  574. data.drawCount++;
  575. });
  576. });
  577. };
  578. /** 生成曲谱节拍器数据 */
  579. const productMetronomeData = () => {
  580. const times = new ABCJS.TimingCallbacks(abcData.visualObj);
  581. data.times = times.noteTimings;
  582. const list: any[] = [];
  583. let meter = abcData.abc.meter || "";
  584. // length - 1是为了去除最后一个空的结束事件
  585. for (let i = 0; i < times.noteTimings.length - 1; i++) {
  586. const timeNote = times.noteTimings[i];
  587. const abcNote = getNextNote(timeNote.startChar as number);
  588. let indexStr: any = abcNote.chord?.find((n) => n.position === "left")?.name || "";
  589. indexStr = indexStr.split(".").map((n: string) => Number(n));
  590. if (indexStr.length === 2) {
  591. const measure = abcData.abc.measures[indexStr[0]];
  592. // 如果小节里面有拍号,后面一直延用这个拍号,以此类推, ps: 下个版本
  593. // if (measure.meter){
  594. // meter = measure.meter;
  595. // }
  596. const reg = new RegExp(/M:(\d+)\/\d+/);
  597. const numerator = Number(meter.match(reg)?.[1]);
  598. // console.log("🚀 ~ reg:", meter.match(reg)?.[1], abcData.abc.meter)
  599. // console.log("🚀 ~ measure:", measure)
  600. const note = measure.notes[indexStr[1]];
  601. list.push({
  602. ...note,
  603. timeNote,
  604. abcNote,
  605. measure: {
  606. numerator,
  607. },
  608. });
  609. }
  610. }
  611. // console.log("abcData.abc.measures", list);
  612. if (!metronomeData.metro) {
  613. metronomeData.metro = new Metronome();
  614. }
  615. try {
  616. metronomeData.activeIndex = -1;
  617. metronomeData.metro.init(list);
  618. } catch (error) {
  619. console.log("🚀 ~ 生成节拍器数据错误:", error);
  620. }
  621. };
  622. // 高亮选中的音符
  623. const rangeHighlight = (startChar: number) => {
  624. // console.log(data.active.endChar, abcData.visualObj.getElementFromChar(data.active.startChar));
  625. const abcElem: AbcElem = abcData.visualObj.getElementFromChar(startChar);
  626. if (abcElem) {
  627. abcData.visualObj.engraver.rangeHighlight(abcElem.startChar, abcElem.endChar);
  628. }
  629. return abcElem;
  630. };
  631. const useIndexGetNote = (indexStr: string) => {
  632. const index = data.music.indexOf(indexStr);
  633. const note = abcData.visualObj.getElementFromChar(index);
  634. return note;
  635. };
  636. const getMeasureNotes = (measureIndex: number) => {
  637. const measure = abcData.abc.measures[measureIndex];
  638. const notes = [];
  639. for (let k = 0; k < measure.notes.length; k++) {
  640. const indexStr = `${measureIndex}.${k}`;
  641. const note = useIndexGetNote(indexStr);
  642. notes.push(note);
  643. }
  644. return notes;
  645. };
  646. const handleClose = () => {
  647. // 判断是否在应用中
  648. console.log("点击退出", window.matchMedia("(display-mode: standalone)").matches);
  649. if (window.matchMedia("(display-mode: standalone)").matches) {
  650. window.onbeforeunload = null;
  651. console.log("准备发消息");
  652. window.parent.postMessage(
  653. {
  654. api: "notation_exit",
  655. },
  656. "*"
  657. );
  658. } else {
  659. // 那就都发个消息吧
  660. window.parent.postMessage(
  661. {
  662. api: "notation_exit",
  663. },
  664. "*"
  665. );
  666. window.close();
  667. }
  668. };
  669. const handleClickExit = async () => {
  670. if (data.saveLoading) return;
  671. const msg = message.loading("保存中...", { duration: 0 });
  672. await handleSaveMusic(false);
  673. setTimeout(async () => {
  674. msg.type = "success";
  675. msg.content = "保存成功";
  676. setTimeout(() => {
  677. msg.destroy();
  678. }, 500);
  679. }, 300);
  680. if (data.uploadStatus !== "NO") {
  681. dialog.warning({
  682. maskClosable: true,
  683. autoFocus: false,
  684. class: "deleteDialog saveDialog",
  685. title: "温馨提示",
  686. content: "是否更新到我的资源?",
  687. positiveText: "更新",
  688. positiveButtonProps: {
  689. type: "primary",
  690. },
  691. negativeText: "不更新",
  692. negativeButtonProps: {
  693. type: "default",
  694. ghost: false,
  695. },
  696. onPositiveClick: async () => {
  697. data.uploadClick = true;
  698. await handleUpdate();
  699. },
  700. onNegativeClick: () => {
  701. handleClose();
  702. },
  703. });
  704. } else {
  705. handleClose();
  706. }
  707. };
  708. /**
  709. *
  710. * @param key
  711. * @param type note 音符 accidental 临时升降记号
  712. * @returns
  713. */
  714. const handleChange = async (params: { type: string; value: any }) => {
  715. // 最多记录30步
  716. if (data.undoList.length > 30) {
  717. data.undoList.shift();
  718. }
  719. data.undoList.push(cleanDeep(abcData.abc));
  720. abcData.synthControl.disable(true);
  721. if (data.playState) {
  722. data.playState = false;
  723. }
  724. const type = params.type;
  725. const value = params.value;
  726. const activeNote =
  727. abcData.abc.measures[data.active?.measureIndex]?.notes[data.active?.noteIndex] || null;
  728. if (type === "exit") {
  729. if (!data.isSave) {
  730. clearTimeout(saveTimer);
  731. data.uploadClick = false;
  732. dialog.warning({
  733. maskClosable: true,
  734. autoFocus: false,
  735. class: "deleteDialog saveDialog",
  736. title: "温馨提示",
  737. content: "是否保存当前曲谱?",
  738. positiveText: "保存",
  739. positiveButtonProps: {
  740. type: "primary",
  741. },
  742. negativeText: "不保存",
  743. negativeButtonProps: {
  744. type: "default",
  745. ghost: false,
  746. },
  747. onPositiveClick: () => {
  748. handleClickExit();
  749. },
  750. onNegativeClick: () => {
  751. handleClose();
  752. },
  753. });
  754. return;
  755. }
  756. handleClose();
  757. }
  758. // console.log(params, activeNote);
  759. if (type === "type") {
  760. // 设置音符类型
  761. data.noteType = value;
  762. if (activeNote) {
  763. activeNote.noteType = value;
  764. await handleResetRender();
  765. const abcElem: AbcElem = rangeHighlight(data.active.startChar);
  766. const active: any = abcElem
  767. ? {
  768. ...cloneDeep(abcElem),
  769. measureIndex: data.active.measureIndex,
  770. noteIndex: data.active.noteIndex,
  771. isFirstChecked: true,
  772. }
  773. : null;
  774. data.active = active;
  775. }
  776. return;
  777. }
  778. // 分割
  779. if (type === "segno") {
  780. if (!data.active) {
  781. showToast("请先选择音符");
  782. return;
  783. }
  784. if (!activeNote) return;
  785. activeNote.segno = activeNote.segno ? "" : value;
  786. await handleResetRender();
  787. rangeHighlight(data.active.startChar);
  788. }
  789. // 修改音符,或者添加音符
  790. if (type === "note") {
  791. if (data.active && data.active.el_type == "note") {
  792. const activeNote =
  793. abcData.abc.measures[data.active.measureIndex]?.notes[data.active.noteIndex] || null;
  794. const _values = value.split("-");
  795. if (data.active.isFirstChecked) {
  796. activeNote.content = _values[0];
  797. activeNote.noteType = data.noteType;
  798. if (_values[1]) {
  799. activeNote.accidental = _values[1] || "";
  800. }
  801. data.active.isFirstChecked = false;
  802. }
  803. await handleResetRender();
  804. const oldNote = useIndexGetNote(`${data.active.measureIndex}.${data.active.noteIndex}`);
  805. if (oldNote?.abselem?.beam?.elems?.length) {
  806. // 判断是否需要分割beam
  807. const elems: AbcElem[] = oldNote.abselem.beam.elems;
  808. const beatDuration = abcData.visualObj.getBeatLength();
  809. const beamLength = elems.map((n) => n.duration).reduce((a, b) => a + b);
  810. if (beamLength >= beatDuration) {
  811. abcData.abc.measures[data.active.measureIndex].notes[data.active.noteIndex].segno = " ";
  812. await handleResetRender();
  813. }
  814. }
  815. if (oldNote?.midiPitches) {
  816. ABCJS.synth.playEvent(oldNote.midiPitches, oldNote.midiGraceNotePitches, 1000);
  817. }
  818. const nextNote =
  819. abcData.abc.measures[data.active.measureIndex]?.notes[data.active.noteIndex + 1];
  820. if (nextNote) {
  821. const abcNextElem: AbcElem = useIndexGetNote(
  822. `${data.active.measureIndex}.${data.active.noteIndex + 1}`
  823. );
  824. rangeHighlight(abcNextElem.startChar);
  825. data.active = {
  826. ...abcNextElem,
  827. measureIndex: data.active.measureIndex,
  828. noteIndex: data.active.noteIndex + 1,
  829. isFirstChecked: true,
  830. };
  831. } else {
  832. const notes = getMeasureNotes(data.active.measureIndex);
  833. const duration = notes.map((n) => n.duration).reduce((a, b) => a + b);
  834. if (duration >= 1) {
  835. // 小节内音符总时值过长,自动跳转到下一小节
  836. const nextMeasureNote = abcData.abc.measures[data.active.measureIndex + 1]?.notes[0];
  837. if (nextMeasureNote) {
  838. const abcNextElem: AbcElem = useIndexGetNote(`${data.active.measureIndex + 1}.${0}`);
  839. rangeHighlight(abcNextElem.startChar);
  840. data.active = {
  841. ...abcNextElem,
  842. measureIndex: data.active.measureIndex + 1,
  843. noteIndex: 0,
  844. isFirstChecked: true,
  845. };
  846. } else {
  847. // 到最后一个小节的最后一个音符了
  848. rangeHighlight(data.active.startChar);
  849. data.active.isFirstChecked = true;
  850. }
  851. } else {
  852. handleCreateNote(
  853. data.active.measureIndex,
  854. data.active.noteIndex,
  855. createNote({
  856. content: "z",
  857. noteType: data.noteType,
  858. })
  859. );
  860. await handleResetRender();
  861. const newNote = useIndexGetNote(
  862. `${data.active.measureIndex}.${data.active.noteIndex + 1}`
  863. );
  864. rangeHighlight(newNote.startChar);
  865. data.active = {
  866. ...newNote,
  867. measureIndex: data.active.measureIndex,
  868. noteIndex: data.active.noteIndex + 1,
  869. isFirstChecked: true,
  870. };
  871. }
  872. }
  873. }
  874. }
  875. // 临时升降记号
  876. if (type === "accidentals") {
  877. if (!data.active) {
  878. message.warning("请先选择音符");
  879. return;
  880. }
  881. if (activeNote.content === "z") {
  882. message.warning("休止符无法添加临时升降记号");
  883. return;
  884. }
  885. activeNote.accidental = activeNote.accidental == value ? "" : value;
  886. await handleResetRender();
  887. const abcElem: AbcElem = rangeHighlight(data.active.startChar);
  888. const active: any = abcElem
  889. ? {
  890. ...cloneDeep(abcElem),
  891. measureIndex: data.active.measureIndex,
  892. noteIndex: data.active.noteIndex,
  893. isFirstChecked: true,
  894. }
  895. : null;
  896. data.active = active;
  897. }
  898. // 谱号
  899. if (type === "clef") {
  900. if (data.active) {
  901. if (!activeNote) return;
  902. activeNote.clef = `[${value}]`;
  903. await handleResetRender();
  904. } else {
  905. abcData.abc.celf = value;
  906. handleResetRender();
  907. }
  908. }
  909. // 调号
  910. if (type === "key") {
  911. if (data.active) {
  912. if (!activeNote) return;
  913. activeNote.key = `[${value}]`;
  914. await handleResetRender();
  915. } else {
  916. abcData.abc.key = value;
  917. await handleResetRender();
  918. }
  919. }
  920. // 拍号
  921. if (type === "meter") {
  922. if (data.active && data.active.measureIndex !== 0) {
  923. if (!activeNote) return;
  924. const measure = abcData.abc.measures[data.active.measureIndex];
  925. measure.meter = `[${value}]`;
  926. await handleResetRender();
  927. const oldNote = useIndexGetNote(`${data.active.measureIndex}.${data.active.noteIndex}`);
  928. rangeHighlight(oldNote.startChar);
  929. } else {
  930. abcData.abc.meter = value;
  931. await handleResetRender();
  932. }
  933. }
  934. // 演奏技法
  935. if (type === "play") {
  936. if (!data.active) {
  937. message.warning("请先选择音符");
  938. return;
  939. }
  940. if (!activeNote) return;
  941. if (activeNote.play.includes(value)) {
  942. activeNote.play = activeNote.play.filter((item) => item !== value);
  943. } else {
  944. activeNote.play.push(value);
  945. }
  946. await handleResetRender();
  947. rangeHighlight(data.active.startChar);
  948. }
  949. // 力度标记,渐强渐弱
  950. if (type === "dynamics") {
  951. if (!data.active) {
  952. message.info("请先选择音符");
  953. return;
  954. }
  955. if (!activeNote) return;
  956. if (Array.isArray(value)) {
  957. if (activeNote?.dynamics) {
  958. activeNote.dynamics = "";
  959. for (let i = 0; i < abcData.abc.measures.length; i++) {
  960. const measure = abcData.abc.measures[i];
  961. for (let j = 0; j < measure.notes.length; j++) {
  962. const note = measure.notes[j];
  963. if (note.dCode === activeNote.dCode) {
  964. note.dynamics = "";
  965. }
  966. }
  967. }
  968. await handleResetRender();
  969. } else {
  970. data.select.list = [cloneDeep(data.active)];
  971. data.select.state = true;
  972. data.select.parmas = params;
  973. message.info("请选择结束音符");
  974. }
  975. return;
  976. }
  977. if (activeNote.dynamics === value) {
  978. activeNote.dynamics = "";
  979. } else {
  980. activeNote.dynamics = value;
  981. }
  982. await handleResetRender();
  983. rangeHighlight(data.active.startChar);
  984. }
  985. // 延音
  986. if (type === "tie") {
  987. if (!data.active) {
  988. message.info("请先选择音符");
  989. return;
  990. }
  991. if (!activeNote) return;
  992. if (Array.isArray(value)) {
  993. if (activeNote?.tie) {
  994. activeNote.tie = "";
  995. for (let i = 0; i < abcData.abc.measures.length; i++) {
  996. const measure = abcData.abc.measures[i];
  997. for (let j = 0; j < measure.notes.length; j++) {
  998. const note = measure.notes[j];
  999. if (note.tCode === activeNote.tCode) {
  1000. note.tie = "";
  1001. }
  1002. }
  1003. }
  1004. await handleResetRender();
  1005. return;
  1006. } else {
  1007. data.select.list = [cloneDeep(data.active)];
  1008. data.select.state = true;
  1009. data.select.parmas = params;
  1010. message.info("请选择结束音符");
  1011. return;
  1012. }
  1013. }
  1014. const abcElem: any = getNextNote(data.active.endChar);
  1015. if (activeNote.tieline) {
  1016. activeNote.tieline = "";
  1017. } else {
  1018. if (data.active.averagepitch != abcElem.averagepitch) {
  1019. message.warning("必须同音高才能添加延音线");
  1020. return;
  1021. }
  1022. activeNote.tieline = value;
  1023. }
  1024. await handleResetRender();
  1025. rangeHighlight(data.active.startChar);
  1026. }
  1027. // 反复
  1028. if (type === "repeat") {
  1029. if (!data.active) {
  1030. return;
  1031. }
  1032. const activeMeasure = abcData.abc.measures[data.active.measureIndex] || null;
  1033. if (!activeMeasure) return;
  1034. if (activeMeasure.repeat === value) {
  1035. activeMeasure.repeat = "";
  1036. } else {
  1037. activeMeasure.repeat = value;
  1038. }
  1039. await handleResetRender();
  1040. rangeHighlight(data.active.startChar + value.length);
  1041. }
  1042. // 小节线
  1043. if (type === "barline") {
  1044. if (!data.active) {
  1045. return;
  1046. }
  1047. const activeMeasure = abcData.abc.measures[data.active.measureIndex] || null;
  1048. if (!activeMeasure) return;
  1049. // 如果是开始重复,就修改前一个小节的barline
  1050. if (value === "|:") {
  1051. const prevMeasure = abcData.abc.measures[data.active.measureIndex - 1] || null;
  1052. if (!prevMeasure) return;
  1053. prevMeasure.barline = prevMeasure.barline === value ? "|" : value;
  1054. } else {
  1055. activeMeasure.barline = activeMeasure.barline === value ? "|" : value;
  1056. }
  1057. await handleResetRender();
  1058. }
  1059. // 速度
  1060. if (type === "speeds") {
  1061. if (data.active) {
  1062. if (data.active.measureIndex === 0 && data.active.noteIndex === 0) {
  1063. abcData.abc.speed = value;
  1064. await handleResetRender();
  1065. } else {
  1066. const activeNote =
  1067. abcData.abc.measures[data.active.measureIndex]?.notes[data.active.noteIndex] || null;
  1068. if (!activeNote) return;
  1069. activeNote.speed = `[${value}]`;
  1070. await handleResetRender();
  1071. }
  1072. rangeHighlight(data.active.startChar);
  1073. } else {
  1074. abcData.abc.speed = value;
  1075. await handleResetRender();
  1076. }
  1077. }
  1078. // 附点
  1079. if (type === "dot") {
  1080. if (!data.active) {
  1081. showToast("请先选择音符");
  1082. return;
  1083. }
  1084. if (!activeNote) return;
  1085. activeNote.dot = activeNote.dot ? "" : value;
  1086. // activeNote.dot = activeNote.dot ? "" : NOTE_DOT[activeNote.noteType];
  1087. await handleResetRender();
  1088. rangeHighlight(data.active.startChar);
  1089. }
  1090. // 3连音
  1091. if (type === "slus") {
  1092. const activeNote =
  1093. abcData.abc.measures[data.active.measureIndex]?.notes[data.active.noteIndex] || null;
  1094. if (!activeNote) return;
  1095. activeNote.slus = activeNote.slus === value ? "" : value;
  1096. await handleResetRender();
  1097. rangeHighlight(data.active.startChar);
  1098. }
  1099. // 移动音符
  1100. if (type === "move") {
  1101. const step = value.action === "drag" ? value.step : value.action === "up" ? -1 : 1;
  1102. if (!activeNote) return;
  1103. activeNote.content = moveNote(activeNote.content, step);
  1104. // arr now contains elements that are either a chord, a decoration, a note name, or anything else. It can be put back to its original string with .join("").
  1105. await handleResetRender();
  1106. const _abcElem = rangeHighlight(data.active.startChar);
  1107. if (!_abcElem?.midiPitches) return;
  1108. ABCJS.synth.playEvent(_abcElem.midiPitches, _abcElem.midiGraceNotePitches, 1000);
  1109. }
  1110. // 删除音符
  1111. if (type === "delete") {
  1112. if (!data.active) return;
  1113. if (data.active.startChar === 0) return;
  1114. abcData.abc.measures[data.active.measureIndex].notes.splice(data.active.noteIndex, 1);
  1115. if (abcData.abc.measures[data.active.measureIndex].notes.length === 0) {
  1116. abcData.abc.measures.splice(data.active.measureIndex, 1);
  1117. }
  1118. await handleResetRender();
  1119. data.active = null as unknown as INoteActive;
  1120. }
  1121. };
  1122. const getNextNote = (index: number): AbcElem => {
  1123. const abcElem = abcData.visualObj.getElementFromChar(index);
  1124. if (abcElem.el_type === "note") {
  1125. return abcElem;
  1126. } else {
  1127. return getNextNote(abcElem.endChar);
  1128. }
  1129. };
  1130. const handleDeleteNote = () => {
  1131. if (!data.active) return;
  1132. if (data.active.startChar === 0) return;
  1133. abcData.abc.measures[data.active.measureIndex].notes.splice(data.active.noteIndex, 1);
  1134. if (abcData.abc.measures[data.active.measureIndex].notes.length === 0) {
  1135. abcData.abc.measures.splice(data.active.measureIndex, 1);
  1136. }
  1137. handleResetRender();
  1138. data.active = null as unknown as INoteActive;
  1139. };
  1140. const clearSelectNote = () => {
  1141. data.active = null as unknown as INoteActive;
  1142. const notes = document.querySelectorAll(".abcjs-note_selected");
  1143. notes.forEach((item) => {
  1144. item.classList.remove("abcjs-note_selected");
  1145. item.setAttribute("fill", "currentColor");
  1146. });
  1147. };
  1148. const handleSelectNote = async () => {
  1149. const type = data.select.parmas?.type;
  1150. const value = data.select.parmas?.value;
  1151. const startItem = data.select.list[0];
  1152. const endItem = data.select.list[1];
  1153. // 力度标记,渐强渐弱
  1154. if (type === "dynamics") {
  1155. if (
  1156. abcData.abc.measures[endItem.measureIndex].notes[endItem.noteIndex].dynamics ||
  1157. abcData.abc.measures[startItem.measureIndex].notes[startItem.noteIndex].dynamics
  1158. ) {
  1159. message.warning("已经添加了力度标记");
  1160. } else {
  1161. const crescendo = Date.now() + "";
  1162. abcData.abc.measures[startItem.measureIndex].notes[startItem.noteIndex].dynamics = value[0];
  1163. abcData.abc.measures[startItem.measureIndex].notes[startItem.noteIndex].dCode = crescendo;
  1164. abcData.abc.measures[endItem.measureIndex].notes[endItem.noteIndex].dynamics = value[1];
  1165. abcData.abc.measures[endItem.measureIndex].notes[endItem.noteIndex].dCode = crescendo;
  1166. await handleResetRender();
  1167. }
  1168. }
  1169. // 连音
  1170. if (type === "tie") {
  1171. const crescendo = Date.now() + "";
  1172. if (abcData.abc.measures[startItem.measureIndex].notes[startItem.noteIndex].tie) {
  1173. const tie = abcData.abc.measures[startItem.measureIndex].notes[startItem.noteIndex].tie;
  1174. abcData.abc.measures[startItem.measureIndex].notes[startItem.noteIndex].tie = value[0] + tie;
  1175. } else {
  1176. abcData.abc.measures[startItem.measureIndex].notes[startItem.noteIndex].tie = value[0];
  1177. abcData.abc.measures[startItem.measureIndex].notes[startItem.noteIndex].tCode = crescendo;
  1178. }
  1179. if (abcData.abc.measures[endItem.measureIndex].notes[endItem.noteIndex].tie) {
  1180. const tie = abcData.abc.measures[endItem.measureIndex].notes[endItem.noteIndex].tie;
  1181. abcData.abc.measures[endItem.measureIndex].notes[endItem.noteIndex].tie = tie + value[1];
  1182. } else {
  1183. abcData.abc.measures[endItem.measureIndex].notes[endItem.noteIndex].tie = value[1];
  1184. abcData.abc.measures[endItem.measureIndex].notes[endItem.noteIndex].tCode = crescendo;
  1185. }
  1186. await handleResetRender();
  1187. }
  1188. data.select.state = false;
  1189. data.select.list = [];
  1190. data.select.parmas = null;
  1191. clearSelectNote();
  1192. message.destroyAll();
  1193. };
  1194. /** 移调 */
  1195. const handleMoveKey = async (item: (typeof ABC_DATA.key)[0]) => {
  1196. // const moveData = getKeyStep(item.value, abcData.abc.key, data.moveKeyType);
  1197. // console.log("🚀 ~ item:", abcData.abc.key, "=>", item.value, moveData);
  1198. // 将所有的音符移调
  1199. // for (let i = 0; i < abcData.abc.measures.length; i++) {
  1200. // const measure = abcData.abc.measures[i];
  1201. // for (let j = 0; j < measure.notes.length; j++) {
  1202. // const note = measure.notes[j];
  1203. // if (note.content == "z") continue;
  1204. // const content = moveNoteKey(note.content, moveData);
  1205. // const _a = content.substring(0, 1);
  1206. // if (_a === "^" || _a === "_") {
  1207. // note.content = content.substring(1);
  1208. // } else {
  1209. // note.content = content;
  1210. // }
  1211. // console.log("🚀 ~ note.content:", note.content);
  1212. // }
  1213. // }
  1214. // // console.log(abcData.abc.visualTranspose, item.step, item.value)
  1215. // abcData.abc.key = item.value;
  1216. // const step =
  1217. // data.moveKeyType === "up"
  1218. // ? item.step > 0
  1219. // ? item.step
  1220. // : item.step + 12
  1221. // : data.moveKeyType === "down"
  1222. // ? item.step < 0
  1223. // ? item.step
  1224. // : item.step + 12
  1225. // : item.step;
  1226. console.log(item);
  1227. abcData.abc.visualTranspose = item.step;
  1228. abcData.abc.visualKey = item.value;
  1229. popup.moveKeyShow = false;
  1230. if (data.playState) {
  1231. abcData.synthControl.disable(true);
  1232. data.playState = false;
  1233. }
  1234. await handleResetRender();
  1235. };
  1236. const keyDownData = reactive({
  1237. wait: false,
  1238. control: false,
  1239. });
  1240. const handleKeyDonw = async (e: KeyboardEvent) => {
  1241. if ((e.target as HTMLElement).nodeName === "INPUT") return;
  1242. if (e.key === "Control" || e.key === "Meta") {
  1243. keyDownData.control = true;
  1244. }
  1245. if (e.key === "z" && keyDownData.control && !keyDownData.wait) {
  1246. e.preventDefault();
  1247. if (data.undoList.length) {
  1248. abcData.abc = cloneDeep(data.undoList[data.undoList.length - 1]);
  1249. data.undoList.pop();
  1250. keyDownData.wait = true;
  1251. await handleResetRender();
  1252. nextTick(() => {
  1253. keyDownData.wait = false;
  1254. });
  1255. }
  1256. }
  1257. };
  1258. const handleKeyUp = (e: KeyboardEvent) => {
  1259. if ((e.target as HTMLElement).nodeName === "INPUT") return;
  1260. console.log(e.key);
  1261. if (e.key === "Control" || e.key === "Meta") {
  1262. keyDownData.control = false;
  1263. }
  1264. if (!data.active) return false;
  1265. if (e.key === "Backspace") {
  1266. handleChange({ type: "delete", value: "" });
  1267. }
  1268. if (/^[A-Ga-g]$/.test(e.key)) {
  1269. handleChange({ type: "note", value: e.key.toLocaleUpperCase() });
  1270. }
  1271. if (["ArrowUp", "ArrowDown"].includes(e.key)) {
  1272. e.preventDefault();
  1273. e.stopPropagation();
  1274. handleChange({ type: "move", value: { action: e.key === "ArrowUp" ? "up" : "donw" } });
  1275. return false;
  1276. }
  1277. };
  1278. /** 重置曲谱 */
  1279. const handleCreateSvg = () => {
  1280. abcData.abc.measures = initMusic(30);
  1281. handleResetRender();
  1282. };
  1283. const instruments = computed(() => {
  1284. return ABCJS.synth.instrumentIndexToName.map((name, index) => ({
  1285. label: instrumentsNames[name as keyof typeof instrumentsNames],
  1286. value: index,
  1287. }));
  1288. });
  1289. const instrumentName = computed(() => {
  1290. const code = ABCJS.synth.instrumentIndexToName[abcData.synthOptions.program];
  1291. return instrumentsNames[code as keyof typeof instrumentsNames];
  1292. });
  1293. const getDetailData = async () => {
  1294. const query = getQuery();
  1295. data.loading = true;
  1296. const res = await api_musicSheetCreationDetail(query.id);
  1297. if (res?.code == 200) {
  1298. data.uploadStatus = res.data.uploadStatus || "";
  1299. data.musicId = res.data.id || "";
  1300. data.musicName = res.data.name || "";
  1301. data.creator = res.data.creator || "";
  1302. data.subjectId = res.data.subjectId || "";
  1303. let abc = "" as any;
  1304. try {
  1305. abc = JSON.parse(res.data.creationData);
  1306. } catch (error) {
  1307. console.log(error);
  1308. }
  1309. if (abc) {
  1310. console.log("🚀 ~ abc:", abc);
  1311. data.musicName = abc.title ?? data.musicName;
  1312. abcData.abc.celf = abc.celf || "K:treble";
  1313. abcData.abc.key = abc.key.value || abc.key || "K:C";
  1314. abcData.abc.meter = abc.meter.value || abc.meter || "M:4/4";
  1315. abcData.abc.speed = abc.speed || "Q:1/4=60";
  1316. abcData.abc.visualTranspose = abc.visualTranspose || 0;
  1317. abcData.abc.visualKey = abc.visualKey || "K:C";
  1318. abcData.abc.subjectCode = abc.subjectCode || "acoustic_grand_piano";
  1319. const _instruments = ABCJS.synth.instrumentIndexToName.indexOf(abcData.abc.subjectCode as any);
  1320. abcData.synthOptions.program = _instruments > -1 ? _instruments : 0;
  1321. abcData.abc.measures = abc.measures || initMusic(30);
  1322. // console.log("🚀 ~ abcData.abc:", abcData.abc);
  1323. }
  1324. }
  1325. data.loading = false;
  1326. return res;
  1327. };
  1328. const setSaveLoading = (tips: boolean) => {
  1329. data.saveLoading = true;
  1330. if (tips) {
  1331. message.loading("保存中...", { duration: 0 });
  1332. }
  1333. };
  1334. const handleSaveMusic = async (tips = true) => {
  1335. const query = getQuery();
  1336. abcData.abc.title = data.musicName;
  1337. abcData.abc.creator = data.creator;
  1338. setSaveLoading(tips);
  1339. const wavUrl = await productWav(false);
  1340. const pngUrl = await productPng(false);
  1341. console.log("🚀 ~ pngUrl:", pngUrl);
  1342. try {
  1343. if (query.id) {
  1344. await api_musicSheetCreationUpdate({
  1345. name: data.musicName || "未命名乐谱",
  1346. creator: data.creator || "未命名乐谱",
  1347. creationConfig: renderMeasures(abcData.abc, {
  1348. hiddenIndex: true,
  1349. showTitle: true,
  1350. showCreator: true,
  1351. }),
  1352. creationData: JSON.stringify(cleanDeep(abcData.abc)),
  1353. id: query.id,
  1354. subjectId: data.subjectId,
  1355. filePath: wavUrl,
  1356. coverImg: pngUrl,
  1357. });
  1358. } else {
  1359. const res = await api_musicSheetCreationSave({
  1360. name: data.musicName || "未命名乐谱",
  1361. creator: data.creator || "未命名乐谱",
  1362. creationConfig: renderMeasures(abcData.abc, {
  1363. hiddenIndex: true,
  1364. showTitle: true,
  1365. showCreator: true,
  1366. }),
  1367. creationData: JSON.stringify(cleanDeep(abcData.abc)),
  1368. subjectId: data.subjectId,
  1369. filePath: wavUrl,
  1370. coverImg: pngUrl,
  1371. });
  1372. if (res?.data) {
  1373. const hash = location.hash.split("?");
  1374. const qs_data = qs.parse(hash[1]);
  1375. qs_data.id = res.data;
  1376. try {
  1377. delete qs_data.config;
  1378. } catch (error) {
  1379. console.log("🚀 ~ error:", error);
  1380. }
  1381. location.hash = hash[0] + "?" + qs.stringify(qs_data);
  1382. }
  1383. }
  1384. } catch (error) {
  1385. console.log(error);
  1386. }
  1387. if (tips) {
  1388. message.destroyAll();
  1389. message.success("保存成功");
  1390. }
  1391. data.isSave = true;
  1392. data.saveLoading = false;
  1393. data.uploadClick = false;
  1394. };
  1395. const hanldeInitCreate = () => {
  1396. const query = getQuery();
  1397. const abc = decodeUrl(query.config);
  1398. console.log("🚀 ~ abc:", abc);
  1399. data.subjectId = abc.subjectId || "";
  1400. abcData.abc.celf = abc.celf ?? "K:treble";
  1401. abcData.abc.key = abc.key ?? "K:C";
  1402. abcData.abc.meter = abc.meter ?? "M:4/4";
  1403. abcData.abc.speed = abc.speed ?? "Q:1/4=80";
  1404. abcData.abc.visualTranspose = abc.visualTranspose ?? 0;
  1405. abcData.abc.subjectCode = abc.subjectCode ?? "acoustic_grand_piano";
  1406. const _instruments = ABCJS.synth.instrumentIndexToName.indexOf(abcData.abc.subjectCode as any);
  1407. abcData.synthOptions.program = _instruments > -1 ? _instruments : 0;
  1408. abcData.abc.measures = initMusic(abc.measure ?? 30);
  1409. data.loading = false;
  1410. };
  1411. const visibility = useDocumentVisibility();
  1412. watch(
  1413. () => visibility.value,
  1414. (val: any) => {
  1415. if (val === "hidden") {
  1416. if (data.playState) {
  1417. togglePlay("pause");
  1418. }
  1419. }
  1420. }
  1421. );
  1422. onMounted(async () => {
  1423. const query = getQuery();
  1424. if (query.id) {
  1425. await getDetailData();
  1426. } else {
  1427. hanldeInitCreate();
  1428. }
  1429. if (ABCJS.synth.supportsAudio()) {
  1430. abcData.synthControl = new ABCJS.synth.SynthController();
  1431. // console.log("🚀 ~ abcData.synthControl:", abcData.synthControl)
  1432. abcData.synthControl.load("#audio", cursorControl, {
  1433. displayLoop: true,
  1434. displayRestart: true,
  1435. displayPlay: true,
  1436. displayProgress: true,
  1437. });
  1438. }
  1439. console.log(ABCJS);
  1440. await handleResetRender();
  1441. loadMiniMp3();
  1442. document.addEventListener("keyup", handleKeyUp);
  1443. document.addEventListener("keydown", handleKeyDonw);
  1444. window.onbeforeunload = (e) => {
  1445. if (!data.isSave) {
  1446. e.preventDefault();
  1447. e.returnValue = "还有没保存的";
  1448. }
  1449. };
  1450. abcData.synthControl.restart();
  1451. const selectMearesBtn = document.querySelector("#selectMearesBtn");
  1452. if (selectMearesBtn) {
  1453. const rect = selectMearesBtn.getBoundingClientRect();
  1454. data.selectMeasures.x = document.body.clientWidth - 320;
  1455. data.selectMeasures.y = rect.top + 70;
  1456. data.selectMeasures.state = true;
  1457. }
  1458. });
  1459. onUnmounted(() => {
  1460. document.removeEventListener("keyup", handleKeyUp);
  1461. document.removeEventListener("keydown", handleKeyDonw);
  1462. });
  1463. const measureComputed = computed(() => {
  1464. if (!data.active) return {} as unknown as IMeasure;
  1465. const activeMeasure = abcData.abc.measures[data.active.measureIndex] || {};
  1466. return activeMeasure;
  1467. });
  1468. const noteComputed = computed(() => {
  1469. if (!data.active) return {} as unknown as INote;
  1470. const activeNote =
  1471. abcData.abc.measures[data.active.measureIndex]?.notes[data.active.noteIndex] || {};
  1472. return activeNote;
  1473. });
  1474. /** 新建曲谱 */
  1475. const handleCreateMusic = () => {
  1476. showConfirmDialog({
  1477. title: "温馨提示",
  1478. message: "是否覆盖当前乐谱?",
  1479. }).then(() => {
  1480. handleCreateSvg();
  1481. data.active = null as unknown as INoteActive;
  1482. });
  1483. };
  1484. /** 添加小节 */
  1485. const handleAddMearse = () => {
  1486. for (let i = 0; i < data.addMearseNumber; i++) {
  1487. if (["pre", "next"].includes(data.addMearseType)) {
  1488. if (!data.active) {
  1489. message.warning("请选择小节");
  1490. return;
  1491. }
  1492. if (data.addMearseType === "pre") {
  1493. abcData.abc.measures.splice(data.active.measureIndex, 0, createMeasure());
  1494. } else if (data.addMearseType === "next") {
  1495. abcData.abc.measures.splice(data.active.measureIndex + 1, 0, createMeasure());
  1496. }
  1497. } else {
  1498. abcData.abc.measures.push(createMeasure());
  1499. }
  1500. }
  1501. popup.barShow = false;
  1502. handleResetRender();
  1503. };
  1504. const handleDeleteMearse = () => {
  1505. if (data.deleteMearseType === "ing") {
  1506. if (!data.active) {
  1507. message.warning("请选择小节");
  1508. return;
  1509. }
  1510. abcData.abc.measures.splice(data.active.measureIndex, 1);
  1511. } else if (data.deleteMearseType === "finish") {
  1512. let len = abcData.abc.measures.length;
  1513. for (let i = len; i > 0; i--) {
  1514. if (
  1515. abcData.abc.measures[i - 1].notes.length === 1 &&
  1516. abcData.abc.measures[i - 1].notes[0].content === "z"
  1517. ) {
  1518. if (abcData.abc.measures.length === 1) {
  1519. break;
  1520. }
  1521. abcData.abc.measures.splice(i - 1, 1);
  1522. } else {
  1523. break;
  1524. }
  1525. }
  1526. }
  1527. popup.mearseDeleteShow = false;
  1528. handleResetRender();
  1529. };
  1530. const productPng = (isUrl = true) => {
  1531. return new Promise((resolve) => {
  1532. const paper = document.getElementById("exportPng");
  1533. if (!paper) return;
  1534. const abc = renderMeasures(abcData.abc, {
  1535. hiddenIndex: true,
  1536. showTitle: true,
  1537. showCreator: true,
  1538. });
  1539. ABCJS.renderAbc(paper, abc, abcData.abcOptions);
  1540. const svg: any = paper.children[0]?.cloneNode(true);
  1541. const svgBox = paper.getBoundingClientRect();
  1542. svg.setAttribute("width", `${svgBox.width * 3}`);
  1543. svg.setAttribute("height", `${svgBox.height * 3}`);
  1544. const rect = document.createElementNS("http://www.w3.org/2000/svg", "rect");
  1545. rect.setAttribute("x", "0");
  1546. rect.setAttribute("y", "0");
  1547. rect.setAttribute("width", `${svgBox.width * 10}`);
  1548. rect.setAttribute("height", `${svgBox.height * 10}`);
  1549. rect.setAttribute("fill", "#fff");
  1550. svg.prepend(rect);
  1551. if (svg) {
  1552. const _canvas = svg2canvas(svg.outerHTML);
  1553. if (isUrl) {
  1554. // document.body.appendChild(_canvas);
  1555. let el: any = document.createElement("a");
  1556. // 设置 href 为图片经过 base64 编码后的字符串,默认为 png 格式
  1557. el.href = _canvas.toDataURL();
  1558. el.download = data.musicName + ".png";
  1559. // 创建一个点击事件并对 a 标签进行触发
  1560. const event = new MouseEvent("click");
  1561. el.dispatchEvent(event);
  1562. } else {
  1563. _canvas.toBlob(async (blob) => {
  1564. const pngUrl = await api_uploadFile(blob, data.musicId + ".png");
  1565. resolve(pngUrl);
  1566. }, "image/png");
  1567. }
  1568. }
  1569. });
  1570. };
  1571. const downPng = async () => {
  1572. abcData.abc.title = `T:${data.musicName}`;
  1573. abcData.abc.creator = `R:${data.creator}`;
  1574. productPng();
  1575. };
  1576. const downRef = ref();
  1577. const downMidi = () => {
  1578. const midi = ABCJS.synth.getMidiFile(abcData.visualObj, {
  1579. chordsOff: true,
  1580. midiOutputType: "link",
  1581. fileName: "曲谱",
  1582. });
  1583. // console.log("🚀 ~ midi:", midi)
  1584. downRef.value.innerHTML = midi;
  1585. downRef.value.querySelector("a").click();
  1586. };
  1587. const productWav = async (isUrl = true) => {
  1588. return new Promise((resolve) => {
  1589. const midiBuffer = new ABCJS.synth.CreateSynth();
  1590. midiBuffer
  1591. .init({
  1592. visualObj: abcData.visualObj,
  1593. options: abcData.synthOptions,
  1594. })
  1595. .then(() => {
  1596. midiBuffer.prime().then(async () => {
  1597. if (isUrl) {
  1598. downloadFile(midiBuffer.download(), (data.musicName || "曲谱") + ".wav");
  1599. } else {
  1600. const blob = bufferToWave((midiBuffer as any).getAudioBuffer());
  1601. const wavurl = await api_uploadFile(blob, data.musicId + ".wav");
  1602. resolve(wavurl);
  1603. }
  1604. });
  1605. });
  1606. });
  1607. };
  1608. const downWav = () => {
  1609. try {
  1610. if (abcData.synthControl) {
  1611. abcData.synthControl.download((data.musicName || "曲谱") + ".wav");
  1612. }
  1613. } catch (error) {
  1614. productWav();
  1615. }
  1616. };
  1617. const downXML = async () => {
  1618. const msg = message.loading("导出中...");
  1619. await handleSaveMusic(false);
  1620. const res = await getDetailData();
  1621. if (!res?.data?.xml) {
  1622. msg.type = "error";
  1623. msg.content = "导出失败";
  1624. return;
  1625. }
  1626. saveAs(res.data.xml, (data.musicName || "曲谱") + ".xml");
  1627. msg.type = "success";
  1628. msg.content = "导出成功";
  1629. };
  1630. const handleDownFile = (type: IFileBtnType) => {
  1631. if (type === "png") {
  1632. downPng();
  1633. } else if (type === "midi") {
  1634. downMidi();
  1635. } else if (type === "wav") {
  1636. downWav();
  1637. } else if (type === "down-xml") {
  1638. downXML();
  1639. }
  1640. };
  1641. const handleExport = () => {
  1642. const input = document.createElement("input");
  1643. input.type = "file";
  1644. input.accept = ".xml,.musicxml";
  1645. input.onchange = async (e: any) => {
  1646. data.loadingAudioSrouce = true;
  1647. const file = e.target.files[0];
  1648. // const formData = new FormData();
  1649. // formData.append("xmlFile", file);
  1650. // const res = await api_xmlToAbc(formData);
  1651. // console.log("🚀 ~ res:", res.data)
  1652. const reader = new FileReader();
  1653. reader.onload = async (e: any) => {
  1654. let abc = e.target.result;
  1655. abc = new DOMParser().parseFromString(abc, "text/xml");
  1656. // // console.log("🚀 ~ abc:", abc);
  1657. abc = (window as any).vertaal(abc, { p: "f", t: 1, u: 0, v: 3, mnum: 0 });
  1658. // console.log('abc', abc);
  1659. const parseData = ABCJS.renderAbc("importRef", abc[0], { responsive: "resize" });
  1660. console.log("🚀 ~ parseData:", parseData);
  1661. abcData.abc = formateAbc(parseData[0], { subjectCode: abcData.abc.subjectCode });
  1662. data.musicName = abcData.abc.title || data.musicName;
  1663. data.creator = abcData.abc.creator || data.creator;
  1664. await handleResetRender();
  1665. data.loadingAudioSrouce = false;
  1666. };
  1667. reader.readAsText(file);
  1668. };
  1669. input.click();
  1670. };
  1671. /** 设置选段小节 */
  1672. const handleSetSelectMeares = (index: number | null, type: "start" | "end") => {
  1673. console.log("🚀 ~ index:", index);
  1674. if (data.playState) {
  1675. togglePlay("pause");
  1676. }
  1677. if (type === "start") {
  1678. let note = index ? useIndexGetNote(`${index - 1}.0`) : null;
  1679. note = data.times.find((_note: any) => _note.startChar === note.startChar);
  1680. // console.log("🚀 ~ note:", note, data.times);
  1681. data.selectMeasures.start = index ? index - 1 : 0;
  1682. data.selectMeasures.startNote = note;
  1683. if (
  1684. data.selectMeasures.start &&
  1685. data.selectMeasures.end &&
  1686. data.selectMeasures.end < data.selectMeasures.start
  1687. ) {
  1688. data.selectMeasures.end = 0;
  1689. data.selectMeasures.endNote = null;
  1690. }
  1691. } else {
  1692. let note = index ? useIndexGetNote(`${index}.0`) : null;
  1693. note = data.times.find((_note: any) => _note.startChar === note.startChar);
  1694. // console.log("🚀 ~ note:", note);
  1695. data.selectMeasures.end = index ? index - 1 : 0;
  1696. data.selectMeasures.endNote = note;
  1697. if (
  1698. data.selectMeasures.start &&
  1699. data.selectMeasures.end &&
  1700. data.selectMeasures.start > data.selectMeasures.end
  1701. ) {
  1702. // console.log(data.selectMeasures.start, data.selectMeasures.end);
  1703. data.selectMeasures.start = 0;
  1704. data.selectMeasures.startNote = null;
  1705. }
  1706. }
  1707. };
  1708. const handleUpdate = async () => {
  1709. if (!data.isSave) {
  1710. await handleSaveMusic();
  1711. }
  1712. const query = getQuery();
  1713. const res = await api_musicSheetCreationDetail(query.id);
  1714. if (res.data) {
  1715. if (res.data.uploadStatus !== "YES") {
  1716. data.item = { ...res.data };
  1717. data.uploadShow = true;
  1718. }
  1719. }
  1720. };
  1721. return () => (
  1722. <>
  1723. <div class={styles.container}>
  1724. <div class={styles.containerTop} onKeyup={(e: Event) => e.stopPropagation()}>
  1725. <div class={styles.topWrap}>
  1726. <div class={styles.topBtn} onClick={() => handleChange({ type: "exit", value: "exit" })}>
  1727. <div class={[styles.btnImg]}>
  1728. <img class={styles.topBtnIcon} src={getImage("icon_-1.png")} />
  1729. </div>
  1730. <div>退出</div>
  1731. </div>
  1732. <div class={styles.topBtn}>
  1733. <FileBtn
  1734. saveLoading={data.saveLoading}
  1735. onSelect={(val: IFileBtnType) => {
  1736. if (val === "newMusic") {
  1737. handleCreateMusic();
  1738. } else if (val === "save") {
  1739. handleSaveMusic();
  1740. } else if (["xml"].includes(val)) {
  1741. handleExport();
  1742. } else if (val === "upload") {
  1743. handleUpdate();
  1744. } else if (["png", "midi", "wav", "down-xml"].includes(val)) {
  1745. handleDownFile(val);
  1746. } else if (val === "print") {
  1747. }
  1748. }}
  1749. />
  1750. <div>文件</div>
  1751. </div>
  1752. <div class={styles.topLine}></div>
  1753. <div class={styles.topBtn} onClick={() => handleChange({ type: "dot", value: ">" })}>
  1754. <div class={[styles.btnImg, noteComputed.value.dot === ">" && styles.btnImgActive]}>
  1755. <img class={styles.topBtnIcon} src={getImage("icon_1.png")} />
  1756. </div>
  1757. <div>附点</div>
  1758. </div>
  1759. <div class={styles.topLine}></div>
  1760. {ABC_DATA.accidentals.map((item) => (
  1761. <div
  1762. class={styles.topBtn}
  1763. onClick={() => handleChange({ type: "accidentals", value: item.value })}
  1764. >
  1765. <div
  1766. class={[
  1767. styles.btnImg,
  1768. noteComputed.value.accidental === item.value && styles.btnImgActive,
  1769. ]}
  1770. >
  1771. <img class={styles.topBtnIcon} src={item.icon} />
  1772. </div>
  1773. <div class={styles.btnName}>{item.name}</div>
  1774. </div>
  1775. ))}
  1776. <div class={styles.topLine}></div>
  1777. <div
  1778. class={styles.topBtn}
  1779. onClick={() => handleChange({ type: "tie", value: ABC_DATA.tie[0].value })}
  1780. >
  1781. <div
  1782. class={[
  1783. styles.btnImg,
  1784. noteComputed.value.tieline === ABC_DATA.tie[0].value && styles.btnImgActive,
  1785. ]}
  1786. >
  1787. <img class={styles.topBtnIcon} src={ABC_DATA.tie[0].icon} />
  1788. </div>
  1789. <div>{ABC_DATA.tie[0].name}</div>
  1790. </div>
  1791. <div
  1792. class={styles.topBtn}
  1793. onClick={() => handleChange({ type: "tie", value: ABC_DATA.tie[1].value })}
  1794. >
  1795. <div
  1796. class={[
  1797. styles.btnImg,
  1798. ABC_DATA.tie[1].value.includes(noteComputed.value.tie) && styles.btnImgActive,
  1799. ]}
  1800. >
  1801. <img class={styles.topBtnIcon} src={ABC_DATA.tie[1].icon} />
  1802. </div>
  1803. <div>{ABC_DATA.tie[1].name}</div>
  1804. </div>
  1805. <div class={styles.topLine}></div>
  1806. {ABC_DATA.play.slice(0, 4).map((item) => (
  1807. <div
  1808. class={[styles.topBtn]}
  1809. onClick={() => handleChange({ type: "play", value: item.value })}
  1810. >
  1811. <div
  1812. class={[
  1813. styles.btnImg,
  1814. noteComputed.value.play?.includes(item.value) && styles.btnImgActive,
  1815. ]}
  1816. >
  1817. <img class={styles.topBtnIcon} src={item.icon} />
  1818. </div>
  1819. <div>{item.name}</div>
  1820. </div>
  1821. ))}
  1822. <NPopover
  1823. class={styles.popupWrap}
  1824. showArrow={false}
  1825. trigger="click"
  1826. contentStyle={{ width: "400px" }}
  1827. >
  1828. {{
  1829. trigger: () => (
  1830. <div class={styles.topDownArrow}>
  1831. <img src={getImage("icon_arrow.png")} />
  1832. </div>
  1833. ),
  1834. default: () => (
  1835. <NGrid cols={4} yGap={8}>
  1836. {ABC_DATA.play.slice(4).map((item) => (
  1837. <NGi>
  1838. <div
  1839. class={[
  1840. styles.btnItem,
  1841. noteComputed.value.play?.includes(item.value) && styles.btnItemActive,
  1842. ]}
  1843. onClick={() => {
  1844. data.morePlay = false;
  1845. handleChange({ type: "play", value: item.value });
  1846. }}
  1847. >
  1848. <div class={styles.btnItemIcon}>
  1849. <TheIcon iconClassName={item.icon} />
  1850. </div>
  1851. <div>{item.name}</div>
  1852. </div>
  1853. </NGi>
  1854. ))}
  1855. </NGrid>
  1856. ),
  1857. }}
  1858. </NPopover>
  1859. <div class={styles.topLine}></div>
  1860. <NDropdown
  1861. trigger="click"
  1862. options={ABC_DATA.slus as any}
  1863. labelField="name"
  1864. keyField="value"
  1865. onSelect={(val) => {
  1866. console.log(val);
  1867. handleChange({ type: "slus", value: val });
  1868. }}
  1869. >
  1870. <div class={[styles.topBtn]}>
  1871. <div class={styles.btnImg}>
  1872. <img class={styles.topBtnIcon} src={getImage("icon_13.png")} />
  1873. </div>
  1874. <div>连音</div>
  1875. </div>
  1876. </NDropdown>
  1877. <div class={[styles.topBtn, styles.btnDisabled]}>
  1878. <div class={styles.btnImg}>
  1879. <img class={styles.topBtnIcon} src={getImage("icon_14.png")} />
  1880. </div>
  1881. <div>翻转</div>
  1882. </div>
  1883. <div class={styles.topLine}></div>
  1884. <NPopover
  1885. class={styles.popupWrap}
  1886. showArrow={false}
  1887. v-model:show={popup.selectSubjectShow}
  1888. trigger="click"
  1889. contentStyle={{ width: "320px" }}
  1890. >
  1891. {{
  1892. trigger: () => (
  1893. <div class={styles.topBtn}>
  1894. <div class={styles.btnImg} onClick={() => (popup.instrument = true)}>
  1895. <img class={styles.topBtnIcon} src={getImage("icon_25.png")} />
  1896. </div>
  1897. <div
  1898. style={{
  1899. overflow: "hidden",
  1900. textOverflow: "ellipsis",
  1901. whiteSpace: "nowrap",
  1902. maxWidth: "60px",
  1903. }}
  1904. >
  1905. {instrumentName.value}
  1906. </div>
  1907. </div>
  1908. ),
  1909. default: () => (
  1910. <>
  1911. <div class={styles.btnLineTitle}>选择声部</div>
  1912. <NSelect
  1913. filterable
  1914. options={instruments.value}
  1915. v-model:value={abcData.synthOptions.program}
  1916. onUpdate:value={() => {
  1917. abcData.synthControl.pause();
  1918. data.playState = false;
  1919. nextTick(async () => {
  1920. await loadMiniMp3();
  1921. resetMidi(true);
  1922. popup.selectSubjectShow = false;
  1923. abcData.abc.subjectCode =
  1924. ABCJS.synth.instrumentIndexToName[abcData.synthOptions.program];
  1925. autoSave();
  1926. });
  1927. }}
  1928. ></NSelect>
  1929. </>
  1930. ),
  1931. }}
  1932. </NPopover>
  1933. <NPopover
  1934. class={styles.popupWrap}
  1935. showArrow={false}
  1936. v-model:show={popup.moveKeyShow}
  1937. trigger="click"
  1938. contentStyle={{ width: "320px" }}
  1939. >
  1940. {{
  1941. trigger: () => (
  1942. <div class={styles.topBtn}>
  1943. <div class={styles.btnImg}>
  1944. <img class={styles.topBtnIcon} src={getImage("icon_15.png")} />
  1945. </div>
  1946. <div>移调</div>
  1947. </div>
  1948. ),
  1949. default: () => (
  1950. <>
  1951. <div class={styles.btnLineTitle}>移调方式</div>
  1952. <NSpace>
  1953. <NButton
  1954. secondary
  1955. type={data.moveKeyType === "inset" ? "primary" : "default"}
  1956. onClick={() => (data.moveKeyType = "inset")}
  1957. >
  1958. <NIcon component={GripLinesVertical} />
  1959. 最靠近
  1960. </NButton>
  1961. <NButton
  1962. secondary
  1963. type={data.moveKeyType === "down" ? "primary" : "default"}
  1964. onClick={() => (data.moveKeyType = "down")}
  1965. >
  1966. <NIcon component={LongArrowAltDown} />
  1967. 向下移调
  1968. </NButton>
  1969. <NButton
  1970. secondary
  1971. type={data.moveKeyType === "up" ? "primary" : "default"}
  1972. onClick={() => (data.moveKeyType = "up")}
  1973. >
  1974. <NIcon component={LongArrowAltUp} />
  1975. 向上移调
  1976. </NButton>
  1977. </NSpace>
  1978. <div class={styles.btnLineTitle}>目标音调</div>
  1979. <NGrid cols={5} yGap={8}>
  1980. {ABC_DATA.key
  1981. .sort((a, b) => b.step - a.step)
  1982. .map((item) => (
  1983. <NGi>
  1984. <div
  1985. class={[
  1986. styles.btnItem,
  1987. abcData.abc.visualKey === item.value && styles.btnItemActive,
  1988. ]}
  1989. onClick={() => handleMoveKey(item)}
  1990. >
  1991. <div class={[styles.btnItemIcon]}>
  1992. <TheIcon iconClassName={item.icon} />
  1993. </div>
  1994. <div class={styles.btnItemName}>{item.name}</div>
  1995. </div>
  1996. </NGi>
  1997. ))}
  1998. </NGrid>
  1999. </>
  2000. ),
  2001. }}
  2002. </NPopover>
  2003. <NPopover
  2004. class={styles.popupWrap}
  2005. showArrow={false}
  2006. v-model:value={popup.speedShow}
  2007. trigger="click"
  2008. placement="bottom"
  2009. displayDirective="show"
  2010. >
  2011. {{
  2012. trigger: () => (
  2013. <div class={[styles.topBtn]}>
  2014. <div class={styles.btnImg}>
  2015. <img class={styles.topBtnIcon} src={getImage("icon_16.png")} />
  2016. </div>
  2017. <div>速度调整</div>
  2018. </div>
  2019. ),
  2020. default: () => <TheSpeed onChange={(val) => handleChange(val)} />,
  2021. }}
  2022. </NPopover>
  2023. <NPopover
  2024. class={styles.popupWrap}
  2025. showArrow={false}
  2026. v-model:show={popup.staffShow}
  2027. trigger="click"
  2028. placement="bottom"
  2029. contentStyle={{ width: "320px" }}
  2030. >
  2031. {{
  2032. trigger: () => (
  2033. <div class={[styles.topBtn]}>
  2034. <div class={styles.btnImg}>
  2035. <img class={styles.topBtnIcon} src={getImage("icon_17.png")} />
  2036. </div>
  2037. <div>谱面显示</div>
  2038. </div>
  2039. ),
  2040. default: () => (
  2041. <>
  2042. <div class={styles.btnLineTitle}>乐谱大小</div>
  2043. <NSpace>
  2044. <NButton
  2045. type={abcData.abcOptions.staffwidth === 1200 ? "primary" : "default"}
  2046. secondary
  2047. onClick={() => {
  2048. abcData.abcOptions.staffwidth = 1200;
  2049. handleResetRender();
  2050. }}
  2051. >
  2052. </NButton>
  2053. <NButton
  2054. type={abcData.abcOptions.staffwidth === 800 ? "primary" : "default"}
  2055. secondary
  2056. onClick={() => {
  2057. abcData.abcOptions.staffwidth = 800;
  2058. handleResetRender();
  2059. }}
  2060. >
  2061. </NButton>
  2062. <NButton
  2063. type={abcData.abcOptions.staffwidth === 400 ? "primary" : "default"}
  2064. secondary
  2065. onClick={() => {
  2066. abcData.abcOptions.staffwidth = 400;
  2067. handleResetRender();
  2068. }}
  2069. >
  2070. </NButton>
  2071. </NSpace>
  2072. <div class={styles.btnLineTitle}>小节数</div>
  2073. <NSpace vertical>
  2074. <NInputNumber
  2075. min={1}
  2076. v-model:value={(abcData.abcOptions.wrap as any).preferredMeasuresPerLine}
  2077. placeholder="请输入小节数"
  2078. onUpdate:value={() => {
  2079. handleResetRender();
  2080. }}
  2081. />
  2082. {/* <NSpace style={{ marginTop: "20px" }} align="center" wrap={false} wrapItem={false}>
  2083. <NButton style={{ width: "48%" }} round onClick={() => (popup.staffShow = false)}>
  2084. 取消
  2085. </NButton>
  2086. <NButton
  2087. style={{ width: "48%" }}
  2088. round
  2089. type="primary"
  2090. >
  2091. 确定
  2092. </NButton>
  2093. </NSpace> */}
  2094. </NSpace>
  2095. </>
  2096. ),
  2097. }}
  2098. </NPopover>
  2099. <NPopover
  2100. class={styles.popupWrap}
  2101. showArrow={false}
  2102. v-model:show={popup.barShow}
  2103. trigger="click"
  2104. placement="bottom"
  2105. contentStyle={{ width: "320px" }}
  2106. >
  2107. {{
  2108. trigger: () => (
  2109. <div class={[styles.topBtn]}>
  2110. <div class={styles.btnImg}>
  2111. <img class={styles.topBtnIcon} src={getImage("icon_18.png")} />
  2112. </div>
  2113. <div>添加小节</div>
  2114. </div>
  2115. ),
  2116. default: () => (
  2117. <>
  2118. <div class={styles.btnLineTitle}>添加方式</div>
  2119. <NSpace>
  2120. <NButton
  2121. type={data.addMearseType === "pre" ? "primary" : "default"}
  2122. secondary
  2123. onClick={() => (data.addMearseType = "pre")}
  2124. >
  2125. 当前小节前
  2126. </NButton>
  2127. <NButton
  2128. type={data.addMearseType === "next" ? "primary" : "default"}
  2129. secondary
  2130. onClick={() => (data.addMearseType = "next")}
  2131. >
  2132. 当前小节后
  2133. </NButton>
  2134. <NButton
  2135. type={data.addMearseType === "finish" ? "primary" : "default"}
  2136. secondary
  2137. onClick={() => (data.addMearseType = "finish")}
  2138. >
  2139. 曲谱末尾
  2140. </NButton>
  2141. </NSpace>
  2142. <div class={styles.btnLineTitle}>小节数</div>
  2143. <NSpace vertical>
  2144. <NInputNumber
  2145. min={1}
  2146. v-model:value={data.addMearseNumber}
  2147. placeholder="请输入小节数"
  2148. />
  2149. <NSpace
  2150. style={{ marginTop: "20px" }}
  2151. align="center"
  2152. wrap={false}
  2153. wrapItem={false}
  2154. >
  2155. <NButton
  2156. style={{ width: "48%" }}
  2157. round
  2158. onClick={() => (popup.barShow = false)}
  2159. >
  2160. 取消
  2161. </NButton>
  2162. <NButton
  2163. style={{ width: "48%" }}
  2164. round
  2165. type="primary"
  2166. onClick={() => handleAddMearse()}
  2167. >
  2168. 确定
  2169. </NButton>
  2170. </NSpace>
  2171. </NSpace>
  2172. </>
  2173. ),
  2174. }}
  2175. </NPopover>
  2176. <NPopover
  2177. class={styles.popupWrap}
  2178. v-model:show={popup.mearseDeleteShow}
  2179. trigger="click"
  2180. placement="bottom"
  2181. >
  2182. {{
  2183. trigger: () => (
  2184. <div class={[styles.topBtn]}>
  2185. <div class={styles.btnImg}>
  2186. <img class={styles.topBtnIcon} src={getImage("icon_19.png")} />
  2187. </div>
  2188. <div>删除小节</div>
  2189. </div>
  2190. ),
  2191. default: () => (
  2192. <>
  2193. <div class={styles.btnLineTitle}>删除方式</div>
  2194. <NSpace vertical>
  2195. <NSpace>
  2196. <NButton
  2197. type={data.deleteMearseType === "ing" ? "primary" : "default"}
  2198. secondary
  2199. onClick={() => (data.deleteMearseType = "ing")}
  2200. >
  2201. 当前选中小节
  2202. </NButton>
  2203. <NButton
  2204. type={data.deleteMearseType === "finish" ? "primary" : "default"}
  2205. secondary
  2206. onClick={() => (data.deleteMearseType = "finish")}
  2207. >
  2208. 末尾空白小节
  2209. </NButton>
  2210. </NSpace>
  2211. <NSpace
  2212. style={{ marginTop: "20px" }}
  2213. align="center"
  2214. wrap={false}
  2215. wrapItem={false}
  2216. >
  2217. <NButton
  2218. style={{ width: "48%" }}
  2219. round
  2220. onClick={() => (popup.mearseDeleteShow = false)}
  2221. >
  2222. 取消
  2223. </NButton>
  2224. <NButton
  2225. style={{ width: "48%" }}
  2226. round
  2227. type="primary"
  2228. onClick={() => handleDeleteMearse()}
  2229. >
  2230. 确定
  2231. </NButton>
  2232. </NSpace>
  2233. </NSpace>
  2234. </>
  2235. ),
  2236. }}
  2237. </NPopover>
  2238. <div class={styles.topLine}></div>
  2239. <div style={{ marginLeft: "auto" }} class={styles.topBtn}>
  2240. <NSpin show={data.loadingAudioSrouce} size="small">
  2241. <div class={styles.btnImg} onClick={() => togglePlay("reset")}>
  2242. <img class={styles.topBtnIcon} src={getImage("icon_20.png")} />
  2243. </div>
  2244. </NSpin>
  2245. <div>重播</div>
  2246. </div>
  2247. <div class={styles.topBtn}>
  2248. <NSpin show={data.loadingAudioSrouce} size="small">
  2249. <div
  2250. class={styles.btnImg}
  2251. onClick={() => togglePlay(data.playState ? "pause" : "play")}
  2252. >
  2253. <img
  2254. style={{ display: data.playState ? "" : "none" }}
  2255. class={styles.topBtnIcon}
  2256. src={getImage("icon_21_1.png")}
  2257. />
  2258. <img
  2259. style={{ display: data.playState ? "none" : "" }}
  2260. class={styles.topBtnIcon}
  2261. src={getImage("icon_21.png")}
  2262. />
  2263. </div>
  2264. </NSpin>
  2265. <div>{data.playState ? "暂停" : "播放"}</div>
  2266. </div>
  2267. {/* styles.btnDisabled */}
  2268. <div
  2269. id="selectMearesBtn"
  2270. class={[styles.topBtn]}
  2271. onClick={() => (popup.selectMearesShow = !popup.selectMearesShow)}
  2272. >
  2273. <div class={[styles.btnImg, popup.selectMearesShow && styles.btnImgActive]}>
  2274. <img class={styles.topBtnIcon} src={getImage("icon_22.png")} />
  2275. </div>
  2276. <div>选段</div>
  2277. </div>
  2278. <div
  2279. class={[styles.topBtn]}
  2280. onClick={() => {
  2281. metronomeData.disable = !metronomeData.disable;
  2282. metronomeData.metro?.initPlayer();
  2283. }}
  2284. >
  2285. <div class={[styles.btnImg, !metronomeData.disable && styles.btnImgActive]}>
  2286. <img class={styles.topBtnIcon} src={getImage("icon_23.png")} />
  2287. </div>
  2288. <div>节拍器</div>
  2289. </div>
  2290. <div class={[styles.topBtn]} onClick={() => (popup.settingShow = true)}>
  2291. <div class={styles.btnImg}>
  2292. <img class={styles.topBtnIcon} src={getImage("icon_24.png")} />
  2293. </div>
  2294. <div>设置</div>
  2295. </div>
  2296. </div>
  2297. </div>
  2298. <div class={styles.content}>
  2299. <div class={styles.slide}>
  2300. <Collapse v-model={data.slide} elevation={false} divider={false}>
  2301. <CollapseItem title="音符时值" name="note">
  2302. <div class={styles.wrapBox}>
  2303. {ABC_DATA.types.map((item) => (
  2304. <div
  2305. class={styles.topBtn}
  2306. onClick={() => handleChange({ type: "type", value: item.value })}
  2307. >
  2308. <div
  2309. class={[styles.btnImg, data.noteType === item.value && styles.btnImgActive]}
  2310. >
  2311. <TheIcon iconClassName={item.icon} />
  2312. </div>
  2313. <div>{item.name}</div>
  2314. </div>
  2315. ))}
  2316. <div
  2317. class={styles.topBtn}
  2318. onClick={() => handleChange({ type: "note", value: "z" })}
  2319. >
  2320. <div
  2321. class={[
  2322. styles.btnImg,
  2323. noteComputed.value.content === "z" && styles.btnImgActive,
  2324. ]}
  2325. >
  2326. <img style={{ width: "20px", height: "20px" }} src={getImage("icon_rest.png")} />
  2327. </div>
  2328. <div>休止符</div>
  2329. </div>
  2330. <div
  2331. class={styles.topBtn}
  2332. onClick={() => handleChange({ type: "segno", value: " " })}
  2333. >
  2334. <div
  2335. class={[styles.btnImg, noteComputed.value.segno === " " && styles.btnImgActive]}
  2336. >
  2337. {/* <img style={{ width: "20px", height: "20px" }} src={getImage("icon_rest.png")} /> */}
  2338. </div>
  2339. <div>分割</div>
  2340. </div>
  2341. </div>
  2342. </CollapseItem>
  2343. <CollapseItem title="拍号" name="meter">
  2344. <div class={styles.wrapBox}>
  2345. {ABC_DATA.meter.map((item) => (
  2346. <div
  2347. class={styles.topBtn}
  2348. onClick={() => handleChange({ type: "meter", value: item.value })}
  2349. >
  2350. <div class={[styles.btnImg]}>
  2351. <TheIcon iconClassName={item.icon} />
  2352. </div>
  2353. <div>{item.name}</div>
  2354. </div>
  2355. ))}
  2356. </div>
  2357. </CollapseItem>
  2358. <CollapseItem title="力度记号" name="dynamics">
  2359. <div class={styles.wrapBox}>
  2360. {ABC_DATA.dynamics.slice(0, 8).map((item) => (
  2361. <div
  2362. class={styles.topBtn}
  2363. onClick={() => handleChange({ type: "dynamics", value: item.value })}
  2364. >
  2365. <div
  2366. class={[
  2367. styles.btnImg,
  2368. noteComputed.value.dynamics === item.value && styles.btnImgActive,
  2369. ]}
  2370. >
  2371. <TheIcon iconClassName={item.icon} size={["2em", "2em"]} />
  2372. </div>
  2373. <div>{item.name}</div>
  2374. </div>
  2375. ))}
  2376. <div
  2377. class={styles.topBtn}
  2378. onClick={() =>
  2379. handleChange({ type: "dynamics", value: ABC_DATA.dynamics[8].value })
  2380. }
  2381. >
  2382. <div
  2383. class={[
  2384. styles.btnImg,
  2385. ABC_DATA.dynamics[8].value.includes(noteComputed.value.dynamics) &&
  2386. styles.btnImgActive,
  2387. ]}
  2388. >
  2389. <TheIcon iconClassName={ABC_DATA.dynamics[8].icon} size={["2em", "2em"]} />
  2390. </div>
  2391. <div>{ABC_DATA.dynamics[8].name}</div>
  2392. </div>
  2393. <div
  2394. class={styles.topBtn}
  2395. onClick={() =>
  2396. handleChange({ type: "dynamics", value: ABC_DATA.dynamics[9].value })
  2397. }
  2398. >
  2399. <div
  2400. class={[
  2401. styles.btnImg,
  2402. ABC_DATA.dynamics[9].value.includes(noteComputed.value.dynamics) &&
  2403. styles.btnImgActive,
  2404. ]}
  2405. >
  2406. <TheIcon iconClassName={ABC_DATA.dynamics[9].icon} size={["2em", "2em"]} />
  2407. </div>
  2408. <div>{ABC_DATA.dynamics[9].name}</div>
  2409. </div>
  2410. </div>
  2411. </CollapseItem>
  2412. <CollapseItem title="反复与跳跃" name="repeat">
  2413. <div class={styles.wrapBox}>
  2414. {ABC_DATA.repeat.map((item) => (
  2415. <div
  2416. class={[styles.topBtn, styles.longTopBtn]}
  2417. onClick={() => handleChange({ type: "repeat", value: item.value })}
  2418. >
  2419. <div
  2420. class={[
  2421. styles.btnImg,
  2422. measureComputed.value.repeat === item.value && styles.btnImgActive,
  2423. ]}
  2424. >
  2425. <TheIcon iconClassName={item.icon} size={["5em", "1em"]} />
  2426. </div>
  2427. <div>{item.name}</div>
  2428. </div>
  2429. ))}
  2430. </div>
  2431. </CollapseItem>
  2432. <CollapseItem title="小节线" name="line">
  2433. <div class={styles.wrapBox}>
  2434. {ABC_DATA.bar.map((item) => (
  2435. <div
  2436. class={styles.topBtn}
  2437. onClick={() => {
  2438. data.morePlay = false;
  2439. handleChange({ type: "barline", value: item.value });
  2440. }}
  2441. >
  2442. <div
  2443. class={[
  2444. styles.btnImg,
  2445. measureComputed.value.barline === item.value && styles.btnImgActive,
  2446. ]}
  2447. >
  2448. <TheIcon iconClassName={item.icon} size={["2em", "2em"]} />
  2449. </div>
  2450. <div>{item.name}</div>
  2451. </div>
  2452. ))}
  2453. </div>
  2454. </CollapseItem>
  2455. <CollapseItem title="谱号" name="clef">
  2456. <div class={styles.wrapBox}>
  2457. {ABC_DATA.clef.map((item) => (
  2458. <div
  2459. class={styles.topBtn}
  2460. onClick={() => handleChange({ type: "clef", value: item.value })}
  2461. >
  2462. <div class={[styles.btnImg]}>
  2463. <TheIcon iconClassName={item.icon} />
  2464. </div>
  2465. <div>{item.name}</div>
  2466. </div>
  2467. ))}
  2468. </div>
  2469. </CollapseItem>
  2470. <CollapseItem title="调号" name="key">
  2471. <div class={styles.wrapBox}>
  2472. {ABC_DATA.key.map((item) => (
  2473. <div
  2474. class={styles.topBtn}
  2475. onClick={() => handleChange({ type: "key", value: item.value })}
  2476. >
  2477. <div class={[styles.btnImg]}>
  2478. <TheIcon iconClassName={item.icon} />
  2479. </div>
  2480. <div>{item.name}</div>
  2481. </div>
  2482. ))}
  2483. </div>
  2484. </CollapseItem>
  2485. </Collapse>
  2486. </div>
  2487. <div class={styles.box}>
  2488. <div class={styles.titleBox}>
  2489. <div class={styles.titleName} style={{ width: "50%", margin: "0 auto" }}>
  2490. <NInput
  2491. onBlur={() => {
  2492. data.isSave = false;
  2493. autoSave();
  2494. }}
  2495. onKeyup={(e: Event) => e.stopPropagation()}
  2496. v-model:value={data.musicName}
  2497. placeholder="曲谱名称"
  2498. />
  2499. </div>
  2500. <div style={{ width: "30%", margin: "10px 0 0 auto" }}>
  2501. <NInput
  2502. onBlur={() => {
  2503. data.isSave = false;
  2504. autoSave();
  2505. }}
  2506. onKeyup={(e: Event) => e.stopPropagation()}
  2507. v-model:value={data.creator}
  2508. placeholder="曲谱作者"
  2509. />
  2510. </div>
  2511. </div>
  2512. <div id="paper"></div>
  2513. {!data.loading && (
  2514. <Keys
  2515. show={data.active ? true : false}
  2516. instrumentCode={abcData.abc.subjectCode}
  2517. onClick={(val) => handleChange(val)}
  2518. />
  2519. )}
  2520. {/* <textarea ref={textAreaRef} class={styles.value} id="abc"></textarea> */}
  2521. <div id="importRef" style={{ display: "none" }}></div>
  2522. <div id="audio" style={{ display: "none" }}></div>
  2523. </div>
  2524. {data.loadingAudioSrouce && (
  2525. <div class={styles.loading}>
  2526. <NSpin description="资源加载中..."></NSpin>
  2527. </div>
  2528. )}
  2529. </div>
  2530. <div ref={downRef}></div>
  2531. <TheSetting v-model:show={popup.settingShow} />
  2532. {data.selectMeasures.state && (
  2533. <div
  2534. style={{ left: data.selectMeasures.x + "px", top: data.selectMeasures.y + "px" }}
  2535. class={[styles.selectMearesBox, !popup.selectMearesShow && styles.selectMearesHidden]}
  2536. >
  2537. <div onKeyup={(e: Event) => e.stopPropagation()}>
  2538. <NSpace justify="space-between">
  2539. <div class={styles.btnLineTitle}>输入小节范围</div>
  2540. <NButton
  2541. circle
  2542. quaternary
  2543. size="small"
  2544. onClick={() => (popup.selectMearesShow = false)}
  2545. >
  2546. <NIcon size={16} component={<Close />} />
  2547. </NButton>
  2548. </NSpace>
  2549. <NSpace align="center" wrap={false} wrapItem={false}>
  2550. <div class={styles.mearesInput}>
  2551. <NInputNumber
  2552. min={1}
  2553. max={
  2554. (data.selectMeasures.end ? data.selectMeasures.end + 1 : 0) ||
  2555. data.selectMeasures.max
  2556. }
  2557. bordered={false}
  2558. placeholder="开始小节"
  2559. showButton={false}
  2560. onUpdate:value={(val) => handleSetSelectMeares(val, "start")}
  2561. ></NInputNumber>
  2562. -
  2563. <NInputNumber
  2564. min={data.selectMeasures.start}
  2565. max={data.selectMeasures.max}
  2566. bordered={false}
  2567. placeholder="结束小节"
  2568. showButton={false}
  2569. onUpdate:value={(val) => handleSetSelectMeares(val, "end")}
  2570. ></NInputNumber>
  2571. </div>
  2572. <div class={styles.topBtn}>
  2573. <NSpin show={data.loadingAudioSrouce} size="small">
  2574. <div
  2575. class={styles.btnImg}
  2576. onClick={() => togglePlay(data.playState ? "pause" : "play")}
  2577. >
  2578. <img
  2579. style={{ display: data.playState ? "" : "none" }}
  2580. class={styles.topBtnIcon}
  2581. src={getImage("icon_21_1.png")}
  2582. />
  2583. <img
  2584. style={{ display: data.playState ? "none" : "" }}
  2585. class={styles.topBtnIcon}
  2586. src={getImage("icon_21.png")}
  2587. />
  2588. </div>
  2589. </NSpin>
  2590. </div>
  2591. </NSpace>
  2592. </div>
  2593. </div>
  2594. )}
  2595. </div>
  2596. <div class={styles.exportPng}>
  2597. <div id="exportPng"></div>
  2598. </div>
  2599. <UploadToResources
  2600. v-model:show={data.uploadShow}
  2601. item={data.item}
  2602. onSuccess={() => {
  2603. data.uploadStatus = "YES";
  2604. message.success("上传成功");
  2605. if (data.uploadClick) {
  2606. setTimeout(() => {
  2607. handleClose();
  2608. }, 300);
  2609. }
  2610. }}
  2611. />
  2612. </>
  2613. );
  2614. },
  2615. });