瀏覽代碼

feat: 跟练完成增加自动结束功能

TIANYONG 1 年之前
父節點
當前提交
00c5a2937e
共有 1 個文件被更改,包括 22 次插入0 次删除
  1. 22 0
      src/subpages/colexiu/popups/follow/index.tsx

+ 22 - 0
src/subpages/colexiu/popups/follow/index.tsx

@@ -106,6 +106,7 @@ const getDefaultIndex = () => {
 
 // 开始
 const handleStart = () => {
+  checking = false;
   onClear()
   data.start = true
   openToggleRecord(true)
@@ -126,6 +127,26 @@ const handleEnd = () => {
   getNoteIndex()
 }
 
+/**
+ * 2024.7.9 新增自动结束跟练模式功能
+ * 如果跟练模式,唱完了最后一个有频率的音符,需要自动结束掉跟练模式
+ * 需要判断当前音符的后面是否都是休止音符(休止音符的频率都是-1),或者是否是最后一个音符了
+ */
+const autoEndFollow = () => {
+	if (data.index >= detailState.times.length) {
+		handleEnd()
+		return
+	}
+	let nextIndex = data.index + 1;
+	const rightTimes = detailState.times.slice(data.index,detailState.times.length)
+	// 后面的音符是否都是休止音符
+	const isAllRest = !rightTimes.some((item: any) => item.frequency > 1);
+	if (isAllRest && detailState.times[data.index].frequency < 1) {
+		handleEnd()
+		return
+	}
+}
+
 // 下一个
 const next = () => {
   if (state.osmd.product) {
@@ -134,6 +155,7 @@ const next = () => {
     state.osmd.cursor.next()
   }
   refreshView()
+  autoEndFollow()
 }
 
 // 获取当前音符