Skip to content

Commit

Permalink
chore: exportをやめる
Browse files Browse the repository at this point in the history
  • Loading branch information
sevenc-nanashi committed Feb 15, 2025
1 parent 1c769a0 commit 9651239
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 10 deletions.
25 changes: 17 additions & 8 deletions src/backend/vst/vstPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ import {
AllMutations,
Phrase,
PhraseKey,
SingingVoice,
SingingVoiceKey,
State,
} from "@/store/type";
import { secondToTick, tickToSecond } from "@/sing/domain";
import { phraseSingingVoices, singingVoiceCache } from "@/store/singing";
import onetimeWatch from "@/helpers/onetimeWatch";
import { createLogger } from "@/helpers/log";
import { getOrThrow } from "@/helpers/mapHelper";
Expand Down Expand Up @@ -185,12 +185,19 @@ export const vstPlugin: Plugin = {
// キャッシュされた歌声を読み込む
log.info("Loading cached voices");
const encodedVoices = await getVoices();
for (const [key, encodedVoice] of Object.entries(encodedVoices)) {
singingVoiceCache.set(
SingingVoiceKey(key),
new Blob([await toBytes(encodedVoice)]),
);
}
await store.actions.LOAD_SINGING_VOICE_CACHE({
cache: new Map(
await Promise.all(
Object.entries(encodedVoices).map(
async ([key, encodedVoice]) =>
[
SingingVoiceKey(key),
new Blob([await toBytes(encodedVoice)]),
] satisfies [SingingVoiceKey, SingingVoice],
),
),
),
});

log.info(`Loaded ${Object.keys(encodedVoices).length} voices`);

Expand Down Expand Up @@ -238,7 +245,9 @@ export const vstPlugin: Plugin = {
log.info(`Missing ${missingVoices.length} voices`);
const voices: Record<SingingVoiceKey, string> = {};
for (const voice of missingVoices) {
const cachedVoice = phraseSingingVoices.get(voice);
const cachedVoice = await store.actions.GET_SINGING_VOICE({
key: voice,
});
if (cachedVoice) {
voices[voice] = await toBase64(
new Uint8Array(await cachedVoice.arrayBuffer()),
Expand Down
18 changes: 16 additions & 2 deletions src/store/singing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -535,14 +535,14 @@ if (window.AudioContext) {
}

const playheadPosition = ref(0); // 単位はtick
export const phraseSingingVoices = new Map<SingingVoiceKey, SingingVoice>();
const phraseSingingVoices = new Map<SingingVoiceKey, SingingVoice>();
const sequences = new Map<SequenceId, Sequence & { trackId: TrackId }>();
const animationTimer = new AnimationTimer();

const queryCache = new Map<EditorFrameAudioQueryKey, EditorFrameAudioQuery>();
const singingPitchCache = new Map<SingingPitchKey, SingingPitch>();
const singingVolumeCache = new Map<SingingVolumeKey, SingingVolume>();
export const singingVoiceCache = new Map<SingingVoiceKey, SingingVoice>();
const singingVoiceCache = new Map<SingingVoiceKey, SingingVoice>();

const initialTrackId = TrackId(uuid4());

Expand Down Expand Up @@ -3542,6 +3542,20 @@ export const singingStore = createPartialStore<SingingStoreTypes>({
},
),
},

LOAD_SINGING_VOICE_CACHE: {
action(_, { cache }) {
for (const [key, value] of cache.entries()) {
singingVoiceCache.set(key, value);
}
},
},

GET_SINGING_VOICE: {
action(_, { key }) {
return singingVoiceCache.get(key);
},
},
});

export const singingCommandStoreState: SingingCommandStoreState = {};
Expand Down
8 changes: 8 additions & 0 deletions src/store/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1386,6 +1386,14 @@ export type SingingStoreTypes = {
fileTypeLabel: string;
}): Promise<SaveResultObject>;
};

LOAD_SINGING_VOICE_CACHE: {
action(payload: { cache: Map<SingingVoiceKey, SingingVoice> }): void;
};

GET_SINGING_VOICE: {
action(payload: { key: SingingVoiceKey }): SingingVoice | undefined;
};
};

export type SingingCommandStoreState = {
Expand Down

0 comments on commit 9651239

Please sign in to comment.