Add timeout to pause player
This commit is contained in:
parent
92ec5271fd
commit
f65fe1c864
|
@ -50,8 +50,14 @@ export default function Home() {
|
||||||
|
|
||||||
// Settings
|
// Settings
|
||||||
const [denoising, setDenoising] = useState(0.75);
|
const [denoising, setDenoising] = useState(0.75);
|
||||||
const [seedImageId, setSeedImageId] = useState(initialSeeds[Math.floor(Math.random() * initialSeeds.length)]);
|
const [seedImageId, setSeedImageId] = useState(
|
||||||
const [seed, setSeed] = useState(initialSeedImageMap[seedImageId][Math.floor(Math.random() * initialSeedImageMap[seedImageId].length)]);
|
initialSeeds[Math.floor(Math.random() * initialSeeds.length)]
|
||||||
|
);
|
||||||
|
const [seed, setSeed] = useState(
|
||||||
|
initialSeedImageMap[seedImageId][
|
||||||
|
Math.floor(Math.random() * initialSeedImageMap[seedImageId].length)
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
// Prompts shown on screen and maintained by the prompt panel
|
// Prompts shown on screen and maintained by the prompt panel
|
||||||
const [promptInputs, setPromptInputs] = useState<PromptInput[]>([]);
|
const [promptInputs, setPromptInputs] = useState<PromptInput[]>([]);
|
||||||
|
@ -195,40 +201,66 @@ export default function Home() {
|
||||||
[alpha, alphaVelocity]
|
[alpha, alphaVelocity]
|
||||||
);
|
);
|
||||||
|
|
||||||
const nowPlayingCallback = (result: InferenceResult, playerTime: number) => {
|
// State to handle the timeout for the player to not hog GPU forever. If you are
|
||||||
console.log(
|
// in SAME_PROMPT for this long, it will pause the player and bring up an alert.
|
||||||
"Now playing result ",
|
const timeoutIncrement = 600.0;
|
||||||
result.counter,
|
const [timeoutPlayerTime, setTimeoutPlayerTime] = useState(timeoutIncrement);
|
||||||
", player time is ",
|
|
||||||
playerTime
|
|
||||||
);
|
|
||||||
|
|
||||||
setNowPlayingResult(result);
|
const nowPlayingCallback = useCallback(
|
||||||
|
(result: InferenceResult, playerTime: number) => {
|
||||||
// find the first promptInput that matches the result.input.end.prompt and set it's transitionCounter to the result.counter if not already set
|
console.log(
|
||||||
setPromptInputs((prevPromptInputs) => {
|
"Now playing result ",
|
||||||
const newPromptInputs = [...prevPromptInputs];
|
result.counter,
|
||||||
const promptInputIndex = newPromptInputs.findIndex(
|
", player time is ",
|
||||||
(p) => p.prompt == result.input.end.prompt
|
playerTime
|
||||||
);
|
);
|
||||||
if (promptInputIndex >= 0) {
|
|
||||||
if (newPromptInputs[promptInputIndex].transitionCounter == null) {
|
|
||||||
newPromptInputs[promptInputIndex].transitionCounter = result.counter;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return newPromptInputs;
|
|
||||||
});
|
|
||||||
|
|
||||||
// set played state for the result to true
|
setNowPlayingResult(result);
|
||||||
setInferenceResults((prevResults: InferenceResult[]) => {
|
|
||||||
return prevResults.map((r) => {
|
// find the first promptInput that matches the result.input.end.prompt and set it's transitionCounter to the result.counter if not already set
|
||||||
if (r.counter == result.counter) {
|
setPromptInputs((prevPromptInputs) => {
|
||||||
r.played = true;
|
const newPromptInputs = [...prevPromptInputs];
|
||||||
|
const promptInputIndex = newPromptInputs.findIndex(
|
||||||
|
(p) => p.prompt == result.input.end.prompt
|
||||||
|
);
|
||||||
|
if (promptInputIndex >= 0) {
|
||||||
|
if (newPromptInputs[promptInputIndex].transitionCounter == null) {
|
||||||
|
newPromptInputs[promptInputIndex].transitionCounter =
|
||||||
|
result.counter;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return r;
|
return newPromptInputs;
|
||||||
});
|
});
|
||||||
});
|
|
||||||
};
|
// set played state for the result to true
|
||||||
|
setInferenceResults((prevResults: InferenceResult[]) => {
|
||||||
|
return prevResults.map((r) => {
|
||||||
|
if (r.counter == result.counter) {
|
||||||
|
r.played = true;
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Extend the timeout if we're transitioning
|
||||||
|
if (appState == AppState.TRANSITION) {
|
||||||
|
setTimeoutPlayerTime(playerTime + timeoutIncrement);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we've hit the timeout, pause and increment the timeout
|
||||||
|
if (playerTime > timeoutPlayerTime) {
|
||||||
|
setTimeoutPlayerTime(playerTime + timeoutIncrement);
|
||||||
|
setPaused(true);
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
if (confirm("Are you still riffing?")) {
|
||||||
|
setPaused(false);
|
||||||
|
}
|
||||||
|
}, 100);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[timeoutPlayerTime, appState]
|
||||||
|
);
|
||||||
|
|
||||||
// Track from the audio player whether we're behind on having new inference results,
|
// Track from the audio player whether we're behind on having new inference results,
|
||||||
// in order to display an alert.
|
// in order to display an alert.
|
||||||
|
@ -330,10 +362,7 @@ export default function Home() {
|
||||||
resetCallback={resetCallback}
|
resetCallback={resetCallback}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Pause
|
<Pause paused={paused} setPaused={setPaused} />
|
||||||
paused={paused}
|
|
||||||
setPaused={setPaused}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<Share
|
<Share
|
||||||
inferenceResults={inferenceResults}
|
inferenceResults={inferenceResults}
|
||||||
|
|
Loading…
Reference in New Issue