use of com.helospark.tactview.core.timeline.TimelineInterval 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.TimelineInterval 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.TimelineInterval in project tactview by helospark.
the class ClipInsertCommand method findCombinedInterval.
private TimelineInterval findCombinedInterval(List<TimelineClip> clipsToMove) {
TimelinePosition startPosition = clipsToMove.get(0).getInterval().getStartPosition();
TimelinePosition endPosition = clipsToMove.get(0).getInterval().getEndPosition();
for (var clip : clipsToMove) {
TimelineInterval interval = clip.getInterval();
if (interval.getStartPosition().isLessThan(startPosition)) {
startPosition = interval.getStartPosition();
}
if (interval.getEndPosition().isGreaterThan(endPosition)) {
endPosition = interval.getEndPosition();
}
}
return new TimelineInterval(startPosition, endPosition);
}
use of com.helospark.tactview.core.timeline.TimelineInterval in project tactview by helospark.
the class ClipMovedCommand method execute.
@Override
public void execute() {
MoveClipRequest request = MoveClipRequest.builder().withClipId(clipId).withAdditionalClipIds(additionalClipIds).withNewPosition(newPosition).withNewChannelId(newChannelId).withMaximumJump(maximumJumpLength).withMoreMoveExpected(moreMoveExpected).withEnableJumpingToSpecialPosition(enableJumpingToSpecialPosition).withAdditionalSpecialPositions(additionalPositions).build();
TimelineInterval newInterval = timelineManager.findClipById(clipId).get().getInterval();
wasOperationSuccessful = timelineManager.moveClip(request);
hasIntervalChanged = !previousPosition.equals(newInterval.getStartPosition());
}
use of com.helospark.tactview.core.timeline.TimelineInterval in project tactview by helospark.
the class RippleRemoveClipCommand method checkIfRippleDeleteCanBePerformed.
private boolean checkIfRippleDeleteCanBePerformed(List<TimelineClip> clipsToRemove, TimelineLength maxLengthOfClip, List<TimelineClip> clipsToMoveBack) {
List<String> excludedIdsInCheck = new ArrayList<>();
clipsToMoveBack.stream().forEach(a -> excludedIdsInCheck.add(a.getId()));
clipsToRemove.stream().forEach(a -> excludedIdsInCheck.add(a.getId()));
Set<Integer> conflictingChannels = new HashSet<>();
for (var clip : clipsToMoveBack) {
TimelineChannel channel = timelineManager.findChannelForClipId(clip.getId()).get();
int channelIndex = timelineManager.findChannelIndexForClipId(clip.getId()).get();
TimelineInterval newInterval = clip.getInterval().butAddOffset(maxLengthOfClip.toPosition().negate());
boolean canAddResource = channel.canAddResourceAtExcluding(newInterval, excludedIdsInCheck);
if (!canAddResource) {
conflictingChannels.add(channelIndex);
}
}
boolean canPerformRippleDelete = conflictingChannels.isEmpty();
if (!canPerformRippleDelete) {
messagingService.sendMessage(new NotificationMessage("Unable to ripple delete", "Clips in channel " + conflictingChannels + " cannot be moved back", Level.ERROR));
}
return canPerformRippleDelete;
}
Aggregations