use of com.helospark.tactview.core.timeline.TimelineClip in project tactview by helospark.
the class ClipInsertCommand method moveBackClipsBehind.
private TimelinePosition moveBackClipsBehind(TimelinePosition positionToInsertTo, List<Integer> channelIndices, TimelinePosition distanceToMove, boolean moveBackward, TimelineInterval combinedInterval) {
TreeSet<TimelineClip> clipsToMoveBack = new TreeSet<>();
if (timelineEditMode.equals(TimelineEditMode.SINGLE_CHANNEL_RIPPLE)) {
clipsToMoveBack = timelineManager.findClipsRightFromPositionAndOnChannelIgnoring(positionToInsertTo, channelIndices, List.of());
} else if (timelineEditMode.equals(TimelineEditMode.ALL_CHANNEL_RIPPLE)) {
clipsToMoveBack = timelineManager.findClipsRightFromPositionAndOnChannelIgnoring(positionToInsertTo, timelineManager.getAllChannelIndices(), List.of());
} else {
if (moveBackward) {
TreeSet<TimelineClip> clipsRightOf = timelineManager.findClipsRightFromPositionAndOnChannelIgnoring(positionToInsertTo, channelIndices, clipIdsToInsert);
TreeSet<TimelineClip> clipsLeftOf = timelineManager.findClipLeftOfPositionIncludingPartialOnChannels(combinedInterval.getStartPosition(), channelIndices, clipIdsToInsert);
clipsRightOf.retainAll(clipsLeftOf);
clipsToMoveBack = clipsRightOf;
} else {
TreeSet<TimelineClip> clipsRightOf = timelineManager.findClipsRightFromPositionAndOnChannelIgnoring(combinedInterval.getEndPosition(), channelIndices, clipIdsToInsert);
TreeSet<TimelineClip> clipsLeftOf = timelineManager.findClipLeftOfPositionOnChannels(positionToInsertTo.add(insertInPlace.getInterval().getLength()), channelIndices, clipIdsToInsert);
clipsRightOf.retainAll(clipsLeftOf);
clipsToMoveBack = clipsRightOf;
}
}
if (clipsToMoveBack.size() > 0) {
TimelineClip firstClipToMove = clipsToMoveBack.stream().findFirst().get();
MoveClipRequest moveClipRequest = MoveClipRequest.builder().withAdditionalClipIds(clipsToMoveBack.stream().map(a -> a.getId()).collect(Collectors.toList())).withAdditionalSpecialPositions(List.of()).withClipId(firstClipToMove.getId()).withEnableJumpingToSpecialPosition(false).withMoreMoveExpected(false).withNewChannelId(timelineManager.findChannelForClipId(firstClipToMove.getId()).get().getId()).withNewPosition(firstClipToMove.getInterval().getStartPosition().add(distanceToMove)).build();
timelineManager.moveClip(moveClipRequest);
}
if (moveBackward || clipsToMoveBack.size() == 0) {
return positionToInsertTo;
} else {
return findCombinedInterval(new ArrayList<>(clipsToMoveBack)).getEndPosition();
}
}
use of com.helospark.tactview.core.timeline.TimelineClip in project tactview by helospark.
the class ClipResizedCommand method revert.
@Override
public void revert() {
boolean isAnyRippleModeEnabled = !timelineEditMode.equals(TimelineEditMode.NORMAL);
TimelinePosition lengthToJumpToUse = lengthToJump;
for (var clipId : clipIds) {
TimelineClip clip = timelineManager.findClipById(clipId).orElseThrow(() -> new IllegalArgumentException("No clip found"));
TimelinePosition previousPosition = originalPosition;
boolean wasLeftRipple = left && isAnyRippleModeEnabled;
TimelinePosition positionToUse = previousPosition;
if (wasLeftRipple) {
TimelineLength intervalSizeDiff = clip.getGlobalInterval().getLength().subtract(originalInterval.getLength());
positionToUse = positionToUse.add(intervalSizeDiff.toPosition());
lengthToJumpToUse = intervalSizeDiff.toPosition().negate();
} else {
lengthToJumpToUse = originalInterval.getEndPosition().subtract(clip.getInterval().getEndPosition());
}
ResizeClipRequest request = ResizeClipRequest.builder().withClip(clip).withLeft(left).withUseSpecialPoints(false).withPosition(positionToUse).withKeepLeftSideOfClipAtSamePlace(wasLeftRipple).withIgnoreIntersection(clipsToMove.stream().map(a -> a.clip).collect(Collectors.toList())).build();
timelineManager.resizeClip(request);
}
if (clipsToMove.size() > 0) {
TimelineClip firstClipToMove = clipsToMove.stream().findFirst().get().clip;
MoveClipRequest moveClipRequest = MoveClipRequest.builder().withAdditionalClipIds(clipsToMove.stream().map(a -> a.clip.getId()).collect(Collectors.toList())).withAdditionalSpecialPositions(List.of()).withClipId(firstClipToMove.getId()).withEnableJumpingToSpecialPosition(false).withMoreMoveExpected(false).withNewChannelId(timelineManager.findChannelForClipId(firstClipToMove.getId()).get().getId()).withNewPosition(firstClipToMove.getInterval().getStartPosition().add(lengthToJumpToUse)).build();
timelineManager.moveClip(moveClipRequest);
}
}
use of com.helospark.tactview.core.timeline.TimelineClip in project tactview by helospark.
the class ClipToLeftCommand method execute.
@Override
public void execute() {
TimelineClip clip = timelineManager.findClipById(clipId).get();
previousPosition = clip.getInterval().getStartPosition();
originalChannelId = timelineManager.findChannelForClipId(clipId).get().getId();
Optional<TimelineClip> firstClipToLeft = timelineManager.findFirstClipToLeft(clipId);
TimelinePosition positionToMoveTo = firstClipToLeft.map(a -> a.getInterval().getEndPosition()).orElse(TimelinePosition.ofZero());
MoveClipRequest request = MoveClipRequest.builder().withClipId(clipId).withAdditionalClipIds(additionalClipIds).withNewPosition(positionToMoveTo).withNewChannelId(originalChannelId).withMoreMoveExpected(false).withEnableJumpingToSpecialPosition(false).build();
wasOperationSuccessful = timelineManager.moveClip(request);
}
use of com.helospark.tactview.core.timeline.TimelineClip in project tactview by helospark.
the class RemoveGapCommand method execute.
@Override
public void execute() {
List<String> excludedClips = List.of();
if (timelineEditMode.equals(TimelineEditMode.ALL_CHANNEL_RIPPLE)) {
clipsToMove = new ArrayList<>(timelineManager.findClipsRightFromPositionIgnoring(position, excludedClips));
} else {
TreeSet<TimelineClip> clipsToRight = timelineManager.findClipsRightFromPositionAndOnChannelIgnoring(position, List.of(channelIndex), excludedClips);
if (clipsToRight.isEmpty()) {
messagingService.sendMessage(new NotificationMessage("No gap at position", "No gap at position", Level.ERROR));
return;
}
TimelineClip clipToMove = clipsToRight.first();
clipsToMove = timelineManager.resolveClipIdsWithAllLinkedClip(List.of(clipToMove.getId()));
if (timelineEditMode.equals(TimelineEditMode.SINGLE_CHANNEL_RIPPLE)) {
List<Integer> channelIds = getChannelsForAllClips(clipsToMove);
Set<TimelineClip> newList = new TreeSet<>((a, b) -> a.getInterval().getStartPosition().compareTo(b.getInterval().getStartPosition()));
newList.addAll(clipsToMove);
newList.addAll(timelineManager.findClipsRightFromPositionAndOnChannelIgnoring(position, channelIds, excludedClips));
clipsToMove = new ArrayList<>(newList);
}
}
List<Integer> channelIds = getChannelsForAllClips(clipsToMove);
Optional<TimelineClip> intersectingClip = channelIds.stream().flatMap(channelId -> timelineManager.getChannels().get(channelId).getDataAt(position).stream()).findFirst();
if (intersectingClip.isPresent()) {
messagingService.sendMessage(new NotificationMessage("No gap at position", "No gap at position", Level.ERROR));
return;
}
jump = calculateRelativeJumpForChannels(excludedClips, channelIds);
if (jump.equals(TimelinePosition.ofZero())) {
messagingService.sendMessage(new NotificationMessage("No gap at position", "No gap at position", Level.ERROR));
return;
}
MoveClipRequest moveClipRequest = MoveClipRequest.builder().withAdditionalClipIds(clipsToMove.stream().map(a -> a.getId()).collect(Collectors.toList())).withAdditionalSpecialPositions(List.of()).withClipId(clipsToMove.get(0).getId()).withEnableJumpingToSpecialPosition(false).withMoreMoveExpected(false).withNewChannelId(timelineManager.findChannelForClipId(clipsToMove.get(0).getId()).get().getId()).withNewPosition(clipsToMove.get(0).getInterval().getStartPosition().subtract(jump)).build();
timelineManager.moveClip(moveClipRequest);
successful = true;
}
use of com.helospark.tactview.core.timeline.TimelineClip in project tactview by helospark.
the class ReplaceTimelineWithSubtimelineCommand method execute.
@Override
public void execute() {
synchronized (timelineManagerAccessor.getFullLock()) {
SubtimelineVisualClip newVideoClip = null;
SubtimelineAudioClip newAudioClip = null;
if (projectRepository.isVideoInitialized()) {
newVideoClip = subtimelineFromTimelineFactory.createSubtimelineVideoClipFromCurrentTimeline(exposedDescriptors);
}
if (projectRepository.isAudioInitialized()) {
newAudioClip = subtimelineFromTimelineFactory.createSubtimelineAudioClipFromCurrentTimeline(exposedDescriptors);
}
for (var id : timelineManagerAccessor.getAllClipIds()) {
TimelineChannel channel = timelineManagerAccessor.findChannelForClipId(id).get();
TimelineClip clip = timelineManagerAccessor.findClipById(id).get().cloneClip(CloneRequestMetadata.fullCopy());
clipsRemoved.add(new ChannelClipPair(channel, clip));
timelineManagerAccessor.removeClip(id);
}
if (newVideoClip != null) {
timelineManagerAccessor.addClip(timelineManagerAccessor.getChannels().get(0), newVideoClip);
addedIds.add(newVideoClip.getId());
}
if (newAudioClip != null) {
timelineManagerAccessor.addClip(timelineManagerAccessor.getChannels().get(1), newAudioClip);
addedIds.add(newAudioClip.getId());
}
if (newVideoClip != null && newAudioClip != null) {
linkClipRepository.linkClip(newVideoClip.getId(), newAudioClip.getId());
}
}
}
Aggregations