Search in sources :

Example 1 with ClipChannelIdPair

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);
    }
}
Also used : ClipChannelIdPair(com.helospark.tactview.core.timeline.ClipChannelIdPair) TimelineInterval(com.helospark.tactview.core.timeline.TimelineInterval)

Example 2 with ClipChannelIdPair

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

Example 3 with ClipChannelIdPair

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);
        }
    }
}
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)

Aggregations

ClipChannelIdPair (com.helospark.tactview.core.timeline.ClipChannelIdPair)3 TimelineInterval (com.helospark.tactview.core.timeline.TimelineInterval)2 ArrayList (java.util.ArrayList)2 MoveClipRequest (com.helospark.tactview.core.timeline.MoveClipRequest)1 ResizeClipRequest (com.helospark.tactview.core.timeline.ResizeClipRequest)1 TimelineChannel (com.helospark.tactview.core.timeline.TimelineChannel)1 TimelineClip (com.helospark.tactview.core.timeline.TimelineClip)1 TimelineLength (com.helospark.tactview.core.timeline.TimelineLength)1 TimelineManagerAccessor (com.helospark.tactview.core.timeline.TimelineManagerAccessor)1 TimelinePosition (com.helospark.tactview.core.timeline.TimelinePosition)1 UiCommand (com.helospark.tactview.ui.javafx.commands.UiCommand)1 TimelineEditMode (com.helospark.tactview.ui.javafx.repository.timelineeditmode.TimelineEditMode)1 List (java.util.List)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Generated (javax.annotation.Generated)1