Composition Option: Only Auto Play Generated Content

This commit is contained in:
josc146 2023-12-14 22:06:39 +08:00
parent f7494b0cfb
commit 2a7d22dab1
5 changed files with 29 additions and 5 deletions

View File

@ -320,5 +320,6 @@
"Play With External Player": "外部プレーヤーで再生",
"Core API URL": "コアAPI URL",
"Override core API URL(/chat/completions and /completions). If you don't know what this is, leave it blank.": "コアAPI URLを上書きします(/chat/completions と /completions)。何であるかわからない場合は空白のままにしてください。",
"Please change Strategy to CPU (rwkv.cpp) to use ggml format": "StrategyをCPU (rwkv.cpp)に変更して、ggml形式を使用してください"
"Please change Strategy to CPU (rwkv.cpp) to use ggml format": "StrategyをCPU (rwkv.cpp)に変更して、ggml形式を使用してください",
"Only Auto Play Generated Content": "生成されたコンテンツのみ自動再生"
}

View File

@ -320,5 +320,6 @@
"Play With External Player": "使用外部播放器播放",
"Core API URL": "核心 API URL",
"Override core API URL(/chat/completions and /completions). If you don't know what this is, leave it blank.": "覆盖核心的 API URL (/chat/completions 和 /completions)。如果你不知道这是什么,请留空",
"Please change Strategy to CPU (rwkv.cpp) to use ggml format": "请将Strategy改为CPU (rwkv.cpp)以使用ggml格式"
"Please change Strategy to CPU (rwkv.cpp) to use ggml format": "请将Strategy改为CPU (rwkv.cpp)以使用ggml格式",
"Only Auto Play Generated Content": "仅自动播放新生成的内容"
}

View File

@ -152,10 +152,14 @@ const CompositionPanel: FC = observer(() => {
if (autoPlay) {
if (commonStore.compositionParams.externalPlay)
externalPlayListener();
else
else {
if (commonStore.compositionParams.playOnlyGeneratedContent && playerRef.current) {
playerRef.current.currentTime = Math.max(commonStore.compositionParams.generationStartTime - 1, 0);
}
setTimeout(() => {
playerRef.current?.start();
});
}
}
});
});
@ -314,6 +318,14 @@ const CompositionPanel: FC = observer(() => {
autoPlay: data.checked as boolean
});
}} />
<Checkbox className="select-none"
size="large" label={t('Only Auto Play Generated Content')} checked={params.playOnlyGeneratedContent}
onChange={async (_, data) => {
setParams({
autoPlay: data.checked as boolean || commonStore.compositionParams.autoPlay,
playOnlyGeneratedContent: data.checked as boolean
});
}} />
<Labeled flex breakline label={t('MIDI Input')}
desc={t('Select the MIDI input device to be used.')}
content={
@ -359,6 +371,9 @@ const CompositionPanel: FC = observer(() => {
contentText={t('Are you sure you want to reset this page? It cannot be undone.')}
onConfirm={() => {
commonStore.setCompositionSubmittedPrompt(defaultCompositionPrompt);
setParams({
generationStartTime: 0
});
setPrompt(defaultCompositionPrompt);
}} />
<Button className="grow" appearance="primary" onClick={() => {
@ -368,6 +383,9 @@ const CompositionPanel: FC = observer(() => {
generateNs(params.autoPlay);
} else {
commonStore.setCompositionGenerating(true);
setParams({
generationStartTime: playerRef.current ? playerRef.current.duration : 0
});
onSubmit(params.prompt);
}
}}>{!commonStore.compositionGenerating ? t('Generate') : t('Stop')}</Button>

View File

@ -96,7 +96,9 @@ class CommonStore {
useLocalSoundFont: false,
externalPlay: false,
midi: null,
ns: null
ns: null,
generationStartTime: 0,
playOnlyGeneratedContent: true
};
compositionGenerating: boolean = false;
compositionSubmittedPrompt: string = defaultCompositionPrompt;

View File

@ -11,7 +11,9 @@ export type CompositionParams = {
useLocalSoundFont: boolean,
externalPlay: boolean,
midi: ArrayBuffer | null,
ns: NoteSequence | null
ns: NoteSequence | null,
generationStartTime: number,
playOnlyGeneratedContent: boolean,
}
export type Track = {
id: string;