diff --git a/src/util/notation.js b/src/util/notation.js index e5a889e..74e7a43 100644 --- a/src/util/notation.js +++ b/src/util/notation.js @@ -1,4 +1,8 @@ +import { message } from "antd"; import { toJS } from "mobx"; +import state from "../store/state"; +import { wrappedAction } from "../store/history"; +import { findParagraphAndNotation } from "./editor"; const notations = { zero: "0", @@ -11,8 +15,8 @@ const notations = { si: "7", extend: "─", separator: "│", - crackerOpen: "(", - crackerClose: ")" + crackerOpen: "(", + crackerClose: ")", }; const notes = [ notations.zero, @@ -61,6 +65,35 @@ function cloneNotation(notation) { return n; } +// 放置连音线 +const placeTie = wrappedAction((notation) => { + if (state.tieSourceKey) { + // 处理连音线 + if (state.tieSourceKey === notation.key) { + state.tieSourceKey = null; + // NOTICE: 如果要添加其他逻辑注意这里的return + return; + } + const { + notation: sourceNotation, + paragraph: sourceParagraph, + } = findParagraphAndNotation(state.tieSourceKey); + if (!sourceNotation) { + state.tieSourceKey = null; + return; + } + if (!sourceParagraph.notations.includes(notation)) { + message.warn("只允许相同段落的音符相连!"); + } else if (!isNote(notation)) { + message.warn("只允许在音符上添加连音线!"); + } else { + sourceNotation.tieTo = notation.key; + notation.tieTo = sourceNotation.key; + } + state.tieSourceKey = null; + } +}); + export { notations, isNote, @@ -68,4 +101,5 @@ export { isSeparator, createNotation, cloneNotation, + placeTie, }; diff --git a/src/view/HelpModal/index.js b/src/view/HelpModal/index.js index 60e0792..5490cd2 100644 --- a/src/view/HelpModal/index.js +++ b/src/view/HelpModal/index.js @@ -40,9 +40,14 @@ function HelpModal({ visible, onVisibleChange }) {

仅选中符号时

-

输入

+

输入音符

+ 直接按键盘上相应的键即可输入到当前符号。支持的音符符号有: +

+ 0~7 + ( ) +

+

输入辅助元素