Search in sources :

Example 11 with MoveClipRequest

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);
        }
    }
}
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) TimelineLength(com.helospark.tactview.core.timeline.TimelineLength) TimelineClip(com.helospark.tactview.core.timeline.TimelineClip) TimelineInterval(com.helospark.tactview.core.timeline.TimelineInterval) ArrayList(java.util.ArrayList) List(java.util.List) Generated(javax.annotation.Generated) ClipChannelIdPair(com.helospark.tactview.core.timeline.ClipChannelIdPair) UiCommand(com.helospark.tactview.ui.javafx.commands.UiCommand) TimelineManagerAccessor(com.helospark.tactview.core.timeline.TimelineManagerAccessor) ResizeClipRequest(com.helospark.tactview.core.timeline.ResizeClipRequest) ClipChannelIdPair(com.helospark.tactview.core.timeline.ClipChannelIdPair) TimelineInterval(com.helospark.tactview.core.timeline.TimelineInterval) ArrayList(java.util.ArrayList) ResizeClipRequest(com.helospark.tactview.core.timeline.ResizeClipRequest) MoveClipRequest(com.helospark.tactview.core.timeline.MoveClipRequest) TimelinePosition(com.helospark.tactview.core.timeline.TimelinePosition) TimelineClip(com.helospark.tactview.core.timeline.TimelineClip)

Example 12 with 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);
}
Also used : List(java.util.List) Generated(javax.annotation.Generated) UiCommand(com.helospark.tactview.ui.javafx.commands.UiCommand) MoveClipRequest(com.helospark.tactview.core.timeline.MoveClipRequest) TimelineManagerAccessor(com.helospark.tactview.core.timeline.TimelineManagerAccessor) TimelinePosition(com.helospark.tactview.core.timeline.TimelinePosition) Optional(java.util.Optional) Collections(java.util.Collections) TimelineClip(com.helospark.tactview.core.timeline.TimelineClip) MoveClipRequest(com.helospark.tactview.core.timeline.MoveClipRequest) TimelinePosition(com.helospark.tactview.core.timeline.TimelinePosition) TimelineClip(com.helospark.tactview.core.timeline.TimelineClip)

Example 13 with MoveClipRequest

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;
}
Also used : TimelineEditMode(com.helospark.tactview.ui.javafx.repository.timelineeditmode.TimelineEditMode) MultiValuedMap(org.apache.commons.collections4.MultiValuedMap) MoveClipRequest(com.helospark.tactview.core.timeline.MoveClipRequest) TimelinePosition(com.helospark.tactview.core.timeline.TimelinePosition) Set(java.util.Set) Collectors(java.util.stream.Collectors) TimelineLength(com.helospark.tactview.core.timeline.TimelineLength) MessagingService(com.helospark.tactview.core.util.messaging.MessagingService) TimelineClip(com.helospark.tactview.core.timeline.TimelineClip) TimelineInterval(com.helospark.tactview.core.timeline.TimelineInterval) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ArrayListValuedHashMap(org.apache.commons.collections4.multimap.ArrayListValuedHashMap) List(java.util.List) CloneRequestMetadata(com.helospark.tactview.core.clone.CloneRequestMetadata) 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) Level(com.helospark.tactview.core.timeline.message.NotificationMessage.Level) MoveClipRequest(com.helospark.tactview.core.timeline.MoveClipRequest) TimelinePosition(com.helospark.tactview.core.timeline.TimelinePosition) TimelineClip(com.helospark.tactview.core.timeline.TimelineClip) TimelineLength(com.helospark.tactview.core.timeline.TimelineLength)

Example 14 with MoveClipRequest

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);
}
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) MoveClipRequest(com.helospark.tactview.core.timeline.MoveClipRequest)

Aggregations

MoveClipRequest (com.helospark.tactview.core.timeline.MoveClipRequest)14 TimelineClip (com.helospark.tactview.core.timeline.TimelineClip)9 TimelineManagerAccessor (com.helospark.tactview.core.timeline.TimelineManagerAccessor)9 TimelinePosition (com.helospark.tactview.core.timeline.TimelinePosition)9 UiCommand (com.helospark.tactview.ui.javafx.commands.UiCommand)9 List (java.util.List)9 TimelineEditMode (com.helospark.tactview.ui.javafx.repository.timelineeditmode.TimelineEditMode)7 ArrayList (java.util.ArrayList)7 Collectors (java.util.stream.Collectors)7 TimelineInterval (com.helospark.tactview.core.timeline.TimelineInterval)6 Set (java.util.Set)6 NotificationMessage (com.helospark.tactview.core.timeline.message.NotificationMessage)5 TimelineLength (com.helospark.tactview.core.timeline.TimelineLength)4 Level (com.helospark.tactview.core.timeline.message.NotificationMessage.Level)4 Optional (java.util.Optional)4 Generated (javax.annotation.Generated)4 ClipChannelIdPair (com.helospark.tactview.core.timeline.ClipChannelIdPair)3 TimelineChannel (com.helospark.tactview.core.timeline.TimelineChannel)3 MessagingService (com.helospark.tactview.core.util.messaging.MessagingService)3 Collections (java.util.Collections)3