state.ts 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067
  1. import { closeToast, showToast } from "vant";
  2. import { nextTick, reactive, watch } from "vue";
  3. import { OpenSheetMusicDisplay } from "../osmd-extended/src";
  4. import { metronomeData } from "./helpers/metronome";
  5. import { GradualNote, GradualTimes, GradualVersion } from "./type";
  6. import { handleEndEvaluat, handleStartEvaluat } from "./view/evaluating";
  7. import { IFingering, mappingVoicePart, subjectFingering, matchVoicePart } from "/src/view/fingering/fingering-config";
  8. import { handleStartTick, closeTick } from "./view/tick";
  9. import { audioListStart, getAudioCurrentTime, getAudioDuration, setAudioCurrentTime, setAudioPlaybackRate, audioData } from "./view/audio-list";
  10. import { toggleFollow } from "./view/follow-practice";
  11. import { browser, setStorageSpeed, setGlobalData } from "./utils";
  12. import { api_cloudGetMediaStatus, api_createMusicPlayer, api_cloudChangeSpeed, api_cloudSuspend, api_cloudSetCurrentTime, api_cloudDestroy } from "./helpers/communication";
  13. import { verifyCanRepeat, getDuration, xmlAddPartName } from "./helpers/formateMusic";
  14. import { getMusicSheetDetail } from "./utils/baseApi"
  15. import { getQuery } from "/src/utils/queryString";
  16. import { followData, skipNotePractice } from "/src/view/follow-practice/index"
  17. import { changeSongSourceByBate } from "/src/view/audio-list"
  18. import { moveSmoothAnimation, smoothAnimationState, moveSmoothAnimationByPlayTime, moveTranslateXNum, destroySmoothAnimation, calcClientWidth } from "/src/page-instrument/view-detail/smoothAnimation"
  19. import { storeData } from "/src/store";
  20. import { downloadXmlStr } from "./view/music-score"
  21. import { musicScoreRef, headerColumnHide } from "/src/page-instrument/view-detail/index"
  22. import { headTopData } from "/src/page-instrument/header-top/index";
  23. const query: any = getQuery();
  24. /** 入门 | 进阶 | 大师 */
  25. export type IDifficulty = "BEGINNER" | "ADVANCED" | "PERFORMER";
  26. /** 渲染类型: 五线谱,简谱 */
  27. export enum EnumMusicRenderType {
  28. /** 五线谱 */
  29. staff = "staff",
  30. /** 简谱(首调) */
  31. firstTone = "firstTone",
  32. /** 固定音高 */
  33. fixedTone = "fixedTone",
  34. }
  35. export const musicscoresettingKey = "musicscoresetting";
  36. /** 有声音的是那个音源 */
  37. export type IPlayState = "music" | "background" | "mingSong";
  38. /** 播放状态 */
  39. export type IAudioState = "play" | "paused";
  40. /** 来源 */
  41. export enum IPlatform {
  42. APP = "APP",
  43. PC = "PC",
  44. }
  45. export type ISonges = {
  46. background?: string
  47. music?: string
  48. }
  49. /**
  50. * 特殊教材分类id
  51. */
  52. const classids = [1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 30, 31, 35, 36, 38, 108, 150, 151, 152, 153, 154, 155, 156, 157, 158, 178, 179, 180, 181, 182]; // 大雅金唐, 竖笛教程, 声部训练展开的分类ID
  53. // 乐器code码
  54. export const musicalInstrumentCodeInfo = [
  55. {
  56. name: '长笛',
  57. code: 'Flute',
  58. id: 1
  59. },
  60. {
  61. name: '短笛',
  62. code: 'Piccolo',
  63. id: 2
  64. },
  65. {
  66. name: '单簧管',
  67. code: 'Clarinet',
  68. id: 3
  69. },
  70. {
  71. name: '低音单簧管',
  72. code: 'Bass Clarinet',
  73. id: 4
  74. },
  75. {
  76. name: '中音萨克斯',
  77. code: 'Alto Saxophone',
  78. id: 5
  79. },
  80. {
  81. name: '次中音萨克斯',
  82. code: 'Tenor Saxophone',
  83. id: 6
  84. },
  85. {
  86. name: '高音萨克斯',
  87. code: 'Soprano Saxophone',
  88. id: 7
  89. },
  90. {
  91. name: '上低音萨克斯',
  92. code: 'Baritone Saxophone',
  93. id: 8
  94. },
  95. {
  96. name: '双簧管',
  97. code: 'Oboe',
  98. id: 9
  99. },
  100. {
  101. name: '大管',
  102. code: 'Bassoon',
  103. id: 10
  104. },
  105. {
  106. name: '小号',
  107. code: 'Trumpet',
  108. id: 11
  109. },
  110. {
  111. name: '圆号',
  112. code: 'Horn',
  113. id: 12
  114. },
  115. {
  116. name: '长号',
  117. code: 'Trombone',
  118. id: 13
  119. },
  120. {
  121. name: '上低音号',
  122. code: 'Baritone',
  123. id: 14
  124. },
  125. {
  126. name: '次中音号',
  127. code: 'Euphonium',
  128. id: 15
  129. },
  130. {
  131. name: '大号',
  132. code: 'Tuba',
  133. id: 16
  134. },
  135. {
  136. name: '钢琴',
  137. code: 'Piano',
  138. id: 17
  139. },
  140. {
  141. name: '电钢琴',
  142. code: 'Electronical Piano',
  143. id: 18
  144. },
  145. {
  146. name: '钢片琴',
  147. code: 'Glockenspiel',
  148. id: 19
  149. },
  150. {
  151. name: '小提琴',
  152. code: 'Violin',
  153. id: 20
  154. },
  155. {
  156. name: '中提琴',
  157. code: 'Viola',
  158. id: 21
  159. },
  160. {
  161. name: '大提琴',
  162. code: 'Violoncello',
  163. id: 22
  164. },
  165. {
  166. name: '低音提琴',
  167. code: 'Contrabass',
  168. id: 23
  169. },
  170. {
  171. name: '架子鼓',
  172. code: 'Drum Set',
  173. id: 24
  174. },
  175. {
  176. name: '小鼓',
  177. code: 'Snare Drum',
  178. id: 25
  179. },
  180. {
  181. name: '马林巴',
  182. code: 'Marimba',
  183. id: 26
  184. },
  185. {
  186. name: '颤音琴',
  187. code: 'Vibraphone',
  188. id: 27
  189. },
  190. {
  191. name: '钟琴',
  192. code: 'Chimes',
  193. id: 28
  194. },
  195. {
  196. name: '木琴',
  197. code: 'Xylophone',
  198. id: 29
  199. },
  200. {
  201. name: '管钟',
  202. code: 'Tubular Bells',
  203. id: 30
  204. },
  205. {
  206. name: '定音鼓',
  207. code: 'Timpani',
  208. id: 31
  209. },
  210. {
  211. name: '键盘',
  212. code: 'Mallets',
  213. id: 32
  214. },
  215. {
  216. name: '排箫',
  217. code: 'Panpipes',
  218. id: 33
  219. },
  220. {
  221. name: '陶笛',
  222. code: 'Ocarina',
  223. id: 34
  224. },
  225. {
  226. name: '陶笛',
  227. code: 'Alto Ocarina',
  228. id: 34
  229. },
  230. {
  231. name: '葫芦丝',
  232. code: 'Woodwind',
  233. id: 35
  234. },
  235. {
  236. name: '葫芦丝',
  237. code: 'Hulusi',
  238. id: 35
  239. },
  240. {
  241. name: '口风琴',
  242. code: 'Nai',
  243. id: 36
  244. },
  245. {
  246. name: '口风琴',
  247. code: 'Melodica',
  248. id: 36
  249. },
  250. {
  251. name: '德式竖笛',
  252. code: 'Tenor Recorder',
  253. id: 37
  254. },
  255. {
  256. name: '德式竖笛',
  257. code: 'German Recorder',
  258. id: 37
  259. },
  260. {
  261. name: '英式竖笛',
  262. code: 'Baroque Recorder',
  263. id: 38
  264. },
  265. {
  266. name: '高音陶笛',
  267. code: 'Whistling',
  268. id: 39
  269. },
  270. {
  271. name: '高音陶笛',
  272. code: 'Soprano Ocarina',
  273. id: 39
  274. },
  275. ]
  276. const state = reactive({
  277. /** 来源 : PC , app */
  278. platform: "" as IPlatform,
  279. appName: "" as "GYM" | "COLEXIU",
  280. musicRenderType: EnumMusicRenderType.staff as EnumMusicRenderType,
  281. /**曲谱是否渲染完成 */
  282. musicRendered: false,
  283. /** 当前曲谱数据ID, 和曲谱ID不一致 */
  284. detailId: "",
  285. /** 曲谱资源URL */
  286. xmlUrl: "",
  287. /** 声部ID */
  288. subjectId: 0 as number,
  289. trackId: 0 as string | number,
  290. isVip: false, // 是否会员
  291. /** 分类ID */
  292. categoriesId: 0,
  293. /** 分类名称 */
  294. categoriesName: "",
  295. /** 是否支持评测 */
  296. enableEvaluation: true,
  297. /** 是否支持转谱 */
  298. enableNotation: false,
  299. /** 后台设置不能转谱,但是默认谱面不是五线谱时,需要显示转谱按钮,此时只能转首调和固定调 */
  300. specialShowNotation: false,
  301. /** 曲谱ID */
  302. examSongId: "",
  303. /** 内容平台的曲谱ID,可能会和业务端的id不一样 */
  304. cbsExamSongId: "",
  305. /** 曲谱名称 */
  306. examSongName: "",
  307. /** 曲谱封面 */
  308. coverImg: "",
  309. /** 扩展字段 */
  310. extConfigJson: {} as any,
  311. /** 扩展样式字段 */
  312. extStyleConfigJson: {} as any,
  313. /** 是否开启节拍器(mp3节拍器) */
  314. isOpenMetronome: false,
  315. /** 演唱模式是否开启节拍器(mp3节拍器) */
  316. isSingOpenMetronome: false,
  317. /** 是否显示指法 */
  318. isShowFingering: false,
  319. /** 原音 */
  320. music: "",
  321. /** 伴奏 */
  322. accompany: "",
  323. /** 范唱 */
  324. fanSong: "",
  325. /** 伴唱 */
  326. banSong: "",
  327. /** 唱名 */
  328. mingSong: "",
  329. /** 唱名女 如果有男唱名的情况下*/
  330. mingSongGirl:"",
  331. /** 节拍器音乐资源 */
  332. beatSong: {
  333. music: "",
  334. accompany: "",
  335. fanSong: "",
  336. banSong: "",
  337. mingSong: "",
  338. mingSongGirl: ""
  339. },
  340. /** midiURL */
  341. midiUrl: "",
  342. /** 父分ID */
  343. parentCategoriesId: 0,
  344. /** 分类ID */
  345. musicSheetCategoriesId: 0,
  346. /** 各产品端的分类ID,(管乐迷、管乐团、酷乐秀、课堂乐器) */
  347. bizMusicCategoryId: 0,
  348. /** 资源类型: mp3 | midi */
  349. playMode: "MP3" as "MP3" | "MIDI",
  350. /** 设置的速度 */
  351. speed: 0,
  352. /** 曲谱音频正常的速度 */
  353. originSpeed: 0,
  354. /** 播放过程中显示的速度 */
  355. playIngSpeed: 0,
  356. /** 分轨名称 */
  357. track: "",
  358. /** 当前显示声部索引 */
  359. partIndex: 0,
  360. /** 演奏是否需要节拍器 */
  361. needTick: false,
  362. /** 演唱模式是否需要节拍器 */
  363. needSingTick: false,
  364. /** 曲谱实例 */
  365. osmd: null as unknown as OpenSheetMusicDisplay,
  366. /**是否是特殊乐谱类型, 主要针对管乐迷 */
  367. isSpecialBookCategory: false,
  368. /** 播放状态 */
  369. playState: "paused" as IAudioState,
  370. /** 播放结束状态 */
  371. playEnd: false,
  372. /** 播放类型 演奏 演唱 */
  373. playType: "play" as "play" | "sing",
  374. /** 播放那个: 原音,伴奏 */
  375. playSource: "music" as IPlayState,
  376. /** 播放进度 */
  377. playProgress: 0,
  378. /** 激活的note index */
  379. activeNoteIndex: 0,
  380. /** 激活的小节 */
  381. activeMeasureIndex: -1,
  382. /** 选段状态 */
  383. sectionStatus: false,
  384. /** 选段数据 */
  385. section: [] as any[],
  386. /** 选段背景 */
  387. sectionBoundingBoxs: [] as any[],
  388. /** 开启选段预备 */
  389. isOpenPrepare: false,
  390. /** 选段预备 */
  391. sectionFirst: null as any,
  392. /** 音符数据 */
  393. times: [] as any[],
  394. /** 播放模式 */
  395. modeType: "practise" as "practise" | "follow" | "evaluating",
  396. /** 设置 */
  397. setting: {
  398. /** 效音提醒 */
  399. soundEffect: true,
  400. /** 护眼模式 */
  401. eyeProtection: false,
  402. /** 摄像头 */
  403. camera: false,
  404. /** 摄像头透明度 */
  405. cameraOpacity: 70,
  406. /** 循环播放 */
  407. repeatAutoPlay: true,
  408. /** 显示指法 */
  409. displayFingering: true,
  410. /** 显示光标 */
  411. displayCursor: true,
  412. /** 频率 */
  413. frequency: 0,
  414. /** 评测难度 */
  415. evaluationDifficulty: "BEGINNER" as IDifficulty,
  416. /** 保存到相册 */
  417. saveToAlbum: true,
  418. /** 开启伴奏 */
  419. enableAccompaniment: true,
  420. /** 反应时间 */
  421. reactionTimeMs: 0,
  422. /** 节拍器音量 */
  423. beatVolume: 50,
  424. },
  425. /** 后台设置的基准评测频率 */
  426. baseFrequency: 440,
  427. /** mp3节拍器的时间,统计拍数、速度计算得出,evxml通过读取xml元素获取 */
  428. fixtime: 0,
  429. /** evxml等待播放的时间 */
  430. evXmlBeginTime: 0,
  431. /** 第二遍循环evxml等待播放的时间 */
  432. secondEvXmlBeginTime: 0,
  433. /** evxml等待播放的时间集合,多遍反复播放,会有多个timegap(前奏)时间 */
  434. evXmlBeginArr: [] as any,
  435. /** 指法信息 */
  436. fingeringInfo: {} as IFingering,
  437. /** 滚动容器的ID */
  438. scrollContainer: "musicAndSelection",
  439. /** 是否是打击乐 */
  440. isPercussion: false,
  441. /** 评测标准 */
  442. evaluationStandard: '',
  443. /** 是否重复节拍器的时间 */
  444. repeatedBeats: 0,
  445. /**当前曲谱中所有声部名字 */
  446. partListNames: [] as any,
  447. /** 渐变速度信息 */
  448. gradual: [] as GradualNote[],
  449. /** 渐变速度版本 */
  450. gradualVersion: GradualVersion.BASE as GradualVersion,
  451. /** 渐变时间信息 */
  452. gradualTimes: null as GradualTimes,
  453. /** 单声部多声轨 */
  454. multitrack: 0,
  455. /** 缩放 */
  456. zoom: 0.8,
  457. /** 渲染曲谱比例 */
  458. musicZoom: 1,
  459. /** 练习,评测是否是选段模式 */
  460. isSelectMeasureMode: false,
  461. /** 是否是评分显示 */
  462. isReport: false,
  463. /** 是否隐藏评测报告弹窗,保存演奏按钮,默认不隐藏 */
  464. isHideEvaluatReportSaveBtn: false,
  465. /** 是否是合奏 */
  466. isConcert: false,
  467. /** 用户选择的结束小节数 */
  468. userChooseEndIndex: 0,
  469. /** 重播小节集合信息 */
  470. repeatInfo: [] as any,
  471. /** 多分轨的曲子,可支持筛选的分轨 */
  472. canSelectTracks: [] as any,
  473. /** 声部codeId */
  474. subjectCodeId: 0 as number,
  475. /** 乐器codeId,用于匹配乐器指法、声部转调、特殊声部处理等 */
  476. musicalCodeId: 0 as number,
  477. /** 乐器code,用于评测传参 */
  478. musicalCode: '' as any,
  479. /** 合奏曲目是否合并展示 */
  480. isCombineRender: false,
  481. /** 是否支持总谱 */
  482. isScoreRender: false,
  483. /** 是否默认显示总谱 */
  484. defaultScoreRender: false,
  485. /** 没有音源字段 */
  486. noMusicSource: false,
  487. /** 小节的持续时长,以后台设置的播放速度计算 */
  488. measureTime: 0,
  489. /** 跟练模式,节拍器播放的时间 */
  490. beatStartTime: 0,
  491. /** 是否为详情预览模式 */
  492. isPreView: false,
  493. /** 是否为评测报告模式 */
  494. isEvaluatReport: false,
  495. /** midi播放器是否初始化中 */
  496. midiPlayIniting: false,
  497. /** 曲目信息 */
  498. songs: {} as ISonges,
  499. isAppPlay: false, // 是否midi音频,midi是app播放
  500. /** 音频播放器实例 */
  501. audiosInstance: null as any,
  502. /** midi音频的时长 */
  503. durationNum: 0,
  504. midiSectionStart: 0,
  505. /** 音频文件是否加载完成 */
  506. audioDone: false,
  507. /** 是否为单行谱渲染模式 */
  508. isSingleLine: false,
  509. /** 是否是evxml */
  510. isEvxml: false,
  511. noTimes: [] as any,
  512. /** 老师端:功能按钮布局方向 */
  513. playBtnDirection: "left" as "left" | "right",
  514. /** 云练习按钮方向,如果有指法并且是竖向的指法,为了防止播放按钮把指法挡住,此时云练习播放按钮方向应该取反 */
  515. musicScoreBtnDirection: "right" as "left" | "right",
  516. /** 是否在老师端上课页面 */
  517. isAttendClass: false,
  518. /** 引导页信息 */
  519. guideInfo: null as any,
  520. noteCoords: [] as any,
  521. specialPosInit: false,
  522. /** 资源类型 */
  523. paymentType: null,
  524. /** 播放模式,默认练习模式 */
  525. defaultModeType: 1,
  526. /** 音符最多歌词次数 */
  527. maxLyricNum: 0,
  528. /** 小节dom集合 */
  529. vfmeasures: [] as SVGAElement[],
  530. /** 作曲家 */
  531. musicComposer: '',
  532. /** 作词家 */
  533. musicLyricist: '',
  534. // 加载条
  535. isLoading: true,
  536. /** 加载中的文案 */
  537. loadingText: '音频资源加载中,请稍后…',
  538. /** 是否是简单的单行谱模式页面 */
  539. isSimplePage: false,
  540. /** xml的速度和后台设置的速度,计算出的基础音频播放倍率 */
  541. originAudioPlayRate: 1,
  542. /** 开始播放时,记录的mp3播放倍率,用户当前设置的速度/当前小节的速度 */
  543. basePlayRate: 1,
  544. /** 引导页显示状态 */
  545. hasDriverPop: false,
  546. /** 播放倍率不等于1,或者是选段评测,APP暂时不支持保存演奏,需要给出提示 */
  547. noSavePopShow: true,
  548. /** xml里面是否有歌词 */
  549. xmlHasLyric: false,
  550. /** 生成图片的模式 */
  551. isCreateImg: false,
  552. /** 切换谱面后,作业选段是否需要刷新 */
  553. workSectionNeedReset: false,
  554. /** 旋律线开关 */
  555. melodyLine: true,
  556. /** 是否是C调,切换到唱名时,只有C调所有的谱面类型都可以播放唱名文件;其它调的只有首调可以播放唱名,因为唱名是按照C调制作的,没有其它调的唱名文件 */
  557. isCTone: false,
  558. });
  559. const browserInfo = browser();
  560. let offset_duration = 0;
  561. /** 自定义数据 */
  562. export const customData = reactive({
  563. /** 自定义音符时值 */
  564. customNoteRealValue: [] as any,
  565. /** 自定义音符按读取到的时值 */
  566. customNoteCurrentTime: false,
  567. });
  568. /** 在渲染前后计算光标应该走到的音符 */
  569. export const setStep = () => {
  570. // console.log('播放状态',state.playState)
  571. if (state.playState !== "play") {
  572. console.log("暂停播放");
  573. return;
  574. }
  575. let startTime = Date.now();
  576. requestAnimationFrame(() => {
  577. const endTime = Date.now();
  578. // 渲染时间大于16.6,就会让页面卡顿, 如果渲染时间大与16.6就下一个渲染帧去计算
  579. if (endTime - startTime < 16.7) {
  580. handlePlaying();
  581. setStep();
  582. } else {
  583. setTimeout(() => {
  584. handlePlaying();
  585. setStep();
  586. }, 16.7);
  587. }
  588. });
  589. };
  590. /** 开始播放 */
  591. export const onPlay = () => {
  592. console.log("开始播放", '音频总时长:', getAudioDuration());
  593. state.playEnd = false;
  594. // offset_duration = browserInfo.xiaomi ? 0.2 : 0.08;
  595. offset_duration = 0.2;
  596. setStep();
  597. };
  598. /** 播放模式结束自动重播 */
  599. const autoResetPlay = () => {
  600. if (state.modeType !== "practise") return;
  601. skipNotePlay(0, true);
  602. // 没有开启自动重播, 不是练习模式
  603. if (!state.setting.repeatAutoPlay) return;
  604. scrollViewNote();
  605. setTimeout(() => {
  606. togglePlay("play");
  607. }, 1000);
  608. };
  609. /** 播放完成事件 */
  610. export const onEnded = () => {
  611. console.log("音频播放结束");
  612. // if (state.isAppPlay) {
  613. // // 销毁播放器
  614. // api_cloudDestroy();
  615. // }
  616. if (state.playEnd) {
  617. console.log('音频播放结束,无需再次执行')
  618. return
  619. }
  620. // 修改状态为结束
  621. state.playEnd = true;
  622. state.playState = "paused";
  623. // 结束播放
  624. audioListStart(state.playState);
  625. // 调用结束评测
  626. handleEndEvaluat(true);
  627. // 调用自动重复播放
  628. autoResetPlay();
  629. };
  630. // 根据当前小节动态设置,右上角展示的速度
  631. const dynamicShowPlaySpeed = (index: number) => {
  632. if (!headerColumnHide.value) {
  633. console.log('动态计算速度')
  634. const item: any = state.times[index];
  635. if (item && item.measureSpeed ) {
  636. // console.log('速度1',item.measureSpeed)
  637. const newSpeed = Math.floor(state.basePlayRate * item.measureSpeed)
  638. if (state.speed !== newSpeed) {
  639. state.speed = newSpeed;
  640. }
  641. }
  642. }
  643. }
  644. // 开始播放时,计算mp3的播放倍率
  645. export const initSetPlayRate = () => {
  646. const item: any = (state.sectionStatus && state.section.length === 2) ? state.sectionFirst || state.section[0] : state.times[state.activeNoteIndex];
  647. if (item && item.measureSpeed) {
  648. const ratio = state.speed / item.measureSpeed
  649. // state.audiosInstance?.setSpeed(ratio)
  650. state.basePlayRate = ratio || 1;
  651. console.log('播放倍率',state.basePlayRate)
  652. }
  653. }
  654. // 重置播放倍率
  655. export const resetBaseRate = (idx?: number) => {
  656. const index = idx ? idx : 0;
  657. const currentItem: any = state.times[index];
  658. const currentSpeed = currentItem?.measureSpeed ? currentItem.measureSpeed : state.originSpeed;
  659. console.log('速度2',currentSpeed)
  660. state.speed = currentSpeed
  661. //state.activeNoteIndex = 0
  662. state.basePlayRate = 1;
  663. }
  664. /**
  665. * 播放一直触发的事件
  666. */
  667. const handlePlaying = () => {
  668. const currentTime = getAudioCurrentTime();
  669. const duration = getAudioDuration();
  670. state.playProgress = (currentTime / duration) * 100;
  671. let item = getNote(currentTime);
  672. if (item) {
  673. // 选段状态下
  674. if (state.sectionStatus && state.section.length === 2) {
  675. // 如果开启了预备拍
  676. const selectStartItem = state.sectionFirst ? state.sectionFirst : state.section[0];
  677. const selectEndItem = state.section[1];
  678. /**
  679. * #9374,反复小节的曲目播放错误, bug修复
  680. * 曲目:噢!苏珊娜-排箫-人音
  681. * 现象:重播小节为2-9,选段为4-12,当播完第9小节后会回到第2小节重播2-8,再播放10-12
  682. * 4-12,不符合重播规则,所以播完第9小节后,音频需要跳转到第10小节播放
  683. */
  684. if (state.repeatInfo.length) {
  685. const canRepeatInfo = verifyCanRepeat(state.section[0].MeasureNumberXML, state.section[1].MeasureNumberXML)
  686. const repeatIdx = canRepeatInfo.repeatIdx == -1 ? 0 : canRepeatInfo.repeatIdx
  687. if (state.modeType === "practise" && !canRepeatInfo.canRepeat && state.section[1].MeasureNumberXML > state.repeatInfo[repeatIdx].end) {
  688. const preItem = state.times[item.i - 1]
  689. if (preItem && preItem.MeasureNumberXML > item.MeasureNumberXML) {
  690. const skipItem = state.times.find((item: any) => item.MeasureNumberXML === preItem.MeasureNumberXML + 1)
  691. if (skipItem) {
  692. // 跳转到指定的音频位置
  693. setAudioCurrentTime(skipItem.time, skipItem.i);
  694. gotoNext(skipItem);
  695. return
  696. }
  697. }
  698. }
  699. }
  700. // if (Math.abs(selectEndItem.endtime - currentTime) < offset_duration) {
  701. // if (currentTime - selectEndItem.endtime > offset_duration) {
  702. //console.log(currentTime,selectEndItem.endtime)
  703. if (currentTime - selectEndItem.endtime >= 0) {
  704. console.log("选段播放结束", state.setting.repeatAutoPlay);
  705. // 如果为选段评测模式
  706. if (state.modeType === "evaluating" && state.isSelectMeasureMode) {
  707. onEnded();
  708. return;
  709. }
  710. // #8698 bug修复
  711. if (state.modeType === "practise" && state.sectionStatus) {
  712. onEnded();
  713. // state.activeNoteIndex = state.sectionFirst ? state.sectionFirst.i : state.section[0].i
  714. // dynamicShowPlaySpeed(state.activeNoteIndex)
  715. resetPlaybackToStart();
  716. return;
  717. }
  718. item = selectStartItem;
  719. setAudioCurrentTime(selectStartItem.time, selectStartItem.i);
  720. }
  721. }
  722. gotoNext(item);
  723. dynamicShowPlaySpeed(item.i);
  724. }
  725. // 评测不播放叮咚节拍器
  726. // if (state.modeType !== "evaluating") {
  727. // metronomeData.metro?.sound(currentTime);
  728. // }
  729. // 不需要播放节拍器的声音,因为音频带有节拍器的声音
  730. // metronomeData.metro?.sound(currentTime);
  731. // 一行谱,需要滚动小节
  732. if (state.isSingleLine) {
  733. moveSmoothAnimationByPlayTime()
  734. }
  735. };
  736. /** 跳转到指定音符开始播放 */
  737. export const skipNotePlay = async (itemIndex: number, isStart = false) => {
  738. console.log('点击音符')
  739. const item = state.times[itemIndex];
  740. let itemTime = item.time;
  741. if (isStart) {
  742. itemTime = 0;
  743. }
  744. if (item) {
  745. // 非选段模式,点击音符,动态设置右下角的速度
  746. if (item.measureSpeed && state.section.length < 2) {
  747. state.speed = Math.floor(state.basePlayRate * item.measureSpeed)
  748. }
  749. setAudioCurrentTime(itemTime, itemIndex);
  750. // 一行谱,点击音符,或者播放完成,需要跳转音符位置
  751. gotoNext(item, true);
  752. // 不需要播放节拍器的声音,因为音频带有节拍器的声音
  753. // metronomeData.metro?.sound(itemTime);
  754. if (state.isAppPlay) {
  755. await api_cloudSetCurrentTime({
  756. currentTime: itemTime * 1000,
  757. songID: state.examSongId,
  758. })
  759. audioData.progress = itemTime
  760. state.midiSectionStart = itemTime
  761. }
  762. // 如果是跟练模式
  763. if (followData.start) {
  764. skipNotePractice()
  765. }
  766. }
  767. };
  768. /**
  769. * 切换曲谱播放状态
  770. * @param playState 需要切换的状态 play:播放, paused: 暂停
  771. */
  772. export const togglePlay = async (playState: "play" | "paused", isForceCLoseToast?:boolean) => {
  773. // 如果mp3资源还在加载中,给出提示
  774. if (!state.isAppPlay && !state.audioDone) {
  775. if (!isForceCLoseToast) showToast('音频资源加载中,请稍后')
  776. return
  777. }
  778. // 播放之前 当为评测模式和不为MIDI时候按 是否禁用节拍器 切换音源
  779. if (playState === 'play' && state.modeType === "practise" && state.playMode !== "MIDI") {
  780. console.log("设置音源")
  781. changeSongSourceByBate(metronomeData.disable)
  782. }
  783. // midi播放
  784. if (state.isAppPlay) {
  785. if (playState === "paused") {
  786. await api_cloudSuspend({
  787. songID: state.examSongId,
  788. })
  789. state.playState = 'paused'
  790. // 当在节拍器播放期间暂停的话 就暂停节拍器
  791. closeTick()
  792. return
  793. }
  794. skipNotePlay(state.activeNoteIndex, false);
  795. await api_cloudChangeSpeed({
  796. speed: state.modeType === "evaluating" ? state.originSpeed : state.speed,
  797. originalSpeed: state.originSpeed,
  798. songID: state.examSongId,
  799. });
  800. const cloudGetMediaStatus = await api_cloudGetMediaStatus();
  801. const status = cloudGetMediaStatus?.content.status === "suspend" ? "play" : "paused"
  802. state.playState = status
  803. } else {
  804. state.playState = playState;
  805. }
  806. if (state.playState === "play" && state.sectionStatus && state.section.length == 2 && state.playProgress === 0) {
  807. resetPlaybackToStart();
  808. }
  809. // 当在节拍器播放期间暂停的话 就暂停节拍器
  810. if (state.playState === "paused") {
  811. closeTick()
  812. }
  813. // 设置为开始播放时, 如果需要节拍,先播放节拍器 只有在当前播放时间不为0的时候开启节拍器
  814. const isOneMeasureNumberXML = state.section.length === 2 && state.section[0].MeasureNumberXML === 2 //当是选段模式 并且开始小节是第二小节 就不播节拍器(这种情况有预选小节,currentTime是0)
  815. if (state.playState === "play" && getAudioCurrentTime() === 0 && !isOneMeasureNumberXML && ((state.playType === "play" && state.needTick) || (state.playType === "sing" && state.needSingTick))) {
  816. // 如果是系统节拍器 等系统节拍器播完了再播,如果是mp3节拍器 直接播
  817. if ((state.playType === "play" && !state.isOpenMetronome) || (state.playType === "sing" && !state.isSingOpenMetronome)) {
  818. const tickend = await handleStartTick();
  819. // console.log("🚀 ~ tickend:", tickend)
  820. // 节拍器返回false, 取消播放
  821. if (!tickend) {
  822. state.playState = "paused";
  823. return false;
  824. }
  825. } else {
  826. handleStartTick()
  827. }
  828. }
  829. // 如果选段没有结束, 直接开始播放,清空选段状态
  830. if (state.playState == "play") {
  831. if (state.sectionStatus && state.section.length < 2) {
  832. clearSelection();
  833. }
  834. }
  835. initSetPlayRate();
  836. audioListStart(state.playState);
  837. return true;
  838. };
  839. /** 结束播放 */
  840. export const handleStopPlay = () => {
  841. state.playState = "paused";
  842. audioListStart(state.playState);
  843. };
  844. /** 重置播放为开始 */
  845. export const resetPlaybackToStart = () => {
  846. // 如果为选段状态
  847. if (state.sectionStatus && state.section.length === 2) {
  848. state.section = formateSelectMearure(state.section);
  849. return;
  850. } else {
  851. // 非选段状态,重播需要重置当前选中的小节为第一个小节
  852. metronomeData.activeMetro = metronomeData.metroMeasure[0]?.[0] || {};
  853. }
  854. skipNotePlay(0, true);
  855. };
  856. /** 跳转到指定音符 */
  857. export const gotoCustomNote = (index: number) => {
  858. try {
  859. state.osmd.cursor.reset();
  860. } catch (error) { }
  861. for (let i = 0; i < index; i++) {
  862. state.osmd.cursor.next();
  863. }
  864. };
  865. // 找出离目标元素最近的音符
  866. const computedDistance = (x: number, y: number) => {
  867. let minDistance = -1, minidx = 0;
  868. let a, b, c;
  869. state.noteCoords.forEach((note: any, idx: any) => {
  870. //a,b为直角三角形的两个直角边
  871. a = Math.abs(note.x - x)
  872. b = Math.abs(note.y - y)
  873. //c为直角三角形的斜边
  874. c = Math.sqrt(a * a + b * b) as 0
  875. c = Number(c.toFixed(0)) as 0
  876. if (c !== 0 && (minDistance === - 1 || c < minDistance)) {
  877. //min为元素中离目标元素最近元素的距离
  878. minDistance = c
  879. minidx = idx
  880. }
  881. })
  882. return minidx
  883. };
  884. const customNotePosition = (note: any, cursor: any) => {
  885. const specialIds = ['1788850864767643649', '1788502467554750466', '1788501975122489346'];
  886. if (specialIds.includes(state.cbsExamSongId) && note.multipleRestMeasures === 0) {
  887. const pageLeft = document.getElementById('scrollContainer')?.getBoundingClientRect()?.x || 0;
  888. // 元素的位置
  889. const element = document.getElementById('cursorImg-0')?.getBoundingClientRect?.() || { x: 0, y: 0 };
  890. // 找出距离元素最近的音符
  891. if (element.x && element.y) {
  892. const noteIdx = computedDistance(element.x, element.y);
  893. const targetX = state.noteCoords[noteIdx]?.x - pageLeft;
  894. console.log('音符索引', noteIdx)
  895. cursor.cursorElement.style.left = targetX + "px";
  896. cursor.cursorElement.style.transform = `translateX(0px)`;
  897. }
  898. }
  899. }
  900. const setCursorPosition = (note: any, cursor: any, flag?: string) => {
  901. // console.log('音符',note?.i,state.osmd.Cursor.noteGraphicalId,note.svgElement?.attrs?.id)
  902. if (state.musicRenderType === EnumMusicRenderType.firstTone || state.musicRenderType === EnumMusicRenderType.fixedTone) {
  903. /**
  904. * bug:#9920、#9940
  905. * 简谱选段模式,预备小节为休止小节时,选段播放结束,指针会重置到第一小节位置的初始位置
  906. */
  907. if (state.sectionStatus && state.playState === 'paused' && state.sectionFirst && (note.multipleRestMeasures || note.MeasureNumberXML !== state.sectionFirst?.MeasureNumberXML)) {
  908. return
  909. }
  910. const specialIds = ['1788850864767643649', '1788502467554750466', '1788501975122489346'];
  911. if (specialIds.includes(state.cbsExamSongId) && note.multipleRestMeasures === 0) {
  912. // console.log('音符idx',note?.i,cursor.cursorElement.style.left)
  913. const cursorLeft = cursor?.cursorElement?.style?.left ? parseFloat(cursor.cursorElement.style.left) : 0;
  914. let patchX = 0;
  915. if (state.cbsExamSongId == '1788502467554750466') {
  916. if (state.musicRenderType === EnumMusicRenderType.firstTone) {
  917. patchX = (note.i == 0 || note.i == 60) ? 21 : (note.i == 1 || note.i == 7 || note.i == 23 || note.i == 38 || note.i == 44 || note.i == 52 || note.i == 58) ? -6 : (note.i >= 2 || note.i <= 6) || (note.i >= 8 || note.i <= 22) || (note.i >= 24 || note.i <= 37) || (note.i >= 39 || note.i <= 43) || (note.i >= 45 || note.i <= 51) || (note.i >= 53 || note.i <= 57) || (note.i == 59) ? 6 : 0;
  918. }
  919. if (state.musicRenderType === EnumMusicRenderType.fixedTone) {
  920. patchX = note.i == 0 ? 31 : (note.i == 8 || note.i == 14 || note.i == 30 || note.i == 45 || note.i == 51 || note.i == 59 || note.i == 65) ? -10 : note.i == 67 ? 31 : 0;
  921. }
  922. } else if (state.cbsExamSongId == '1788501975122489346') {
  923. if (state.musicRenderType === EnumMusicRenderType.firstTone) {
  924. patchX = (note.i == 0) ? 21 : (note.i == 1 || note.i == 7 || note.i == 23 || note.i == 38 || note.i == 44 || note.i == 52 || note.i == 58) ? -6 : (note.i == 9 || note.i == 10 || note.i == 12 || note.i == 13) ? 3 : (note.i == 14 || note.i == 30 || note.i == 45 || note.i == 51 || note.i == 59) ? 6 : (note.i == 45) ? -8 : (note.i >= 15 || note.i <= 29) || (note.i >= 31 || note.i <= 36) || (note.i >= 38 || note.i <= 44) || (note.i >= 46 || note.i <= 50) || (note.i >= 52 || note.i <= 58) || (note.i >= 60 || note.i <= 64) || (note.i == 66) ? 4 : 0;
  925. }
  926. if (state.musicRenderType === EnumMusicRenderType.fixedTone) {
  927. patchX = note.i == 0 ? 31 : (note.i == 8 || note.i == 14 || note.i == 30 || note.i == 45 || note.i == 51 || note.i == 59 || note.i == 65) ? -10 : note.i == 67 ? 31 : 0;
  928. }
  929. }
  930. if (flag === 'refresh' || (flag === 'init' && !state.specialPosInit)) {
  931. // console.log('音符idx',note?.i,cursor.cursorElement.style.left)
  932. cursor.cursorElement.style.left = cursorLeft + patchX + "px";
  933. state.specialPosInit = true;
  934. }
  935. } else {
  936. nextTick(() => {
  937. let bbox = note.bbox;
  938. if (!bbox) {
  939. const musicContainer = document.getElementById("musicAndSelection")?.getBoundingClientRect() || {
  940. x: 0,
  941. y: 0,
  942. };
  943. const parentLeft = musicContainer.x || 0;
  944. const noteEle = document.querySelector(`#vf-${note.svgElement?.attrs?.id}`);
  945. if (noteEle) {
  946. const noteHead = noteEle.querySelector(".vf-numbered-note-head");
  947. const noteHeadBbox = noteHead?.getBoundingClientRect?.();
  948. if (noteHeadBbox) {
  949. note.bbox = {
  950. left: noteHeadBbox.x - parentLeft - noteHeadBbox.width / 4,
  951. width: noteHeadBbox.width * 1.5,
  952. };
  953. bbox = note.bbox;
  954. }
  955. }
  956. }
  957. if (!bbox) return;
  958. const baseW = state.platform === IPlatform.PC ? 29 : 18;
  959. const width = (bbox.width - baseW) / 3;
  960. // console.log(555555,bbox.left,width)
  961. cursor.cursorElement.style.left = bbox.left + "px";
  962. cursor.cursorElement.style.transform = `translateX(${width}px)`;
  963. });
  964. }
  965. }
  966. };
  967. /**
  968. * 跳转到下一个音符
  969. * 一行谱,点击音符,或者播放完成,需要跳转音符位置,增加参数skipNote
  970. **/
  971. export const gotoNext = (note: any, skipNote?: boolean) => {
  972. // console.log(33333333333,state.activeNoteIndex,note.i)
  973. const num = note.i;
  974. if (state.activeNoteIndex === note.i) {
  975. /* 没有光标了 这里就算加上光标也要性能优化 */
  976. // try {
  977. // setCursorPosition(note, state.osmd.cursor, 'init');
  978. // } catch (error) {
  979. // console.log(error);
  980. // }
  981. // 重置 或者切换演奏演唱的时候 可能出现 state.activeNoteIndex === note.i的情况 执行
  982. if(state.playState === "paused"){
  983. fillWordColor();
  984. }
  985. if (state.isSingleLine && state.playState === "paused") {
  986. moveSvgDom(skipNote);
  987. }
  988. return;
  989. }
  990. const osmd = state.osmd;
  991. let prev = state.activeNoteIndex;
  992. state.activeNoteIndex = num;
  993. state.activeMeasureIndex = note.MeasureNumberXML;
  994. dynamicShowPlaySpeed(state.activeNoteIndex);
  995. if (prev && num - prev === 1) {
  996. // console.log('跳转音符',11111,osmd.cursor)
  997. // if (!note.id && note.multipleRestMeasures === 0) {
  998. // } else {
  999. // osmd.cursor.next();
  1000. // }
  1001. osmd.cursor.next();
  1002. } else if (prev && num - prev > 0) {
  1003. while (num - prev > 0) {
  1004. prev++;
  1005. // console.log('跳转音符',22222)
  1006. osmd.cursor.next();
  1007. }
  1008. } else {
  1009. gotoCustomNote(num);
  1010. }
  1011. /* 取消光标了 */
  1012. // try {
  1013. // setCursorPosition(note, state.osmd.cursor, 'refresh');
  1014. // } catch (error) {
  1015. // console.log(error);
  1016. // }
  1017. fillWordColor();
  1018. // 一行谱,需要滚动小节
  1019. if (state.isSingleLine) {
  1020. moveSvgDom(skipNote);
  1021. }
  1022. scrollViewNote();
  1023. };
  1024. /** 获取指定音符 */
  1025. export const getNote = (currentTime: number) => {
  1026. const times = state.times;
  1027. const len = state.times.length;
  1028. /** 播放超过了最后一个音符的时间,直接结束, 2秒误差 */
  1029. if (currentTime > times[len - 1].endtime + 2 && !state.isAppPlay && !state.isSimplePage) {
  1030. // onEnded();
  1031. return;
  1032. }
  1033. let _item = null as any;
  1034. for (let i = state.activeNoteIndex; i < len; i++) {
  1035. let item = times[i];
  1036. const prevItem = times[i - 1];
  1037. // if (state.isEvxml) {
  1038. // let diffArr: any[] = [];
  1039. // times.forEach((note: any, noteIdx: number) => {
  1040. // if (currentTime >= note.time && currentTime <= times[noteIdx+1].time) {
  1041. // let diffTime = times[noteIdx+1].time - currentTime;
  1042. // diffArr.push({
  1043. // diffTime,
  1044. // idx: noteIdx
  1045. // })
  1046. // }
  1047. // })
  1048. // diffArr.sort((a, b) => a.diffTime - b.diffTime);
  1049. // item = diffArr.length ? times[diffArr[0].idx] : item;
  1050. // }
  1051. if (currentTime >= item.time) {
  1052. if (!prevItem || item.time != prevItem.time) {
  1053. _item = item;
  1054. }
  1055. } else {
  1056. break;
  1057. }
  1058. }
  1059. // console.log("activeNoteIndex", currentTime, state.activeNoteIndex, _item.i);
  1060. return _item;
  1061. };
  1062. /** 重播 */
  1063. export const handleResetPlay = () => {
  1064. // 如果是midi需要重置播放进度
  1065. if (state.isAppPlay) {
  1066. audioData.progress = 0
  1067. }
  1068. // 如果是作业模式,不还原速度
  1069. if (!query.workRecord) {
  1070. resetBaseRate();
  1071. }
  1072. resetPlaybackToStart();
  1073. // 如果是暂停, 直接播放
  1074. togglePlay("play");
  1075. };
  1076. /** 设置速度 */
  1077. export const handleSetSpeed = (speed: number) => {
  1078. // setStorageSpeed(state.examSongId, speed);
  1079. state.speed = speed;
  1080. // 当前的音符
  1081. const currentItem: any = (state.sectionStatus && state.section.length === 2) ? state.sectionFirst || state.section[0] : state.times[state.activeNoteIndex];
  1082. state.basePlayRate = currentItem?.measureSpeed ? state.speed / currentItem.measureSpeed : state.speed / state.originSpeed;
  1083. const actualRate = state.originAudioPlayRate * state.basePlayRate;
  1084. console.log('速度设置',speed,'小节计算的倍率',state.basePlayRate,'实际播放倍率',actualRate)
  1085. };
  1086. /** 清除选段状态 */
  1087. export const clearSelection = () => {
  1088. state.sectionStatus = false;
  1089. state.section = [];
  1090. closeToast();
  1091. };
  1092. /** 开启选段 */
  1093. export const handleChangeSection = () => {
  1094. // 如果开启了选段,再次点击取消选段
  1095. if (state.sectionStatus) {
  1096. togglePlay("paused");
  1097. clearSelection();
  1098. // 重置速度和播放倍率
  1099. resetBaseRate(state.activeNoteIndex);
  1100. //skipNotePlay(0, true); 取消选段的时候 不跳回开头
  1101. state.sectionFirst = null;
  1102. return;
  1103. }
  1104. state.sectionStatus = true;
  1105. // 开启
  1106. if (state.sectionStatus) {
  1107. togglePlay("paused");
  1108. }
  1109. showToast({
  1110. message: "请选择开始小节",
  1111. duration: 0,
  1112. position: "top",
  1113. className: "selectionToast",
  1114. });
  1115. };
  1116. /** 效验并格式化选段小节 */
  1117. const formateSelectMearure = (_list: any[]): any[] => {
  1118. if (!_list.length) return [];
  1119. const list = _list.sort((a, b) => a.time - b.time);
  1120. const startXml = list[0]?.measureOpenIndex;
  1121. const endXml = list.last()?.measureOpenIndex;
  1122. const selectStartMeasure = state.times.filter((n: any) => startXml === n.measureOpenIndex) || [];
  1123. const selectEndMeasure = state.times.filter((n: any) => endXml === n.measureOpenIndex) || [];
  1124. // 没有找到选段小节
  1125. if (!selectStartMeasure.length || !selectEndMeasure.length) {
  1126. clearSelection();
  1127. return [];
  1128. }
  1129. list[0] = selectStartMeasure[0];
  1130. list[1] = selectEndMeasure.last();
  1131. let startItemINdex = list[0].i;
  1132. // 开启预备拍
  1133. if (state.isOpenPrepare) {
  1134. const startXmlIndex = list[0].MeasureNumberXML;
  1135. state.sectionFirst = state.times.find((n: any) => startXmlIndex - n.MeasureNumberXML === 1);
  1136. startItemINdex = state.sectionFirst ? state.sectionFirst.i : startItemINdex;
  1137. }
  1138. skipNotePlay(startItemINdex, startItemINdex === 0);
  1139. return list;
  1140. };
  1141. /** 选择选段 */
  1142. export const handleSelection = (item: any) => {
  1143. if (!state.sectionStatus || state.section.length > 1) return;
  1144. if (state.section.length !== 2 && item) {
  1145. state.section.push(item);
  1146. if (state.section.length === 2) {
  1147. setSection(state.section[0].MeasureNumberXML, state.section[1].MeasureNumberXML)
  1148. //state.section = formateSelectMearure(state.section);
  1149. closeToast();
  1150. }
  1151. }
  1152. if (state.section.length === 1) {
  1153. showToast({
  1154. message: "请选择结束小节",
  1155. duration: 0,
  1156. position: "top",
  1157. className: "selectionToast",
  1158. });
  1159. }
  1160. };
  1161. /** 阶段练习、阶段评测设置选段小节 */
  1162. export const setSection = (start: number, end: number, userSpeed?: number) => {
  1163. const startNotes = state.times.filter(
  1164. (n: any) => n.noteElement.sourceMeasure.MeasureNumberXML == start
  1165. )
  1166. const endNotes = state.times.filter(
  1167. (n: any) => n.noteElement.sourceMeasure.MeasureNumberXML == end
  1168. )
  1169. state.userChooseEndIndex = end
  1170. const lastEndId = endNotes[endNotes.length - 1].noteId
  1171. let lastEndNotes = endNotes.filter((n: any) => n.noteId === lastEndId)
  1172. // 是否符合重播规则
  1173. const canRepeatInfo = verifyCanRepeat(start, end)
  1174. console.log('能否重播', canRepeatInfo)
  1175. const isCanRepeat = canRepeatInfo.canRepeat
  1176. // 如果符合重播规则,但是lastEndNotes长度为1,则需要向前找,直到找到lastEndNotes长度为2
  1177. /**
  1178. * 如果符合重播规则,但是lastEndNotes长度为1,则需要向前找,直到找到lastEndNotes长度为2
  1179. * 2024.03.28 新增逻辑,如果当前选中的结束小节是跳房子,则不向前找,因为这种场景不符合重播规则(bug:#9921)
  1180. * TODO:通过vf-volta判断是否是跳房子
  1181. */
  1182. let isSkipVolta = false; // 结束小节是否是跳房子小节
  1183. if (lastEndNotes.length === 1) {
  1184. isSkipVolta = lastEndNotes[0]?.stave?.modifiers?.some((item: any) => item.getAttribute('type') === 'Volta')
  1185. }
  1186. let currentEndNum: number = end
  1187. const lastEndIndex: any = state.repeatInfo[canRepeatInfo.repeatIdx]?.end || 0
  1188. while (isCanRepeat && lastEndNotes.length === 1 && lastEndNotes[0].MeasureNumberXML <= lastEndIndex && !isSkipVolta) {
  1189. currentEndNum = currentEndNum - 1
  1190. const newEndNotes = state.times.filter(
  1191. (n: any) => n.noteElement.sourceMeasure.MeasureNumberXML == currentEndNum
  1192. )
  1193. const newLastEndId = newEndNotes[newEndNotes.length - 1].noteId
  1194. lastEndNotes = newEndNotes.filter((n: any) => n.noteId === newLastEndId)
  1195. }
  1196. const endIdx: any = (isCanRepeat && canRepeatInfo.repeatIdx == state.repeatInfo.length - 1) ? lastEndNotes.length - 1 : 0
  1197. const startNote = startNotes[0]
  1198. // const endNote = endNotes[endNotes.length - 1]
  1199. const endNote = lastEndNotes[endIdx]
  1200. if (startNote && endNote) {
  1201. state.isSelectMeasureMode = true;
  1202. // 设置小节
  1203. hanldeDirectSelection([startNote, endNote]);
  1204. // 评测作业,练习作业的场景,需要用老师布置的速度,设置播放速度
  1205. if (userSpeed) {
  1206. handleSetSpeed(userSpeed);
  1207. }
  1208. }
  1209. }
  1210. /** 直接设置选段 */
  1211. export const hanldeDirectSelection = (list: any[]) => {
  1212. if (!Array.isArray(list) || list.length !== 2) return;
  1213. state.sectionStatus = true;
  1214. setTimeout(() => {
  1215. state.section = formateSelectMearure(list);
  1216. // 选段完成后,需要根据预报小节的速度,设置右下角显示的速度
  1217. const currentItem: any = (state.sectionStatus && state.section.length === 2) ? state.sectionFirst || state.section[0] : state.times[state.activeNoteIndex];
  1218. if (currentItem.measureSpeed && query.workRecord === undefined) {
  1219. handleSetSpeed(currentItem.measureSpeed);
  1220. }
  1221. console.log('选段小节', state.section)
  1222. }, 0);
  1223. };
  1224. let offsetTop = 0;
  1225. /**
  1226. * 窗口内滚动到音符的区域
  1227. * @param isScroll 可选: 强制滚动到顶部, 默认: false
  1228. * @returns void
  1229. */
  1230. export const scrollViewNote = () => {
  1231. const cursorElement = document.getElementById("cursorImg-0")!;
  1232. const musicAndSelection = document.getElementById(state.scrollContainer)!;
  1233. if (!cursorElement || !musicAndSelection || offsetTop === cursorElement.offsetTop) return;
  1234. offsetTop = cursorElement.offsetTop;
  1235. if (offsetTop > 50) {
  1236. musicAndSelection.scrollTo({
  1237. top: (offsetTop - 50) * state.musicZoom,
  1238. behavior: "smooth",
  1239. });
  1240. } else {
  1241. musicAndSelection.scrollTo({
  1242. top: 0,
  1243. behavior: "smooth",
  1244. });
  1245. }
  1246. };
  1247. /** 检测是否是节奏练习 */
  1248. export const isRhythmicExercises = () => {
  1249. return state.examSongName.indexOf("节奏练习") > -1;
  1250. };
  1251. /** 重置状态 */
  1252. export const handleRessetState = () => {
  1253. // 切换模式,清除选段
  1254. state.noSavePopShow = true;
  1255. clearSelection();
  1256. skipNotePlay(0, true);
  1257. resetBaseRate();
  1258. // midi 重置播放进度
  1259. if (state.isAppPlay) {
  1260. audioData.progress = 0;
  1261. }
  1262. if (state.modeType === "evaluating") {
  1263. handleStartEvaluat();
  1264. } else if (state.modeType === "practise") {
  1265. togglePlay("paused", true);
  1266. } else if (state.modeType === "follow") {
  1267. toggleFollow(false);
  1268. }
  1269. };
  1270. export default state;
  1271. /** 初始化评测音频 */
  1272. export const evaluatCreateMusicPlayer = () => {
  1273. return api_createMusicPlayer({
  1274. musicSrc: state.accompany || state.music, // 曲谱音频url
  1275. // tuneSrc: "https://oss.dayaedu.com/cloud-coach/1686725501654check_music1_(1).mp3", //效音音频url
  1276. tuneSrc: "https://oss.dayaedu.com/MECMP/1722593665681.mp3", //效音音频url
  1277. checkFrequence: 496,
  1278. });
  1279. };
  1280. /** 获取内容平台的接口详情并初始化state信息 */
  1281. export const getMusicDetail = async (id: string, type?: string) => {
  1282. const res = await getMusicSheetDetail(id, type);
  1283. if (res?.code === 200) {
  1284. await getMusicInfo(res)
  1285. }
  1286. };
  1287. const getMusicInfo = async (res: any) => {
  1288. // 是否支持总谱
  1289. state.isScoreRender = res.data?.isScoreRender
  1290. // 是否默认显示总谱
  1291. state.defaultScoreRender = res.data?.defaultScoreRender
  1292. const partIndex = query["part-index"] ? parseInt(query["part-index"]) : -1 // -1为partIndex没有值的时候
  1293. /* 获取声轨列表 */
  1294. let xmlString = await fetch(res.data.xmlFileUrl).then((response) => response.text());
  1295. xmlString = xmlAddPartName(xmlString);
  1296. downloadXmlStr.value = xmlString //给musice-score 赋值xmlString 以免加载2次
  1297. const tracks = xmlToTracks(xmlString) //获取声轨列表
  1298. // 设置音源 track 为当前的声轨 index为当前的
  1299. const { track, index, musicalInstrumentId } = state.isSimplePage ? { track:tracks[0], index:0, musicalInstrumentId: '' } : initMusicSource(res.data, tracks, partIndex)
  1300. const realTrack = musicalInstrumentId && res.data?.musicalInstruments?.length ? res.data?.musicalInstruments.find((item: any) => item?.id == musicalInstrumentId)?.code?.split(',')?.[0] : '';
  1301. const musicInfo = {
  1302. ...res.data,
  1303. track: res.data.musicSheetType === 'CONCERT' ? track : realTrack
  1304. };
  1305. console.log("🚀 ~ musicInfo:", musicInfo);
  1306. setState(musicInfo, index);
  1307. };
  1308. //获取xml中的音轨数据
  1309. function xmlToTracks(xmlString: string) {
  1310. const xmlParse = new DOMParser().parseFromString(xmlString, "text/xml");
  1311. const partNames = Array.from(xmlParse.getElementsByTagName('part-name'));
  1312. return partNames.reduce((arr: string[], item) => {
  1313. const textContent = item?.textContent?.trim()
  1314. if (textContent != "COMMON" && textContent != "common" && textContent) {
  1315. arr.push(textContent)
  1316. }
  1317. return arr
  1318. }, []);
  1319. }
  1320. // 设置音源
  1321. function initMusicSource(data: any, tracks: string[], partIndex: number) {
  1322. let track:string,index:number, musicalInstrumentId: string
  1323. const instrumentId = query.instrumentId || storeData.user?.instrumentId
  1324. let { musicSheetType, isAllSubject, musicSheetSoundList, musicSheetAccompanimentList } = data
  1325. musicSheetSoundList || (musicSheetSoundList = [])
  1326. musicSheetAccompanimentList || (musicSheetAccompanimentList = [])
  1327. let musicObj, accompanyObj, fanSongObj, banSongObj
  1328. /* 独奏 */
  1329. if (musicSheetType === "SINGLE") {
  1330. // 适用声部(isAllSubject)为true 时候没有乐器只有一个原音;当前用户有乐器就匹配 不然取第一个原音
  1331. musicObj = musicSheetSoundList.find((item: any) => {
  1332. return (isAllSubject || !instrumentId) ? item.audioPlayType === "PLAY" : (item.audioPlayType === "PLAY" && item.musicalInstrumentId == instrumentId)
  1333. })
  1334. // 因为可能根据学生的乐器id也找不到曲目所以尝试取第一个
  1335. musicObj || (musicObj = musicSheetSoundList.find((item: any) => {
  1336. return item.audioPlayType === "PLAY"
  1337. }))
  1338. fanSongObj = musicSheetSoundList.find((item: any) => {
  1339. return item.audioPlayType === "SING"
  1340. })
  1341. banSongObj = musicSheetAccompanimentList.find((item: any) => {
  1342. return item.audioPlayType === "SING"
  1343. })
  1344. accompanyObj = musicSheetAccompanimentList.find((item: any) => {
  1345. return item.audioPlayType === "PLAY"
  1346. })
  1347. track = musicObj?.track //没有原音的时候track为空 不显示指法
  1348. index = tracks.findIndex(item => {
  1349. return item === track
  1350. })
  1351. musicalInstrumentId = musicObj?.musicalInstrumentId
  1352. } else {
  1353. /* 合奏 */
  1354. // 支持总谱 并且当前是总谱。partIndex是999时候,或者默认是总谱并且partIndex为-1时候 -1就是partIndex没有值
  1355. if(state.isScoreRender && (partIndex===999 || (state.defaultScoreRender && partIndex===-1))){
  1356. // 总谱渲染
  1357. state.isCombineRender = true
  1358. state.partListNames = tracks
  1359. // 总谱演唱模式是 范唱
  1360. fanSongObj = musicSheetAccompanimentList.find((item: any) => {
  1361. return item.audioPlayType === "SING"
  1362. })
  1363. // 先取scoreAudioFileUrl的值
  1364. if(fanSongObj?.scoreAudioFileUrl){
  1365. fanSongObj.audioFileUrl = fanSongObj.scoreAudioFileUrl
  1366. fanSongObj.audioBeatMixUrl = fanSongObj.scoreAudioBeatMixUrl
  1367. }
  1368. // 总谱演奏模式是 伴奏
  1369. accompanyObj = musicSheetAccompanimentList.find((item: any) => {
  1370. return item.audioPlayType === "PLAY"
  1371. })
  1372. // 先取scoreAudioFileUrl的值
  1373. if(accompanyObj?.scoreAudioFileUrl){
  1374. accompanyObj.audioFileUrl = accompanyObj.scoreAudioFileUrl
  1375. accompanyObj.audioBeatMixUrl = accompanyObj.scoreAudioBeatMixUrl
  1376. }
  1377. track = "总谱"
  1378. index = 999
  1379. musicalInstrumentId = ''
  1380. }else{
  1381. // 合奏只显示一个声轨
  1382. track = tracks[partIndex===-1?0:partIndex]
  1383. // 根据当前的声轨 取数据
  1384. musicObj = musicSheetSoundList.find((item: any) => {
  1385. return item.audioPlayType === "PLAY" && item.track === track
  1386. })
  1387. fanSongObj = musicSheetSoundList.find((item: any) => {
  1388. return item.audioPlayType === "SING" && item.track === track
  1389. })
  1390. banSongObj = musicSheetAccompanimentList.find((item: any) => {
  1391. return item.audioPlayType === "SING"
  1392. })
  1393. accompanyObj = musicSheetAccompanimentList.find((item: any) => {
  1394. return item.audioPlayType === "PLAY"
  1395. })
  1396. index = tracks.findIndex(item => {
  1397. return item === track
  1398. })
  1399. musicalInstrumentId = musicObj?.musicalInstrumentId
  1400. }
  1401. }
  1402. // 当没有任何曲目的时候报错
  1403. if (!musicObj?.audioFileUrl && !accompanyObj?.audioFileUrl && !fanSongObj?.audioFileUrl && !banSongObj?.audioFileUrl && !fanSongObj?.solmizationFileUrl && !fanSongObj?.femaleSolmizationFileUrl) {
  1404. state.noMusicSource = true // 没有音源文件
  1405. // 独奏的时候
  1406. if(musicSheetType === "SINGLE"){
  1407. // 并且是midi没有midi文件的时候
  1408. if(data.playMode === "MIDI" && !data.midiFileUrl) {
  1409. // 是预览的时候 不报错
  1410. if(!query.isPreView){
  1411. throw new Error("该曲目无任何音源");
  1412. }
  1413. }
  1414. }
  1415. }
  1416. Object.assign(state, {
  1417. music: musicObj?.audioFileUrl,
  1418. accompany: accompanyObj?.audioFileUrl,
  1419. fanSong: fanSongObj?.audioFileUrl,
  1420. banSong: banSongObj?.audioFileUrl,
  1421. })
  1422. // 如果没有男唱名
  1423. if(!fanSongObj?.solmizationFileUrl){
  1424. state.mingSong = fanSongObj?.femaleSolmizationFileUrl
  1425. }else{
  1426. state.mingSong = fanSongObj?.solmizationFileUrl
  1427. state.mingSongGirl = fanSongObj?.femaleSolmizationFileUrl
  1428. }
  1429. Object.assign(state.beatSong, {
  1430. music: musicObj?.audioBeatMixUrl,
  1431. accompany: accompanyObj?.audioBeatMixUrl,
  1432. fanSong: fanSongObj?.audioBeatMixUrl,
  1433. banSong: banSongObj?.audioBeatMixUrl
  1434. })
  1435. // 如果没有男唱名
  1436. if(!fanSongObj?.solmizationBeatUrl){
  1437. state.beatSong.mingSong = fanSongObj?.femaleSolmizationBeatUrl
  1438. }else{
  1439. state.beatSong.mingSong = fanSongObj?.solmizationBeatUrl
  1440. state.beatSong.mingSongGirl = fanSongObj?.femaleSolmizationBeatUrl
  1441. }
  1442. return {
  1443. index,
  1444. track,
  1445. musicalInstrumentId
  1446. }
  1447. }
  1448. const setState = (data: any, index: number) => {
  1449. // 获取当前模式 声部切换用
  1450. const localStoragePlayType = localStorage.getItem("musicScorePlayType")
  1451. if(localStoragePlayType) {
  1452. localStorage.removeItem("musicScorePlayType")
  1453. state.playType = localStoragePlayType as any
  1454. }
  1455. // 根据当前文件有没有 设置当前的播放模式
  1456. if(state.playType === "play"){
  1457. if(state.music){
  1458. state.playSource = "music"
  1459. }else if(state.accompany){
  1460. state.playSource = "background"
  1461. }else{
  1462. if(state.fanSong){
  1463. state.playType = "sing"
  1464. state.playSource = "music"
  1465. }else if(state.banSong){
  1466. state.playType = "sing"
  1467. state.playSource = "background"
  1468. }else if(state.mingSong){
  1469. state.playType = "sing"
  1470. state.playSource = "mingSong"
  1471. }
  1472. }
  1473. }else{
  1474. if(state.fanSong){
  1475. state.playSource = "music"
  1476. }else if(state.banSong){
  1477. state.playSource = "background"
  1478. }else if(state.mingSong){
  1479. state.playSource = "mingSong"
  1480. }else{
  1481. if(state.music){
  1482. state.playType = "play"
  1483. state.playSource = "music"
  1484. }else if(state.accompany){
  1485. state.playType = "play"
  1486. state.playSource = "background"
  1487. }
  1488. }
  1489. }
  1490. state.appName = "COLEXIU";
  1491. state.detailId = data.bizId;
  1492. state.xmlUrl = data.xmlFileUrl;
  1493. state.paymentType = data.paymentType
  1494. state.partIndex = index >= 0 ? index : 0;
  1495. state.trackId = data.track;
  1496. state.subjectId = data.subjectIds ? data.subjectIds.split(',')?.[0] : 0;
  1497. // 声部code
  1498. const subjectCode = data.subjectCodes ? data.subjectCodes.split(',')?.[0] : '';
  1499. // 乐器code
  1500. // let musicalCode = data.musicalInstrumentIdCodes ? data.musicalInstrumentIdCodes.split(',')?.[0] : '';
  1501. /**
  1502. * 单曲,指法根据用户当前的乐器来显示,如果没有则取musicSheetSoundList第一个track
  1503. */
  1504. const currentInstrumentId = query.instrumentId || storeData.user?.instrumentId;
  1505. let musicalCode = !currentInstrumentId ? data.musicSheetSoundList?.find((item:any)=>{ return item.audioPlayType === "PLAY" })?.track || '' : data.musicSheetSoundList?.find((item: any) => item?.musicalInstrumentId == currentInstrumentId && item.audioPlayType === "PLAY")?.track || '';
  1506. const pitchSubject = musicalInstrumentCodeInfo.find((n) => n.code.toLocaleLowerCase() === subjectCode.toLocaleLowerCase())
  1507. const pitchMusical = musicalInstrumentCodeInfo.find((n) => n.code.toLocaleLowerCase() === musicalCode.toLocaleLowerCase())
  1508. state.subjectCodeId = pitchSubject ? pitchSubject.id : 0
  1509. state.musicalCodeId = pitchMusical ? pitchMusical.id : 0
  1510. state.categoriesId = data.musicCategoryId;
  1511. state.categoriesName = data.musicTagNames;
  1512. // state.enableEvaluation = data.isEvaluated ? true : false;
  1513. state.examSongId = data.bizId + "";
  1514. state.cbsExamSongId = data.id + "";
  1515. state.examSongName = data.name;
  1516. state.coverImg = data.musicCover ?? "";
  1517. // 如果是simple页面,只显示单轨
  1518. if (state.isSimplePage) {
  1519. state.isCombineRender = false;
  1520. }
  1521. setCustom(state.isCombineRender ? data.musicSheetSoundList?.length : 0);
  1522. // 解析扩展字段
  1523. if (data.extConfigJson) {
  1524. try {
  1525. state.extConfigJson = JSON.parse(data.extConfigJson as string);
  1526. } catch (error) {
  1527. console.error("解析扩展字段错误:", error);
  1528. }
  1529. }
  1530. state.gradualTimes = state.extConfigJson.gradualTimes;
  1531. state.repeatedBeats = state.extConfigJson.repeatedBeats || 0;
  1532. state.isEvxml = state.extConfigJson.isEvxml == 1 ? true : false;
  1533. // 是否开启节拍器
  1534. state.needTick = !!data.isPlayBeat
  1535. state.needSingTick = !!data.isPlaySingBeat
  1536. // state.isOpenMetronome = data.isUseSystemBeat ? false : true;
  1537. // 演奏模式是否播mp3节拍器
  1538. state.isOpenMetronome = data.isPlayBeat && !data.isUseSystemBeat ? true : false
  1539. // 演唱模式是否播mp3节拍器
  1540. state.isSingOpenMetronome = data.isPlaySingBeat && !data.isUseSingSystemBeat ? true : false
  1541. state.isShowFingering = data.isShowFingering ? true : false;
  1542. // 设置曲谱的播放模式, APP播放(midi音频是app播放) | h5播放
  1543. state.isAppPlay = data.playMode === 'MIDI';
  1544. state.midiUrl = data.midiFileUrl;
  1545. state.parentCategoriesId = data.musicTag;
  1546. state.musicSheetCategoriesId = data.musicCategoryId;
  1547. state.bizMusicCategoryId = data.bizMusicCategoryId
  1548. state.playMode = data.playMode === "MP3" ? "MP3" : "MIDI";
  1549. state.originSpeed = state.speed = parseFloat(data.playSpeed) || 0;
  1550. // state.originSpeed = state.speed = data.playSpeed;
  1551. // state.playIngSpeed = data.playSpeed;
  1552. const track = data.code || data.track;
  1553. state.track = track ? track.replace(/ /g, "").toLocaleLowerCase() : "";
  1554. // 能否评测,根据当前声轨有无伴奏判断
  1555. if (state.isAppPlay) {
  1556. state.enableEvaluation = state.midiUrl ? true : false
  1557. } else {
  1558. state.enableEvaluation = state.accompany || state.music ? true : false
  1559. }
  1560. state.isConcert = data.musicSheetType === "CONCERT" ? true : false;
  1561. // multiTracksSelection 返回为空,默认代表全部分轨
  1562. state.canSelectTracks = data.multiTracksSelection === "null" || data.multiTracksSelection === "" || data.multiTracksSelection === null ? [] : data.multiTracksSelection?.split(',');
  1563. // 开启预备小节
  1564. state.isOpenPrepare = true;
  1565. state.extStyleConfigJson = data.extStyleConfigJson || {}
  1566. // console.log("🚀 ~ state.subjectId:", state.subjectId, state.track as any , state.subjectId)
  1567. // 是否打击乐
  1568. /**
  1569. * 是否打击乐:AMPLITUDE & 节奏练习:DECIBELS
  1570. * evaluationStandard:("评测标准 节奏 AMPLITUDE 音准 FREQUENCY 分贝 DECIBELS")
  1571. * 打击乐&节奏练习,没有跟练模式
  1572. */
  1573. // state.isPercussion = isRhythmicExercises();
  1574. state.isPercussion = data.evaluationStandard === "AMPLITUDE" || data.evaluationStandard === "DECIBELS";
  1575. state.evaluationStandard = data.evaluationStandard?.toLocaleLowerCase() || ''
  1576. // 设置是否特殊曲谱, 是特殊曲谱取反(不理解之前的思考逻辑), 使用后台设置的速度
  1577. state.isSpecialBookCategory = !classids.includes(Number(data.musicCategoryId));
  1578. // 设置指法
  1579. // const code = state.isConcert ? mappingVoicePart(state.trackId, "ENSEMBLE") : mappingVoicePart(state.subjectId, "INSTRUMENT");
  1580. /**
  1581. * 各平台的乐器声部id不统一,为了兼容处理老的数据,加上乐器code码,此码唯一
  1582. * 获取指法code
  1583. */
  1584. // const code = state.isConcert ? matchVoicePart(state.trackId, "CONCERT") : matchVoicePart(state.musicalCodeId, "SINGLE");
  1585. const code = matchVoicePart(state.trackId, "CONCERT")
  1586. state.fingeringInfo = subjectFingering(code);
  1587. console.log("🚀 ~ state.fingeringInfo:", code, state.fingeringInfo, state.trackId, state.track);
  1588. state.musicalCodeId = state.fingeringInfo?.id || 0
  1589. state.musicalCode = musicalInstrumentCodeInfo.find(item => item.id === state.musicalCodeId)?.code || state.trackId
  1590. ; (window as any).DYSubjectId = state.musicalCodeId
  1591. // 开启自定义每行显示的小节数
  1592. ; (window as any).customSectionAmount = true
  1593. // 标识是课堂乐器,用于移调时进行区分处理
  1594. ; (window as any).DYProjectName = 'musicScore';
  1595. // 如果切换的声轨没有指法,择指法开关置灰并且不可点击
  1596. if (!state.fingeringInfo.name && state.setting.displayFingering) {
  1597. state.setting.displayFingering = false
  1598. }
  1599. // 如果是PC端,放大曲谱
  1600. state.platform = query.platform?.toLocaleUpperCase() || "";
  1601. if (state.platform === IPlatform.PC) {
  1602. state.zoom = query.zoom || 1.5;
  1603. state.enableEvaluation = false;
  1604. }
  1605. /**
  1606. * 默认渲染什么谱面类型 & 能否转谱逻辑
  1607. * 渲染类型:首先取url参数musicRenderType,没有该参数则取musicalInstruments字段匹配的当前分轨的defaultScore,没有匹配到则取默认值('firstTone')
  1608. * 能否转谱:先取isConvertibleScore字段,如果isConvertibleScore为true,则取musicalInstruments字段匹配的当前分轨的transferFlag,都为true则可以转谱
  1609. *
  1610. */
  1611. let pitchTrack = null
  1612. if (state.isConcert) {
  1613. musicalCode = musicalInstrumentCodeInfo.find((item: any) => item.id === state.musicalCodeId)?.code
  1614. pitchTrack = data.musicalInstruments?.find((item: any) => item.code?.split(',')[0] === musicalCode)
  1615. } else {
  1616. pitchTrack = data.musicalInstruments?.find((item: any) => item.code?.split(',')[0] === musicalCode)
  1617. }
  1618. let musicalRenderType = ''
  1619. // if (pitchTrack?.defaultScore) {
  1620. // musicalRenderType = pitchTrack?.defaultScore === 'STAVE' ? 'staff' : pitchTrack?.defaultScore === 'JIAN' ? 'fixedTone' : pitchTrack?.defaultScore === 'FIRST' ? 'firstTone' : ''
  1621. // }
  1622. // state.musicRenderType = query.musicRenderType || musicalRenderType || EnumMusicRenderType.firstTone;
  1623. /**
  1624. * 2024.7.30,使用新的字段
  1625. * 谱面类型,scoreType
  1626. * STAVE("五线谱"),JIAN("固定调"),FIRST("首调"),
  1627. */
  1628. musicalRenderType = data.scoreType === 'STAVE' ? 'staff' : data.scoreType === 'JIAN' ? 'fixedTone' : data.scoreType === 'FIRST' ? '' : 'firstTone';
  1629. if (!state.isEvaluatReport) {
  1630. state.musicRenderType = query.musicRenderType || musicalRenderType || EnumMusicRenderType.firstTone;
  1631. }
  1632. state.musicRenderType = query.musicRenderType || musicalRenderType || EnumMusicRenderType.firstTone;
  1633. /**
  1634. * TODO:摇篮曲特殊处理
  1635. */
  1636. if (['1788501975122489346', '1788502467554750466', '1789839575249596417'].includes(state.cbsExamSongId)) {
  1637. if (state.musicRenderType === 'fixedTone') {
  1638. state.musicRenderType = EnumMusicRenderType.firstTone;
  1639. }
  1640. }
  1641. /**
  1642. * 2024.7.30,使用新的字段
  1643. * 能否转谱,isConvertibleScore
  1644. * true:能转谱,false:不能转谱
  1645. * 额外的逻辑:后台设置不能转谱时,如果默认谱面不是五线谱,需要显示转谱按钮,但是只能转首调和固定调
  1646. */
  1647. // state.enableNotation = pitchTrack ? data.isConvertibleScore && pitchTrack.transferFlag : data.isConvertibleScore
  1648. state.enableNotation = data.isConvertibleScore
  1649. state.specialShowNotation = !data.isConvertibleScore && data.scoreType !== 'STAVE';
  1650. console.log("state对象", state);
  1651. // 评测基准频率
  1652. state.baseFrequency = data.evaluationFrequency ? data.evaluationFrequency.split(",")[0] : 440
  1653. state.baseFrequency = Number(state.baseFrequency)
  1654. // 用户上次的频率和基准频率误差超过10,则重置
  1655. if (Math.abs(state.setting.frequency - state.baseFrequency) > 10) {
  1656. state.setting.frequency = state.baseFrequency >= 0 ? state.baseFrequency : 440
  1657. } else {
  1658. state.setting.frequency = state.setting.frequency || state.baseFrequency
  1659. }
  1660. state.playBtnDirection = query.imagePos === 'left' ? 'left' : 'right';
  1661. state.isAttendClass = (query.imagePos === 'left' || query.imagePos === 'right') ? true : false;
  1662. };
  1663. // 多分轨合并显示标示
  1664. const setCustom = (trackNum?: number) => {
  1665. if (trackNum || state.extConfigJson.multitrack) {
  1666. state.multitrack = trackNum || 0
  1667. setGlobalData("multitrack", trackNum || state.extConfigJson.multitrack);
  1668. }
  1669. };
  1670. /** 跟练模式播放节拍器(叮咚) */
  1671. export const followBeatPaly = () => {
  1672. let metroTimer: any = null;
  1673. if (!followData.start) {
  1674. clearTimeout(metroTimer)
  1675. metroTimer = null
  1676. return;
  1677. }
  1678. const time = state.measureTime * 1000 / metronomeData.totalNumerator / state.basePlayRate;
  1679. requestAnimationFrame(() => {
  1680. const endTime = Date.now();
  1681. if (endTime - state.beatStartTime < time) {
  1682. followBeatPaly();
  1683. } else {
  1684. // metroTimer = setTimeout(() => {
  1685. // metronomeData.metro?.simulatePlayAudio()
  1686. // startTime = Date.now();
  1687. // followBeatPaly();
  1688. // }, time);
  1689. metronomeData.metro?.simulatePlayAudio()
  1690. state.beatStartTime = Date.now();
  1691. followBeatPaly();
  1692. }
  1693. });
  1694. };
  1695. // 音符添加bbox
  1696. export const addNoteBBox = (list: any[]) => {
  1697. const musicContainer = document.getElementById("musicAndSelection")?.getBoundingClientRect() || {
  1698. x: 0,
  1699. y: 0,
  1700. };
  1701. const parentLeft = musicContainer.x || 0;
  1702. let voicesBBox: any = null;
  1703. for (let i = 0; i < list.length; i++) {
  1704. const note = list[i];
  1705. const { svgElement, multipleRestMeasures, totalMultipleRestMeasures, stave } = note;
  1706. /**
  1707. * 兼容合并休止小节没有音符的情况,将合并的小节宽度等分,音符位置就在等分的位置
  1708. */
  1709. let bbox: any = null;
  1710. if (svgElement?.attrs.id) {
  1711. // @ts-ignore
  1712. bbox = document.getElementById(`vf-${svgElement?.attrs?.id}`)?.getBBox();
  1713. const noteBbox = document.getElementById(`vf-${svgElement?.attrs?.id}`)?.getBoundingClientRect?.() || { x: 0, width: 0 };
  1714. bbox = {
  1715. left: noteBbox.x - parentLeft - noteBbox.width / 4, // 用于简谱模式,跳动音符时,设置光标的位置(五线谱:osmd自动设置光标位置,简谱:需要手动设置光标位置)
  1716. x: bbox?.x * state.zoom,
  1717. y: bbox?.y * state.zoom,
  1718. width: bbox?.width * state.zoom,
  1719. height: bbox?.height * state.zoom,
  1720. }
  1721. } else {
  1722. // @ts-ignore
  1723. let currentVoicesBBox: any = document.getElementById(`${stave?.attrs?.id}`)?.nextSibling?.getBBox();
  1724. const svgBodyBBox: any = document.getElementById('musicAndSelection')?.getBoundingClientRect();
  1725. if (!currentVoicesBBox && multipleRestMeasures <= totalMultipleRestMeasures) {
  1726. currentVoicesBBox = voicesBBox;
  1727. }
  1728. let nextIndex = i + 1;
  1729. while (!list[nextIndex]?.id && nextIndex < list.length) {
  1730. nextIndex += 1;
  1731. }
  1732. // 休止小节的开头和下一个音符之间的间距
  1733. let multipleWidth: any = currentVoicesBBox?.width * state.zoom;
  1734. if (list[nextIndex]?.id) {
  1735. // @ts-ignore
  1736. multipleWidth = document.getElementById(`${list[nextIndex]?.stave?.attrs?.id}`)?.getBBox()?.x * state.zoom - currentVoicesBBox?.x * state.zoom;
  1737. }
  1738. const ratioWidth = multipleWidth / totalMultipleRestMeasures || 0;
  1739. bbox = currentVoicesBBox ? {
  1740. bottom: currentVoicesBBox.bottom,
  1741. height: 30,
  1742. left: currentVoicesBBox.x * state.zoom + ratioWidth * (multipleRestMeasures - 1),
  1743. right: currentVoicesBBox.y,
  1744. top: currentVoicesBBox.top,
  1745. width: 1,
  1746. x: currentVoicesBBox.x * state.zoom + ratioWidth * (multipleRestMeasures - 1),
  1747. y: currentVoicesBBox.y,
  1748. svgBodyLeft: svgBodyBBox?.x,
  1749. } : null;
  1750. voicesBBox = currentVoicesBBox;
  1751. }
  1752. note.bbox = bbox;
  1753. }
  1754. }
  1755. // 给歌词和音符添加动态颜色
  1756. let prevActiveNoteIndex = -1 // 上一个激活的
  1757. export const fillWordColor = () => {
  1758. // console.log('当前音符',state.activeNoteIndex,prevActiveNoteIndex)
  1759. if(prevActiveNoteIndex !== -1) {
  1760. const prevActiveNoteId = state.times[prevActiveNoteIndex]?.svgElement?.attrs?.id
  1761. const svgEl = document.getElementById(`vf-${prevActiveNoteId}`)
  1762. const stemEl = document.getElementById(`vf-${prevActiveNoteId}-stem`)
  1763. const stemLine = document.getElementById(`vf-${prevActiveNoteId}-lines`)
  1764. svgEl?.classList.remove('noteActive')
  1765. stemEl?.classList.remove('noteActive')
  1766. stemLine?.classList.remove('noteActive')
  1767. }
  1768. const activeNoteId = state.times[state.activeNoteIndex]?.svgElement?.attrs?.id
  1769. const svgEl = document.getElementById(`vf-${activeNoteId}`)
  1770. const stemEl = document.getElementById(`vf-${activeNoteId}-stem`)
  1771. const stemLine = document.getElementById(`vf-${activeNoteId}-lines`)
  1772. svgEl?.classList.add('noteActive')
  1773. stemEl?.classList.add('noteActive')
  1774. stemLine?.classList.add('noteActive')
  1775. prevActiveNoteIndex = state.activeNoteIndex
  1776. // 给当前匹配到的歌词添加颜色
  1777. const currentNote = state.times[state.activeNoteIndex];
  1778. const lyrics: SVGAElement[] = Array.from(document.querySelectorAll(".vf-lyric"));
  1779. lyrics.forEach((lyric) => {
  1780. lyric?.classList.remove('lyricActive')
  1781. })
  1782. const currentLyrics: SVGAElement[] = Array.from(document.querySelectorAll(`.lyric${currentNote?.noteId}`));
  1783. currentLyrics.forEach((lyric, index) => {
  1784. const lyricIndex = lyric.getAttribute('lyricIndex');
  1785. // bug:#10942,如果需要反复唱的小节,只有一遍歌词,反复唱的时候,歌词都需要高亮
  1786. const onlyOneLyric = currentNote.measures?.every((item: any) => item?.formatLyricsEntries?.length <= 1);
  1787. if ((index === currentNote.repeatIdx && currentNote.repeatIdx + 1 == lyricIndex) || (currentNote.repeatIdx != index && !onlyOneLyric && currentNote.repeatIdx + 1 == lyricIndex) || (currentNote.repeatIdx > 0 && currentNote.formatLyricsEntries?.length === 1 && onlyOneLyric)) {
  1788. lyric?.classList.add('lyricActive')
  1789. }
  1790. // if ((index === currentNote.repeatIdx && currentNote.repeatIdx + 1 == lyricIndex)) {
  1791. // lyric?.classList.add('lyricActive')
  1792. // }
  1793. })
  1794. }
  1795. /** 跳动svgdom */
  1796. export const moveSvgDom = (skipNote?: boolean) => {
  1797. /**
  1798. * 计算需要移动的距离
  1799. * 当前选中的音符和第一个音符之间的间距
  1800. */
  1801. if (skipNote) {
  1802. // 点击 清空translateXNum
  1803. smoothAnimationState.translateXNum = 0
  1804. moveTranslateXNum(0)
  1805. // 移动小鸟的位置
  1806. moveSmoothAnimation(0, state.activeNoteIndex, false)
  1807. // 移动谱面当当前音符的位置
  1808. const noteWidth = state.times[state.activeNoteIndex].bbox?.originWidth || state.times[state.activeNoteIndex].bbox?.width;
  1809. const firstNoteWidth = state.times[0].bbox?.originWidth || state.times[0].bbox?.width;
  1810. const distance = state.times[state.activeNoteIndex].bbox?.x - state.times[0].bbox?.x + noteWidth / 2 - firstNoteWidth / 2;
  1811. smoothAnimationState.osdmScrollDom!.scrollTo({
  1812. left: distance,
  1813. behavior: "smooth",
  1814. });
  1815. }
  1816. }
  1817. // 暂停的时候 恢复一行谱偏移位置信息
  1818. watch(
  1819. () => state.playState,
  1820. () => {
  1821. if (state.isSingleLine) {
  1822. // 当在播放中暂停 执行这个方法
  1823. if (!state.playEnd && state.playState === "paused") {
  1824. moveTranslateXNum(0)
  1825. // 因为safari浏览器scrollWidth的值一直变化,scrollLeft + smoothAnimationState.translateXNum 为最大宽度的时候,实际上scrollLeft滚不到最大宽度,所以在下一帧处理滚动,能滚动到最大滚动位置
  1826. requestAnimationFrame(() => {
  1827. const scrollLeft = smoothAnimationState.osdmScrollDom!.scrollLeft
  1828. smoothAnimationState.osdmScrollDom!.scrollLeft = scrollLeft + smoothAnimationState.translateXNum
  1829. smoothAnimationState.translateXNum = 0
  1830. });
  1831. }
  1832. }
  1833. }
  1834. )
  1835. /* 根据当前的小节获取前面有多少需要去除的合并小节 */
  1836. function getNeedReduceMultipleRestNum(currMeasureIndex: number) {
  1837. let needReduceMultipleRestNum = 0;
  1838. for (let noteIndex = 0; noteIndex < state.times.length; noteIndex++) {
  1839. const note = state.times[noteIndex];
  1840. if (note.MeasureNumberXML > currMeasureIndex) {
  1841. break;
  1842. }
  1843. if (note.multipleRestMeasures && note.multipleRestMeasures > 1) {
  1844. needReduceMultipleRestNum += 1;
  1845. }
  1846. }
  1847. return needReduceMultipleRestNum
  1848. }
  1849. watch(
  1850. () => state.activeMeasureIndex,
  1851. () => {
  1852. // 需要减去的合并小节数
  1853. // const needReduceMultipleRestNum = getNeedReduceMultipleRestNum(state.activeMeasureIndex)
  1854. // const matchMeasureNum = state.activeMeasureIndex - needReduceMultipleRestNum - 1
  1855. // console.log('选中的小节',matchMeasureNum,'需要减去的小节',needReduceMultipleRestNum,'当前的小节',state.activeMeasureIndex)
  1856. state.vfmeasures.forEach((item: any, idx: number) => {
  1857. const dataNum = item.getAttribute('data-num') // 值可能为字符串类型的undefined
  1858. let measureNum = (dataNum && dataNum !== "undefined") ? Number(dataNum) : -1;
  1859. let nextDataNum = state.vfmeasures[idx+1]?.getAttribute('data-num')
  1860. // 当有换行小节,下个小节的nextDataNum是undefined,所以这里需要往后找一个
  1861. if(!(nextDataNum && nextDataNum !== "undefined")){
  1862. nextDataNum = state.vfmeasures[idx + 2]?.getAttribute('data-num')
  1863. }
  1864. const nextMeasureNum = Number(nextDataNum)
  1865. // 当measureNum 为undefined 则是下一个小节的换行小节,所以这里等于下一个小节
  1866. if(measureNum === -1) {
  1867. measureNum = nextMeasureNum
  1868. }
  1869. if (measureNum >= 0 && (measureNum === state.activeMeasureIndex || (measureNum < state.activeMeasureIndex && nextMeasureNum > state.activeMeasureIndex))) {
  1870. item.querySelector('.vf-custom-bg')?.setAttribute("fill", "#132D4C")
  1871. item.querySelector('.vf-custom-bot')?.setAttribute("fill", "#040D1E")
  1872. // 预备小节
  1873. if(state.sectionFirst && measureNum === state.sectionFirst.MeasureNumberXML && state.section.length === 2){
  1874. item?.querySelector('.vf-custom-bg')?.setAttribute("fill", "#71B8BD")
  1875. item?.querySelector('.vf-custom-bot')?.setAttribute("fill", "#448F9C")
  1876. }
  1877. } else {
  1878. // 有选段只清除选段处的
  1879. if (state.section.length === 2) {
  1880. // 把中间置灰
  1881. let leftMeasureNumberXML = state.section[0].MeasureNumberXML
  1882. let rightMeasureNumberXML = state.section[1].MeasureNumberXML
  1883. if (leftMeasureNumberXML > rightMeasureNumberXML) {
  1884. leftMeasureNumberXML = state.section[1].MeasureNumberXML
  1885. rightMeasureNumberXML = state.section[0].MeasureNumberXML
  1886. }
  1887. if(measureNum >= leftMeasureNumberXML && measureNum <= rightMeasureNumberXML){
  1888. item.querySelector('.vf-custom-bg')?.setAttribute("fill", "#609FCF")
  1889. item.querySelector('.vf-custom-bot')?.setAttribute("fill", "#2B70A5")
  1890. }
  1891. // 预备小节
  1892. if(state.sectionFirst && measureNum === state.sectionFirst.MeasureNumberXML){
  1893. item?.querySelector('.vf-custom-bg')?.setAttribute("fill", "#71B8BD")
  1894. item?.querySelector('.vf-custom-bot')?.setAttribute("fill", "#448F9C")
  1895. }
  1896. } else {
  1897. item.querySelector('.vf-custom-bg')?.setAttribute("fill", "#609FCF")
  1898. item.querySelector('.vf-custom-bot')?.setAttribute("fill", "#2B70A5")
  1899. }
  1900. }
  1901. })
  1902. }
  1903. );
  1904. watch(
  1905. () => state.section,
  1906. () => {
  1907. if (state.section.length === 2) {
  1908. // 把前面和 后面置灰
  1909. let leftMeasureNumberXML = state.section[0].MeasureNumberXML
  1910. let rightMeasureNumberXML = state.section[1].MeasureNumberXML
  1911. if (leftMeasureNumberXML > rightMeasureNumberXML) {
  1912. leftMeasureNumberXML = state.section[1].MeasureNumberXML
  1913. rightMeasureNumberXML = state.section[0].MeasureNumberXML
  1914. }
  1915. state.vfmeasures.forEach((item: any, idx: number) => {
  1916. const dataNum = item.getAttribute('data-num') // 值可能为字符串类型的undefined
  1917. let measureNum = (dataNum && dataNum !== "undefined") ? Number(dataNum) : -1;
  1918. let nextDataNum = state.vfmeasures[idx+1]?.getAttribute('data-num')
  1919. // 当有换行小节,下个小节的nextDataNum是undefined,所以这里需要往后找一个
  1920. if(!(nextDataNum && nextDataNum !== "undefined")){
  1921. nextDataNum = state.vfmeasures[idx + 2]?.getAttribute('data-num')
  1922. }
  1923. const nextMeasureNum = Number(nextDataNum)
  1924. // 当measureNum 为undefined 则是下一个小节的换行小节,所以这里等于下一个小节
  1925. if(measureNum === -1) {
  1926. measureNum = nextMeasureNum
  1927. }
  1928. // 小于选中置灰
  1929. if (measureNum < leftMeasureNumberXML) {
  1930. item.querySelector('.vf-custom-bg')?.setAttribute("fill", "rgba(96,159,207,0.5)")
  1931. item.querySelector('.vf-custom-bot')?.setAttribute("fill", "rgba(43,112,165,0.5)")
  1932. }
  1933. // 大于选中置灰
  1934. if(measureNum > rightMeasureNumberXML){
  1935. item.querySelector('.vf-custom-bg')?.setAttribute("fill", "rgba(96,159,207,0.5)")
  1936. item.querySelector('.vf-custom-bot')?.setAttribute("fill", "rgba(43,112,165,0.5)")
  1937. }
  1938. // 预备小节
  1939. if(state.sectionFirst && measureNum === state.sectionFirst.MeasureNumberXML){
  1940. item?.querySelector('.vf-custom-bg')?.setAttribute("fill", "#71B8BD")
  1941. item?.querySelector('.vf-custom-bot')?.setAttribute("fill", "#448F9C")
  1942. }
  1943. })
  1944. }else{
  1945. // 恢复选段前
  1946. state.vfmeasures.forEach((item: any, idx: number) => {
  1947. const dataNum = item.getAttribute('data-num') // 值可能为字符串类型的undefined
  1948. let measureNum = (dataNum && dataNum !== "undefined") ? Number(dataNum) : -1;
  1949. let nextDataNum = state.vfmeasures[idx+1]?.getAttribute('data-num')
  1950. // 当有换行小节,下个小节的nextDataNum是undefined,所以这里需要往后找一个
  1951. if(!(nextDataNum && nextDataNum !== "undefined")){
  1952. nextDataNum = state.vfmeasures[idx + 2]?.getAttribute('data-num')
  1953. }
  1954. const nextMeasureNum = Number(nextDataNum)
  1955. // 当measureNum 为undefined 则是下一个小节的换行小节,所以这里等于下一个小节
  1956. if(measureNum === -1) {
  1957. measureNum = nextMeasureNum
  1958. }
  1959. if (measureNum >= 0 && (measureNum === state.activeMeasureIndex || (measureNum < state.activeMeasureIndex && nextMeasureNum > state.activeMeasureIndex)) ) {
  1960. item.querySelector('.vf-custom-bg')?.setAttribute("fill", "#132D4C")
  1961. item.querySelector('.vf-custom-bot')?.setAttribute("fill", "#040D1E")
  1962. } else {
  1963. item.querySelector('.vf-custom-bg')?.setAttribute("fill", "#609FCF")
  1964. item.querySelector('.vf-custom-bot')?.setAttribute("fill", "#2B70A5")
  1965. }
  1966. })
  1967. }
  1968. }
  1969. )
  1970. /** 刷新谱面 */
  1971. export const refreshMusicSvg = () => {
  1972. clearSelection();
  1973. resetBaseRate();
  1974. state.activeMeasureIndex = -1;
  1975. if (query.workRecord) {
  1976. state.workSectionNeedReset = true;
  1977. }
  1978. // 销毁旋律线
  1979. destroySmoothAnimation()
  1980. musicScoreRef.value?.refreshMusicScore()
  1981. }
  1982. // 指法改变显示的时候 osdmScrollDomWith 宽度会变化 所以指法改变的时候这个宽度重新计算
  1983. watch(
  1984. () => state.setting.displayFingering,
  1985. () => {
  1986. // 有字符 并且是竖向指法 并且是一行谱
  1987. if(state.fingeringInfo?.name && state.fingeringInfo.direction === "vertical" && state.isSingleLine){
  1988. nextTick(() => {
  1989. calcClientWidth()
  1990. })
  1991. }
  1992. // 如果有指法,并且是竖向指法时,切换指法时,谱面宽度变化,需要重新渲染谱面
  1993. if (state.fingeringInfo?.name && state.fingeringInfo.direction === "vertical" && !state.isSingleLine) {
  1994. headTopData.settingMode = false;
  1995. refreshMusicSvg();
  1996. }
  1997. }
  1998. )