Skip to content

Commit 2e552dc

Browse files
複数選択:イントネーションのリセットを複数選択対応 (#1659)
* Add: イントネーションリセットを複数選択対応 * Change: Multiを追加 * Change: === undefinedを削除
1 parent 88cfdfc commit 2e552dc

File tree

3 files changed

+62
-62
lines changed

3 files changed

+62
-62
lines changed

src/components/AudioDetail.vue

+10-7
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,11 @@ const hotkeyMap = new Map<HotkeyAction, () => HotkeyReturnType>([
148148
"全体のイントネーションをリセット",
149149
() => {
150150
if (!uiLocked.value && store.getters.ACTIVE_AUDIO_KEY) {
151-
store.dispatch("COMMAND_RESET_MORA_PITCH_AND_LENGTH", {
152-
audioKey: store.getters.ACTIVE_AUDIO_KEY,
151+
const audioKeys = store.state.experimentalSetting.enableMultiSelect
152+
? store.getters.SELECTED_AUDIO_KEYS
153+
: [store.getters.ACTIVE_AUDIO_KEY];
154+
store.dispatch("COMMAND_MULTI_RESET_MORA_PITCH_AND_LENGTH", {
155+
audioKeys,
153156
});
154157
}
155158
},
@@ -160,7 +163,7 @@ const hotkeyMap = new Map<HotkeyAction, () => HotkeyReturnType>([
160163
if (
161164
!uiLocked.value &&
162165
store.getters.ACTIVE_AUDIO_KEY &&
163-
store.getters.AUDIO_PLAY_START_POINT !== undefined
166+
store.getters.AUDIO_PLAY_START_POINT != undefined
164167
) {
165168
store.dispatch("COMMAND_RESET_SELECTED_MORA_PITCH_AND_LENGTH", {
166169
audioKey: store.getters.ACTIVE_AUDIO_KEY,
@@ -273,7 +276,7 @@ const accentPhraseComponents = ref<InstanceType<typeof AccentPhrase>[]>([]);
273276
274277
const scrollToActivePoint = () => {
275278
if (
276-
activePoint.value === undefined ||
279+
activePoint.value == undefined ||
277280
!audioDetail.value ||
278281
accentPhraseComponents.value.length === 0
279282
)
@@ -320,7 +323,7 @@ watch(nowPlaying, async (newState) => {
320323
// それに合わせてフォーカスするアクセント句を変えていく
321324
const focusAccentPhrase = () => {
322325
const currentTime = store.getters.ACTIVE_AUDIO_ELEM_CURRENT_TIME;
323-
if (currentTime === undefined) {
326+
if (currentTime == undefined) {
324327
throw new Error("currentTime === undefined)");
325328
}
326329
const playingAccentPhraseIndex =
@@ -343,13 +346,13 @@ watch(nowPlaying, async (newState) => {
343346
requestId = window.requestAnimationFrame(focusAccentPhrase);
344347
};
345348
requestId = window.requestAnimationFrame(focusAccentPhrase);
346-
} else if (requestId !== undefined) {
349+
} else if (requestId != undefined) {
347350
window.cancelAnimationFrame(requestId);
348351
requestId = undefined;
349352
// startPointがundefinedの場合、一旦最初のアクセント句までスクロール、その後activePointの選択を解除(undefinedに)する
350353
activePoint.value = startPoint.value ?? 0;
351354
scrollToActivePoint();
352-
if (startPoint.value === undefined) activePoint.value = startPoint.value;
355+
if (startPoint.value == undefined) activePoint.value = startPoint.value;
353356
}
354357
});
355358

src/store/audio.ts

+50-53
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import path from "path";
22
import { v4 as uuidv4 } from "uuid";
33
import Encoding from "encoding-japanese";
4-
import { toRaw } from "vue";
54
import { createUILockAction, withProgress } from "./ui";
65
import {
76
AudioItem,
@@ -26,7 +25,6 @@ import {
2625
sanitizeFileName,
2726
DEFAULT_STYLE_NAME,
2827
formatCharacterStyleName,
29-
joinTextsInAccentPhrases,
3028
TuningTranscription,
3129
} from "./utility";
3230
import { convertAudioQueryFromEditorToEngine } from "./proxy";
@@ -133,7 +131,7 @@ function parseTextFile(
133131
if (lastVoice == undefined) throw new Error(`lastStyle is undefined.`);
134132
for (const splitText of body.split(new RegExp(`${seps.join("|")}`, "g"))) {
135133
const voice = name2Voice.get(splitText);
136-
if (voice !== undefined) {
134+
if (voice != undefined) {
137135
lastVoice = voice;
138136
continue;
139137
}
@@ -413,7 +411,7 @@ export const audioStore = createPartialStore<AudioStoreTypes>({
413411
Object.entries(rawMorphableTargets).map(([key, value]) => {
414412
const isMorphable = (value as unknown as { is_morphable: boolean })
415413
.is_morphable;
416-
if (isMorphable === undefined || typeof isMorphable !== "boolean") {
414+
if (isMorphable == undefined || typeof isMorphable !== "boolean") {
417415
throw Error(
418416
"The is_morphable property does not exist, it is either CamelCase or the engine type is wrong."
419417
);
@@ -457,13 +455,13 @@ export const audioStore = createPartialStore<AudioStoreTypes>({
457455
voice.engineId,
458456
voice.styleId
459457
);
460-
if (characterInfo === undefined)
461-
throw new Error("assert characterInfo !== undefined");
458+
if (characterInfo == undefined)
459+
throw new Error("assert characterInfo != undefined");
462460

463461
const style = characterInfo.metas.styles.find(
464462
(style) => style.styleId === voice.styleId
465463
);
466-
if (style === undefined) throw new Error("assert style !== undefined");
464+
if (style == undefined) throw new Error("assert style != undefined");
467465

468466
const speakerName = characterInfo.metas.speakerName;
469467
const styleName = style.styleName;
@@ -699,7 +697,7 @@ export const audioStore = createPartialStore<AudioStoreTypes>({
699697
}
700698
) {
701699
const index =
702-
prevAudioKey !== undefined
700+
prevAudioKey != undefined
703701
? state.audioKeys.indexOf(prevAudioKey) + 1
704702
: state.audioKeys.length;
705703
state.audioKeys.splice(index, 0, audioKey);
@@ -722,7 +720,7 @@ export const audioStore = createPartialStore<AudioStoreTypes>({
722720
}
723721
) {
724722
const index =
725-
prevAudioKey !== undefined
723+
prevAudioKey != undefined
726724
? state.audioKeys.indexOf(prevAudioKey) + 1
727725
: state.audioKeys.length;
728726
const audioKeys = audioKeyItemPairs.map((pair) => pair.audioKey);
@@ -1043,7 +1041,7 @@ export const audioStore = createPartialStore<AudioStoreTypes>({
10431041
break;
10441042
case "pause": {
10451043
const pauseMora = query.accentPhrases[accentPhraseIndex].pauseMora;
1046-
if (pauseMora !== undefined && pauseMora !== null) {
1044+
if (pauseMora != undefined) {
10471045
pauseMora.vowelLength = data;
10481046
}
10491047
break;
@@ -1169,13 +1167,13 @@ export const audioStore = createPartialStore<AudioStoreTypes>({
11691167
audioItem.voice.engineId,
11701168
audioItem.voice.styleId
11711169
);
1172-
if (character === undefined)
1173-
throw new Error("assert character !== undefined");
1170+
if (character == undefined)
1171+
throw new Error("assert character != undefined");
11741172

11751173
const style = character.metas.styles.find(
11761174
(style) => style.styleId === audioItem.voice.styleId
11771175
);
1178-
if (style === undefined) throw new Error("assert style !== undefined");
1176+
if (style == undefined) throw new Error("assert style != undefined");
11791177

11801178
const styleName = style.styleName || DEFAULT_STYLE_NAME;
11811179
return buildAudioFileNameFromRawData(fileNamePattern, {
@@ -1199,7 +1197,7 @@ export const audioStore = createPartialStore<AudioStoreTypes>({
11991197
const speedScale = query.speedScale;
12001198

12011199
let labString = "";
1202-
let timestamp = offset !== undefined ? offset : 0;
1200+
let timestamp = offset != undefined ? offset : 0;
12031201

12041202
labString += timestamp.toFixed() + " ";
12051203
timestamp += (query.prePhonemeLength * 10000000) / speedScale;
@@ -1209,8 +1207,8 @@ export const audioStore = createPartialStore<AudioStoreTypes>({
12091207
query.accentPhrases.forEach((accentPhrase) => {
12101208
accentPhrase.moras.forEach((mora) => {
12111209
if (
1212-
mora.consonantLength !== undefined &&
1213-
mora.consonant !== undefined
1210+
mora.consonantLength != undefined &&
1211+
mora.consonant != undefined
12141212
) {
12151213
labString += timestamp.toFixed() + " ";
12161214
timestamp += (mora.consonantLength * 10000000) / speedScale;
@@ -1226,10 +1224,7 @@ export const audioStore = createPartialStore<AudioStoreTypes>({
12261224
labString += mora.vowel + "\n";
12271225
}
12281226
});
1229-
if (
1230-
accentPhrase.pauseMora !== undefined &&
1231-
accentPhrase.pauseMora !== null
1232-
) {
1227+
if (accentPhrase.pauseMora != undefined) {
12331228
labString += timestamp.toFixed() + " ";
12341229
timestamp +=
12351230
(accentPhrase.pauseMora.vowelLength * 10000000) / speedScale;
@@ -1252,8 +1247,8 @@ export const audioStore = createPartialStore<AudioStoreTypes>({
12521247
action({ state }, { audioKey }: { audioKey: AudioKey }) {
12531248
const query = state.audioItems[audioKey].query;
12541249
const accentPhrases = query?.accentPhrases;
1255-
if (query === undefined || accentPhrases === undefined)
1256-
throw Error("query === undefined or accentPhrases === undefined");
1250+
if (query == undefined || accentPhrases == undefined)
1251+
throw Error("query == undefined or accentPhrases == undefined");
12571252

12581253
const offsets: number[] = [];
12591254
let length = 0;
@@ -1263,7 +1258,7 @@ export const audioStore = createPartialStore<AudioStoreTypes>({
12631258
let i = 0;
12641259
for (const phrase of accentPhrases) {
12651260
phrase.moras.forEach((m) => {
1266-
length += m.consonantLength !== undefined ? m.consonantLength : 0;
1261+
length += m.consonantLength != undefined ? m.consonantLength : 0;
12671262
length += m.vowelLength;
12681263
});
12691264
length += phrase.pauseMora ? phrase.pauseMora.vowelLength : 0;
@@ -1347,7 +1342,7 @@ export const audioStore = createPartialStore<AudioStoreTypes>({
13471342
{ encodedBlobs }: { encodedBlobs: string[] }
13481343
) => {
13491344
const engineId: EngineId | undefined = state.engineIds[0]; // TODO: 複数エンジン対応, 暫定的に音声結合機能は0番目のエンジンのみを使用する
1350-
if (engineId === undefined)
1345+
if (engineId == undefined)
13511346
throw new Error(`No such engine registered: index == 0`);
13521347

13531348
return dispatch("INSTANTIATE_ENGINE_CONNECTOR", {
@@ -1432,7 +1427,7 @@ export const audioStore = createPartialStore<AudioStoreTypes>({
14321427

14331428
if (state.savingSetting.exportLab) {
14341429
const labString = await dispatch("GENERATE_LAB", { audioKey });
1435-
if (labString === undefined)
1430+
if (labString == undefined)
14361431
return {
14371432
result: "WRITE_ERROR",
14381433
path: filePath,
@@ -1790,7 +1785,7 @@ export const audioStore = createPartialStore<AudioStoreTypes>({
17901785
throw new Error("accentPhraseOffsets.length === 0");
17911786
const startTime =
17921787
accentPhraseOffsets[getters.AUDIO_PLAY_START_POINT ?? 0];
1793-
if (startTime === undefined) throw Error("startTime === undefined");
1788+
if (startTime == undefined) throw Error("startTime == undefined");
17941789
// 小さい値が切り捨てられることでフォーカスされるアクセントフレーズが一瞬元に戻るので、
17951790
// 再生に影響のない程度かつ切り捨てられない値を加算する
17961791
offset = startTime + 10e-6;
@@ -1809,7 +1804,7 @@ export const audioStore = createPartialStore<AudioStoreTypes>({
18091804
presetKey,
18101805
}: { audioKey: AudioKey; presetKey: PresetKey | undefined }
18111806
) {
1812-
if (presetKey === undefined) {
1807+
if (presetKey == undefined) {
18131808
delete state.audioItems[audioKey].presetKey;
18141809
} else {
18151810
state.audioItems[audioKey].presetKey = presetKey;
@@ -1823,7 +1818,7 @@ export const audioStore = createPartialStore<AudioStoreTypes>({
18231818
const currentAudioPlayStartPoint = getters.AUDIO_PLAY_START_POINT;
18241819

18251820
let index = 0;
1826-
if (currentAudioKey !== undefined) {
1821+
if (currentAudioKey != undefined) {
18271822
index = state.audioKeys.findIndex((v) => v === currentAudioKey);
18281823
}
18291824

@@ -1954,7 +1949,7 @@ export const audioCommandStore = transformCommandStore(
19541949
const skippedText = extractYomiText(text);
19551950

19561951
try {
1957-
if (query !== undefined) {
1952+
if (query != undefined) {
19581953
const accentPhrases: AccentPhrase[] = await dispatch(
19591954
"FETCH_ACCENT_PHRASES",
19601955
{
@@ -2083,7 +2078,7 @@ export const audioCommandStore = transformCommandStore(
20832078
audioKeys.map(async (audioKey) => {
20842079
try {
20852080
const query = state.audioItems[audioKey].query;
2086-
if (query !== undefined) {
2081+
if (query != undefined) {
20872082
const accentPhrases = query.accentPhrases;
20882083
const newAccentPhrases: AccentPhrase[] = await dispatch(
20892084
"FETCH_MORA_DATA",
@@ -2148,7 +2143,7 @@ export const audioCommandStore = transformCommandStore(
21482143
}: { audioKey: AudioKey; accentPhraseIndex: number; accent: number }
21492144
) {
21502145
const query = state.audioItems[audioKey].query;
2151-
if (query !== undefined) {
2146+
if (query != undefined) {
21522147
const newAccentPhrases: AccentPhrase[] = JSON.parse(
21532148
JSON.stringify(query.accentPhrases)
21542149
);
@@ -2206,7 +2201,7 @@ export const audioCommandStore = transformCommandStore(
22062201
const engineId = state.audioItems[audioKey].voice.engineId;
22072202
const styleId = state.audioItems[audioKey].voice.styleId;
22082203

2209-
if (query === undefined) {
2204+
if (query == undefined) {
22102205
throw Error(
22112206
"`COMMAND_CHANGE_ACCENT_PHRASE_SPLIT` should not be called if the query does not exist."
22122207
);
@@ -2405,7 +2400,7 @@ export const audioCommandStore = transformCommandStore(
24052400
if (popUntilPause) {
24062401
while (
24072402
newAccentPhrasesSegment[newAccentPhrasesSegment.length - 1]
2408-
.pauseMora === undefined
2403+
.pauseMora == undefined
24092404
) {
24102405
newAccentPhrasesSegment.pop();
24112406
}
@@ -2451,24 +2446,26 @@ export const audioCommandStore = transformCommandStore(
24512446
},
24522447
},
24532448

2454-
COMMAND_RESET_MORA_PITCH_AND_LENGTH: {
2455-
async action({ state, dispatch, commit }, { audioKey }) {
2456-
const engineId = state.audioItems[audioKey].voice.engineId;
2457-
const styleId = state.audioItems[audioKey].voice.styleId;
2449+
COMMAND_MULTI_RESET_MORA_PITCH_AND_LENGTH: {
2450+
async action({ state, dispatch, commit }, { audioKeys }) {
2451+
for (const audioKey of audioKeys) {
2452+
const engineId = state.audioItems[audioKey].voice.engineId;
2453+
const styleId = state.audioItems[audioKey].voice.styleId;
24582454

2459-
const query = state.audioItems[audioKey].query;
2460-
if (query === undefined) throw new Error("assert query !== undefined");
2455+
const query = state.audioItems[audioKey].query;
2456+
if (query == undefined) throw new Error("assert query != undefined");
24612457

2462-
const newAccentPhrases = await dispatch("FETCH_MORA_DATA", {
2463-
accentPhrases: query.accentPhrases,
2464-
engineId,
2465-
styleId,
2466-
});
2458+
const newAccentPhrases = await dispatch("FETCH_MORA_DATA", {
2459+
accentPhrases: query.accentPhrases,
2460+
engineId,
2461+
styleId,
2462+
});
24672463

2468-
commit("COMMAND_CHANGE_ACCENT", {
2469-
audioKey,
2470-
accentPhrases: newAccentPhrases,
2471-
});
2464+
commit("COMMAND_CHANGE_ACCENT", {
2465+
audioKey,
2466+
accentPhrases: newAccentPhrases,
2467+
});
2468+
}
24722469
},
24732470
},
24742471

@@ -2541,8 +2538,8 @@ export const audioCommandStore = transformCommandStore(
25412538
const minMoraLength = 0;
25422539
const { audioKey, accentPhraseIndex, moraIndex, data, type } = payload;
25432540
const audioItem = draft.audioItems[audioKey];
2544-
if (audioItem.query === undefined) {
2545-
throw Error("draft.audioItems[audioKey].query === undefined");
2541+
if (audioItem.query == undefined) {
2542+
throw Error("draft.audioItems[audioKey].query == undefined");
25462543
}
25472544
const accentPhrase = audioItem.query.accentPhrases[accentPhraseIndex];
25482545
const targetMora = accentPhrase.moras[moraIndex];
@@ -2553,7 +2550,7 @@ export const audioCommandStore = transformCommandStore(
25532550
diffData -= targetMora.pitch;
25542551
break;
25552552
case "consonant":
2556-
if (targetMora.consonantLength !== undefined) {
2553+
if (targetMora.consonantLength != undefined) {
25572554
diffData -= targetMora.consonantLength;
25582555
}
25592556
break;
@@ -2581,7 +2578,7 @@ export const audioCommandStore = transformCommandStore(
25812578
break;
25822579
case "consonant":
25832580
case "vowel":
2584-
if (mora.consonantLength !== undefined) {
2581+
if (mora.consonantLength != undefined) {
25852582
audioStore.mutations.SET_AUDIO_MORA_DATA(draft, {
25862583
audioKey,
25872584
accentPhraseIndex,
@@ -2843,7 +2840,7 @@ export const audioCommandStore = transformCommandStore(
28432840
}
28442841
const audioItems: AudioItem[] = [];
28452842
let baseAudioItem: AudioItem | undefined = undefined;
2846-
if (state._activeAudioKey !== undefined) {
2843+
if (state._activeAudioKey != undefined) {
28472844
baseAudioItem = state.audioItems[state._activeAudioKey];
28482845
}
28492846

src/store/type.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -549,8 +549,8 @@ export type AudioCommandStoreTypes = {
549549
}): void;
550550
};
551551

552-
COMMAND_RESET_MORA_PITCH_AND_LENGTH: {
553-
action(payload: { audioKey: AudioKey }): void;
552+
COMMAND_MULTI_RESET_MORA_PITCH_AND_LENGTH: {
553+
action(payload: { audioKeys: AudioKey[] }): void;
554554
};
555555

556556
COMMAND_RESET_SELECTED_MORA_PITCH_AND_LENGTH: {

0 commit comments

Comments
 (0)