Search in sources :

Example 1 with EffectFactory

use of com.helospark.tactview.core.timeline.effect.EffectFactory in project tactview by helospark.

the class CommonEffectTest method testThatEffectCanBeSavedAndRestored.

@Test
public void testThatEffectCanBeSavedAndRestored() throws IOException {
    LightDiContext lightDi = IntegrationTestUtil.startContext();
    List<EffectFactory> effectFactories = lightDi.getListOfBeans(EffectFactory.class);
    FakeUi fakeUi = lightDi.getBean(FakeUi.class);
    VisualTimelineClip clip = (VisualTimelineClip) fakeUi.dragProceduralClipToFirstChannel("singlecolor", TimelinePosition.ofZero());
    for (var effectFactory : effectFactories) {
        StatelessEffect effect = effectFactory.createEffect(new CreateEffectRequest(TimelinePosition.ofZero(), effectFactory.getEffectId(), TimelineClipType.VIDEO, clip.getInterval()));
        if (!(effect instanceof StatelessVideoEffect)) {
            continue;
        }
        if (!(effect instanceof StatelessVideoEffect) || effectFactory.getEffectId().equals("lensdistort")) /**
         * trello.201, check why this occasionally fails
         */
        {
            continue;
        }
        ReadOnlyClipImage originalFrame = getFrame((StatelessVideoEffect) effect, clip);
        SaveMetadata saveMetadata = new SaveMetadata(false);
        Object savedEffect = effect.generateSavedContent(saveMetadata);
        String saveData = createObjectMapper(saveMetadata).writeValueAsString(savedEffect);
        JsonNode readData = StaticObjectMapper.objectMapper.readTree(saveData);
        StatelessEffect restoredEffect = effectFactory.restoreEffect(readData, new LoadMetadata("filepath", StaticObjectMapper.objectMapper, lightDi));
        ReadOnlyClipImage clonedFrame = getFrame((StatelessVideoEffect) restoredEffect, clip);
        IntegrationTestUtil.assertFrameEquals(originalFrame, clonedFrame, effectFactory.getEffectId() + " is generating different image after save and restore");
        freeFrame(originalFrame);
        freeFrame(clonedFrame);
    }
    lightDi.close();
}
Also used : LightDiContext(com.helospark.lightdi.LightDiContext) StatelessEffect(com.helospark.tactview.core.timeline.StatelessEffect) LoadMetadata(com.helospark.tactview.core.save.LoadMetadata) JsonNode(com.fasterxml.jackson.databind.JsonNode) VisualTimelineClip(com.helospark.tactview.core.timeline.VisualTimelineClip) EffectFactory(com.helospark.tactview.core.timeline.effect.EffectFactory) SaveMetadata(com.helospark.tactview.core.save.SaveMetadata) FakeUi(com.helospark.tactview.core.it.util.ui.FakeUi) ReadOnlyClipImage(com.helospark.tactview.core.timeline.image.ReadOnlyClipImage) StatelessVideoEffect(com.helospark.tactview.core.timeline.StatelessVideoEffect) CreateEffectRequest(com.helospark.tactview.core.timeline.effect.CreateEffectRequest) Test(org.junit.jupiter.api.Test)

Example 2 with EffectFactory

use of com.helospark.tactview.core.timeline.effect.EffectFactory in project tactview by helospark.

the class EffectFactoryChain method createEffect.

public StatelessEffect createEffect(CreateEffectRequest request) {
    EffectFactory factory = findSupportedFactory(request).orElseThrow(() -> new IllegalArgumentException("No factory for " + request));
    StatelessEffect result = factory.createEffect(request);
    result.setFactoryId(factory.getId());
    if (result instanceof LongProcessAware) {
        ((LongProcessAware) result).setLongProcessRequestor(longProcessRequestor);
    }
    if (factory.isFullWidth()) {
        result.setInterval(new TimelineInterval(TimelinePosition.ofZero(), request.getClipInterval().getLength()));
    }
    return result;
}
Also used : LongProcessAware(com.helospark.tactview.core.timeline.longprocess.LongProcessAware) EffectFactory(com.helospark.tactview.core.timeline.effect.EffectFactory)

Example 3 with EffectFactory

use of com.helospark.tactview.core.timeline.effect.EffectFactory in project tactview by helospark.

the class EffectFactoryChain method restoreEffect.

public StatelessEffect restoreEffect(JsonNode node, LoadMetadata loadMetadata) {
    String factoryId = node.get("factoryId").asText();
    EffectFactory factory = context.getListOfBeans(EffectFactory.class).stream().filter(effectFactory -> effectFactory.getId().equals(factoryId)).findFirst().orElseThrow(() -> new IllegalArgumentException("No factory for " + factoryId));
    StatelessEffect result = factory.restoreEffect(node, loadMetadata);
    if (result instanceof LongProcessAware) {
        ((LongProcessAware) result).setLongProcessRequestor(longProcessRequestor);
    }
    return result;
}
Also used : LongProcessAware(com.helospark.tactview.core.timeline.longprocess.LongProcessAware) EffectFactory(com.helospark.tactview.core.timeline.effect.EffectFactory)

Example 4 with EffectFactory

use of com.helospark.tactview.core.timeline.effect.EffectFactory in project tactview by helospark.

the class AbstractEffectTabFactory method fillFlowPane.

@Override
protected void fillFlowPane(FlowPane effectTabContent, String searchData) {
    List<EffectFactory> effects = lightDi.getListOfBeans(EffectFactory.class);
    List<ScoredNodeHolder> icons = new ArrayList<>();
    effects.stream().filter(factory -> factory.getEffectType().equals(effectType)).sorted((a, b) -> a.getEffectName().compareToIgnoreCase(b.getEffectName())).forEach(factory -> {
        Optional<LocalizedDetailDomain> localizedDetail = localizedDetailRepository.queryData(factory.getEffectId());
        int score = getScore(localizedDetail, factory.getId(), factory.getEffectName(), searchData);
        if (score > 0) {
            String iconUri = localizedDetail.flatMap(data -> data.getIconUrl()).orElse(DEFAULT_URI);
            Optional<String> description = localizedDetail.map(a -> a.getDescription());
            VBox icon = iconFactory.createIcon("effect:" + factory.getEffectId(), factory.getEffectName(), iconUri, description);
            icons.add(new ScoredNodeHolder(icon, score));
        }
    });
    effectTabContent.getChildren().clear();
    icons.stream().sorted().forEach(entry -> {
        effectTabContent.getChildren().add(entry.node);
    });
}
Also used : LocalizedDetailRepositoryChain(com.helospark.tactview.ui.javafx.uicomponents.detailsdata.localizeddetail.LocalizedDetailRepositoryChain) List(java.util.List) EffectFactory(com.helospark.tactview.core.timeline.effect.EffectFactory) FlowPane(javafx.scene.layout.FlowPane) TimelineEffectType(com.helospark.tactview.core.timeline.effect.TimelineEffectType) Optional(java.util.Optional) VBox(javafx.scene.layout.VBox) LightDiContext(com.helospark.lightdi.LightDiContext) ArrayList(java.util.ArrayList) LocalizedDetailDomain(com.helospark.tactview.ui.javafx.uicomponents.detailsdata.localizeddetail.LocalizedDetailDomain) LocalizedDetailDomain(com.helospark.tactview.ui.javafx.uicomponents.detailsdata.localizeddetail.LocalizedDetailDomain) ArrayList(java.util.ArrayList) EffectFactory(com.helospark.tactview.core.timeline.effect.EffectFactory) VBox(javafx.scene.layout.VBox)

Example 5 with EffectFactory

use of com.helospark.tactview.core.timeline.effect.EffectFactory in project tactview by helospark.

the class StandardClipContextMenuChainItemConfiguration method scaleToFrameMenuItem.

@Bean
@Order(0)
public ClipContextMenuChainItem scaleToFrameMenuItem(UiCommandInterpreterService commandInterpreter, TimelineManagerAccessor timelineManager, ProjectRepository projectRepository, @Qualifier("scaleEffect") EffectFactory scaleFactory, EffectFactoryChain effectFactoryChain, SelectedNodeRepository selectedNodeRepository) {
    return typeSupportingContextMenuItem(VisualTimelineClip.class, request -> {
        MenuItem scaleToImageMenuItem = new MenuItem("Scale to frame");
        scaleToImageMenuItem.setOnAction(e -> {
            List<AddScaleCommand> commands = request.getAllClips().stream().map(a -> a.getId()).map(clipId -> AddScaleCommand.builder().withClipId(clipId).withProjectRepository(projectRepository).withScaleEffectFactory(scaleFactory).withTimelineManager(timelineManager).withEffectFactoryChain(effectFactoryChain).build()).collect(Collectors.toList());
            if (commands.size() > 0) {
                commandInterpreter.sendWithResult(new CompositeCommand(commands));
            }
        });
        return scaleToImageMenuItem;
    });
}
Also used : EffectFactoryChain(com.helospark.tactview.core.timeline.EffectFactoryChain) Qualifier(com.helospark.lightdi.annotation.Qualifier) AddScaleCommand(com.helospark.tactview.ui.javafx.commands.impl.AddScaleCommand) TimelineEditMode(com.helospark.tactview.ui.javafx.repository.timelineeditmode.TimelineEditMode) MenuItem(javafx.scene.control.MenuItem) SelectedNodeRepository(com.helospark.tactview.ui.javafx.repository.SelectedNodeRepository) UiCommandInterpreterService(com.helospark.tactview.ui.javafx.UiCommandInterpreterService) CompositeCommand(com.helospark.tactview.ui.javafx.commands.impl.CompositeCommand) RemoveEffectCommand(com.helospark.tactview.ui.javafx.commands.impl.RemoveEffectCommand) RemoveClipService(com.helospark.tactview.ui.javafx.RemoveClipService) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) TimelineClip(com.helospark.tactview.core.timeline.TimelineClip) VisualTimelineClip(com.helospark.tactview.core.timeline.VisualTimelineClip) Configuration(com.helospark.lightdi.annotation.Configuration) Order(com.helospark.lightdi.annotation.Order) List(java.util.List) EffectFactory(com.helospark.tactview.core.timeline.effect.EffectFactory) TimelineManagerAccessor(com.helospark.tactview.core.timeline.TimelineManagerAccessor) ProjectRepository(com.helospark.tactview.core.repository.ProjectRepository) CopyPasteRepository(com.helospark.tactview.ui.javafx.repository.CopyPasteRepository) Bean(com.helospark.lightdi.annotation.Bean) MenuItem(javafx.scene.control.MenuItem) AddScaleCommand(com.helospark.tactview.ui.javafx.commands.impl.AddScaleCommand) CompositeCommand(com.helospark.tactview.ui.javafx.commands.impl.CompositeCommand) Order(com.helospark.lightdi.annotation.Order) Bean(com.helospark.lightdi.annotation.Bean)

Aggregations

EffectFactory (com.helospark.tactview.core.timeline.effect.EffectFactory)6 LightDiContext (com.helospark.lightdi.LightDiContext)3 VisualTimelineClip (com.helospark.tactview.core.timeline.VisualTimelineClip)3 FakeUi (com.helospark.tactview.core.it.util.ui.FakeUi)2 StatelessEffect (com.helospark.tactview.core.timeline.StatelessEffect)2 StatelessVideoEffect (com.helospark.tactview.core.timeline.StatelessVideoEffect)2 CreateEffectRequest (com.helospark.tactview.core.timeline.effect.CreateEffectRequest)2 ReadOnlyClipImage (com.helospark.tactview.core.timeline.image.ReadOnlyClipImage)2 LongProcessAware (com.helospark.tactview.core.timeline.longprocess.LongProcessAware)2 List (java.util.List)2 Test (org.junit.jupiter.api.Test)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Bean (com.helospark.lightdi.annotation.Bean)1 Configuration (com.helospark.lightdi.annotation.Configuration)1 Order (com.helospark.lightdi.annotation.Order)1 Qualifier (com.helospark.lightdi.annotation.Qualifier)1 ProjectRepository (com.helospark.tactview.core.repository.ProjectRepository)1 LoadMetadata (com.helospark.tactview.core.save.LoadMetadata)1 SaveMetadata (com.helospark.tactview.core.save.SaveMetadata)1 EffectFactoryChain (com.helospark.tactview.core.timeline.EffectFactoryChain)1