use of com.helospark.tactview.core.timeline.message.NotificationMessage in project tactview by helospark.
the class ClipInsertCommand method execute.
@Override
public void execute() {
synchronized (timelineManager.getFullLock()) {
clipsToMove = timelineManager.resolveClipIdsWithAllLinkedClip(clipIdsToInsert);
List<TimelineChannel> channels = clipsToMove.stream().flatMap(clip -> timelineManager.findChannelForClipId(clip.getId()).stream()).collect(Collectors.toList());
List<String> clipIds = clipsToMove.stream().map(a -> a.getId()).collect(Collectors.toList());
TimelinePosition positionToInsertTo = insertInPlace.getInterval().getStartPosition();
channelIndices = channels.stream().flatMap(a -> timelineManager.findChannelIndexByChannelId(a.getId()).stream()).collect(Collectors.toList());
boolean isThereACutAtClipPositions = channels.stream().allMatch(channel -> isThereACatAtPosition(channel, positionToInsertTo, clipIds));
if (!isThereACutAtClipPositions) {
success = false;
messagingService.sendMessage(new NotificationMessage("Cannot insert", "Not all channels have cut at position", NotificationMessage.Level.WARNING));
return;
}
if (clipsToMove.size() == 0) {
messagingService.sendMessage(new NotificationMessage("Cannot insert", "No clips found to move", NotificationMessage.Level.WARNING));
return;
}
combinedInterval = findCombinedInterval(clipsToMove);
distanceToMove = combinedInterval.getEndPosition().subtract(combinedInterval.getStartPosition());
moveBackward = true;
if (combinedInterval.getStartPosition().subtract(positionToInsertTo).isLessThan(TimelinePosition.ofZero())) {
distanceToMove = distanceToMove.negate();
moveBackward = false;
}
actuallyInsertedClips = removeClipsToInsert(clipsToMove);
TimelinePosition newPos = moveBackClipsBehind(positionToInsertTo, channelIndices, distanceToMove, moveBackward, combinedInterval);
insertClipsAt(newPos, combinedInterval, actuallyInsertedClips);
success = true;
}
}
use of com.helospark.tactview.core.timeline.message.NotificationMessage 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.message.NotificationMessage 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;
}
use of com.helospark.tactview.core.timeline.message.NotificationMessage in project tactview by helospark.
the class UiCutHandler method cutSelectedUntilCursor.
public void cutSelectedUntilCursor(boolean isLeft) {
TimelinePosition currentPosition = uiTimelineManager.getCurrentPosition();
List<TimelineClip> elementsToCut = timelineManager.resolveClipIdsWithAllLinkedClip(selectedNodeRepository.getSelectedClipIds()).stream().filter(a -> a.getInterval().contains(currentPosition)).collect(Collectors.toList());
if (elementsToCut.size() > 0) {
ClipResizedCommand command = ClipResizedCommand.builder().withClipIds(elementsToCut.stream().map(a -> a.getId()).collect(Collectors.toList())).withLeft(isLeft).withUseSpecialPoints(false).withPosition(currentPosition).withMoreResizeExpected(false).withOriginalPosition(isLeft ? elementsToCut.get(0).getInterval().getStartPosition() : elementsToCut.get(0).getInterval().getEndPosition()).withOriginalInterval(elementsToCut.get(0).getGlobalInterval()).withRevertable(true).withTimelineEditMode(timelineEditModeRepository.getMode()).withTimelineManager(timelineManager).build();
commandInterpreter.sendWithResult(command);
} else {
messagingService.sendMessage(new NotificationMessage("No selected clips intersecting the playhead", "Unable to cut", Level.WARNING));
}
}
Aggregations