|
@@ -44,35 +44,38 @@ const onClear = () => {
|
|
|
state.times.forEach((item: any) => {
|
|
|
const note: HTMLElement = document.querySelector(`div[data-vf=vf${item.id}]`)!;
|
|
|
if (note) {
|
|
|
- note.classList.remove("error");
|
|
|
- note.classList.remove("success");
|
|
|
+ note.classList.remove("follow-up", "follow-down", "follow-error", "follow-success");
|
|
|
+ }
|
|
|
+ const _note: HTMLElement = document.getElementById(`vf-${item.id}`)!;
|
|
|
+ if (_note) {
|
|
|
+ _note.classList.remove("follow-up", "follow-down");
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
|
|
|
/** 开始跟练 */
|
|
|
export const handleFollowStart = () => {
|
|
|
- if (!storeData.isApp) {
|
|
|
- Snackbar({
|
|
|
- content: "请在APP端使用",
|
|
|
- type: "warning",
|
|
|
- });
|
|
|
- return;
|
|
|
- }
|
|
|
+ // if (!storeData.isApp) {
|
|
|
+ // Snackbar({
|
|
|
+ // content: "请在APP端使用",
|
|
|
+ // type: "warning",
|
|
|
+ // });
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
onClear();
|
|
|
followData.start = true;
|
|
|
followData.index = 0;
|
|
|
followData.list = [];
|
|
|
resetPlaybackToStart();
|
|
|
openToggleRecord(true);
|
|
|
- setStep();
|
|
|
+ getNoteIndex()
|
|
|
};
|
|
|
/** 结束跟练 */
|
|
|
export const handleFollowEnd = () => {
|
|
|
followData.start = false;
|
|
|
openToggleRecord(false);
|
|
|
followData.index = 0;
|
|
|
- console.log('结束')
|
|
|
+ console.log("结束");
|
|
|
};
|
|
|
|
|
|
// 下一个
|
|
@@ -92,59 +95,72 @@ const getNoteIndex = (): any => {
|
|
|
// state.fixedKey = item.realKey;
|
|
|
return {
|
|
|
id: item.id,
|
|
|
- min: item.frequency - item.prevFrequency * 0.1,
|
|
|
- max: item.frequency + item.nextFrequency * 0.1,
|
|
|
+ min: item.frequency - (item.frequency - item.prevFrequency) * 0.5,
|
|
|
+ max: item.frequency + (item.nextFrequency - item.frequency) * 0.5,
|
|
|
+ duration: item.duration,
|
|
|
+ baseFrequency: item.frequency,
|
|
|
};
|
|
|
};
|
|
|
let checking = false;
|
|
|
/** 录音回调 */
|
|
|
const onFollowTime = (evt?: IPostMessage) => {
|
|
|
const frequency: number = evt?.content?.frequency;
|
|
|
- audioFrequency.value = frequency;
|
|
|
- followData.list.push(frequency);
|
|
|
-};
|
|
|
-
|
|
|
-/** 在渲染前后计算光标应该走到的音符 */
|
|
|
-const setStep = () => {
|
|
|
- if (!followData.start) {
|
|
|
- return;
|
|
|
+ // 没有开始, 不处理
|
|
|
+ if (!followData.start) return
|
|
|
+ // console.log('频率', frequency)
|
|
|
+ if (frequency > 0) {
|
|
|
+ audioFrequency.value = frequency
|
|
|
+ // data.list.push(frequency)
|
|
|
+ checked()
|
|
|
}
|
|
|
- checked();
|
|
|
- setTimeout(() => {
|
|
|
- setStep();
|
|
|
- }, 50)
|
|
|
};
|
|
|
|
|
|
+let startTime = 0;
|
|
|
const checked = () => {
|
|
|
if (checking) return;
|
|
|
checking = true;
|
|
|
const item = getNoteIndex();
|
|
|
- for (let i = 0; i < followData.list.length; i++) {
|
|
|
- const frequency = followData.list[i];
|
|
|
- if (frequency > item.min && frequency < item.max) {
|
|
|
- // console.log(item.min, frequency, item.max);
|
|
|
- next();
|
|
|
- followData.index += 1;
|
|
|
- followData.list = followData.list.slice(i + 1);
|
|
|
- setColor(item, true);
|
|
|
- checking = false;
|
|
|
- return;
|
|
|
+ // 降噪处理, 频率低于 当前音的50% 时, 不处理
|
|
|
+ if (audioFrequency.value < item.baseFrequency * 0.5) {
|
|
|
+ checking = false;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (audioFrequency.value >= item.min && audioFrequency.value <= item.max) {
|
|
|
+ if (startTime === 0) {
|
|
|
+ startTime = Date.now();
|
|
|
+ } else {
|
|
|
+ const playTime = (Date.now() - startTime) / 1000;
|
|
|
+ // console.log('时长', playTime, item.duration / 2)
|
|
|
+ if (playTime >= item.duration * 0.6) {
|
|
|
+ startTime = 0;
|
|
|
+ followData.index = followData.index + 1;
|
|
|
+ setColor(item, "", true);
|
|
|
+ next();
|
|
|
+ checking = false;
|
|
|
+ return;
|
|
|
+ }
|
|
|
}
|
|
|
+ console.log("频率对了", item.min, audioFrequency.value, item.max, item.duration);
|
|
|
}
|
|
|
- setColor(item);
|
|
|
+ console.log("频率不对", item.min, audioFrequency.value, item.max, item.baseFrequency);
|
|
|
+ setColor(item, audioFrequency.value > item.baseFrequency ? "follow-up" : "follow-down");
|
|
|
checking = false;
|
|
|
};
|
|
|
-const setColor = (item: any, isRight = false) => {
|
|
|
+const setColor = (item: any, state: "follow-up" | "follow-down" | "", isRight = false) => {
|
|
|
const note: HTMLElement = document.querySelector(`div[data-vf=vf${item.id}]`)!;
|
|
|
if (note) {
|
|
|
+ note.classList.remove("follow-up", "follow-down", "follow-error", "follow-success");
|
|
|
if (isRight) {
|
|
|
- note.classList.remove("error");
|
|
|
- note.classList.add("success");
|
|
|
+ note.classList.add("follow-success");
|
|
|
} else {
|
|
|
- note.classList.remove("success");
|
|
|
- note.classList.add("error");
|
|
|
+ note.classList.add("follow-error", state);
|
|
|
}
|
|
|
}
|
|
|
+ const _note: HTMLElement = document.getElementById(`vf-${item.id}`)!;
|
|
|
+ if (_note) {
|
|
|
+ _note.classList.remove("follow-up", "follow-down");
|
|
|
+ state && _note.classList.add(state);
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
export default defineComponent({
|