index.tsx 74 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969
  1. import { computed, defineComponent, nextTick, onMounted, onUnmounted, reactive, ref } from "vue";
  2. import ABCJS, { AbcElem, AbcVisualParams, ClickListenerAnalysis, ClickListenerDrag, SynthObjectController } from "abcjs";
  3. import "ABCJS/ABCJS-audio.css";
  4. import styles from "./index.module.less";
  5. import { showConfirmDialog, showToast } from "vant";
  6. import Keys from "../component/keys";
  7. import { Collapse, CollapseItem } from "@varlet/ui";
  8. import { IAbc, IMeasure, INote, INoteActive } from "../types";
  9. import { ABC_DATA, createMeasure, createNote, formateAbc, getKeyStep, moveNoteKey, renderMeasures } from "./runtime";
  10. import TheIcon from "/src/components/The-icon";
  11. import { cloneDeep } from "lodash";
  12. import TheSpeed from "./component/the-speed";
  13. import { getImage } from "./images";
  14. import { NButton, NDropdown, NGi, NGrid, NIcon, NInput, NInputNumber, NModal, NPopover, NPopselect, NSelect, NSpace, NSpin, useDialog, useMessage } from "naive-ui";
  15. import { LongArrowAltDown, LongArrowAltUp, GripLinesVertical } from "@vicons/fa";
  16. import { svg2canvas } from "/src/utils/svg2canvas";
  17. import { downloadFile } from "/src/utils";
  18. import FileBtn, { IFileBtnType } from "./component/file-btn";
  19. import TheSetting from "./component/the-setting";
  20. import { useRoute } from "vue-router";
  21. import { api_musicSheetCreationDetail, api_musicSheetCreationUpdate } from "../api";
  22. import instrumentsNames from "/src/constant/instrmentsNames.json";
  23. import { ALL_NOTES, NOTE_DOT } from "./noteData";
  24. import { Close } from "@vicons/ionicons5";
  25. import { UseDraggable } from "@vueuse/components";
  26. import { getQuery } from "/src/utils/queryString";
  27. const allPitches = [
  28. "C,,,,",
  29. "D,,,,",
  30. "E,,,,",
  31. "F,,,,",
  32. "G,,,,",
  33. "A,,,,",
  34. "B,,,,",
  35. "C,,,",
  36. "D,,,",
  37. "E,,,",
  38. "F,,,",
  39. "G,,,",
  40. "A,,,",
  41. "B,,,",
  42. "C,,",
  43. "D,,",
  44. "E,,",
  45. "F,,",
  46. "G,,",
  47. "A,,",
  48. "B,,",
  49. "C,",
  50. "D,",
  51. "E,",
  52. "F,",
  53. "G,",
  54. "A,",
  55. "B,",
  56. "C",
  57. "D",
  58. "E",
  59. "F",
  60. "G",
  61. "A",
  62. "B",
  63. "c",
  64. "d",
  65. "e",
  66. "f",
  67. "g",
  68. "a",
  69. "b",
  70. "c'",
  71. "d'",
  72. "e'",
  73. "f'",
  74. "g'",
  75. "a'",
  76. "b'",
  77. "c''",
  78. "d''",
  79. "e''",
  80. "f''",
  81. "g''",
  82. "a''",
  83. "b''",
  84. "c'''",
  85. "d'''",
  86. "e'''",
  87. "f'''",
  88. "g'''",
  89. "a'''",
  90. "b'''",
  91. "c''''",
  92. "d''''",
  93. "e''''",
  94. "f''''",
  95. "g''''",
  96. "a''''",
  97. "b''''",
  98. ];
  99. export const initMusic = (total: number): IMeasure[] => {
  100. return new Array(total).fill(0).map((item, index) => {
  101. return {
  102. measureNumber: index + 1,
  103. barline: "|",
  104. celf: "",
  105. key: "",
  106. repeat: "",
  107. notes: [
  108. {
  109. accidental: "",
  110. clef: "",
  111. meter: "",
  112. content: "z",
  113. noteType: "4",
  114. play: [],
  115. key: "",
  116. speed: "",
  117. dynamics: "",
  118. dCode: "",
  119. tie: "",
  120. tCode: "",
  121. dot: "",
  122. slus: "",
  123. tieline: "",
  124. segno: "",
  125. },
  126. ],
  127. };
  128. });
  129. };
  130. function moveNote(note: string, step: number) {
  131. var x = allPitches.indexOf(note);
  132. if (x >= 0) {
  133. const _note = allPitches[x - step];
  134. return _note ? _note : note;
  135. }
  136. return note;
  137. }
  138. export default defineComponent({
  139. name: "Home",
  140. setup() {
  141. const route = useRoute();
  142. const message = useMessage();
  143. const dialog = useDialog();
  144. const popup = reactive({
  145. instrument: false,
  146. selectSubjectShow: false, // 声部弹窗
  147. moveKeyShow: false, // 移调弹窗
  148. speedShow: false, // 节拍弹窗
  149. accidentalsShow: false, // 临时升降记号弹窗
  150. clefShow: false, // 谱号弹窗
  151. keyShow: false, // 调号弹窗
  152. meterShow: false, // 拍号弹窗
  153. playShow: false, // 演奏技法弹窗
  154. dynamicsShow: false, // 力度标记弹窗
  155. barShow: false, // 小节弹窗
  156. mearseDeleteShow: false,
  157. staffShow: false, // 五线谱弹窗
  158. settingShow: false, // 设置弹窗
  159. selectMearesShow: false, // 选择小节弹窗
  160. });
  161. const data = reactive({
  162. drawCount: 0,
  163. isSave: false,
  164. musicId: "",
  165. musicName: "", // 曲谱名称
  166. creator: "", // 创建者
  167. subjectId: "", // 声部
  168. speed: "",
  169. music: "",
  170. playState: false, // 播放状态
  171. active: null as unknown as INoteActive,
  172. select: {
  173. state: false,
  174. list: [] as any[],
  175. parmas: null as any,
  176. },
  177. isClickNote: false,
  178. /** 音符类型 */
  179. noteType: "",
  180. /** 选择小节范围 */
  181. selectMeasures: {
  182. state: false,
  183. x: 0,
  184. y: 0,
  185. start: 1,
  186. startNote: null as any,
  187. end: 0,
  188. endNote: null as any,
  189. max: 30,
  190. },
  191. slide: ["note", "meter", "dynamics"],
  192. morePlay: false, // 更多演奏技法
  193. addMearseType: "pre" as "pre" | "next" | "finish", // 添加小节类型
  194. addMearseNumber: 1, // 添加小节数量
  195. deleteMearseType: "ing" as "ing" | "finish", // 删除小节类型
  196. loadingAudioSrouce: false, // 加载音频资源
  197. /** 移调类型 */
  198. moveKeyType: "inset" as "inset" | "up" | "down", // 移调类型
  199. });
  200. const noteTypes = ABC_DATA.types.map((item) => item.value).filter(Boolean);
  201. const accidentals = ABC_DATA.accidentals.map((item) => item.value).filter(Boolean);
  202. const clefs = ABC_DATA.clef.map((item) => item.value).filter(Boolean);
  203. const playTypes = ABC_DATA.play.map((item) => item.value).filter(Boolean);
  204. const dynamics = ABC_DATA.dynamics
  205. .map((item) => item.value)
  206. .flat()
  207. .filter(Boolean);
  208. const barTypes = ABC_DATA.bar.map((item) => item.value).filter(Boolean);
  209. console.log("🚀 ~ noteTypes:", noteTypes, accidentals, clefs, playTypes, dynamics);
  210. /** 点击音符 */
  211. const clickListener = (abcElem: AbcElem, tuneNumber: number, classes: string, analysis: ClickListenerAnalysis, drag: ClickListenerDrag) => {
  212. // console.log("🚀 ~ data.select.state:", data.select.state);
  213. let indexStr: any = abcElem.chord?.find((n) => n.position === "left")?.name || "";
  214. indexStr = indexStr.split(".").map((n: string) => Number(n));
  215. const active = {
  216. ...cloneDeep(abcElem),
  217. measureIndex: indexStr[0],
  218. noteIndex: indexStr[1],
  219. isFirstChecked: true,
  220. };
  221. // 选择范围模式
  222. if (data.select.state) {
  223. data.select.list.push(active);
  224. if (data.select.list.length === 1) {
  225. showToast("请先选择结束音符");
  226. }
  227. if (data.select.list.length === 2) {
  228. console.log(data.select.list);
  229. data.select.list = data.select.list.sort((a, b) => a.startChar - b.startChar);
  230. handleSelectNote();
  231. }
  232. return;
  233. }
  234. data.active = active;
  235. console.log("🚀 ~ abcElem:", abcElem, data.music.substring(data.active.startChar, data.active.endChar));
  236. if (data.active?.el_type === "note") {
  237. const totalTime = (abcData.synthControl as any).visualObj.getTotalTime();
  238. if (totalTime) {
  239. const progress = (data.active as any).currentTrackMilliseconds / 1000 / totalTime;
  240. // console.log("🚀 ~ data.active:", progress);
  241. (abcData.synthControl as any).seek(progress);
  242. }
  243. }
  244. // if (abcElem.el_type === "tempo") {
  245. // abcData.visualObj.engraver.rangeHighlight(abcElem.startChar, abcElem.endChar);
  246. // }
  247. if (drag && drag.step) {
  248. handleChange({ type: "move", value: { action: "drag", step: drag.step } });
  249. return;
  250. }
  251. if (!abcElem?.midiPitches) return;
  252. ABCJS.synth.playEvent(abcElem.midiPitches, abcElem.midiGraceNotePitches, 1000);
  253. };
  254. const textAreaRef = ref();
  255. const abcData = reactive({
  256. visualObj: null as any,
  257. midiBuffer: null as unknown as ABCJS.MidiBuffer,
  258. abcOptions: {
  259. selectionColor: "#0f81ff",
  260. jazzchords: true,
  261. add_classes: true,
  262. clickListener: clickListener,
  263. responsive: "resize",
  264. dragging: true,
  265. selectTypes: ["note"],
  266. visualTranspose: 0,
  267. wrap: {
  268. minSpacing: 0.1,
  269. maxSpacing: 2.7,
  270. preferredMeasuresPerLine: 4,
  271. },
  272. staffwidth: 800,
  273. } as AbcVisualParams,
  274. synthControl: null as unknown as SynthObjectController,
  275. synthOptions: {
  276. program: 0,
  277. // soundFontUrl: "/soundFonts/",
  278. // soundFontUrl: "https://paulrosen.github.io/midi-js-soundfonts/MusyngKite/",
  279. },
  280. abc: {
  281. celf: "K:treble",
  282. minUnit: "L:1/4",
  283. meter: "M:4/4",
  284. speed: "Q:1/4=60",
  285. key: "K:C",
  286. visualTranspose: 0,
  287. subjectCode: "acoustic_grand_piano",
  288. measures: initMusic(30),
  289. } as IAbc,
  290. });
  291. /** 添加音符 */
  292. const handleCreateNote = (measureIndex: number, noteIndex: number, options: INote) => {
  293. // console.log("🚀 ~ noteIndex:", noteIndex);
  294. const measure = abcData.abc.measures[measureIndex];
  295. if (measure) {
  296. measure.notes.splice(noteIndex + 1, 0, options);
  297. }
  298. };
  299. const hideCursor = () => {
  300. const cursor = document.querySelector("#paper svg .ABCJS-cursor");
  301. if (cursor) {
  302. cursor.setAttribute("x1", "0");
  303. cursor.setAttribute("x2", "0");
  304. cursor.setAttribute("y1", "0");
  305. cursor.setAttribute("y2", "0");
  306. }
  307. };
  308. const cursorControl = {
  309. onReady: function () {},
  310. onStart: function () {
  311. console.log("开始");
  312. data.playState = true;
  313. var svg = document.querySelector("#paper svg");
  314. var cursor = document.createElementNS("http://www.w3.org/2000/svg", "line");
  315. cursor.setAttribute("class", "ABCJS-cursor");
  316. cursor.setAttributeNS(null, "x1", "0");
  317. cursor.setAttributeNS(null, "y1", "0");
  318. cursor.setAttributeNS(null, "x2", "0");
  319. cursor.setAttributeNS(null, "y2", "0");
  320. svg?.appendChild(cursor);
  321. },
  322. onBeat: function (beatNumber: any, totalBeats: any, totalTime: any) {},
  323. onEvent: (ev: any) => {
  324. // console.log("🚀 ~ ev:", ev);
  325. if (!data.playState) return;
  326. if (ev.measureStart && ev.left === null) return; // this was the second part of a tie across a measure line. Just ignore it.
  327. if (popup.selectMearesShow) {
  328. const startTime = data.selectMeasures.startNote?.currentTrackMilliseconds || 0;
  329. const endNote: any = data.selectMeasures.endNote ? data.selectMeasures.endNote : null;
  330. // console.log("🚀 ~ endNote:", ev.milliseconds , endNote.currentTrackMilliseconds)
  331. if (ev.milliseconds < startTime || (endNote && ev.milliseconds > endNote.currentTrackMilliseconds)) {
  332. const totalTime = (abcData.synthControl as any).visualObj.getTotalTime();
  333. if (totalTime) {
  334. const progress = startTime / 1000 / totalTime;
  335. nextTick(() => {
  336. (abcData.synthControl as any).seek(progress);
  337. });
  338. }
  339. }
  340. }
  341. var cursor = document.querySelector("#paper svg .ABCJS-cursor");
  342. if (cursor) {
  343. cursor.setAttribute("x1", ev.left + ev.width / 2);
  344. cursor.setAttribute("x2", ev.left + ev.width / 2);
  345. cursor.setAttribute("y1", ev.top);
  346. cursor.setAttribute("y2", ev.top + ev.height);
  347. }
  348. },
  349. onFinished: function () {
  350. console.log("finished");
  351. data.playState = false;
  352. var els = document.querySelectorAll("svg .highlight");
  353. for (var i = 0; i < els.length; i++) {
  354. els[i].classList.remove("highlight");
  355. }
  356. hideCursor();
  357. },
  358. };
  359. const staffNotes = ALL_NOTES();
  360. const loadMiniMp3 = async () => {
  361. data.loadingAudioSrouce = true;
  362. const midiBuffer = new ABCJS.synth.CreateSynth();
  363. const str = `X: 1\nM:4/4\nL:1/4\n${staffNotes}`;
  364. const visualObj = ABCJS.parseOnly(str);
  365. await midiBuffer.init({
  366. visualObj: visualObj[0],
  367. options: { ...abcData.synthOptions },
  368. });
  369. };
  370. const resetMidi = (useActive = false) => {
  371. const midiBuffer = new ABCJS.synth.CreateSynth();
  372. midiBuffer
  373. .init({
  374. visualObj: abcData.visualObj,
  375. options: { ...abcData.synthOptions },
  376. })
  377. .then(() => {
  378. abcData.synthControl
  379. .setTune(abcData.visualObj, useActive, {
  380. midiTranspose: abcData.abc.visualTranspose,
  381. program: abcData.synthOptions.program,
  382. })
  383. .then(function (response) {
  384. data.loadingAudioSrouce = false;
  385. // console.log("Audio successfully loaded.", {...abcData.synthControl});
  386. // console.log("🚀 ~ abcData.synthControl:", abcData.synthControl);
  387. })
  388. .catch((err) => {
  389. console.log(err);
  390. });
  391. });
  392. };
  393. const togglePlay = (type: "play" | "pause" | "reset") => {
  394. if (type === "play") {
  395. abcData.synthControl.play();
  396. data.playState = true;
  397. } else if (type === "pause") {
  398. abcData.synthControl.play();
  399. data.playState = false;
  400. hideCursor();
  401. } else {
  402. abcData.synthControl.restart();
  403. }
  404. // console.log("🚀 ~ abcData.synthControl:", abcData.synthControl.timer.noteTimings);
  405. };
  406. const renderSvg = () => {
  407. abcData.visualObj = ABCJS.renderAbc("paper", data.music, {
  408. ...abcData.abcOptions,
  409. visualTranspose: abcData.abc.visualTranspose,
  410. })[0];
  411. if (data.drawCount < 3) {
  412. console.log("🚀 ~ visualObj:", abcData.visualObj);
  413. }
  414. };
  415. const renderBoxRect = () => {
  416. const svg = document.querySelector("#paper svg");
  417. const padding = 4;
  418. let measureNumber = 0;
  419. for (let i = 0; i < abcData.visualObj.lines.length; i++) {
  420. const line = abcData.visualObj.lines[i];
  421. // console.log("🚀 ~ line:", line);
  422. for (let j = 0; j < line.staff.length; j++) {
  423. const staff = line.staff[j];
  424. const voices = [...staff.voices].flat();
  425. for (let l = 0; l < voices.length; l++) {
  426. const item = voices[l];
  427. if (item.el_type === "bar") {
  428. measureNumber++;
  429. }
  430. // console.log(item.el_type);
  431. if (["note", "keySignature", "clef", "timeSignature"].includes(item.el_type)) {
  432. const box = item.abselem.elemset?.[0]?.getBBox?.() || null;
  433. // console.log("🚀 ~ box:", item.abselem, box);
  434. if (box) {
  435. const rect = document.createElementNS("http://www.w3.org/2000/svg", "rect");
  436. rect.setAttributeNS(null, "x", box.x - padding + "");
  437. rect.setAttributeNS(null, "y", box.y - padding + "");
  438. rect.setAttributeNS(null, "width", box.width + padding * 2 + "");
  439. rect.setAttributeNS(null, "height", box.height + padding * 2 + "");
  440. rect.setAttributeNS(null, "fill", "rgba(0,0,0,0)");
  441. rect.setAttributeNS(null, "stroke", "rgba(0,0,0,0)");
  442. rect.setAttributeNS(null, "rx", "2");
  443. rect.classList.add("abcjs-note-hover");
  444. svg?.appendChild(rect);
  445. }
  446. }
  447. }
  448. }
  449. }
  450. console.log(measureNumber);
  451. data.selectMeasures.max = measureNumber;
  452. };
  453. /**
  454. * @param isProduct 是否是生成曲谱
  455. */
  456. const handleResetRender = () => {
  457. return new Promise((resolve) => {
  458. nextTick(() => {
  459. data.music = renderMeasures(abcData.abc);
  460. renderSvg();
  461. resetMidi(data.drawCount > 0 ? true : false);
  462. renderBoxRect();
  463. resolve(1);
  464. textAreaRef.value && (textAreaRef.value.value = data.music);
  465. data.drawCount++;
  466. // const times = new ABCJS.TimingCallbacks(abcData.visualObj);
  467. // console.log("🚀 ~ times:", times)
  468. });
  469. });
  470. };
  471. // 高亮选中的音符
  472. const rangeHighlight = (startChar: number) => {
  473. // console.log(data.active.endChar, abcData.visualObj.getElementFromChar(data.active.startChar));
  474. const abcElem: AbcElem = abcData.visualObj.getElementFromChar(startChar);
  475. if (abcElem) {
  476. abcData.visualObj.engraver.rangeHighlight(abcElem.startChar, abcElem.endChar);
  477. }
  478. return abcElem;
  479. };
  480. const useIndexGetNote = (indexStr: string) => {
  481. const index = data.music.indexOf(indexStr);
  482. const note = abcData.visualObj.getElementFromChar(index);
  483. return note;
  484. };
  485. const getMeasureNotes = (measureIndex: number) => {
  486. const measure = abcData.abc.measures[measureIndex];
  487. const notes = [];
  488. for (let k = 0; k < measure.notes.length; k++) {
  489. const indexStr = `${measureIndex}.${k}`;
  490. const note = useIndexGetNote(indexStr);
  491. notes.push(note);
  492. }
  493. return notes;
  494. };
  495. /**
  496. *
  497. * @param key
  498. * @param type note 音符 accidental 临时升降记号
  499. * @returns
  500. */
  501. const handleChange = async (params: { type: string; value: any }) => {
  502. abcData.synthControl.disable(true);
  503. if (data.playState) {
  504. data.playState = false;
  505. }
  506. const type = params.type;
  507. const value = params.value;
  508. const activeNote = abcData.abc.measures[data.active?.measureIndex]?.notes[data.active?.noteIndex] || null;
  509. if (type === "exit") {
  510. // 退出时先保存 不提示
  511. await handleSaveMusic(false);
  512. // 判断是否在应用中
  513. if (window.matchMedia("(display-mode: standalone)").matches) {
  514. window.onbeforeunload = null;
  515. window.parent.postMessage(
  516. {
  517. api: "notation_exit",
  518. },
  519. "*"
  520. );
  521. } else {
  522. dialog.warning({
  523. autoFocus: false,
  524. class: "deleteDialog",
  525. title: "退出制谱",
  526. content: () => <div style={{ paddingRight: "calc(var(--n-close-size) + 6px)" }}>是否退出制谱功能?</div>,
  527. positiveText: "取消",
  528. positiveButtonProps: {
  529. type: "default",
  530. },
  531. negativeText: "确定",
  532. negativeButtonProps: {
  533. type: "primary",
  534. ghost: false,
  535. },
  536. onPositiveClick: () => {},
  537. onNegativeClick: async () => {
  538. window.onbeforeunload = null;
  539. window.close();
  540. },
  541. });
  542. }
  543. }
  544. // console.log(params, activeNote);
  545. if (type === "type") {
  546. // 设置音符类型
  547. data.noteType = value;
  548. if (activeNote) {
  549. activeNote.noteType = value;
  550. await handleResetRender();
  551. const abcElem: AbcElem = rangeHighlight(data.active.startChar);
  552. const active: any = abcElem
  553. ? {
  554. ...cloneDeep(abcElem),
  555. measureIndex: data.active.measureIndex,
  556. noteIndex: data.active.noteIndex,
  557. isFirstChecked: true,
  558. }
  559. : null;
  560. data.active = active;
  561. }
  562. return;
  563. }
  564. // 分割
  565. if (type === "segno") {
  566. if (!data.active) {
  567. showToast("请先选择音符");
  568. return;
  569. }
  570. if (!activeNote) return;
  571. activeNote.segno = activeNote.segno ? "" : value;
  572. await handleResetRender();
  573. rangeHighlight(data.active.startChar);
  574. }
  575. // 修改音符,或者添加音符
  576. if (type === "note") {
  577. if (data.active && data.active.el_type == "note") {
  578. const activeNote = abcData.abc.measures[data.active.measureIndex]?.notes[data.active.noteIndex] || null;
  579. const _values = value.split("-");
  580. if (data.active.isFirstChecked) {
  581. activeNote.content = _values[0];
  582. activeNote.noteType = data.noteType;
  583. if (_values[1]) {
  584. activeNote.accidental = _values[1] || "";
  585. }
  586. data.active.isFirstChecked = false;
  587. }
  588. await handleResetRender();
  589. const oldNote = useIndexGetNote(`${data.active.measureIndex}.${data.active.noteIndex}`);
  590. if (oldNote?.abselem?.beam?.elems?.length) {
  591. // 判断是否需要分割beam
  592. const elems: AbcElem[] = oldNote.abselem.beam.elems;
  593. const beatDuration = abcData.visualObj.getBeatLength();
  594. const beamLength = elems.map((n) => n.duration).reduce((a, b) => a + b);
  595. if (beamLength >= beatDuration) {
  596. abcData.abc.measures[data.active.measureIndex].notes[data.active.noteIndex].segno = " ";
  597. await handleResetRender();
  598. }
  599. }
  600. if (oldNote?.midiPitches) {
  601. ABCJS.synth.playEvent(oldNote.midiPitches, oldNote.midiGraceNotePitches, 1000);
  602. }
  603. const nextNote = abcData.abc.measures[data.active.measureIndex]?.notes[data.active.noteIndex + 1];
  604. if (nextNote) {
  605. const abcNextElem: AbcElem = useIndexGetNote(`${data.active.measureIndex}.${data.active.noteIndex + 1}`);
  606. rangeHighlight(abcNextElem.startChar);
  607. data.active = {
  608. ...abcNextElem,
  609. measureIndex: data.active.measureIndex,
  610. noteIndex: data.active.noteIndex + 1,
  611. isFirstChecked: true,
  612. };
  613. } else {
  614. const notes = getMeasureNotes(data.active.measureIndex);
  615. const duration = notes.map((n) => n.duration).reduce((a, b) => a + b);
  616. if (duration >= 1) {
  617. // 小节内音符总时值过长,自动跳转到下一小节
  618. const nextMeasureNote = abcData.abc.measures[data.active.measureIndex + 1]?.notes[0];
  619. if (nextMeasureNote) {
  620. const abcNextElem: AbcElem = useIndexGetNote(`${data.active.measureIndex + 1}.${0}`);
  621. rangeHighlight(abcNextElem.startChar);
  622. data.active = {
  623. ...abcNextElem,
  624. measureIndex: data.active.measureIndex + 1,
  625. noteIndex: 0,
  626. isFirstChecked: true,
  627. };
  628. } else {
  629. // 到最后一个小节的最后一个音符了
  630. rangeHighlight(data.active.startChar);
  631. data.active.isFirstChecked = true;
  632. }
  633. } else {
  634. handleCreateNote(
  635. data.active.measureIndex,
  636. data.active.noteIndex,
  637. createNote({
  638. content: "z",
  639. noteType: data.noteType,
  640. })
  641. );
  642. await handleResetRender();
  643. const newNote = useIndexGetNote(`${data.active.measureIndex}.${data.active.noteIndex + 1}`);
  644. rangeHighlight(newNote.startChar);
  645. data.active = {
  646. ...newNote,
  647. measureIndex: data.active.measureIndex,
  648. noteIndex: data.active.noteIndex + 1,
  649. isFirstChecked: true,
  650. };
  651. }
  652. }
  653. }
  654. }
  655. // 临时升降记号
  656. if (type === "accidentals") {
  657. if (!data.active) {
  658. message.warning("请先选择音符");
  659. return;
  660. }
  661. if (activeNote.content === "z") {
  662. message.warning("休止符无法添加临时升降记号");
  663. return;
  664. }
  665. activeNote.accidental = activeNote.accidental == value ? "" : value;
  666. await handleResetRender();
  667. const abcElem: AbcElem = rangeHighlight(data.active.startChar);
  668. const active: any = abcElem
  669. ? {
  670. ...cloneDeep(abcElem),
  671. measureIndex: data.active.measureIndex,
  672. noteIndex: data.active.noteIndex,
  673. isFirstChecked: true,
  674. }
  675. : null;
  676. data.active = active;
  677. }
  678. // 谱号
  679. if (type === "clef") {
  680. if (data.active) {
  681. if (!activeNote) return;
  682. activeNote.clef = `[${value}]`;
  683. await handleResetRender();
  684. } else {
  685. abcData.abc.celf = value;
  686. handleResetRender();
  687. }
  688. }
  689. // 调号
  690. if (type === "key") {
  691. if (data.active) {
  692. if (!activeNote) return;
  693. activeNote.key = `[${value}]`;
  694. await handleResetRender();
  695. } else {
  696. abcData.abc.key = value;
  697. await handleResetRender();
  698. }
  699. }
  700. // 拍号
  701. if (type === "meter") {
  702. if (data.active) {
  703. if (!activeNote) return;
  704. activeNote.meter = `[${value}]`;
  705. await handleResetRender();
  706. const oldNote = useIndexGetNote(`${data.active.measureIndex}.${data.active.noteIndex}`);
  707. rangeHighlight(oldNote.startChar);
  708. } else {
  709. abcData.abc.meter = value;
  710. await handleResetRender();
  711. }
  712. }
  713. // 演奏技法
  714. if (type === "play") {
  715. if (!data.active) {
  716. message.warning("请先选择音符");
  717. return;
  718. }
  719. if (!activeNote) return;
  720. if (activeNote.play.includes(value)) {
  721. activeNote.play = activeNote.play.filter((item) => item !== value);
  722. } else {
  723. activeNote.play.push(value);
  724. }
  725. await handleResetRender();
  726. rangeHighlight(data.active.startChar);
  727. }
  728. // 力度标记,渐强渐弱
  729. if (type === "dynamics") {
  730. if (!data.active) {
  731. message.info("请先选择音符");
  732. return;
  733. }
  734. if (!activeNote) return;
  735. if (Array.isArray(value)) {
  736. if (activeNote?.dynamics) {
  737. activeNote.dynamics = "";
  738. for (let i = 0; i < abcData.abc.measures.length; i++) {
  739. const measure = abcData.abc.measures[i];
  740. for (let j = 0; j < measure.notes.length; j++) {
  741. const note = measure.notes[j];
  742. if (note.dCode === activeNote.dCode) {
  743. note.dynamics = "";
  744. }
  745. }
  746. }
  747. await handleResetRender();
  748. } else {
  749. data.select.list = [cloneDeep(data.active)];
  750. data.select.state = true;
  751. data.select.parmas = params;
  752. message.info("请选择结束音符");
  753. }
  754. return;
  755. }
  756. if (activeNote.dynamics === value) {
  757. activeNote.dynamics = "";
  758. } else {
  759. activeNote.dynamics = value;
  760. }
  761. await handleResetRender();
  762. rangeHighlight(data.active.startChar);
  763. }
  764. // 延音
  765. if (type === "tie") {
  766. if (!data.active) {
  767. message.info("请先选择音符");
  768. return;
  769. }
  770. if (!activeNote) return;
  771. if (Array.isArray(value)) {
  772. if (activeNote?.tie) {
  773. activeNote.tie = "";
  774. for (let i = 0; i < abcData.abc.measures.length; i++) {
  775. const measure = abcData.abc.measures[i];
  776. for (let j = 0; j < measure.notes.length; j++) {
  777. const note = measure.notes[j];
  778. if (note.tCode === activeNote.tCode) {
  779. note.tie = "";
  780. }
  781. }
  782. }
  783. await handleResetRender();
  784. return;
  785. } else {
  786. data.select.list = [cloneDeep(data.active)];
  787. data.select.state = true;
  788. data.select.parmas = params;
  789. message.info("请选择结束音符");
  790. return;
  791. }
  792. }
  793. const abcElem: any = getNextNote(data.active.endChar);
  794. if (activeNote.tieline) {
  795. activeNote.tieline = "";
  796. } else {
  797. if (data.active.averagepitch != abcElem.averagepitch) {
  798. message.warning("必须同音高才能添加延音线");
  799. return;
  800. }
  801. activeNote.tieline = value;
  802. }
  803. await handleResetRender();
  804. rangeHighlight(data.active.startChar);
  805. }
  806. // 反复
  807. if (type === "repeat") {
  808. if (!data.active) {
  809. return;
  810. }
  811. const activeMeasure = abcData.abc.measures[data.active.measureIndex] || null;
  812. if (!activeMeasure) return;
  813. if (activeMeasure.repeat === value) {
  814. activeMeasure.repeat = "";
  815. } else {
  816. activeMeasure.repeat = value;
  817. }
  818. await handleResetRender();
  819. rangeHighlight(data.active.startChar + value.length);
  820. }
  821. // 小节线
  822. if (type === "barline") {
  823. if (!data.active) {
  824. return;
  825. }
  826. const activeMeasure = abcData.abc.measures[data.active.measureIndex] || null;
  827. if (!activeMeasure) return;
  828. // 如果是开始重复,就修改前一个小节的barline
  829. if (value === "|:") {
  830. const prevMeasure = abcData.abc.measures[data.active.measureIndex - 1] || null;
  831. if (!prevMeasure) return;
  832. prevMeasure.barline = value;
  833. } else {
  834. activeMeasure.barline = value;
  835. }
  836. await handleResetRender();
  837. }
  838. // 速度
  839. if (type === "speeds") {
  840. if (data.active) {
  841. if (data.active.measureIndex === 0 && data.active.noteIndex === 0) {
  842. abcData.abc.speed = value;
  843. await handleResetRender();
  844. } else {
  845. const activeNote = abcData.abc.measures[data.active.measureIndex]?.notes[data.active.noteIndex] || null;
  846. if (!activeNote) return;
  847. activeNote.speed = `[${value}]`;
  848. await handleResetRender();
  849. }
  850. rangeHighlight(data.active.startChar);
  851. } else {
  852. abcData.abc.speed = value;
  853. await handleResetRender();
  854. }
  855. }
  856. // 附点
  857. if (type === "dot") {
  858. if (!data.active) {
  859. showToast("请先选择音符");
  860. return;
  861. }
  862. if (!activeNote) return;
  863. activeNote.dot = activeNote.dot ? "" : value;
  864. // activeNote.dot = activeNote.dot ? "" : NOTE_DOT[activeNote.noteType];
  865. await handleResetRender();
  866. rangeHighlight(data.active.startChar);
  867. }
  868. // 3连音
  869. if (type === "slus") {
  870. const activeNote = abcData.abc.measures[data.active.measureIndex]?.notes[data.active.noteIndex] || null;
  871. if (!activeNote) return;
  872. activeNote.slus = activeNote.slus === value ? "" : value;
  873. await handleResetRender();
  874. rangeHighlight(data.active.startChar);
  875. }
  876. // 移动音符
  877. if (type === "move") {
  878. const step = value._step ? value._step : value.action === "up" ? -1 : 1;
  879. if (!activeNote) return;
  880. activeNote.content = moveNote(activeNote.content, step);
  881. // 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("").
  882. await handleResetRender();
  883. const _abcElem = rangeHighlight(data.active.startChar);
  884. if (!_abcElem?.midiPitches) return;
  885. ABCJS.synth.playEvent(_abcElem.midiPitches, _abcElem.midiGraceNotePitches, 1000);
  886. }
  887. // 删除音符
  888. if (type === "delete") {
  889. if (!data.active) return;
  890. if (data.active.startChar === 0) return;
  891. abcData.abc.measures[data.active.measureIndex].notes.splice(data.active.noteIndex, 1);
  892. if (abcData.abc.measures[data.active.measureIndex].notes.length === 0) {
  893. abcData.abc.measures.splice(data.active.measureIndex, 1);
  894. }
  895. handleResetRender();
  896. data.active = null as unknown as INoteActive;
  897. }
  898. };
  899. const getNextNote = (index: number): AbcElem => {
  900. const abcElem = abcData.visualObj.getElementFromChar(index);
  901. if (abcElem.el_type === "note") {
  902. return abcElem;
  903. } else {
  904. return getNextNote(abcElem.endChar);
  905. }
  906. };
  907. const handleDeleteNote = () => {
  908. if (!data.active) return;
  909. if (data.active.startChar === 0) return;
  910. abcData.abc.measures[data.active.measureIndex].notes.splice(data.active.noteIndex, 1);
  911. if (abcData.abc.measures[data.active.measureIndex].notes.length === 0) {
  912. abcData.abc.measures.splice(data.active.measureIndex, 1);
  913. }
  914. handleResetRender();
  915. data.active = null as unknown as INoteActive;
  916. };
  917. const clearSelectNote = () => {
  918. data.active = null as unknown as INoteActive;
  919. const notes = document.querySelectorAll(".abcjs-note_selected");
  920. notes.forEach((item) => {
  921. item.classList.remove("abcjs-note_selected");
  922. item.setAttribute("fill", "currentColor");
  923. });
  924. };
  925. const handleSelectNote = async () => {
  926. const type = data.select.parmas?.type;
  927. const value = data.select.parmas?.value;
  928. const startItem = data.select.list[0];
  929. const endItem = data.select.list[1];
  930. // 力度标记,渐强渐弱
  931. if (type === "dynamics") {
  932. if (abcData.abc.measures[endItem.measureIndex].notes[endItem.noteIndex].dynamics || abcData.abc.measures[startItem.measureIndex].notes[startItem.noteIndex].dynamics) {
  933. message.warning("已经添加了力度标记");
  934. } else {
  935. const crescendo = Date.now() + "";
  936. abcData.abc.measures[startItem.measureIndex].notes[startItem.noteIndex].dynamics = value[0];
  937. abcData.abc.measures[startItem.measureIndex].notes[startItem.noteIndex].dCode = crescendo;
  938. abcData.abc.measures[endItem.measureIndex].notes[endItem.noteIndex].dynamics = value[1];
  939. abcData.abc.measures[endItem.measureIndex].notes[endItem.noteIndex].dCode = crescendo;
  940. await handleResetRender();
  941. }
  942. }
  943. // 连音
  944. if (type === "tie") {
  945. const crescendo = Date.now() + "";
  946. if (abcData.abc.measures[startItem.measureIndex].notes[startItem.noteIndex].tie) {
  947. const tie = abcData.abc.measures[startItem.measureIndex].notes[startItem.noteIndex].tie;
  948. abcData.abc.measures[startItem.measureIndex].notes[startItem.noteIndex].tie = value[0] + tie;
  949. } else {
  950. abcData.abc.measures[startItem.measureIndex].notes[startItem.noteIndex].tie = value[0];
  951. abcData.abc.measures[startItem.measureIndex].notes[startItem.noteIndex].tCode = crescendo;
  952. }
  953. if (abcData.abc.measures[endItem.measureIndex].notes[endItem.noteIndex].tie) {
  954. const tie = abcData.abc.measures[endItem.measureIndex].notes[endItem.noteIndex].tie;
  955. abcData.abc.measures[endItem.measureIndex].notes[endItem.noteIndex].tie = tie + value[1];
  956. } else {
  957. abcData.abc.measures[endItem.measureIndex].notes[endItem.noteIndex].tie = value[1];
  958. abcData.abc.measures[endItem.measureIndex].notes[endItem.noteIndex].tCode = crescendo;
  959. }
  960. await handleResetRender();
  961. }
  962. data.select.state = false;
  963. data.select.list = [];
  964. data.select.parmas = null;
  965. clearSelectNote();
  966. message.destroyAll();
  967. };
  968. /** 移调 */
  969. const handleMoveKey = async (item: (typeof ABC_DATA.key)[0]) => {
  970. // const moveData = getKeyStep(item.value, abcData.abc.key, data.moveKeyType);
  971. // console.log("🚀 ~ item:", abcData.abc.key, "=>", item.value, moveData);
  972. // 将所有的音符移调
  973. // for (let i = 0; i < abcData.abc.measures.length; i++) {
  974. // const measure = abcData.abc.measures[i];
  975. // for (let j = 0; j < measure.notes.length; j++) {
  976. // const note = measure.notes[j];
  977. // if (note.content == "z") continue;
  978. // const content = moveNoteKey(note.content, moveData);
  979. // const _a = content.substring(0, 1);
  980. // if (_a === "^" || _a === "_") {
  981. // note.content = content.substring(1);
  982. // } else {
  983. // note.content = content;
  984. // }
  985. // console.log("🚀 ~ note.content:", note.content);
  986. // }
  987. // }
  988. // // console.log(abcData.abc.visualTranspose, item.step, item.value)
  989. // abcData.abc.key = item.value;
  990. // const step =
  991. // data.moveKeyType === "up"
  992. // ? item.step > 0
  993. // ? item.step
  994. // : item.step + 12
  995. // : data.moveKeyType === "down"
  996. // ? item.step < 0
  997. // ? item.step
  998. // : item.step + 12
  999. // : item.step;
  1000. abcData.abc.visualTranspose = item.step;
  1001. popup.moveKeyShow = false;
  1002. if (data.playState) {
  1003. abcData.synthControl.disable(true);
  1004. data.playState = false;
  1005. }
  1006. await handleResetRender();
  1007. };
  1008. const handleKeyUp = (e: KeyboardEvent) => {
  1009. if (!data.active) return false;
  1010. console.log(e.key);
  1011. if (e.key === "Backspace") {
  1012. handleChange({ type: "delete", value: "" });
  1013. }
  1014. if (/^[A-Ga-g]$/.test(e.key)) {
  1015. handleChange({ type: "note", value: e.key.toLocaleUpperCase() });
  1016. }
  1017. if (["ArrowUp", "ArrowDown"].includes(e.key)) {
  1018. e.preventDefault();
  1019. e.stopPropagation();
  1020. handleChange({ type: "move", value: { action: e.key === "ArrowUp" ? "up" : "donw" } });
  1021. return false;
  1022. }
  1023. };
  1024. /** 重置曲谱 */
  1025. const handleCreateSvg = () => {
  1026. abcData.abc.measures = initMusic(30);
  1027. handleResetRender();
  1028. };
  1029. const instruments = computed(() => {
  1030. return ABCJS.synth.instrumentIndexToName.map((name, index) => ({
  1031. label: instrumentsNames[name as keyof typeof instrumentsNames],
  1032. value: index,
  1033. }));
  1034. });
  1035. const getDetailData = async () => {
  1036. const query: any = getQuery();
  1037. const res = await api_musicSheetCreationDetail(query.id);
  1038. if (res?.code == 200) {
  1039. data.musicId = res.data.id || "";
  1040. data.musicName = res.data.name || "";
  1041. data.creator = res.data.creator || "";
  1042. let abc = "" as any;
  1043. try {
  1044. abc = JSON.parse(res.data.creationData);
  1045. } catch (error) {
  1046. console.log(error);
  1047. }
  1048. if (abc) {
  1049. console.log("🚀 ~ abc:", abc);
  1050. abcData.abc.celf = abc.celf || "K:treble";
  1051. abcData.abc.key = abc.key.value || "K:C";
  1052. abcData.abc.meter = abc.meter.value || "M:4/4";
  1053. abcData.abc.speed = abc.speed || "Q:1/4=60";
  1054. abcData.abc.visualTranspose = abc.visualTranspose || 0;
  1055. abcData.abc.subjectCode = abc.subjectCode || "acoustic_grand_piano";
  1056. const _instruments = ABCJS.synth.instrumentIndexToName.indexOf(abcData.abc.subjectCode as any);
  1057. abcData.synthOptions.program = _instruments > -1 ? _instruments : 0;
  1058. abcData.abc.measures = abc.measures || initMusic(30);
  1059. // console.log("🚀 ~ abcData.abc:", abcData.abc);
  1060. }
  1061. }
  1062. };
  1063. const handleSaveMusic = async (tips = true) => {
  1064. await api_musicSheetCreationUpdate({
  1065. name: data.musicName,
  1066. creator: data.creator,
  1067. creationConfig: data.music,
  1068. creationData: JSON.stringify(abcData.abc),
  1069. id: data.musicId,
  1070. subjectId: 3,
  1071. });
  1072. if (tips) {
  1073. message.success("保存成功");
  1074. }
  1075. data.isSave = true;
  1076. };
  1077. onMounted(async () => {
  1078. await getDetailData();
  1079. loadMiniMp3();
  1080. if (ABCJS.synth.supportsAudio()) {
  1081. abcData.synthControl = new ABCJS.synth.SynthController();
  1082. // console.log("🚀 ~ abcData.synthControl:", abcData.synthControl)
  1083. abcData.synthControl.load("#audio", cursorControl, {
  1084. displayLoop: true,
  1085. displayRestart: true,
  1086. displayPlay: true,
  1087. displayProgress: true,
  1088. });
  1089. }
  1090. console.log(ABCJS);
  1091. await handleResetRender();
  1092. document.addEventListener("keyup", handleKeyUp);
  1093. window.onbeforeunload = (e) => {
  1094. if (!data.isSave) {
  1095. e.preventDefault();
  1096. e.returnValue = "还有没保存的";
  1097. }
  1098. };
  1099. abcData.synthControl.restart();
  1100. // formateAbc(abcData.visualObj);
  1101. const selectMearesBtn = document.querySelector("#selectMearesBtn");
  1102. if (selectMearesBtn) {
  1103. const rect = selectMearesBtn.getBoundingClientRect();
  1104. data.selectMeasures.x = document.body.clientWidth - 320;
  1105. data.selectMeasures.y = rect.top + 70;
  1106. data.selectMeasures.state = true;
  1107. }
  1108. });
  1109. onUnmounted(() => {
  1110. document.removeEventListener("keyup", handleKeyUp);
  1111. });
  1112. const measureComputed = computed(() => {
  1113. if (!data.active) return {} as unknown as IMeasure;
  1114. const activeMeasure = abcData.abc.measures[data.active.measureIndex] || {};
  1115. return activeMeasure;
  1116. });
  1117. const noteComputed = computed(() => {
  1118. if (!data.active) return {} as unknown as INote;
  1119. const activeNote = abcData.abc.measures[data.active.measureIndex]?.notes[data.active.noteIndex] || {};
  1120. return activeNote;
  1121. });
  1122. /** 新建曲谱 */
  1123. const handleCreateMusic = () => {
  1124. showConfirmDialog({
  1125. title: "温馨提示",
  1126. message: "是否覆盖当前乐谱?",
  1127. }).then(() => {
  1128. handleCreateSvg();
  1129. data.active = null as unknown as INoteActive;
  1130. });
  1131. };
  1132. /** 添加小节 */
  1133. const handleAddMearse = () => {
  1134. for (let i = 0; i < data.addMearseNumber; i++) {
  1135. if (["pre", "next"].includes(data.addMearseType)) {
  1136. if (!data.active) {
  1137. message.warning("请选择小节");
  1138. return;
  1139. }
  1140. if (data.addMearseType === "pre") {
  1141. abcData.abc.measures.splice(data.active.measureIndex, 0, createMeasure());
  1142. } else if (data.addMearseType === "next") {
  1143. abcData.abc.measures.splice(data.active.measureIndex + 1, 0, createMeasure());
  1144. }
  1145. } else {
  1146. abcData.abc.measures.push(createMeasure());
  1147. }
  1148. }
  1149. popup.barShow = false;
  1150. handleResetRender();
  1151. };
  1152. const handleDeleteMearse = () => {
  1153. if (data.deleteMearseType === "ing") {
  1154. if (!data.active) {
  1155. message.warning("请选择小节");
  1156. return;
  1157. }
  1158. abcData.abc.measures.splice(data.active.measureIndex, 1);
  1159. } else if (data.deleteMearseType === "finish") {
  1160. let len = abcData.abc.measures.length;
  1161. for (let i = len; i > 0; i--) {
  1162. if (abcData.abc.measures[i - 1].notes.length === 1 && abcData.abc.measures[i - 1].notes[0].content === "z") {
  1163. if (abcData.abc.measures.length === 1) {
  1164. break;
  1165. }
  1166. abcData.abc.measures.splice(i - 1, 1);
  1167. } else {
  1168. break;
  1169. }
  1170. }
  1171. }
  1172. popup.mearseDeleteShow = false;
  1173. handleResetRender();
  1174. };
  1175. const downPng = async () => {
  1176. await handleResetRender();
  1177. const paper = document.getElementById("paper");
  1178. if (!paper) return;
  1179. const svg: any = paper.children[0]?.cloneNode(true);
  1180. const annotation = svg.querySelectorAll(".abcjs-annotation");
  1181. annotation.forEach((n: HTMLElement) => {
  1182. n.remove();
  1183. });
  1184. const svgBox = paper.getBoundingClientRect();
  1185. console.log("🚀 ~ svgBox:", svgBox);
  1186. svg.setAttribute("width", `${svgBox.width * 3}`);
  1187. svg.setAttribute("height", `${svgBox.height * 3}`);
  1188. const rect = document.createElementNS("http://www.w3.org/2000/svg", "rect");
  1189. console.log("🚀 ~ svg:", svg);
  1190. rect.setAttribute("x", "0");
  1191. rect.setAttribute("y", "0");
  1192. rect.setAttribute("width", `${svgBox.width * 10}`);
  1193. rect.setAttribute("height", `${svgBox.height * 10}`);
  1194. rect.setAttribute("fill", "#fff");
  1195. svg.prepend(rect);
  1196. if (svg) {
  1197. const _canvas = svg2canvas(svg.outerHTML);
  1198. // document.body.appendChild(_canvas);
  1199. let el: any = document.createElement("a");
  1200. // 设置 href 为图片经过 base64 编码后的字符串,默认为 png 格式
  1201. el.href = _canvas.toDataURL();
  1202. el.download = data.musicName + ".png";
  1203. // 创建一个点击事件并对 a 标签进行触发
  1204. const event = new MouseEvent("click");
  1205. el.dispatchEvent(event);
  1206. }
  1207. };
  1208. const downRef = ref();
  1209. const downMidi = () => {
  1210. const midi = ABCJS.synth.getMidiFile(abcData.visualObj, {
  1211. chordsOff: true,
  1212. midiOutputType: "link",
  1213. fileName: "曲谱",
  1214. });
  1215. // console.log("🚀 ~ midi:", midi)
  1216. downRef.value.innerHTML = midi;
  1217. downRef.value.querySelector("a").click();
  1218. };
  1219. const downWav = () => {
  1220. try {
  1221. if (abcData.synthControl) {
  1222. abcData.synthControl.download("曲谱.wav");
  1223. }
  1224. } catch (error) {
  1225. const midiBuffer = new ABCJS.synth.CreateSynth();
  1226. midiBuffer
  1227. .init({
  1228. visualObj: abcData.visualObj,
  1229. options: abcData.synthOptions,
  1230. })
  1231. .then(() => {
  1232. midiBuffer.prime().then(() => {
  1233. // console.log(midiBuffer.download());
  1234. downloadFile(midiBuffer.download(), "曲谱.wav");
  1235. });
  1236. });
  1237. }
  1238. };
  1239. const handleDownFile = (type: IFileBtnType) => {
  1240. if (type === "png") {
  1241. downPng();
  1242. } else if (type === "midi") {
  1243. downMidi();
  1244. } else if (type === "wav") {
  1245. downWav();
  1246. }
  1247. };
  1248. const handleExport = () => {
  1249. const input = document.createElement("input");
  1250. input.type = "file";
  1251. input.accept = ".xml,.musicxml";
  1252. input.onchange = (e: any) => {
  1253. const file = e.target.files[0];
  1254. const reader = new FileReader();
  1255. reader.onload = (e: any) => {
  1256. let abc = e.target.result;
  1257. console.log("🚀 ~ abc:", abc);
  1258. abc = new DOMParser().parseFromString(abc, "text/xml");
  1259. console.log("🚀 ~ abc:", abc);
  1260. abc = (window as any).vertaal(abc, { p: "f", t: 1, u: 0, v: 3, mnum: 0 });
  1261. console.log(abc);
  1262. // data.music = abc[0];
  1263. // handleResetRender(false);
  1264. };
  1265. reader.readAsText(file);
  1266. };
  1267. input.click();
  1268. };
  1269. /** 设置选段小节 */
  1270. const handleSetSelectMeares = (index: number | null, type: "start" | "end") => {
  1271. console.log("🚀 ~ index:", index);
  1272. if (type === "start") {
  1273. const note = index ? useIndexGetNote(`${index - 1}.0`) : null;
  1274. // console.log("🚀 ~ note:", note);
  1275. data.selectMeasures.start = index ? index - 1 : 0;
  1276. data.selectMeasures.startNote = note;
  1277. if (data.selectMeasures.start && data.selectMeasures.end && data.selectMeasures.end < data.selectMeasures.start) {
  1278. data.selectMeasures.end = 0;
  1279. data.selectMeasures.endNote = null;
  1280. }
  1281. } else {
  1282. const note = index ? useIndexGetNote(`${index - 1}.${abcData.abc.measures[index - 1]?.notes.length - 1}`) : null;
  1283. // console.log("🚀 ~ note:", note);
  1284. data.selectMeasures.end = index ? index - 1 : 0;
  1285. data.selectMeasures.endNote = note;
  1286. if (data.selectMeasures.start && data.selectMeasures.end && data.selectMeasures.start > data.selectMeasures.end) {
  1287. // console.log(data.selectMeasures.start, data.selectMeasures.end);
  1288. data.selectMeasures.start = 0;
  1289. data.selectMeasures.startNote = null;
  1290. }
  1291. }
  1292. };
  1293. return () => (
  1294. <div class={styles.container}>
  1295. <div class={styles.containerTop} onKeyup={(e: Event) => e.stopPropagation()}>
  1296. <div class={styles.topWrap}>
  1297. <div class={styles.topBtn} onClick={() => handleChange({ type: "exit", value: "exit" })}>
  1298. <div class={[styles.btnImg]}>
  1299. <img class={styles.topBtnIcon} src={getImage("icon_-1.png")} />
  1300. </div>
  1301. <div>退出</div>
  1302. </div>
  1303. <div class={styles.topBtn}>
  1304. <FileBtn
  1305. onSelect={(val: IFileBtnType) => {
  1306. if (val === "newMusic") {
  1307. handleCreateMusic();
  1308. } else if (val === "save") {
  1309. handleSaveMusic();
  1310. } else if (["xml"].includes(val)) {
  1311. handleExport();
  1312. } else if (val === "upload") {
  1313. } else if (["png", "midi", "wav"].includes(val)) {
  1314. handleDownFile(val);
  1315. } else if (val === "print") {
  1316. }
  1317. // else if (val === "exit") {
  1318. // }
  1319. }}
  1320. />
  1321. <div>文件</div>
  1322. </div>
  1323. <div class={styles.topLine}></div>
  1324. <div class={styles.topBtn} onClick={() => handleChange({ type: "dot", value: ">" })}>
  1325. <div class={[styles.btnImg, noteComputed.value.dot === ">" && styles.btnImgActive]}>
  1326. <img class={styles.topBtnIcon} src={getImage("icon_1.png")} />
  1327. </div>
  1328. <div>附点</div>
  1329. </div>
  1330. <div class={styles.topLine}></div>
  1331. {ABC_DATA.accidentals.map((item) => (
  1332. <div class={styles.topBtn} onClick={() => handleChange({ type: "accidentals", value: item.value })}>
  1333. <div class={[styles.btnImg, noteComputed.value.accidental === item.value && styles.btnImgActive]}>
  1334. <img class={styles.topBtnIcon} src={item.icon} />
  1335. </div>
  1336. <div class={styles.btnName}>{item.name}</div>
  1337. </div>
  1338. ))}
  1339. <div class={styles.topLine}></div>
  1340. <div class={styles.topBtn} onClick={() => handleChange({ type: "tie", value: ABC_DATA.tie[0].value })}>
  1341. <div class={[styles.btnImg, noteComputed.value.tieline === ABC_DATA.tie[0].value && styles.btnImgActive]}>
  1342. <img class={styles.topBtnIcon} src={ABC_DATA.tie[0].icon} />
  1343. </div>
  1344. <div>{ABC_DATA.tie[0].name}</div>
  1345. </div>
  1346. <div class={styles.topBtn} onClick={() => handleChange({ type: "tie", value: ABC_DATA.tie[1].value })}>
  1347. <div class={[styles.btnImg, ABC_DATA.tie[1].value.includes(noteComputed.value.tie) && styles.btnImgActive]}>
  1348. <img class={styles.topBtnIcon} src={ABC_DATA.tie[1].icon} />
  1349. </div>
  1350. <div>{ABC_DATA.tie[1].name}</div>
  1351. </div>
  1352. <div class={styles.topLine}></div>
  1353. {ABC_DATA.play.slice(0, 4).map((item) => (
  1354. <div class={[styles.topBtn]} onClick={() => handleChange({ type: "play", value: item.value })}>
  1355. <div class={[styles.btnImg, noteComputed.value.play?.includes(item.value) && styles.btnImgActive]}>
  1356. <img class={styles.topBtnIcon} src={item.icon} />
  1357. </div>
  1358. <div>{item.name}</div>
  1359. </div>
  1360. ))}
  1361. <NPopover class={styles.popupWrap} showArrow={false} trigger="click" contentStyle={{ width: "400px" }}>
  1362. {{
  1363. trigger: () => (
  1364. <div class={styles.topDownArrow}>
  1365. <img src={getImage("icon_arrow.png")} />
  1366. </div>
  1367. ),
  1368. default: () => (
  1369. <NGrid cols={4} yGap={8}>
  1370. {ABC_DATA.play.slice(4).map((item) => (
  1371. <NGi>
  1372. <div
  1373. class={[styles.btnItem, noteComputed.value.play?.includes(item.value) && styles.btnItemActive]}
  1374. onClick={() => {
  1375. data.morePlay = false;
  1376. handleChange({ type: "play", value: item.value });
  1377. }}
  1378. >
  1379. <div class={styles.btnItemIcon}>
  1380. <TheIcon iconClassName={item.icon} />
  1381. </div>
  1382. <div>{item.name}</div>
  1383. </div>
  1384. </NGi>
  1385. ))}
  1386. </NGrid>
  1387. ),
  1388. }}
  1389. </NPopover>
  1390. <div class={styles.topLine}></div>
  1391. <NDropdown
  1392. trigger="click"
  1393. options={ABC_DATA.slus as any}
  1394. labelField="name"
  1395. keyField="value"
  1396. onSelect={(val) => {
  1397. console.log(val);
  1398. handleChange({ type: "slus", value: val });
  1399. }}
  1400. >
  1401. <div class={[styles.topBtn]}>
  1402. <div class={styles.btnImg}>
  1403. <img class={styles.topBtnIcon} src={getImage("icon_13.png")} />
  1404. </div>
  1405. <div>连音</div>
  1406. </div>
  1407. </NDropdown>
  1408. <div class={[styles.topBtn, styles.btnDisabled]}>
  1409. <div class={styles.btnImg}>
  1410. <img class={styles.topBtnIcon} src={getImage("icon_14.png")} />
  1411. </div>
  1412. <div>翻转</div>
  1413. </div>
  1414. <div class={styles.topLine}></div>
  1415. <NPopover class={styles.popupWrap} showArrow={false} v-model:show={popup.selectSubjectShow} trigger="click" contentStyle={{ width: "320px" }}>
  1416. {{
  1417. trigger: () => (
  1418. <div class={styles.topBtn}>
  1419. <div class={styles.btnImg} onClick={() => (popup.instrument = true)}>
  1420. <img class={styles.topBtnIcon} src={getImage("icon_25.png")} />
  1421. </div>
  1422. <div>选择声部</div>
  1423. </div>
  1424. ),
  1425. default: () => (
  1426. <>
  1427. <div class={styles.btnLineTitle}>选择声部</div>
  1428. <NSelect
  1429. filterable
  1430. options={instruments.value}
  1431. v-model:value={abcData.synthOptions.program}
  1432. onUpdate:value={async () => {
  1433. abcData.synthControl.disable(true);
  1434. data.playState = false;
  1435. await loadMiniMp3();
  1436. resetMidi(true);
  1437. popup.selectSubjectShow = false;
  1438. }}
  1439. ></NSelect>
  1440. </>
  1441. ),
  1442. }}
  1443. </NPopover>
  1444. <NPopover class={styles.popupWrap} showArrow={false} v-model:show={popup.moveKeyShow} trigger="click" contentStyle={{ width: "320px" }}>
  1445. {{
  1446. trigger: () => (
  1447. <div class={styles.topBtn}>
  1448. <div class={styles.btnImg}>
  1449. <img class={styles.topBtnIcon} src={getImage("icon_15.png")} />
  1450. </div>
  1451. <div>移调</div>
  1452. </div>
  1453. ),
  1454. default: () => (
  1455. <>
  1456. <div class={styles.btnLineTitle}>移调方式</div>
  1457. <NSpace>
  1458. <NButton secondary type={data.moveKeyType === "inset" ? "primary" : "default"} onClick={() => (data.moveKeyType = "inset")}>
  1459. <NIcon component={GripLinesVertical} />
  1460. 最靠近
  1461. </NButton>
  1462. <NButton secondary type={data.moveKeyType === "down" ? "primary" : "default"} onClick={() => (data.moveKeyType = "down")}>
  1463. <NIcon component={LongArrowAltDown} />
  1464. 向下移调
  1465. </NButton>
  1466. <NButton secondary type={data.moveKeyType === "up" ? "primary" : "default"} onClick={() => (data.moveKeyType = "up")}>
  1467. <NIcon component={LongArrowAltUp} />
  1468. 向上移调
  1469. </NButton>
  1470. </NSpace>
  1471. <div class={styles.btnLineTitle}>目标音调</div>
  1472. <NGrid cols={5} yGap={8}>
  1473. {ABC_DATA.key
  1474. .sort((a, b) => b.step - a.step)
  1475. .map((item) => (
  1476. <NGi>
  1477. <div class={[styles.btnItem, abcData.abc.key === item.value && styles.btnItemActive]} onClick={() => handleMoveKey(item)}>
  1478. <div class={[styles.btnItemIcon]}>
  1479. <TheIcon iconClassName={item.icon} />
  1480. </div>
  1481. <div class={styles.btnItemName}>{item.name}</div>
  1482. </div>
  1483. </NGi>
  1484. ))}
  1485. </NGrid>
  1486. </>
  1487. ),
  1488. }}
  1489. </NPopover>
  1490. <NPopover class={styles.popupWrap} showArrow={false} v-model:value={popup.speedShow} trigger="click" placement="bottom" displayDirective="show">
  1491. {{
  1492. trigger: () => (
  1493. <div class={[styles.topBtn]}>
  1494. <div class={styles.btnImg}>
  1495. <img class={styles.topBtnIcon} src={getImage("icon_16.png")} />
  1496. </div>
  1497. <div>速度调整</div>
  1498. </div>
  1499. ),
  1500. default: () => <TheSpeed onChange={(val) => handleChange(val)} />,
  1501. }}
  1502. </NPopover>
  1503. <NPopover class={styles.popupWrap} showArrow={false} v-model:show={popup.staffShow} trigger="click" placement="bottom" contentStyle={{ width: "320px" }}>
  1504. {{
  1505. trigger: () => (
  1506. <div class={[styles.topBtn]}>
  1507. <div class={styles.btnImg}>
  1508. <img class={styles.topBtnIcon} src={getImage("icon_17.png")} />
  1509. </div>
  1510. <div>谱面显示</div>
  1511. </div>
  1512. ),
  1513. default: () => (
  1514. <>
  1515. <div class={styles.btnLineTitle}>乐谱大小</div>
  1516. <NSpace>
  1517. <NButton
  1518. type={abcData.abcOptions.staffwidth === 1200 ? "primary" : "default"}
  1519. secondary
  1520. onClick={() => {
  1521. abcData.abcOptions.staffwidth = 1200;
  1522. handleResetRender();
  1523. }}
  1524. >
  1525. </NButton>
  1526. <NButton
  1527. type={abcData.abcOptions.staffwidth === 800 ? "primary" : "default"}
  1528. secondary
  1529. onClick={() => {
  1530. abcData.abcOptions.staffwidth = 800;
  1531. handleResetRender();
  1532. }}
  1533. >
  1534. </NButton>
  1535. <NButton
  1536. type={abcData.abcOptions.staffwidth === 400 ? "primary" : "default"}
  1537. secondary
  1538. onClick={() => {
  1539. abcData.abcOptions.staffwidth = 400;
  1540. handleResetRender();
  1541. }}
  1542. >
  1543. </NButton>
  1544. </NSpace>
  1545. <div class={styles.btnLineTitle}>小节数</div>
  1546. <NSpace vertical>
  1547. <NInputNumber
  1548. min={1}
  1549. v-model:value={(abcData.abcOptions.wrap as any).preferredMeasuresPerLine}
  1550. placeholder="请输入小节数"
  1551. onUpdate:value={() => {
  1552. handleResetRender();
  1553. }}
  1554. />
  1555. {/* <NSpace style={{ marginTop: "20px" }} align="center" wrap={false} wrapItem={false}>
  1556. <NButton style={{ width: "48%" }} round onClick={() => (popup.staffShow = false)}>
  1557. 取消
  1558. </NButton>
  1559. <NButton
  1560. style={{ width: "48%" }}
  1561. round
  1562. type="primary"
  1563. >
  1564. 确定
  1565. </NButton>
  1566. </NSpace> */}
  1567. </NSpace>
  1568. </>
  1569. ),
  1570. }}
  1571. </NPopover>
  1572. <NPopover class={styles.popupWrap} showArrow={false} v-model:show={popup.barShow} trigger="click" placement="bottom" contentStyle={{ width: "320px" }}>
  1573. {{
  1574. trigger: () => (
  1575. <div class={[styles.topBtn]}>
  1576. <div class={styles.btnImg}>
  1577. <img class={styles.topBtnIcon} src={getImage("icon_18.png")} />
  1578. </div>
  1579. <div>添加小节</div>
  1580. </div>
  1581. ),
  1582. default: () => (
  1583. <>
  1584. <div class={styles.btnLineTitle}>添加方式</div>
  1585. <NSpace>
  1586. <NButton type={data.addMearseType === "pre" ? "primary" : "default"} secondary onClick={() => (data.addMearseType = "pre")}>
  1587. 当前小节前
  1588. </NButton>
  1589. <NButton type={data.addMearseType === "next" ? "primary" : "default"} secondary onClick={() => (data.addMearseType = "next")}>
  1590. 当前小节后
  1591. </NButton>
  1592. <NButton type={data.addMearseType === "finish" ? "primary" : "default"} secondary onClick={() => (data.addMearseType = "finish")}>
  1593. 曲谱末尾
  1594. </NButton>
  1595. </NSpace>
  1596. <div class={styles.btnLineTitle}>小节数</div>
  1597. <NSpace vertical>
  1598. <NInputNumber min={1} v-model:value={data.addMearseNumber} placeholder="请输入小节数" />
  1599. <NSpace style={{ marginTop: "20px" }} align="center" wrap={false} wrapItem={false}>
  1600. <NButton style={{ width: "48%" }} round onClick={() => (popup.barShow = false)}>
  1601. 取消
  1602. </NButton>
  1603. <NButton style={{ width: "48%" }} round type="primary" onClick={() => handleAddMearse()}>
  1604. 确定
  1605. </NButton>
  1606. </NSpace>
  1607. </NSpace>
  1608. </>
  1609. ),
  1610. }}
  1611. </NPopover>
  1612. <NPopover class={styles.popupWrap} v-model:show={popup.mearseDeleteShow} trigger="click" placement="bottom">
  1613. {{
  1614. trigger: () => (
  1615. <div class={[styles.topBtn]}>
  1616. <div class={styles.btnImg}>
  1617. <img class={styles.topBtnIcon} src={getImage("icon_19.png")} />
  1618. </div>
  1619. <div>删除小节</div>
  1620. </div>
  1621. ),
  1622. default: () => (
  1623. <>
  1624. <div class={styles.btnLineTitle}>删除方式</div>
  1625. <NSpace vertical>
  1626. <NSpace>
  1627. <NButton type={data.deleteMearseType === "ing" ? "primary" : "default"} secondary onClick={() => (data.deleteMearseType = "ing")}>
  1628. 当前选中小节
  1629. </NButton>
  1630. <NButton type={data.deleteMearseType === "finish" ? "primary" : "default"} secondary onClick={() => (data.deleteMearseType = "finish")}>
  1631. 末尾空白小节
  1632. </NButton>
  1633. </NSpace>
  1634. <NSpace style={{ marginTop: "20px" }} align="center" wrap={false} wrapItem={false}>
  1635. <NButton style={{ width: "48%" }} round onClick={() => (popup.mearseDeleteShow = false)}>
  1636. 取消
  1637. </NButton>
  1638. <NButton style={{ width: "48%" }} round type="primary" onClick={() => handleDeleteMearse()}>
  1639. 确定
  1640. </NButton>
  1641. </NSpace>
  1642. </NSpace>
  1643. </>
  1644. ),
  1645. }}
  1646. </NPopover>
  1647. <div class={styles.topLine}></div>
  1648. <div style={{ marginLeft: "auto" }} class={styles.topBtn} onClick={() => togglePlay("reset")}>
  1649. <div class={styles.btnImg}>
  1650. <img class={styles.topBtnIcon} src={getImage("icon_20.png")} />
  1651. </div>
  1652. <div>重播</div>
  1653. </div>
  1654. <div class={styles.topBtn}>
  1655. <NSpin show={data.loadingAudioSrouce} size="small">
  1656. <div class={styles.btnImg} onClick={() => togglePlay(data.playState ? "pause" : "play")}>
  1657. <img style={{ display: data.playState ? "" : "none" }} class={styles.topBtnIcon} src={getImage("icon_21_1.png")} />
  1658. <img style={{ display: data.playState ? "none" : "" }} class={styles.topBtnIcon} src={getImage("icon_21.png")} />
  1659. </div>
  1660. </NSpin>
  1661. <div>{data.playState ? "暂停" : "播放"}</div>
  1662. </div>
  1663. <div id="selectMearesBtn" class={[styles.topBtn]} onClick={() => (popup.selectMearesShow = !popup.selectMearesShow)}>
  1664. <div class={[styles.btnImg, popup.selectMearesShow && styles.btnImgActive]}>
  1665. <img class={styles.topBtnIcon} src={getImage("icon_22.png")} />
  1666. </div>
  1667. <div>选段</div>
  1668. </div>
  1669. <div class={[styles.topBtn, styles.btnDisabled]}>
  1670. <div class={styles.btnImg}>
  1671. <img class={styles.topBtnIcon} src={getImage("icon_23.png")} />
  1672. </div>
  1673. <div>节拍器</div>
  1674. </div>
  1675. <div class={[styles.topBtn]} onClick={() => (popup.settingShow = true)}>
  1676. <div class={styles.btnImg}>
  1677. <img class={styles.topBtnIcon} src={getImage("icon_24.png")} />
  1678. </div>
  1679. <div>设置</div>
  1680. </div>
  1681. </div>
  1682. </div>
  1683. <div class={styles.content}>
  1684. <div class={styles.slide}>
  1685. <Collapse v-model={data.slide} elevation={false} divider={false}>
  1686. <CollapseItem title="音符时值" name="note">
  1687. <div class={styles.wrapBox}>
  1688. {ABC_DATA.types.map((item) => (
  1689. <div class={styles.topBtn} onClick={() => handleChange({ type: "type", value: item.value })}>
  1690. <div class={[styles.btnImg, data.noteType === item.value && styles.btnImgActive]}>
  1691. <TheIcon iconClassName={item.icon} />
  1692. </div>
  1693. <div>{item.name}</div>
  1694. </div>
  1695. ))}
  1696. <div class={styles.topBtn} onClick={() => handleChange({ type: "note", value: "z" })}>
  1697. <div class={[styles.btnImg, noteComputed.value.content === "z" && styles.btnImgActive]}>
  1698. <img style={{ width: "20px", height: "20px" }} src={getImage("icon_rest.png")} />
  1699. </div>
  1700. <div>休止符</div>
  1701. </div>
  1702. <div class={styles.topBtn} onClick={() => handleChange({ type: "segno", value: " " })}>
  1703. <div class={[styles.btnImg, noteComputed.value.segno === " " && styles.btnImgActive]}>{/* <img style={{ width: "20px", height: "20px" }} src={getImage("icon_rest.png")} /> */}</div>
  1704. <div>分割</div>
  1705. </div>
  1706. </div>
  1707. </CollapseItem>
  1708. <CollapseItem title="拍号" name="meter">
  1709. <div class={styles.wrapBox}>
  1710. {ABC_DATA.meter.map((item) => (
  1711. <div class={styles.topBtn} onClick={() => handleChange({ type: "meter", value: item.value })}>
  1712. <div class={[styles.btnImg]}>
  1713. <TheIcon iconClassName={item.icon} />
  1714. </div>
  1715. <div>{item.name}</div>
  1716. </div>
  1717. ))}
  1718. </div>
  1719. </CollapseItem>
  1720. <CollapseItem title="力度记号" name="dynamics">
  1721. <div class={styles.wrapBox}>
  1722. {ABC_DATA.dynamics.slice(0, 8).map((item) => (
  1723. <div class={styles.topBtn} onClick={() => handleChange({ type: "dynamics", value: item.value })}>
  1724. <div class={[styles.btnImg, noteComputed.value.dynamics === item.value && styles.btnImgActive]}>
  1725. <TheIcon iconClassName={item.icon} size={["2em", "2em"]} />
  1726. </div>
  1727. <div>{item.name}</div>
  1728. </div>
  1729. ))}
  1730. <div class={styles.topBtn} onClick={() => handleChange({ type: "dynamics", value: ABC_DATA.dynamics[8].value })}>
  1731. <div class={[styles.btnImg, ABC_DATA.dynamics[8].value.includes(noteComputed.value.dynamics) && styles.btnImgActive]}>
  1732. <TheIcon iconClassName={ABC_DATA.dynamics[8].icon} size={["2em", "2em"]} />
  1733. </div>
  1734. <div>{ABC_DATA.dynamics[8].name}</div>
  1735. </div>
  1736. <div class={styles.topBtn} onClick={() => handleChange({ type: "dynamics", value: ABC_DATA.dynamics[9].value })}>
  1737. <div class={[styles.btnImg, ABC_DATA.dynamics[9].value.includes(noteComputed.value.dynamics) && styles.btnImgActive]}>
  1738. <TheIcon iconClassName={ABC_DATA.dynamics[9].icon} size={["2em", "2em"]} />
  1739. </div>
  1740. <div>{ABC_DATA.dynamics[9].name}</div>
  1741. </div>
  1742. </div>
  1743. </CollapseItem>
  1744. <CollapseItem title="反复与跳跃" name="repeat">
  1745. <div class={styles.wrapBox}>
  1746. {ABC_DATA.repeat.map((item) => (
  1747. <div class={[styles.topBtn, styles.longTopBtn]} onClick={() => handleChange({ type: "repeat", value: item.value })}>
  1748. <div class={[styles.btnImg, measureComputed.value.repeat === item.value && styles.btnImgActive]}>
  1749. <TheIcon iconClassName={item.icon} size={["5em", "1em"]} />
  1750. </div>
  1751. <div>{item.name}</div>
  1752. </div>
  1753. ))}
  1754. </div>
  1755. </CollapseItem>
  1756. <CollapseItem title="小节线" name="line">
  1757. <div class={styles.wrapBox}>
  1758. {ABC_DATA.bar.map((item) => (
  1759. <div
  1760. class={styles.topBtn}
  1761. onClick={() => {
  1762. data.morePlay = false;
  1763. handleChange({ type: "barline", value: item.value });
  1764. }}
  1765. >
  1766. <div class={[styles.btnImg, measureComputed.value.barline === item.value && styles.btnImgActive]}>
  1767. <TheIcon iconClassName={item.icon} size={["2em", "2em"]} />
  1768. </div>
  1769. <div>{item.name}</div>
  1770. </div>
  1771. ))}
  1772. </div>
  1773. </CollapseItem>
  1774. <CollapseItem title="谱号" name="clef">
  1775. <div class={styles.wrapBox}>
  1776. {ABC_DATA.clef.map((item) => (
  1777. <div class={styles.topBtn} onClick={() => handleChange({ type: "clef", value: item.value })}>
  1778. <div class={[styles.btnImg]}>
  1779. <TheIcon iconClassName={item.icon} />
  1780. </div>
  1781. <div>{item.name}</div>
  1782. </div>
  1783. ))}
  1784. </div>
  1785. </CollapseItem>
  1786. <CollapseItem title="调号" name="key">
  1787. <div class={styles.wrapBox}>
  1788. {ABC_DATA.key.map((item) => (
  1789. <div class={styles.topBtn} onClick={() => handleChange({ type: "key", value: item.value })}>
  1790. <div class={[styles.btnImg]}>
  1791. <TheIcon iconClassName={item.icon} />
  1792. </div>
  1793. <div>{item.name}</div>
  1794. </div>
  1795. ))}
  1796. </div>
  1797. </CollapseItem>
  1798. </Collapse>
  1799. </div>
  1800. <div class={styles.box}>
  1801. <div class={styles.titleBox}>
  1802. <div class={styles.titleName} style={{ width: "50%", margin: "0 auto" }}>
  1803. <NInput onKeyup={(e: Event) => e.stopPropagation()} v-model:value={data.musicName} placeholder="曲谱名称" />
  1804. </div>
  1805. <div style={{ width: "30%", margin: "10px 0 0 auto" }}>
  1806. <NInput onKeyup={(e: Event) => e.stopPropagation()} v-model:value={data.creator} placeholder="曲谱作者" />
  1807. </div>
  1808. </div>
  1809. <div id="paper"></div>
  1810. <Keys show={data.active ? true : false} onClick={(val) => handleChange(val)} />
  1811. {/* <textarea ref={textAreaRef} class={styles.value} id="abc"></textarea> */}
  1812. <div id="audio" style={{ opacity: 0 }}></div>
  1813. <div id="warnings"></div>
  1814. <p class="beat"></p>
  1815. <pre class="clicked-info"></pre>
  1816. <pre class="feedback"></pre>
  1817. <div id="container"></div>
  1818. </div>
  1819. </div>
  1820. <div ref={downRef}></div>
  1821. <TheSetting v-model:show={popup.settingShow} />
  1822. {data.selectMeasures.state && (
  1823. <UseDraggable initialValue={{ x: data.selectMeasures.x, y: data.selectMeasures.y }} class={[styles.selectMearesBox, !popup.selectMearesShow && styles.selectMearesHidden]}>
  1824. <div onKeyup={(e: Event) => e.stopPropagation()}>
  1825. <NSpace justify="space-between">
  1826. <div class={styles.btnLineTitle}>输入小节范围</div>
  1827. <NButton circle quaternary size="small" onClick={() => (popup.selectMearesShow = false)}>
  1828. <NIcon size={16} component={<Close />} />
  1829. </NButton>
  1830. </NSpace>
  1831. <NSpace align="center" wrap={false} wrapItem={false}>
  1832. <div class={styles.mearesInput}>
  1833. <NInputNumber min={1} max={data.selectMeasures.max} bordered={false} placeholder="开始小节" showButton={false} onUpdate:value={(val) => handleSetSelectMeares(val, "start")}></NInputNumber>-
  1834. <NInputNumber min={data.selectMeasures.start} max={data.selectMeasures.max} bordered={false} placeholder="结束小节" showButton={false} onUpdate:value={(val) => handleSetSelectMeares(val, "end")}></NInputNumber>
  1835. </div>
  1836. <div class={styles.topBtn}>
  1837. <NSpin show={data.loadingAudioSrouce} size="small">
  1838. <div class={styles.btnImg} onClick={() => togglePlay(data.playState ? "pause" : "play")}>
  1839. <img style={{ display: data.playState ? "" : "none" }} class={styles.topBtnIcon} src={getImage("icon_21_1.png")} />
  1840. <img style={{ display: data.playState ? "none" : "" }} class={styles.topBtnIcon} src={getImage("icon_21.png")} />
  1841. </div>
  1842. </NSpin>
  1843. </div>
  1844. </NSpace>
  1845. </div>
  1846. </UseDraggable>
  1847. )}
  1848. </div>
  1849. );
  1850. },
  1851. });