Search in sources :

Example 1 with NotificationMessage

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;
    }
}
Also used : TimelineEditMode(com.helospark.tactview.ui.javafx.repository.timelineeditmode.TimelineEditMode) MoveClipRequest(com.helospark.tactview.core.timeline.MoveClipRequest) TimelinePosition(com.helospark.tactview.core.timeline.TimelinePosition) Collectors(java.util.stream.Collectors) MessagingService(com.helospark.tactview.core.util.messaging.MessagingService) TreeSet(java.util.TreeSet) TimelineClip(com.helospark.tactview.core.timeline.TimelineClip) TimelineInterval(com.helospark.tactview.core.timeline.TimelineInterval) ArrayList(java.util.ArrayList) List(java.util.List) ClipChannelIdPair(com.helospark.tactview.core.timeline.ClipChannelIdPair) UiCommand(com.helospark.tactview.ui.javafx.commands.UiCommand) TimelineChannel(com.helospark.tactview.core.timeline.TimelineChannel) TimelineManagerAccessor(com.helospark.tactview.core.timeline.TimelineManagerAccessor) NotificationMessage(com.helospark.tactview.core.timeline.message.NotificationMessage) Collections(java.util.Collections) TimelineChannel(com.helospark.tactview.core.timeline.TimelineChannel) NotificationMessage(com.helospark.tactview.core.timeline.message.NotificationMessage) TimelinePosition(com.helospark.tactview.core.timeline.TimelinePosition)

Example 2 with NotificationMessage

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;
}
Also used : TimelineEditMode(com.helospark.tactview.ui.javafx.repository.timelineeditmode.TimelineEditMode) MoveClipRequest(com.helospark.tactview.core.timeline.MoveClipRequest) TimelinePosition(com.helospark.tactview.core.timeline.TimelinePosition) Set(java.util.Set) Collectors(java.util.stream.Collectors) TreeSet(java.util.TreeSet) TimelineClip(com.helospark.tactview.core.timeline.TimelineClip) ArrayList(java.util.ArrayList) List(java.util.List) UiCommand(com.helospark.tactview.ui.javafx.commands.UiCommand) TimelineManagerAccessor(com.helospark.tactview.core.timeline.TimelineManagerAccessor) NotificationMessage(com.helospark.tactview.core.timeline.message.NotificationMessage) Optional(java.util.Optional) Level(com.helospark.tactview.core.timeline.message.NotificationMessage.Level) UiMessagingService(com.helospark.tactview.ui.javafx.UiMessagingService) NotificationMessage(com.helospark.tactview.core.timeline.message.NotificationMessage) TreeSet(java.util.TreeSet) MoveClipRequest(com.helospark.tactview.core.timeline.MoveClipRequest) TimelineClip(com.helospark.tactview.core.timeline.TimelineClip)

Example 3 with NotificationMessage

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;
}
Also used : TimelineChannel(com.helospark.tactview.core.timeline.TimelineChannel) NotificationMessage(com.helospark.tactview.core.timeline.message.NotificationMessage) TimelineInterval(com.helospark.tactview.core.timeline.TimelineInterval) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 4 with NotificationMessage

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));
    }
}
Also used : CutClipCommand(com.helospark.tactview.ui.javafx.commands.impl.CutClipCommand) Component(com.helospark.lightdi.annotation.Component) TimelineEditModeRepository(com.helospark.tactview.ui.javafx.repository.timelineeditmode.TimelineEditModeRepository) SelectedNodeRepository(com.helospark.tactview.ui.javafx.repository.SelectedNodeRepository) UiCommandInterpreterService(com.helospark.tactview.ui.javafx.UiCommandInterpreterService) TimelinePosition(com.helospark.tactview.core.timeline.TimelinePosition) Collectors(java.util.stream.Collectors) MessagingService(com.helospark.tactview.core.util.messaging.MessagingService) TimelineClip(com.helospark.tactview.core.timeline.TimelineClip) List(java.util.List) LinkClipRepository(com.helospark.tactview.core.timeline.LinkClipRepository) ClipResizedCommand(com.helospark.tactview.ui.javafx.commands.impl.ClipResizedCommand) TimelineManagerAccessor(com.helospark.tactview.core.timeline.TimelineManagerAccessor) NotificationMessage(com.helospark.tactview.core.timeline.message.NotificationMessage) Level(com.helospark.tactview.core.timeline.message.NotificationMessage.Level) UiTimelineManager(com.helospark.tactview.ui.javafx.UiTimelineManager) NotificationMessage(com.helospark.tactview.core.timeline.message.NotificationMessage) TimelinePosition(com.helospark.tactview.core.timeline.TimelinePosition) TimelineClip(com.helospark.tactview.core.timeline.TimelineClip) ClipResizedCommand(com.helospark.tactview.ui.javafx.commands.impl.ClipResizedCommand)

Aggregations

NotificationMessage (com.helospark.tactview.core.timeline.message.NotificationMessage)4 TimelineClip (com.helospark.tactview.core.timeline.TimelineClip)3 TimelineManagerAccessor (com.helospark.tactview.core.timeline.TimelineManagerAccessor)3 TimelinePosition (com.helospark.tactview.core.timeline.TimelinePosition)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 MoveClipRequest (com.helospark.tactview.core.timeline.MoveClipRequest)2 TimelineChannel (com.helospark.tactview.core.timeline.TimelineChannel)2 TimelineInterval (com.helospark.tactview.core.timeline.TimelineInterval)2 Level (com.helospark.tactview.core.timeline.message.NotificationMessage.Level)2 MessagingService (com.helospark.tactview.core.util.messaging.MessagingService)2 UiCommand (com.helospark.tactview.ui.javafx.commands.UiCommand)2 TimelineEditMode (com.helospark.tactview.ui.javafx.repository.timelineeditmode.TimelineEditMode)2 TreeSet (java.util.TreeSet)2 Component (com.helospark.lightdi.annotation.Component)1 ClipChannelIdPair (com.helospark.tactview.core.timeline.ClipChannelIdPair)1 LinkClipRepository (com.helospark.tactview.core.timeline.LinkClipRepository)1 UiCommandInterpreterService (com.helospark.tactview.ui.javafx.UiCommandInterpreterService)1 UiMessagingService (com.helospark.tactview.ui.javafx.UiMessagingService)1