use of com.helospark.tactview.core.timeline.ClipChannelIdPair in project tactview by helospark.
the class ClipInsertCommand method revert.
@Override
public void revert() {
if (success) {
TimelineInterval newCombinedInterval = findCombinedInterval(clipsToMove);
List<ClipChannelIdPair> removedClips = removeClipsToInsert(actuallyInsertedClips.stream().map(a -> a.clip).collect(Collectors.toList()));
moveBackClipsBehind(combinedInterval.getStartPosition(), channelIndices, distanceToMove.negate(), !moveBackward, newCombinedInterval);
insertClipsAt(combinedInterval.getStartPosition(), new TimelineInterval(insertInPlace.getInterval().getStartPosition(), distanceToMove.toLength()), removedClips);
}
}
use of com.helospark.tactview.core.timeline.ClipChannelIdPair in project tactview by helospark.
the class ClipInsertCommand method removeClipsToInsert.
private List<ClipChannelIdPair> removeClipsToInsert(List<TimelineClip> clipsToMove) {
// TODO: ripple if set
List<ClipChannelIdPair> clipsRemoved = new ArrayList<>();
for (var clip : clipsToMove) {
TimelineChannel channel = timelineManager.findChannelForClipId(clip.getId()).get();
clipsRemoved.add(new ClipChannelIdPair(clip, channel.getId()));
timelineManager.removeClip(clip.getId());
}
return clipsRemoved;
}
use of com.helospark.tactview.core.timeline.ClipChannelIdPair 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);
}
}
}
Aggregations