Bläddra i källkod

feat: 一行谱平移修改

TIANYONG 1 år sedan
förälder
incheckning
d6996bee4e
2 ändrade filer med 17 tillägg och 11 borttagningar
  1. 16 11
      src/state.ts
  2. 1 0
      src/view/music-score/index.tsx

+ 16 - 11
src/state.ts

@@ -620,7 +620,8 @@ export const skipNotePlay = async (itemIndex: number, isStart = false) => {
   }
   if (item) {
     setAudioCurrentTime(itemTime, itemIndex);
-    gotoNext(item);
+    // 一行谱,点击音符,或者播放完成,需要跳转音符位置
+    gotoNext(item, true);
     metronomeData.metro?.sound(itemTime);
     if (state.isAppPlay) {
       await api_cloudSetCurrentTime({
@@ -753,8 +754,11 @@ const setCursorPosition = (note: any, cursor: any) => {
     });
   }
 };
-/** 跳转到下一个音符 */
-export const gotoNext = (note: any) => {
+/** 
+ * 跳转到下一个音符
+ * 一行谱,点击音符,或者播放完成,需要跳转音符位置,增加参数skipNote
+ **/
+export const gotoNext = (note: any, skipNote?: boolean) => {
   // console.log(33333333333,state.activeNoteIndex,note.i)
   const num = note.i;
 
@@ -766,7 +770,6 @@ export const gotoNext = (note: any) => {
     }
     return;
   }
-  
   const osmd = state.osmd;
   let prev = state.activeNoteIndex;
   state.activeNoteIndex = num;
@@ -789,7 +792,7 @@ export const gotoNext = (note: any) => {
   }
   // 一行谱,需要滚动小节
   if (state.isSingleLine) {
-    moveSvgDom();
+    moveSvgDom(skipNote);
   }
   scrollViewNote();
 };
@@ -1334,7 +1337,7 @@ export const calculateDistance = () => {
 }
 
 /** 跳动svgdom */
-export const moveSvgDom = () => {
+export const moveSvgDom = (skipNote?: boolean) => {
   // const cursorLeft = state.cursorDom?.getBoundingClientRect()?.left || 0;
   // const leftValue = parseFloat(state.cursorDom.style.left) - 47 - 20;
   // console.log(cursorLeft,leftValue,'光标位置')
@@ -1358,11 +1361,13 @@ export const moveSvgDom = () => {
    * 计算需要移动的距离
    * 当前选中的音符和第一个音符之间的间距
    */
-  const distance = state.times[state.activeNoteIndex].bbox?.x - state.times[0].bbox?.x + state.times[state.activeNoteIndex].bbox?.width / 2 - state.times[0].bbox?.width / 2;
-  state.osdmScrollDom.scrollTo({
-    left: distance,
-    behavior: "smooth",
-  });
+  if (skipNote) {
+    const distance = state.times[state.activeNoteIndex].bbox?.x - state.times[0].bbox?.x + state.times[state.activeNoteIndex].bbox?.width / 2 - state.times[0].bbox?.width / 2;
+    state.osdmScrollDom.scrollTo({
+      left: distance,
+      behavior: "smooth",
+    });
+  }
 }
 
 /** 平滑移动svgdom */

+ 1 - 0
src/view/music-score/index.tsx

@@ -105,6 +105,7 @@ export default defineComponent({
 				defaultColorMusic: props.musicColor, // 颜色
 				renderSingleHorizontalStaffline: state.isSingleLine ? true : false,
 				autoGenerateMultipleRestMeasuresFromRestMeasures: state.isSingleLine ? false : true, // 连续休止小节是否合并显示
+				// darkMode: true, // 暗黑模式
 				// pageFormat: 'A4_P',
 				// autoBeam: true,
 				// drawMetronomeMarks: false,