feat(ui): add mini/advanced controlnet ui

This commit is contained in:
psychedelicious
2023-06-03 15:05:49 +10:00
parent 69f0ba65f1
commit d6c08ba469
18 changed files with 430 additions and 548 deletions

View File

@ -71,7 +71,7 @@ import { addStagingAreaImageSavedListener } from './listeners/stagingAreaImageSa
import { addCommitStagingAreaImageListener } from './listeners/addCommitStagingAreaImageListener';
import { addImageCategoriesChangedListener } from './listeners/imageCategoriesChanged';
import { addControlNetImageProcessedListener } from './listeners/controlNetImageProcessed';
import { addControlNetAutoProcessListener } from './listeners/controlNetProcessorParamsChanged';
import { addControlNetAutoProcessListener } from './listeners/controlNetAutoProcess';
export const listenerMiddleware = createListenerMiddleware();

View File

@ -1,3 +1,4 @@
import { AnyAction } from '@reduxjs/toolkit';
import { startAppListening } from '..';
import { log } from 'app/logging/useLogger';
import { controlNetImageProcessed } from 'features/controlNet/store/actions';
@ -5,10 +6,37 @@ import {
controlNetImageChanged,
controlNetProcessorParamsChanged,
controlNetProcessorTypeChanged,
isControlNetImagePreprocessedToggled,
} from 'features/controlNet/store/controlNetSlice';
import { RootState } from 'app/store/store';
const moduleLog = log.child({ namespace: 'controlNet' });
const predicate = (action: AnyAction, state: RootState) => {
const isActionMatched =
controlNetProcessorParamsChanged.match(action) ||
controlNetImageChanged.match(action) ||
controlNetProcessorTypeChanged.match(action) ||
isControlNetImagePreprocessedToggled.match(action);
if (!isActionMatched) {
return false;
}
const { controlNetId } = action.payload;
const shouldAutoProcess =
!state.controlNet.controlNets[controlNetId].isPreprocessed;
const isBusy = state.system.isProcessing;
const hasControlImage = Boolean(
state.controlNet.controlNets[controlNetId].controlImage
);
return shouldAutoProcess && !isBusy && hasControlImage;
};
/**
* Listener that automatically processes a ControlNet image when its processor parameters are changed.
*
@ -16,35 +44,13 @@ const moduleLog = log.child({ namespace: 'controlNet' });
*/
export const addControlNetAutoProcessListener = () => {
startAppListening({
predicate: (action) =>
controlNetProcessorParamsChanged.match(action) ||
controlNetImageChanged.match(action) ||
controlNetProcessorTypeChanged.match(action),
predicate,
effect: async (
action,
{ dispatch, getState, cancelActiveListeners, delay }
) => {
const state = getState();
if (!state.controlNet.shouldAutoProcess) {
// silently skip
return;
}
if (state.system.isProcessing) {
moduleLog.trace('System busy, skipping ControlNet auto-processing');
return;
}
const { controlNetId } = action.payload;
if (!state.controlNet.controlNets[controlNetId].controlImage) {
moduleLog.trace(
{ data: { controlNetId } },
'No ControlNet image to auto-process'
);
return;
}
// Cancel any in-progress instances of this listener
cancelActiveListeners();