Pārlūkot izejas kodu

feat: 阶段练习

TIANYONG 1 gadu atpakaļ
vecāks
revīzija
a5add4dd65

+ 35 - 5
src/page-instrument/custom-plugins/work-ealuating/index.tsx

@@ -2,7 +2,7 @@ import { defineComponent, onMounted, reactive, watch } from "vue";
 import { useRoute } from "vue-router";
 // import { verifyMembershipServices } from "../vip-verify";
 import { api_lessonTrainingSubmitTraining } from "../../api";
-import state, { IDifficulty, handleSetSpeed } from "/src/state";
+import state, { IDifficulty, handleSetSpeed, hanldeDirectSelection } from "/src/state";
 import { getQuery } from "/src/utils/queryString";
 import { evaluatingData } from "/src/view/evaluating";
 
@@ -19,6 +19,9 @@ export default defineComponent({
 		const evaluatingWorkData = reactive({
 			difficulty: "" as IDifficulty,
 			evaluatingRecord: props.workeData?.id,
+			start: "" as any,
+			end: "" as any,
+			evaluateSpeed: 0,
 		});
 		/** 隐藏评测功能 */
 		const handleHide = () => {
@@ -42,12 +45,39 @@ export default defineComponent({
 			if (["BEGINNER", "ADVANCED", "PERFORMER"].includes(trainingContent.evaluateDifficult)) {
 				evaluatingWorkData.difficulty = trainingContent.evaluateDifficult;
 				state.setting.evaluationDifficulty = trainingContent.evaluateDifficult;
-				//设置速度
-				if (trainingContent.evaluateSpeed) {
-					handleSetSpeed(trainingContent.evaluateSpeed);
-				}
+
+				evaluatingWorkData.evaluateSpeed = trainingContent.evaluateSpeed;
+				evaluatingWorkData.start = Number(trainingContent.practiceChapterBegin);
+				evaluatingWorkData.end = Number(trainingContent.practiceChapterEnd);
+				setSection();
 			}
 		};
+		/**设置小节 */
+		const setSection = () => {
+			const startNotes = state.times.filter(
+			  (n: any) => n.noteElement.sourceMeasure.MeasureNumberXML == evaluatingWorkData.start
+			)
+			const endNotes = state.times.filter(
+			  (n: any) => n.noteElement.sourceMeasure.MeasureNumberXML == evaluatingWorkData.end
+			)
+			const startNote = startNotes[0]
+			const endNote = endNotes[endNotes.length - 1]
+			//   console.log('🚀 ~ activeNote', startNote, endNote, questionExtendsInfo.value.end)
+			if (startNote && endNote) {
+			  state.isSelectMeasureMode = true;
+			  // 设置小节
+			  hanldeDirectSelection([startNote, endNote]);
+
+			//   // 设置小节
+			//   state.sectionStatus = true
+			//   state.section = [startNote, endNote]
+
+			  //设置速度
+			  if (evaluatingWorkData.evaluateSpeed) {
+				handleSetSpeed(evaluatingWorkData.evaluateSpeed);
+			  }
+			}
+		  }		
 		/** 添加记录 */
 		const addEvaluatingWorkRecored = async (data: any) => {
 			try {

+ 3 - 3
src/page-instrument/custom-plugins/work-home/index.tsx

@@ -2,7 +2,7 @@ import { defineComponent, onMounted, reactive, watch } from "vue";
 import styles from "./index.module.less";
 // import { verifyMembershipServices } from "../vip-verify";
 import { api_lessonTrainingSubmitTraining, api_lessonTrainingTrainingStudentDetail } from "../../api";
-import state, { handleSetSpeed } from "/src/state";
+import state, { handleSetSpeed, hanldeDirectSelection } from "/src/state";
 
 export default defineComponent({
 	name: "HomeWork",
@@ -69,9 +69,9 @@ export default defineComponent({
 			const endNote = endNotes[endNotes.length - 1]
 			//   console.log('🚀 ~ activeNote', startNote, endNote, questionExtendsInfo.value.end)
 			if (startNote && endNote) {
+			  state.isSelectMeasureMode = true;
 			  // 设置小节
-			  state.sectionStatus = true
-			  state.section = [startNote, endNote]
+			  hanldeDirectSelection([startNote, endNote]);
 			  //设置速度
 			  if (training.trainingSpeed) {
 				handleSetSpeed(training.trainingSpeed);

+ 28 - 4
src/page-instrument/evaluat-model/index.tsx

@@ -24,6 +24,13 @@ import { headTopData } from "../header-top/index";
 // frequency 频率, amplitude 振幅, decibels 分贝
 type TCriteria = "frequency" | "amplitude" | "decibels";
 
+/**
+ * 节拍器时长
+ * 评测模式时,应该传节拍器时长
+ * 阶段评测时,判断是否从第一小节开始,并且曲子本身含有节拍器,需要传节拍器时长,否则传0
+ */
+let actualBeatLength = 0
+
 export default defineComponent({
   name: "evaluat-model",
   setup() {
@@ -104,8 +111,24 @@ export default defineComponent({
       let dontEvaluatingMode = false;
       let skip = false;
       const datas = [];
-      for (let index = 0; index < state.times.length; index++) {
-        const item = state.times[index];
+      let selectTimes = state.times
+      actualBeatLength = Math.round(state.times[0].fixtime * 1000 / 1)
+      // 如果是阶段评测,选取该阶段的times
+			if (state.isSelectMeasureMode) {
+				const startIndex = state.times.findIndex(
+				  (n: any) => n.noteId == state.section[0].noteId
+				)
+				const endIndex = state.times.findIndex(
+				  (n: any) => n.noteId == state.section[1].noteId
+				)
+				actualBeatLength = startIndex == 0 && !state.needTick ? actualBeatLength : 0
+				selectTimes = state.times.filter((n: any, index: number) => {
+				  return index >= startIndex && index <= endIndex
+				})
+			}	
+
+      for (let index = 0; index < selectTimes.length; index++) {
+        const item = selectTimes[index];
         const note = getNoteByMeasuresSlursStart(item);
         // #8701 bug: 评测模式,是以曲谱本身的速度进行评测,所以rate取1,不需要转换
         // const rate = state.speed / state.originSpeed;
@@ -127,7 +150,7 @@ export default defineComponent({
         if (note.formatLyricsEntries.contains("纯律")) {
           dontEvaluatingMode = true;
         }
-        const nextNote = state.times[index + 1];
+        const nextNote = selectTimes[index + 1];
         // console.log("noteinfo", note.noteElement.isRestFlag && !!note.stave && !!nextNote)
         if (skip && (note.stave || !item.noteElement.isRestFlag || (nextNote && !nextNote.noteElement.isRestFlag))) {
           skip = false;
@@ -174,7 +197,8 @@ export default defineComponent({
         reactionTimeMs: state.setting.reactionTimeMs,
         speed: state.speed,
         heardLevel: state.setting.evaluationDifficulty,
-        beatLength: Math.round((state.fixtime * 1000) / rate),
+        // beatLength: Math.round((state.fixtime * 1000) / rate),
+        beatLength: actualBeatLength,
         evaluationCriteria: getEvaluationCriteria(),
       };
       await connectWebsocket(content);

+ 5 - 2
src/state.ts

@@ -254,7 +254,7 @@ const handlePlaying = () => {
   const duration = getAudioDuration();
   state.playProgress = (currentTime / duration) * 100;
   let item = getNote(currentTime);
-
+  // console.log(11111,currentTime,duration,state.playSource)
   if (item) {
     // 选段状态下
     if (state.sectionStatus && state.section.length === 2) {
@@ -529,7 +529,10 @@ export const handleSelection = (item: any) => {
 export const hanldeDirectSelection = (list: any[]) => {
   if (!Array.isArray(list) || list.length !== 2) return;
   state.sectionStatus = true;
-  state.section = formateSelectMearure(list);
+  setTimeout(() => {
+    state.section = formateSelectMearure(list);
+  }, 500);
+  
 };
 let offsetTop = 0;
 /**

+ 3 - 0
src/view/audio-list/index.tsx

@@ -58,6 +58,7 @@ export const getAudioCurrentTime = () => {
 	}
 	if (state.playSource === "music") return audioData.songEle?.currentTime || audioData.progress;
 	if (state.playSource === "background") return audioData.backgroundEle?.currentTime || audioData.progress;
+	
 	return audioData.songEle?.currentTime || audioData.progress;
 };
 /** 获取曲谱的总时间 */
@@ -72,6 +73,7 @@ export const getAudioDuration = () => {
 
 /** 设置播放的开始时间 */
 export const setAudioCurrentTime = (time: number, index = 0) => {
+	// console.log('开始时间12345',time)
 	// 如果是midi播放
 	if (audioData.midiRender) {
 		setMidiCurrentTime(index);
@@ -145,6 +147,7 @@ export default defineComponent({
 		};
 		// 监听评测曲谱音频播放进度,返回
 		const progress = (res: any) => {
+			// console.log(res,'播放进度111')
 			const currentTime = res?.currentTime || res?.content?.currentTime;
 			const total = res?.totalDuration || res?.content?.totalDuration;
 			const time = currentTime / 1000;