use of com.helospark.tactview.core.timeline.VisualTimelineClip 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();
}
use of com.helospark.tactview.core.timeline.VisualTimelineClip in project tactview by helospark.
the class StandardGraphElementFactoryConfiguration method fileClipGraphElementFactory.
@Bean
public GraphElementFactory fileClipGraphElementFactory(List<ClipFactory> clipFactories, ClipFactoryChain clipFactoryChain, MessagingService messagingService) {
return StandardGraphElementFactory.builder().withId("file").withDoesSupport(uri -> uri.startsWith("file://")).withName("File").withCategory(GraphCategory.INPUT).withNeedsInputParam(true).withCreator(graphRequest -> {
AddClipRequest request = AddClipRequest.builder().withAddClipRequestMetadataKey(Map.of()).withPosition(TimelinePosition.ofZero()).withFilePath(graphRequest.uri.replaceFirst("file://", "")).build();
VisualTimelineClip clip = (VisualTimelineClip) clipFactoryChain.createClips(request).get(0);
clip.setInterval(INTERVAL);
messagingService.sendAsyncMessage(new ClipDescriptorsAdded(clip.getId(), clip.getDescriptors(), clip));
return new VisualTimelineClipElement(clip);
}).withRestorer((node, metadata) -> {
node.get("creatorFactoryId").asText();
return new VisualTimelineClipElement(node, metadata, (VisualTimelineClip) clipFactoryChain.restoreClip(node.get("clip"), metadata));
}).build();
}
use of com.helospark.tactview.core.timeline.VisualTimelineClip in project tactview by helospark.
the class ClipAddedListener method initializeProjectOnFirstVideoClipAdded.
private void initializeProjectOnFirstVideoClipAdded(TimelineClip clip) {
if (!projectRepository.isVideoInitialized() && clip instanceof VisualTimelineClip) {
VisualTimelineClip visualClip = (VisualTimelineClip) clip;
VisualMediaMetadata metadata = visualClip.getMediaMetadata();
int width = metadata.getWidth();
int height = metadata.getHeight();
if (metadata instanceof VideoMetadata && visualClip instanceof VideoClip) {
double rotation = ((VideoMetadata) metadata).getRotation();
if (MathUtil.fuzzyEquals(Math.abs(rotation), 90.0) && ((VideoClip) visualClip).isRotationEnabledAt(TimelinePosition.ofZero())) {
int tmp = width;
width = height;
height = tmp;
}
}
BigDecimal fps = metadata instanceof VideoMetadata ? new BigDecimal(((VideoMetadata) metadata).getFps()) : new BigDecimal("30");
projectSizeInitializer.initializeProjectSize(width, height, fps);
}
if (!projectRepository.isAudioInitialized() && clip instanceof AudibleTimelineClip) {
AudibleTimelineClip audioClip = (AudibleTimelineClip) clip;
int sampleRate = audioClip.getMediaMetadata().getSampleRate();
int bytesPerSample = audioClip.getMediaMetadata().getBytesPerSample();
int numberOfChannels = audioClip.getMediaMetadata().getChannels();
projectRepository.initializeAudio(sampleRate, bytesPerSample, numberOfChannels);
}
}
use of com.helospark.tactview.core.timeline.VisualTimelineClip in project tactview by helospark.
the class FrameHoldEffect method createFrame.
@Override
public ReadOnlyClipImage createFrame(StatelessEffectRequest request) {
VisualTimelineClip clip = request.getCurrentTimelineClip();
ReadOnlyClipImage currentFrame = request.getCurrentFrame();
GetFrameRequest frameRequest = GetFrameRequest.builder().withApplyEffects(true).withApplyEffectsLessThanEffectChannel(Optional.of(request.getEffectChannel())).withExpectedWidth(currentFrame.getWidth()).withExpectedHeight(currentFrame.getHeight()).withPosition(getInterval().getStartPosition()).withScale(request.getScale()).build();
ReadOnlyClipImage frame = clip.getFrame(frameRequest);
return frame;
}
use of com.helospark.tactview.core.timeline.VisualTimelineClip in project tactview by helospark.
the class AddScaleCommand method execute.
@Override
public void execute() {
VisualTimelineClip clip = (VisualTimelineClip) timelineManager.findClipById(clipId).orElseThrow();
VisualMediaMetadata metadata = clip.getMediaMetadata();
double scaleX = (double) projectRepository.getWidth() / metadata.getWidth();
double scaleY = (double) projectRepository.getHeight() / metadata.getHeight();
CreateEffectRequest createEffectRequest = new CreateEffectRequest(TimelinePosition.ofZero(), scaleEffectFactory.getEffectId(), TimelineClipType.VIDEO, clip.getInterval());
addedEffect = (ScaleEffect) effectFactoryChain.createEffect(createEffectRequest);
addedEffect.setScale(scaleX, scaleY);
// due to relative position
addedEffect.setInterval(clip.getInterval().butMoveStartPostionTo(TimelinePosition.ofZero()));
timelineManager.addEffectForClip(clip, addedEffect);
}
Aggregations