liushengqiang 2 лет назад
Родитель
Сommit
ea812576e0
4 измененных файлов с 39 добавлено и 22 удалено
  1. 1 1
      src/helpers/formateMusic.ts
  2. 5 2
      src/state.ts
  3. 19 11
      src/view/audio-list/index.tsx
  4. 14 8
      src/view/evaluating/index.tsx

+ 1 - 1
src/helpers/formateMusic.ts

@@ -807,7 +807,7 @@ export const formateTimes = (osmd: OpenSheetMusicDisplay) => {
 			if (i === 0) {
 			if (i === 0) {
 				fixtime += getFixTime(beatSpeed);
 				fixtime += getFixTime(beatSpeed);
 				state.fixtime = fixtime;
 				state.fixtime = fixtime;
-				console.log("🚀 ~ fixtime:", fixtime, beatSpeed, "state.isSpecialBookCategory", state.isSpecialBookCategory);
+				console.log("fixtime:", fixtime, '速度:', beatSpeed, "state.isSpecialBookCategory:", state.isSpecialBookCategory, 'state.isOpenMetronome:', state.isOpenMetronome);
 			}
 			}
 			// console.log(getTimeByBeatUnit(beatUnit, measureSpeed, iterator.currentMeasure.activeTimeSignature.Denominator))
 			// console.log(getTimeByBeatUnit(beatUnit, measureSpeed, iterator.currentMeasure.activeTimeSignature.Denominator))
 			let gradualLength = 0;
 			let gradualLength = 0;

+ 5 - 2
src/state.ts

@@ -14,6 +14,8 @@ import { setStorageSpeed } from "./utils";
 export type IDifficulty = "BEGINNER" | "ADVANCED" | "PERFORMER";
 export type IDifficulty = "BEGINNER" | "ADVANCED" | "PERFORMER";
 export type IMusicRenderType = "staff" | "firstTone" | "fixedTone";
 export type IMusicRenderType = "staff" | "firstTone" | "fixedTone";
 export const musicscoresettingKey = "musicscoresetting";
 export const musicscoresettingKey = "musicscoresetting";
+/** 有声音的是那个音源 */
+export type IPlayState = "music" | "background"
 
 
 const state = reactive({
 const state = reactive({
 	appName: "" as "GYM" | "COLEXIU",
 	appName: "" as "GYM" | "COLEXIU",
@@ -73,7 +75,7 @@ const state = reactive({
 	/** 播放结束状态 */
 	/** 播放结束状态 */
 	playEnd: false,
 	playEnd: false,
 	/** 播放那个: 原音,伴奏 */
 	/** 播放那个: 原音,伴奏 */
-	playSource: "music" as "music" | "background",
+	playSource: "music" as IPlayState,
 	/** 播放进度 */
 	/** 播放进度 */
 	playProgress: 0,
 	playProgress: 0,
 	/** 激活的note index */
 	/** 激活的note index */
@@ -196,11 +198,12 @@ export const onPlay = () => {
 		if (state.isSelectMeasureMode) {
 		if (state.isSelectMeasureMode) {
 			currentTime = currentTime - state.section[0].time;
 			currentTime = currentTime - state.section[0].time;
 		}
 		}
+		sendEvaluatingOffsetTime(getAudioCurrentTime())
 	}
 	}
 };
 };
 /** 播放中事件 */
 /** 播放中事件 */
 export const onTimeupdate = (evt: Event) => {
 export const onTimeupdate = (evt: Event) => {
-	sendEvaluatingOffsetTime(getAudioCurrentTime())
+	
 };
 };
 
 
 /** 播放模式结束自动重播 */
 /** 播放模式结束自动重播 */

+ 19 - 11
src/view/audio-list/index.tsx

@@ -1,7 +1,7 @@
 import { computed, defineComponent, reactive, ref } from "vue";
 import { computed, defineComponent, reactive, ref } from "vue";
-import state, { onEnded, onLoadedmetadata, onPlay, onTimeupdate } from "../../state";
 import styles from "./index.module.less";
 import styles from "./index.module.less";
 import { getMidiCurrentTime, getMidiDuration, handleTogglePlayMidi, hanldeInitMidiData, hanldeSetMidiPlaybackRate, setMidiCurrentTime } from "./midiPlayer";
 import { getMidiCurrentTime, getMidiDuration, handleTogglePlayMidi, hanldeInitMidiData, hanldeSetMidiPlaybackRate, setMidiCurrentTime } from "./midiPlayer";
+import state, { IPlayState, onEnded, onLoadedmetadata, onPlay, onTimeupdate } from "/src/state";
 
 
 const audioData = reactive({
 const audioData = reactive({
 	songEle: null as unknown as HTMLAudioElement,
 	songEle: null as unknown as HTMLAudioElement,
@@ -39,8 +39,8 @@ export const setAudioPlaybackRate = (rate: number) => {
 export const getAudioCurrentTime = () => {
 export const getAudioCurrentTime = () => {
 	// 如果是midi播放
 	// 如果是midi播放
 	if (audioData.midiRender) {
 	if (audioData.midiRender) {
-		const c = getMidiCurrentTime()
-		return c
+		const c = getMidiCurrentTime();
+		return c;
 	}
 	}
 	return audioData.songEle?.currentTime || audioData.backgroundEle?.currentTime || 0;
 	return audioData.songEle?.currentTime || audioData.backgroundEle?.currentTime || 0;
 };
 };
@@ -48,8 +48,8 @@ export const getAudioCurrentTime = () => {
 export const getAudioDuration = () => {
 export const getAudioDuration = () => {
 	// 如果是midi播放
 	// 如果是midi播放
 	if (audioData.midiRender) {
 	if (audioData.midiRender) {
-		const d = getMidiDuration()
-		return d
+		const d = getMidiDuration();
+		return d;
 	}
 	}
 	return audioData.songEle?.duration || audioData.backgroundEle?.duration || 0;
 	return audioData.songEle?.duration || audioData.backgroundEle?.duration || 0;
 };
 };
@@ -58,7 +58,7 @@ export const getAudioDuration = () => {
 export const setAudioCurrentTime = (time: number, index = 0) => {
 export const setAudioCurrentTime = (time: number, index = 0) => {
 	// 如果是midi播放
 	// 如果是midi播放
 	if (audioData.midiRender) {
 	if (audioData.midiRender) {
-		setMidiCurrentTime(index)
+		setMidiCurrentTime(index);
 		return;
 		return;
 	}
 	}
 	audioData.songEle && (audioData.songEle.currentTime = time);
 	audioData.songEle && (audioData.songEle.currentTime = time);
@@ -66,16 +66,24 @@ export const setAudioCurrentTime = (time: number, index = 0) => {
 };
 };
 
 
 /** 设置当前没有播放的音频静音 */
 /** 设置当前没有播放的音频静音 */
-export const toggleMutePlayAudio = () => {
-	if(state.playSource === 'music'){
+export const toggleMutePlayAudio = (source: IPlayState, muted: boolean) => {
+	if (source === "music") {
 		if (audioData.songEle) {
 		if (audioData.songEle) {
-			audioData.songEle.muted = !audioData.songEle.muted
+			audioData.songEle.muted = muted;
 		}
 		}
-	} else if (state.playSource === 'background') {
+	} else if (source === "background") {
 		if (audioData.backgroundEle) {
 		if (audioData.backgroundEle) {
-			audioData.backgroundEle.muted = !audioData.backgroundEle.muted
+			audioData.backgroundEle.muted = muted;
 		}
 		}
 	}
 	}
+};
+
+/** 检测音源数量 */
+export const detectTheNumberOfSoundSources = () => {
+	let total = 0
+	if (audioData.songEle) total += 1
+	if (audioData.backgroundEle) total += 1
+	return total
 }
 }
 
 
 export default defineComponent({
 export default defineComponent({

+ 14 - 8
src/view/evaluating/index.tsx

@@ -69,8 +69,9 @@ export const handleStartEvaluat = () => {
 
 
 /** 开始播放发送延迟时间 */
 /** 开始播放发送延迟时间 */
 export const sendEvaluatingOffsetTime = async (currentTime: number) => {
 export const sendEvaluatingOffsetTime = async (currentTime: number) => {
-	// 没有开始时间点, 没有开始播放, 不处理
-	if (!evaluatingData.backtime || !currentTime) return;
+	console.log("🚀 ~ currentTime:", currentTime)
+	// 没有开始时间点, 不处理
+	if (!evaluatingData.backtime) return;
 	const nowTime = Date.now();
 	const nowTime = Date.now();
 	const delayTime = nowTime - evaluatingData.backtime
 	const delayTime = nowTime - evaluatingData.backtime
 	evaluatingData.backtime = 0
 	evaluatingData.backtime = 0
@@ -84,7 +85,6 @@ export const sendEvaluatingOffsetTime = async (currentTime: number) => {
 			offsetTime: delayTime < 0 ? 0 : delayTime,
 			offsetTime: delayTime < 0 ? 0 : delayTime,
 		},
 		},
 	});
 	});
-	evaluatingData.backtime = 0;
 };
 };
 
 
 /** 检测耳机 */
 /** 检测耳机 */
@@ -199,20 +199,22 @@ export const handleStartBegin = async () => {
 		return;
 		return;
 	}
 	}
 	// 开始播放
 	// 开始播放
-	playMusic();
+	// playMusic();
 	// 开始录音
 	// 开始录音
 	api_startRecording();
 	api_startRecording();
 };
 };
 
 
 /** 播放音乐 */
 /** 播放音乐 */
 const playMusic = async () => {
 const playMusic = async () => {
-	toggleMutePlayAudio()
+	console.time('真正播放开始的延迟')
+	// toggleMutePlayAudio(state.playSource, true)
 	const playState = await togglePlay("play");
 	const playState = await togglePlay("play");
+	console.timeEnd('真正播放开始的延迟')
 	// 取消播放
 	// 取消播放
 	if (!playState) {
 	if (!playState) {
 		evaluatingData.startBegin = false;
 		evaluatingData.startBegin = false;
 		handleCancelEvaluat();
 		handleCancelEvaluat();
-		toggleMutePlayAudio()
+		// toggleMutePlayAudio(state.playSource, false)
 		return;
 		return;
 	}
 	}
 	// 如果开启了摄像头, 开启录制视频
 	// 如果开启了摄像头, 开启录制视频
@@ -224,14 +226,18 @@ const playMusic = async () => {
 
 
 /** 录音开始,记录开始时间点 */
 /** 录音开始,记录开始时间点 */
 const recordStartTimePoint = async (res?: IPostMessage) => {
 const recordStartTimePoint = async (res?: IPostMessage) => {
+	// 没有开始评测,不处理
+	if (!evaluatingData.startBegin) return
 	let inteveral = res?.content?.inteveral || 0;
 	let inteveral = res?.content?.inteveral || 0;
 	if (browserInfo.ios) {
 	if (browserInfo.ios) {
 		inteveral *= 1000;
 		inteveral *= 1000;
 	}
 	}
 	console.log("🚀 ~ 开始时间点:", inteveral)
 	console.log("🚀 ~ 开始时间点:", inteveral)
 	evaluatingData.backtime = inteveral || Date.now();
 	evaluatingData.backtime = inteveral || Date.now();
-	toggleMutePlayAudio()
-	resetPlaybackToStart();
+	// toggleMutePlayAudio(state.playSource, false)
+	// resetPlaybackToStart();
+	// 开始播放
+	playMusic();
 };
 };
 
 
 /**
 /**