Browse Source

feat: 使用声部code

TIANYONG 1 year ago
parent
commit
196df4266e
3 changed files with 197 additions and 3 deletions
  1. 92 3
      src/state.ts
  2. 1 0
      src/utils/request.ts
  3. 104 0
      src/view/fingering/fingering-config.ts

+ 92 - 3
src/state.ts

@@ -4,7 +4,7 @@ import { OpenSheetMusicDisplay } from "../osmd-extended/src";
 import { metronomeData } from "./helpers/metronome";
 import { GradualNote, GradualTimes, GradualVersion } from "./type";
 import { handleEndEvaluat, handleStartEvaluat } from "./view/evaluating";
-import { IFingering, mappingVoicePart, subjectFingering } from "/src/view/fingering/fingering-config";
+import { IFingering, mappingVoicePart, subjectFingering, matchVoicePart } from "/src/view/fingering/fingering-config";
 import { handleStartTick } from "./view/tick";
 import { audioListStart, getAudioCurrentTime, getAudioDuration, setAudioCurrentTime, setAudioPlaybackRate } from "./view/audio-list";
 import { toggleFollow } from "./view/follow-practice";
@@ -44,6 +44,85 @@ 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 = [
+  {
+    name: '排箫',
+    code: 'Panpipes',
+    id: 1
+  },
+  {
+    name: '陶笛',
+    code: 'Ocarina',
+    id: 2
+  },
+  {
+    name: '葫芦丝',
+    code: 'Woodwind',
+    id: 3
+  },
+  {
+    name: '德式竖笛',
+    code: 'Tenor Recorder',
+    id: 4
+  },
+  {
+    name: '口风琴',
+    code: 'Nai',
+    id: 5
+  },
+  {
+    name: '英式竖笛',
+    code: 'BaroqueRecorder',
+    id: 6
+  },
+  {
+    name: '打击乐',
+    code: 'PERCUSSION',
+    id: 7
+  },
+  {
+    name: '长笛',
+    code: 'FLUTE',
+    id: 8
+  },
+  {
+    name: '萨克斯',
+    code: 'SAX',
+    id: 9
+  },
+  {
+    name: '单簧管',
+    code: 'CLARINET',
+    id: 10
+  },
+  {
+    name: '小号',
+    code: 'TRUMPET',
+    id: 11
+  },
+  {
+    name: '长号',
+    code: 'TROMBONE',
+    id: 12
+  },
+  {
+    name: '圆号',
+    code: 'HORN',
+    id: 13
+  },
+  {
+    name: '上低音号',
+    code: 'BARITONE',
+    id: 14
+  },
+  {
+    name: '大号',
+    code: 'TUBA',
+    id: 15
+  }
+]
+
 const state = reactive({
   /** 来源 : PC , app */
   platform: "" as IPlatform,
@@ -197,6 +276,8 @@ const state = reactive({
   repeatInfo: [],  
   /** 多分轨的曲子,可支持筛选的分轨 */
   canSelectTracks: "",
+  /** 声部codeId,用于匹配乐器指法、声部转调、特殊声部处理等 */
+  subjectCodeId: 0 as number,
 });
 const browserInfo = browser();
 let offset_duration = 0;
@@ -684,7 +765,10 @@ const setState = (data: any, index: number) => {
   state.xmlUrl = data.xmlFileUrl;
   state.partIndex = index;
   state.trackId = data.track;
-  state.subjectId = data.subjectIds;
+  state.subjectId = data.subjectIds ? data.subjectIds.split(',')?.[0] : 0;
+  const subjectCode = data.subjectCodes ? data.subjectCodes.split(',')?.[0] : 0;
+  const pitchSubject = musicalInstrumentCodeInfo.find((n) => n.code === subjectCode)
+  state.subjectCodeId = pitchSubject ? pitchSubject.id : 0
   state.categoriesId = data.musicCategoryId;
   state.categoriesName = data.musicTagNames;
   state.enableEvaluation = data.isEvaluated ? true : false;
@@ -729,7 +813,12 @@ const setState = (data: any, index: number) => {
   state.isSpecialBookCategory = !classids.includes(data.musicCategoryId);
 
   // 设置指法
-  const code = state.isConcert ? mappingVoicePart(state.trackId, "ENSEMBLE") : mappingVoicePart(state.subjectId, "INSTRUMENT");
+  // const code = state.isConcert ? mappingVoicePart(state.trackId, "ENSEMBLE") : mappingVoicePart(state.subjectId, "INSTRUMENT");
+  /**
+   * 各平台的乐器声部id不统一,为了兼容处理老的数据,加上乐器code码,此码唯一
+   * 获取指法code
+   */
+  const code = state.isConcert ? matchVoicePart(state.trackId, "CONCERT") : matchVoicePart(state.subjectCodeId, "SINGLE");
   state.fingeringInfo = subjectFingering(code);
   console.log("🚀 ~ state.fingeringInfo:", code, state.fingeringInfo, state.trackId, state.track);
 

+ 1 - 0
src/utils/request.ts

@@ -30,6 +30,7 @@ request.interceptors.request.use(
 		if (Authorization && !options.isContentCenter) {
 			authHeaders.Authorization = Authorization;
 		}
+		
 		return {
 			url: _prefix + url,
 			options: {

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

@@ -226,6 +226,110 @@ export const mappingVoicePart = (id: number | string, soruce: "GYM" | "COLEXIU"
   return 0;
 };
 
+/** 映射声部指法,单曲根据声部codeId,合奏曲根据分轨track  */
+export const matchVoicePart = (id: number | string, type: "SINGLE" | "CONCERT"): number => {
+  if (type === "SINGLE") {
+    const subject: { [_key: string | number]: any } = {
+      1: "pan-flute",
+      2: "ocarina",
+      3: "hulusi-flute",
+      4: "piccolo",
+      5: "melodica",
+      6: "baroque-recorder",
+      7: "",
+      8: 2,
+      9: 5,
+      10: 4,
+      11: 12,
+      12: 14,
+      13: 13,
+      14: 15,
+      15: 17,
+    };
+    return subject[id];
+  } else {
+    let code = id;
+    const subject: { [_key: string | number]: any } = {
+      Piccolo: "piccolo",
+      Flute: 2,
+      "Flute 1": 2,
+      "Flute 2": 2,
+      Oboe: 1,
+      "Clarinet in Bb 1": 4,
+      "Clarinet in Bb 2": 4,
+      "Alto Clarinet in Eb": 4,
+      "Bass Clarinet in Bb": 4,
+      Bassoon: 1,
+      "Alto Saxophone": 5,
+      "Tenor Saxophone": 5,
+      "Baritone Saxophone": 5,
+      "Trumpet in Bb 1": 12,
+      "Trumpet in Bb 2": 12,
+      "Horn in F": 13,
+      "Horn in F 1": 13,
+      "Horn in F 2": 13,
+      "Trombone 1": 14,
+      "Trombone 2": 14,
+      "Trombone 3": 14,
+      Euphonium: 15,
+      Tuba: 17,
+      Chimes: 1,
+      Bells: 1,
+      Xylophone: 1,
+      "Snare Drum": 1,
+      "Bass Drum": 1,
+      Triangle: 1,
+      "Suspended Cymbal": 1,
+      "Crash Cymbals": 1,
+      "Concert Toms": 1,
+      Timpani: 1,
+      flute: 2,
+      oboe: 4,
+      clarinet: 4,
+      trombone: 14,
+      tuba: 17,
+      trumpet: 12,
+      horn: 13,
+      altosaxophone: 6,
+      tenorsaxophone: 6,
+      saxophone: 6,
+      upbasshorn: 15,
+      melodica: 137,
+      hulusiFlute: 136,
+      panflute: 135,
+      recorder: 120,
+      ukulele: 130,
+      mouthorgan: 140,
+      piano: 150,
+      4: "piccolo",
+      3: "hulusi-flute",
+      1: "pan-flute",
+      2: "ocarina",
+      5: "melodica",
+      26: 12,
+      tenorrecorder: "piccolo",
+      woodwind: "hulusi-flute",
+      panpipes: "pan-flute",
+      ocarina: "ocarina",
+      nai: "melodica",
+	    BaroqueRecorder: 'baroque-recorder',
+    };
+    let _track;
+    if (typeof code === "string") {
+      for (let sKey in subject) {
+        if (sKey === code) {
+          _track = subject[sKey];
+          break;
+        }
+      }
+    } else {
+      _track = subject.code;
+    }
+    return _track;
+  }
+  return 0;
+}
+
 /** 声部的指法配置信息 */
 export const subjectFingering = (subjectId: number | string): IFingering => {
   switch (subjectId) {