Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: アクセント句単位でまとめてモーラ設定値を変更できるようにした #623

Merged
2 changes: 2 additions & 0 deletions public/howtouse.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ Apple Silicon搭載のMacとRosettaの詳しい情報はこちらのリソース
- スライダーの値を変更します
- Ctrl キーを押しながらマウスホイールを使うと更に細かく調整できます
- スライダー →<img src="res/image16.png" style="max-height: 1rem" alt="スライダー、緑色の棒。" />
- Alt キーを押しながらアクセントのイントネーションと長さを調整
- 増減させた値分、同じアクセントの値を増減します



Expand Down
122 changes: 98 additions & 24 deletions src/components/AudioDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
:accentPhraseIndex="accentPhraseIndex"
:value="mora.pitch"
:uiLocked="uiLocked"
:min="3"
:max="6.5"
:min="minPitch"
:max="maxPitch"
:disable="mora.pitch == 0.0"
:type="'pitch'"
:clip="false"
Expand All @@ -84,8 +84,8 @@
:accentPhraseIndex="accentPhraseIndex"
:value="mora.consonantLength"
:uiLocked="uiLocked"
:min="0"
:max="0.3"
:min="minMoraLength"
:max="maxMoraLength"
:step="0.001"
:type="'consonant'"
:clip="true"
Expand All @@ -99,8 +99,8 @@
:accentPhraseIndex="accentPhraseIndex"
:value="mora.vowelLength"
:uiLocked="uiLocked"
:min="0"
:max="0.3"
:min="minMoraLength"
:max="maxMoraLength"
:step="0.001"
:type="'vowel'"
:clip="mora.consonant ? true : false"
Expand Down Expand Up @@ -323,22 +323,94 @@ export default defineComponent({
});
};

const maxPitch = 6.5;
const minPitch = 3;
const maxMoraLength = 0.3;
const minMoraLength = 0;
const changeMoraData = (
accentPhraseIndex: number,
moraIndex: number,
data: number,
type: MoraDataType
) => {
if (type == "pitch") {
lastPitches.value[accentPhraseIndex][moraIndex] = data;
if (altKeyFlag.value) {
if (accentPhrases.value !== undefined) {
const accentPhrase = accentPhrases.value[accentPhraseIndex];
const targetMora = accentPhrase.moras[moraIndex];

let diffData = data;
switch (type) {
case "pitch":
diffData -= targetMora.pitch;
break;
case "consonant":
if (targetMora.consonantLength !== undefined) {
diffData -= targetMora.consonantLength;
}
break;
case "vowel":
diffData -= targetMora.vowelLength;
break;
}

accentPhrase.moras.forEach((mora, moraIndex) => {
switch (type) {
case "pitch":
if (mora.pitch > 0) {
const newData = Math.max(
minPitch,
Math.min(maxPitch, mora.pitch + diffData)
);
lastPitches.value[accentPhraseIndex][moraIndex] = newData;
store.dispatch("COMMAND_SET_AUDIO_MORA_DATA", {
audioKey: props.activeAudioKey,
accentPhraseIndex,
moraIndex,
data: newData,
type,
});
}
break;
case "consonant":
case "vowel":
if (mora.consonantLength !== undefined) {
store.dispatch("COMMAND_SET_AUDIO_MORA_DATA", {
audioKey: props.activeAudioKey,
accentPhraseIndex,
moraIndex,
data: Math.max(
minMoraLength,
Math.min(maxMoraLength, mora.consonantLength + diffData)
),
type: "consonant",
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

なるほど!!

この実装だと、コマンドが複数登録されてしまうので、ctrl+zで一気にやり直すことができなそうです。
一括変更する新しいCOMMAND関数を作ってそちらで修正するのが、一番良い解決だと思います。

が、それはCOMMANDの実装などを把握する必要があって結構大変かもしれません。
実装が難しそうであれば、一旦experimental機能にする手もありそうです。

お手数おかけしちゃいますが、どちらか実装をお願いしたいです・・・!
(個人的には、まあ適当なCOMMANDをコピペして、この処理を移動すれば実装完了な気がしているので、実装しちゃっても良いのかなとちょっと思っています。)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

COMMAND内部でaccentPhraseを取得してるところが見当たらなかったのですが、COMMANDの引数としてaccentPhraseを渡しても問題ないでしょうか?
ここでの作法がよくわからずどう実装してよいか迷っています

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

accentPhraseは渡しても問題ないはずです!
COMMANDに渡して良い値は、いまのところ制約がないと思います。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

とりあえずコピペしてCOMMAND化しました

}
store.dispatch("COMMAND_SET_AUDIO_MORA_DATA", {
audioKey: props.activeAudioKey,
accentPhraseIndex,
moraIndex,
data: Math.max(
minMoraLength,
Math.min(maxMoraLength, mora.vowelLength + diffData)
),
type: "vowel",
});
break;
}
});
}
} else {
if (type == "pitch") {
lastPitches.value[accentPhraseIndex][moraIndex] = data;
}
store.dispatch("COMMAND_SET_AUDIO_MORA_DATA", {
audioKey: props.activeAudioKey,
accentPhraseIndex,
moraIndex,
data,
type,
});
}
store.dispatch("COMMAND_SET_AUDIO_MORA_DATA", {
audioKey: props.activeAudioKey,
accentPhraseIndex,
moraIndex,
data,
type,
});
};

// audio play
Expand Down Expand Up @@ -524,15 +596,13 @@ export default defineComponent({
};

const shiftKeyFlag = ref(false);
const altKeyFlag = ref(false);

const setShiftKeyFlag = (event: KeyboardEvent) => {
const keyEventListter = (event: KeyboardEvent) => {
shiftKeyFlag.value = event.shiftKey;
altKeyFlag.value = event.altKey;
};

function resetShiftKeyFlag(event: KeyboardEvent) {
if (event.key === "Shift") shiftKeyFlag.value = false;
}

const handleChangeVoicing = (
mora: Mora,
accentPhraseIndex: number,
Expand All @@ -558,16 +628,20 @@ export default defineComponent({
};

onMounted(() => {
window.addEventListener("keyup", resetShiftKeyFlag);
document.addEventListener("keydown", setShiftKeyFlag);
window.addEventListener("keyup", keyEventListter);
document.addEventListener("keydown", keyEventListter);
});

onUnmounted(() => {
window.removeEventListener("keyup", resetShiftKeyFlag);
document.removeEventListener("keydown", setShiftKeyFlag);
window.removeEventListener("keyup", keyEventListter);
document.removeEventListener("keydown", keyEventListter);
});

return {
maxPitch,
minPitch,
maxMoraLength,
minMoraLength,
selectDetail,
selectedDetail,
uiLocked,
Expand Down