+36
-2
@@ -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,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user