use of com.helospark.tactview.core.timeline.MoveClipRequest in project tactview by helospark.
the class ClipResizedCommand method execute.
@Override
public void execute() {
synchronized (timelineManager.getFullLock()) {
boolean isAnyRippleModeEnabled = !timelineEditMode.equals(TimelineEditMode.NORMAL);
if (isAnyRippleModeEnabled) {
List<Integer> channels;
if (timelineEditMode.equals(TimelineEditMode.SINGLE_CHANNEL_RIPPLE)) {
channels = new ArrayList<>(timelineManager.findChannelIndicesForClips(clipIds));
} else {
channels = timelineManager.getAllChannelIndices();
}
TimelineInterval intervalOfFirstClip = timelineManager.findClipById(clipIds.get(0)).get().getInterval();
TimelinePosition ripplePosition;
if (left) {
ripplePosition = intervalOfFirstClip.getStartPosition();
} else {
ripplePosition = intervalOfFirstClip.getEndPosition();
}
clipsToMove = timelineManager.findClipsRightFromPositionAndOnChannelIgnoring(ripplePosition, channels, clipIds).stream().map(a -> new ClipChannelIdPair(a, timelineManager.findChannelForClipId(a.getId()).get().getId())).collect(Collectors.toSet());
}
TimelinePosition newPosition = null;
for (int i = 0; i < clipIds.size(); ++i) {
String clipId = clipIds.get(i);
TimelineClip clip = timelineManager.findClipById(clipId).orElseThrow(() -> new IllegalArgumentException("No clip found"));
TimelineInterval originalIntervalInternal = clip.getInterval();
List<String> ignoredSuggestions = new ArrayList<>();
ignoredSuggestions.addAll(clipIds);
clipsToMove.stream().map(a -> a.clip.getId()).forEach(a -> ignoredSuggestions.add(a));
TimelinePosition positionToUse;
boolean leftRippleModePositionEnabled = left && isAnyRippleModeEnabled && relativeMove != null;
if (i == 0) {
if (leftRippleModePositionEnabled) {
positionToUse = clip.getInterval().getStartPosition().add(relativeMove);
} else {
positionToUse = position;
}
} else {
positionToUse = newPosition;
}
ResizeClipRequest request = ResizeClipRequest.builder().withClip(clip).withLeft(left).withUseSpecialPoints(i == 0 && useSpecialPoints && !leftRippleModePositionEnabled).withPosition(positionToUse).withMaximumJumpLength(maximumJumpLength).withMoreResizeExpected(moreResizeExpected).withMinimumSize(minimumSize).withIgnoredSpecialSuggestionClips(ignoredSuggestions).withIgnoreIntersection(clipsToMove.stream().map(a -> a.clip).collect(Collectors.toList())).withKeepLeftSideOfClipAtSamePlace(// TODO: it's not ideal that the ripple logic is split between 2 places
leftRippleModePositionEnabled).build();
timelineManager.resizeClip(request);
if (i == 0) {
if (leftRippleModePositionEnabled) {
// No special position enabled, so it's ok
newPosition = positionToUse;
} else {
newPosition = left ? clip.getUnmodifiedInterval().getStartPosition() : clip.getUnmodifiedInterval().getEndPosition();
}
lengthToJump = clip.getInterval().getEndPosition().subtract(originalInterval.getEndPosition());
}
}
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(lengthToJump)).build();
timelineManager.moveClip(moveClipRequest);
}
}
}
use of com.helospark.tactview.core.timeline.MoveClipRequest in project tactview by helospark.
the class ClipToRightCommand method execute.
@Override
public void execute() {
TimelineClip clip = timelineManager.findClipById(clipId).get();
previousPosition = clip.getInterval().getStartPosition();
originalChannelId = timelineManager.findChannelForClipId(clipId).get().getId();
Optional<TimelineClip> firstClipToRight = timelineManager.findFirstClipToRight(clipId);
TimelinePosition positionToMoveTo = firstClipToRight.map(a -> a.getInterval().getStartPosition().subtract(clip.getInterval().getLength())).orElse(clip.getInterval().getStartPosition());
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.MoveClipRequest in project tactview by helospark.
the class RippleRemoveClipCommand method execute.
@Override
public void execute() {
List<TimelineClip> clipsToRemove = clipIds.stream().flatMap(a -> timelineManager.findClipById(a).stream()).collect(Collectors.toList());
if (clipsToRemove.isEmpty()) {
return;
}
TimelineLength maxLengthOfClip = TimelineLength.ofZero();
for (var clip : clipsToRemove) {
if (clip.getInterval().getLength().greaterThan(maxLengthOfClip)) {
maxLengthOfClip = clip.getInterval().getLength();
}
}
TimelinePosition positionToDelete = clipsToRemove.get(0).getInterval().getStartPosition();
for (var clip : clipsToRemove) {
if (clip.getInterval().getStartPosition().isLessThan(positionToDelete)) {
positionToDelete = clip.getInterval().getStartPosition();
}
}
List<TimelineClip> clipsToMoveBack = findClipsToRipple(clipsToRemove, positionToDelete);
if (!checkIfRippleDeleteCanBePerformed(clipsToRemove, maxLengthOfClip, clipsToMoveBack)) {
return;
}
for (var clip : clipsToRemove) {
removedClips.put(timelineManager.findChannelForClipId(clip.getId()).get(), clip.cloneClip(CloneRequestMetadata.fullCopy()));
timelineManager.removeClip(clip.getId());
}
if (clipsToMoveBack.size() > 0) {
moveDistance = maxLengthOfClip.toPosition();
MoveClipRequest moveClipRequest = MoveClipRequest.builder().withAdditionalClipIds(clipsToMoveBack.stream().map(a -> a.getId()).collect(Collectors.toList())).withAdditionalSpecialPositions(List.of()).withClipId(clipsToMoveBack.get(0).getId()).withEnableJumpingToSpecialPosition(false).withMoreMoveExpected(false).withNewChannelId(timelineManager.findChannelForClipId(clipsToMoveBack.get(0).getId()).get().getId()).withNewPosition(clipsToMoveBack.get(0).getInterval().getStartPosition().subtract(moveDistance)).build();
timelineManager.moveClip(moveClipRequest);
clipsToMoveBack.stream().map(clip -> clip.cloneClip(CloneRequestMetadata.fullCopy())).forEach(clip -> movedClips.add(clip));
}
rippleDeletePerformed = true;
}
use of com.helospark.tactview.core.timeline.MoveClipRequest in project tactview by helospark.
the class RemoveGapCommand method revert.
@Override
public void revert() {
if (!successful) {
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().add(jump)).build();
timelineManager.moveClip(moveClipRequest);
}
Aggregations