feat: first version
This commit is contained in:
+39
-22
@@ -21,6 +21,7 @@ import {
|
||||
createParagraph,
|
||||
createParagraphWithNotations,
|
||||
} from "../util/paragraph";
|
||||
import { convertTone, convertToneTo } from "../util/tone-convert";
|
||||
import { exportFile, loadFile, saveFile } from "../util/file";
|
||||
import { findParagraphAndNotation, resetGlobalData } from "../util/editor";
|
||||
import {
|
||||
@@ -74,9 +75,28 @@ const handleEditMenu = wrappedAction(({ key }) => {
|
||||
break;
|
||||
}
|
||||
});
|
||||
const handleConvertMenu = wrappedAction(() => {
|
||||
console.log(111);
|
||||
});
|
||||
const handleConvertMenu = ({ key }) => {
|
||||
switch (true) {
|
||||
case key.startsWith("convertTo"):
|
||||
const destTone = key.split("-", 2)[1];
|
||||
convertToneTo(destTone);
|
||||
break;
|
||||
case key === "convert-up":
|
||||
convertTone(2);
|
||||
break;
|
||||
case key === "convert-down":
|
||||
convertTone(-2);
|
||||
break;
|
||||
case key === "convert-up8":
|
||||
convertTone(12);
|
||||
break;
|
||||
case key === "convert-down8":
|
||||
convertTone(-12);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
// 画布上的点击事件
|
||||
const handleClick = wrappedAction((ev) => {
|
||||
@@ -94,6 +114,9 @@ const handleKeyPress = wrappedAction((ev) => {
|
||||
|
||||
if (state.selectedNotationKey) {
|
||||
// 仅选中符号时作用
|
||||
if (state.helpDialogVisible || state.configDialogVisible) {
|
||||
return;
|
||||
}
|
||||
const {
|
||||
paragraph,
|
||||
notation,
|
||||
@@ -404,33 +427,27 @@ const editMenu = (
|
||||
|
||||
const convertMenu = (
|
||||
<Menu key="tone" onClick={handleConvertMenu}>
|
||||
<SubMenu key="convert-to" title="转到...">
|
||||
<Menu.Item key="convert-to-C">1 = C</Menu.Item>
|
||||
<Menu.Item key="convert-to-D">1 = D</Menu.Item>
|
||||
<Menu.Item key="convert-to-E">1 = E</Menu.Item>
|
||||
<Menu.Item key="convert-to-F">1 = F</Menu.Item>
|
||||
<Menu.Item key="convert-to-G">1 = G</Menu.Item>
|
||||
<Menu.Item key="convert-to-A">1 = A</Menu.Item>
|
||||
<Menu.Item key="convert-to-B">1 = B</Menu.Item>
|
||||
<Menu.Item key="convert-to-bC">
|
||||
1 = <sup>♭</sup>C
|
||||
</Menu.Item>
|
||||
<Menu.Item key="convert-to-bD">
|
||||
<SubMenu key="convertTo" title="转到...">
|
||||
<Menu.Item key="convertTo-C">1 = C</Menu.Item>
|
||||
<Menu.Item key="convertTo-D">1 = D</Menu.Item>
|
||||
<Menu.Item key="convertTo-E">1 = E</Menu.Item>
|
||||
<Menu.Item key="convertTo-F">1 = F</Menu.Item>
|
||||
<Menu.Item key="convertTo-G">1 = G</Menu.Item>
|
||||
<Menu.Item key="convertTo-A">1 = A</Menu.Item>
|
||||
<Menu.Item key="convertTo-B">1 = B</Menu.Item>
|
||||
<Menu.Item key="convertTo-♭D">
|
||||
1 = <sup>♭</sup>D
|
||||
</Menu.Item>
|
||||
<Menu.Item key="convert-to-bE">
|
||||
<Menu.Item key="convertTo-♭E">
|
||||
1 = <sup>♭</sup>E
|
||||
</Menu.Item>
|
||||
<Menu.Item key="convert-to-bF">
|
||||
1 = <sup>♭</sup>F
|
||||
</Menu.Item>
|
||||
<Menu.Item key="convert-to-bG">
|
||||
<Menu.Item key="convertTo-♭G">
|
||||
1 = <sup>♭</sup>G
|
||||
</Menu.Item>
|
||||
<Menu.Item key="convert-to-bA">
|
||||
<Menu.Item key="convertTo-♭A">
|
||||
1 = <sup>♭</sup>A
|
||||
</Menu.Item>
|
||||
<Menu.Item key="convert-to-bB">
|
||||
<Menu.Item key="convertTo-♭B">
|
||||
1 = <sup>♭</sup>B
|
||||
</Menu.Item>
|
||||
</SubMenu>
|
||||
|
||||
+11
-1
@@ -27,6 +27,9 @@ const separators = ["│", "‖"];
|
||||
function isNote(notationOrNote) {
|
||||
return notes.includes(notationOrNote?.note || notationOrNote);
|
||||
}
|
||||
function isPauseNote(notationOrNote) {
|
||||
return notations.zero === (notationOrNote?.note || notationOrNote);
|
||||
}
|
||||
function isSeparator(notationOrNote) {
|
||||
return separators.includes(notationOrNote?.note || notationOrNote);
|
||||
}
|
||||
@@ -56,4 +59,11 @@ function cloneNotation(notation) {
|
||||
return n;
|
||||
}
|
||||
|
||||
export { notations, isNote, isSeparator, createNotation, cloneNotation };
|
||||
export {
|
||||
notations,
|
||||
isNote,
|
||||
isPauseNote,
|
||||
isSeparator,
|
||||
createNotation,
|
||||
cloneNotation,
|
||||
};
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
import store from "../store/global";
|
||||
import { wrappedAction } from "../store/history";
|
||||
import { isNote, isPauseNote } from "./notation";
|
||||
|
||||
// 音符到音数
|
||||
const noteToLevelMap = {
|
||||
1: 0,
|
||||
2: 2,
|
||||
3: 4,
|
||||
4: 5,
|
||||
5: 7,
|
||||
6: 9,
|
||||
7: 11,
|
||||
};
|
||||
// 音数到音符
|
||||
const levelToNoteMap = {
|
||||
0: 1,
|
||||
1: 1,
|
||||
2: 2,
|
||||
3: 2,
|
||||
4: 3,
|
||||
5: 4,
|
||||
6: 4,
|
||||
7: 5,
|
||||
8: 5,
|
||||
9: 6,
|
||||
10: 7,
|
||||
11: 7,
|
||||
};
|
||||
// 升降到音数
|
||||
const bumpSharpToLevelMap = {
|
||||
"♭": -1,
|
||||
"♯": 1,
|
||||
};
|
||||
// 音数到升降
|
||||
const levelToBumpSharpMap = {
|
||||
1: "♯",
|
||||
3: "♯",
|
||||
6: "♯",
|
||||
8: "♯",
|
||||
10: "♭",
|
||||
};
|
||||
|
||||
const toneToLevelMap = {
|
||||
C: 0,
|
||||
D: 2,
|
||||
E: 4,
|
||||
F: 5,
|
||||
G: 7,
|
||||
A: 9,
|
||||
B: 11,
|
||||
};
|
||||
|
||||
/**
|
||||
* 整体转调
|
||||
* @param {number} deltaVolume 要调整的音数
|
||||
*/
|
||||
const convertTone = wrappedAction(function (deltaVolume) {
|
||||
deltaVolume = deltaVolume | 0;
|
||||
store.paragraphs.forEach((p) => {
|
||||
p.notations.forEach((n) => {
|
||||
if (isNote(n) && !isPauseNote(n)) {
|
||||
n.octave += Math.trunc(deltaVolume / 12);
|
||||
let newLevel =
|
||||
noteToLevelMap[n.note] +
|
||||
(deltaVolume % 12) +
|
||||
(n.prefixSups || []).reduce(
|
||||
(prev, next) => prev + (bumpSharpToLevelMap[next] | 0),
|
||||
0
|
||||
);
|
||||
if (newLevel >= 12) {
|
||||
n.octave += 1;
|
||||
newLevel -= 12;
|
||||
} else if (newLevel < 0) {
|
||||
n.octave -= 1;
|
||||
newLevel += 12;
|
||||
}
|
||||
n.note = String(levelToNoteMap[newLevel]);
|
||||
n.prefixSups = (n.prefixSups || []).filter(
|
||||
(c) => c !== "♯" && c !== "♭"
|
||||
);
|
||||
if (levelToBumpSharpMap[newLevel]) {
|
||||
n.prefixSups.unshift(levelToBumpSharpMap[newLevel]);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// 转到1 = *
|
||||
const convertToneTo = wrappedAction((destTone) => {
|
||||
let deltaVolume = -(
|
||||
toneToLevelMap[destTone.split("").at(-1)] -
|
||||
toneToLevelMap[store.tone.split("").at(-1)]
|
||||
);
|
||||
if (destTone.startsWith("♭") || store.tone.startsWith("♯")) {
|
||||
deltaVolume -= 1;
|
||||
}
|
||||
if (destTone.startsWith("♯") || store.tone.startsWith("♭")) {
|
||||
deltaVolume += 1;
|
||||
}
|
||||
convertTone(deltaVolume);
|
||||
store.tone = destTone;
|
||||
});
|
||||
|
||||
export { convertTone, convertToneTo };
|
||||
Reference in New Issue
Block a user