Quellcode durchsuchen

feat: 曲谱默认渲染类型&能否转谱逻辑

TIANYONG vor 1 Jahr
Ursprung
Commit
ccee7f255d

+ 1 - 1
src/page-instrument/evaluat-model/index.tsx

@@ -240,7 +240,7 @@ export default defineComponent({
         heardLevel: state.setting.evaluationDifficulty,
         // beatLength: Math.round((state.fixtime * 1000) / rate),
         beatLength: actualBeatLength,
-        evaluationCriteria: getEvaluationCriteria(),
+        evaluationCriteria: state.evaluationStandard,
       };
       await connectWebsocket(content);
       // state.playSource = "music";

+ 1 - 1
src/page-instrument/header-top/music-type/index.tsx

@@ -29,7 +29,7 @@ export default defineComponent({
 		const handleResult = (type: any) => {
 			if (type){
 				state.musicRenderType = musicTypeData.type
-				sessionStorage.setItem(musicRenderTypeKey, musicTypeData.type)
+				// sessionStorage.setItem(musicRenderTypeKey, musicTypeData.type)
 				resetRenderMusicScore()
 			} else {
 				headData.musicTypeShow = false;

+ 34 - 7
src/state.ts

@@ -46,7 +46,7 @@ export enum IPlatform {
 const classids = [1, 2, 6, 7, 8, 9, 3, 10, 11, 12, 13, 4, 14, 15, 16, 17, 30, 31, 35, 36, 46, 108]; // 大雅金唐, 竖笛教程, 声部训练展开的分类ID
 
 // 乐器code码
-const musicalInstrumentCodeInfo = [
+export const musicalInstrumentCodeInfo = [
   {
     name: '排箫',
     code: 'Panpipes',
@@ -253,6 +253,8 @@ const state = reactive({
   scrollContainer: "musicAndSelection",
   /** 是否是打击乐 */
   isPercussion: false,
+  /** 评测标准 */
+  evaluationStandard: '',
   /** 是否重复节拍器的时间 */
   repeatedBeats: 0,
   /**当前曲谱中所有声部名字 */
@@ -283,8 +285,10 @@ const state = reactive({
   repeatInfo: [],  
   /** 多分轨的曲子,可支持筛选的分轨 */
   canSelectTracks: [] as any,
-  /** 声部codeId,用于匹配乐器指法、声部转调、特殊声部处理等 */
+  /** 声部codeId */
   subjectCodeId: 0 as number,
+  /** 乐器codeId,用于匹配乐器指法、声部转调、特殊声部处理等 */
+  musicalCodeId: 0 as number,
   /** 合奏曲目是否合并展示 */
   isCombineRender: false,
   /** 小节的持续时长,以后台设置的播放速度计算 */
@@ -793,9 +797,14 @@ const setState = (data: any, index: number) => {
   state.partIndex = index;
   state.trackId = data.track;
   state.subjectId = data.subjectIds ? data.subjectIds.split(',')?.[0] : 0;
+  // 声部code
   const subjectCode = data.subjectCodes ? data.subjectCodes.split(',')?.[0] : 0;
+  // 乐器code
+  let musicalCode = data.musicalInstrumentIdCodes ? data.musicalInstrumentIdCodes.split(',')?.[0] : 0;
   const pitchSubject = musicalInstrumentCodeInfo.find((n) => n.code === subjectCode)
+  const pitchMusical = musicalInstrumentCodeInfo.find((n) => n.code === musicalCode)
   state.subjectCodeId = pitchSubject ? pitchSubject.id : 0
+  state.musicalCodeId = pitchMusical ? pitchMusical.id : 0
   state.categoriesId = data.musicCategoryId;
   state.categoriesName = data.musicTagNames;
   // state.enableEvaluation = data.isEvaluated ? true : false;
@@ -813,7 +822,7 @@ const setState = (data: any, index: number) => {
     }
   }
   // 曲子包含节拍器,就不开启节拍器
-  state.needTick = data.isUseSystemBeat ? true : false;
+  state.needTick = data.isUseSystemBeat && data.isPlayBeat ? true : false;
   state.isOpenMetronome = data.isUseSystemBeat ? false : true;
   state.isShowFingering = data.isShowFingering ? true : false;
   state.music = data.music;
@@ -827,7 +836,6 @@ const setState = (data: any, index: number) => {
   state.track = track ? track.replace(/ /g, "").toLocaleLowerCase() : "";
   // 能否评测,根据当前声轨有无伴奏判断
   state.enableEvaluation = state.accompany ? true : false
-  state.enableNotation = data.isConvertibleScore === null ? true : data.isConvertibleScore;
   state.isConcert = data.musicSheetType === "CONCERT" ? true : false;
   // multiTracksSelection 返回为空,默认代表全部分轨
   state.canSelectTracks = data.multiTracksSelection === "null" || data.multiTracksSelection === "" || data.multiTracksSelection === null ? [] : data.multiTracksSelection?.split(',');
@@ -843,6 +851,7 @@ const setState = (data: any, index: number) => {
    */
   // state.isPercussion = isRhythmicExercises();
   state.isPercussion = data.evaluationStandard === "AMPLITUDE" || data.evaluationStandard === "DECIBELS";
+  state.evaluationStandard = data.evaluationStandard?.toLocaleLowerCase() || ''
   // 设置是否特殊曲谱, 是特殊曲谱取反(不理解之前的思考逻辑), 使用后台设置的速度
   // state.isSpecialBookCategory = !classids.includes(data.musicCategoryId);
 
@@ -852,10 +861,11 @@ const setState = (data: any, index: number) => {
    * 各平台的乐器声部id不统一,为了兼容处理老的数据,加上乐器code码,此码唯一
    * 获取指法code
    */
-  const code = state.isConcert ? matchVoicePart(state.trackId, "CONCERT") : matchVoicePart(state.subjectCodeId, "SINGLE");
+  const code = state.isConcert ? matchVoicePart(state.trackId, "CONCERT") : matchVoicePart(state.musicalCodeId, "SINGLE");
   state.fingeringInfo = subjectFingering(code);
   console.log("🚀 ~ state.fingeringInfo:", code, state.fingeringInfo, state.trackId, state.track);
 
+  state.musicalCodeId = state.fingeringInfo?.id || 0
   // 如果切换的声轨没有指法,择指法开关置灰并且不可点击
   if (!state.fingeringInfo.name && state.setting.displayFingering) {
     state.setting.displayFingering = false
@@ -872,8 +882,25 @@ const setState = (data: any, index: number) => {
     state.zoom = query.zoom || 1.5;
   }
 
-  //课堂乐器, 渲染类型: 五线谱, 简谱
-  state.musicRenderType = query.musicRenderType || EnumMusicRenderType.firstTone;
+  /**
+   * 默认渲染什么谱面类型 & 能否转谱逻辑
+   * 渲染类型:首先取url参数musicRenderType,没有该参数则取musicalInstruments字段匹配的当前分轨的defaultScore,没有匹配到则取默认值('firstTone')
+   * 能否转谱:先取isConvertibleScore字段,如果isConvertibleScore为true,则取musicalInstruments字段匹配的当前分轨的transferFlag,都为true则可以转谱
+   * 
+   */
+  let pitchTrack = null
+  if (state.isConcert) {
+    musicalCode = musicalInstrumentCodeInfo.find((item: any) => item.id === state.musicalCodeId)?.code
+    pitchTrack = data.musicalInstruments?.find((item: any) => item.code === musicalCode)
+  } else {
+    pitchTrack = data.musicalInstruments?.find((item: any) => item.code === musicalCode)
+  }
+  let musicalRenderType = ''
+  if (pitchTrack?.defaultScore) {
+    musicalRenderType = pitchTrack?.defaultScore === 'STAVE' ? 'staff' : pitchTrack?.defaultScore === 'JIAN' ? 'firstTone' : pitchTrack?.defaultScore === 'FIRST' ? 'fixedTone' : ''
+  }
+  state.musicRenderType = query.musicRenderType || musicalRenderType || EnumMusicRenderType.firstTone;
+  state.enableNotation = pitchTrack ? data.isConvertibleScore && pitchTrack.transferFlag : data.isConvertibleScore
   console.log("state对象", state);
   // 评测基准频率
   state.baseFrequency = data.evaluationFrequency ? data.evaluationFrequency.split(",")[0] : 440

+ 17 - 0
src/view/fingering/fingering-config.ts

@@ -21,6 +21,8 @@ export type IFingering = {
   code?: string;
   /** 是否有替指 */
   hasTizhi?: boolean;
+  /** 乐器code匹配的id */
+  id?: number;
 };
 
 type ITypeContent = {
@@ -340,6 +342,7 @@ export const subjectFingering = (subjectId: number | string): IFingering => {
         direction: "transverse",
         height: "1.6rem",
         hasTizhi: true,
+        id: 8,
       };
     case 4: // 单簧管
       return {
@@ -347,6 +350,7 @@ export const subjectFingering = (subjectId: number | string): IFingering => {
         direction: "vertical",
         width: "3rem",
         hasTizhi: true,
+        id: 10,
       };
     case 5: // 萨克斯
     case 6: // 中音萨克斯
@@ -355,6 +359,7 @@ export const subjectFingering = (subjectId: number | string): IFingering => {
         direction: "vertical",
         width: "4.34rem",
         hasTizhi: true,
+        id: 9,
       };
     case 12: // 小号
       return {
@@ -362,6 +367,7 @@ export const subjectFingering = (subjectId: number | string): IFingering => {
         direction: "transverse",
         height: "1.6rem",
         hasTizhi: false,
+        id: 11,
       };
     case 13: // 圆号
       return {
@@ -369,6 +375,7 @@ export const subjectFingering = (subjectId: number | string): IFingering => {
         direction: "vertical",
         width: "4.98rem",
         hasTizhi: false,
+        id: 13,
       };
     case 14: // 长号
       return {
@@ -376,6 +383,7 @@ export const subjectFingering = (subjectId: number | string): IFingering => {
         direction: "transverse",
         height: "1.6rem",
         hasTizhi: false,
+        id: 12,
       };
     case 15: // 上低音号
       return {
@@ -383,6 +391,7 @@ export const subjectFingering = (subjectId: number | string): IFingering => {
         direction: "vertical",
         width: "4.34rem",
         hasTizhi: false,
+        id: 14,
       };
     case 17: // 大号
       return {
@@ -390,6 +399,7 @@ export const subjectFingering = (subjectId: number | string): IFingering => {
         direction: "vertical",
         width: "4.34rem",
         hasTizhi: false,
+        id: 15,
       };
     case 120: // 短笛
       return {
@@ -398,6 +408,7 @@ export const subjectFingering = (subjectId: number | string): IFingering => {
         width: "3rem",
         orientation: 1,
         hasTizhi: true,
+        id: 4,
       };
     case "piccolo": // 德式竖笛
       return {
@@ -407,6 +418,7 @@ export const subjectFingering = (subjectId: number | string): IFingering => {
         orientation: 1,
         code: "竖笛",
         hasTizhi: true,
+        id: 4,
       };
     case "hulusi-flute": // 葫芦丝
       return {
@@ -416,6 +428,7 @@ export const subjectFingering = (subjectId: number | string): IFingering => {
         orientation: 1,
         code: "葫芦丝",
         hasTizhi: false,
+        id: 3,
       };
     case "pan-flute": // 排箫
       return {
@@ -426,6 +439,7 @@ export const subjectFingering = (subjectId: number | string): IFingering => {
         orientation: 0,
         code: "排箫",
         hasTizhi: false,
+        id: 1,
       };
     case "ocarina": // 陶笛
       return {
@@ -436,6 +450,7 @@ export const subjectFingering = (subjectId: number | string): IFingering => {
         orientation: 0,
         code: "陶笛",
         hasTizhi: false,
+        id: 2,
       };
     case "melodica": // 口风琴
       return {
@@ -445,6 +460,7 @@ export const subjectFingering = (subjectId: number | string): IFingering => {
         orientation: 0,
         code: "口风琴",
         hasTizhi: false,
+        id: 5,
       };
 	case "baroque-recorder": // 英式竖笛
 	  return {
@@ -454,6 +470,7 @@ export const subjectFingering = (subjectId: number | string): IFingering => {
 		orientation: 1,
 		code: "竖笛",
 		hasTizhi: true,
+    id: 6,
 	  };	  
     default:
       return {};