Search in sources :

Example 1 with TimelineClip

use of com.helospark.tactview.core.timeline.TimelineClip 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();
    }
}
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) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) MoveClipRequest(com.helospark.tactview.core.timeline.MoveClipRequest) TimelineClip(com.helospark.tactview.core.timeline.TimelineClip)

Example 2 with TimelineClip

use of com.helospark.tactview.core.timeline.TimelineClip in project tactview by helospark.

the class ClipResizedCommand method revert.

@Override
public void revert() {
    boolean isAnyRippleModeEnabled = !timelineEditMode.equals(TimelineEditMode.NORMAL);
    TimelinePosition lengthToJumpToUse = lengthToJump;
    for (var clipId : clipIds) {
        TimelineClip clip = timelineManager.findClipById(clipId).orElseThrow(() -> new IllegalArgumentException("No clip found"));
        TimelinePosition previousPosition = originalPosition;
        boolean wasLeftRipple = left && isAnyRippleModeEnabled;
        TimelinePosition positionToUse = previousPosition;
        if (wasLeftRipple) {
            TimelineLength intervalSizeDiff = clip.getGlobalInterval().getLength().subtract(originalInterval.getLength());
            positionToUse = positionToUse.add(intervalSizeDiff.toPosition());
            lengthToJumpToUse = intervalSizeDiff.toPosition().negate();
        } else {
            lengthToJumpToUse = originalInterval.getEndPosition().subtract(clip.getInterval().getEndPosition());
        }
        ResizeClipRequest request = ResizeClipRequest.builder().withClip(clip).withLeft(left).withUseSpecialPoints(false).withPosition(positionToUse).withKeepLeftSideOfClipAtSamePlace(wasLeftRipple).withIgnoreIntersection(clipsToMove.stream().map(a -> a.clip).collect(Collectors.toList())).build();
        timelineManager.resizeClip(request);
    }
    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(lengthToJumpToUse)).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) 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) TimelineLength(com.helospark.tactview.core.timeline.TimelineLength)

Example 3 with TimelineClip

use of com.helospark.tactview.core.timeline.TimelineClip in project tactview by helospark.

the class ClipToLeftCommand method execute.

@Override
public void execute() {
    TimelineClip clip = timelineManager.findClipById(clipId).get();
    previousPosition = clip.getInterval().getStartPosition();
    originalChannelId = timelineManager.findChannelForClipId(clipId).get().getId();
    Optional<TimelineClip> firstClipToLeft = timelineManager.findFirstClipToLeft(clipId);
    TimelinePosition positionToMoveTo = firstClipToLeft.map(a -> a.getInterval().getEndPosition()).orElse(TimelinePosition.ofZero());
    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 4 with TimelineClip

use of com.helospark.tactview.core.timeline.TimelineClip 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 5 with TimelineClip

use of com.helospark.tactview.core.timeline.TimelineClip in project tactview by helospark.

the class ReplaceTimelineWithSubtimelineCommand method execute.

@Override
public void execute() {
    synchronized (timelineManagerAccessor.getFullLock()) {
        SubtimelineVisualClip newVideoClip = null;
        SubtimelineAudioClip newAudioClip = null;
        if (projectRepository.isVideoInitialized()) {
            newVideoClip = subtimelineFromTimelineFactory.createSubtimelineVideoClipFromCurrentTimeline(exposedDescriptors);
        }
        if (projectRepository.isAudioInitialized()) {
            newAudioClip = subtimelineFromTimelineFactory.createSubtimelineAudioClipFromCurrentTimeline(exposedDescriptors);
        }
        for (var id : timelineManagerAccessor.getAllClipIds()) {
            TimelineChannel channel = timelineManagerAccessor.findChannelForClipId(id).get();
            TimelineClip clip = timelineManagerAccessor.findClipById(id).get().cloneClip(CloneRequestMetadata.fullCopy());
            clipsRemoved.add(new ChannelClipPair(channel, clip));
            timelineManagerAccessor.removeClip(id);
        }
        if (newVideoClip != null) {
            timelineManagerAccessor.addClip(timelineManagerAccessor.getChannels().get(0), newVideoClip);
            addedIds.add(newVideoClip.getId());
        }
        if (newAudioClip != null) {
            timelineManagerAccessor.addClip(timelineManagerAccessor.getChannels().get(1), newAudioClip);
            addedIds.add(newAudioClip.getId());
        }
        if (newVideoClip != null && newAudioClip != null) {
            linkClipRepository.linkClip(newVideoClip.getId(), newAudioClip.getId());
        }
    }
}
Also used : TimelineChannel(com.helospark.tactview.core.timeline.TimelineChannel) SubtimelineAudioClip(com.helospark.tactview.core.timeline.subtimeline.audio.SubtimelineAudioClip) SubtimelineVisualClip(com.helospark.tactview.core.timeline.subtimeline.video.SubtimelineVisualClip) TimelineClip(com.helospark.tactview.core.timeline.TimelineClip)

Aggregations

TimelineClip (com.helospark.tactview.core.timeline.TimelineClip)53 TimelinePosition (com.helospark.tactview.core.timeline.TimelinePosition)23 TimelineManagerAccessor (com.helospark.tactview.core.timeline.TimelineManagerAccessor)20 List (java.util.List)20 Collectors (java.util.stream.Collectors)17 AudioVideoFragment (com.helospark.tactview.core.timeline.AudioVideoFragment)15 Test (org.junit.jupiter.api.Test)15 ArrayList (java.util.ArrayList)13 File (java.io.File)11 Component (com.helospark.lightdi.annotation.Component)10 StatelessEffect (com.helospark.tactview.core.timeline.StatelessEffect)10 TimelineChannel (com.helospark.tactview.core.timeline.TimelineChannel)10 TimelineInterval (com.helospark.tactview.core.timeline.TimelineInterval)10 Optional (java.util.Optional)10 CloneRequestMetadata (com.helospark.tactview.core.clone.CloneRequestMetadata)9 MoveClipRequest (com.helospark.tactview.core.timeline.MoveClipRequest)7 UiCommandInterpreterService (com.helospark.tactview.ui.javafx.UiCommandInterpreterService)7 UiCommand (com.helospark.tactview.ui.javafx.commands.UiCommand)7 Color (com.helospark.tactview.core.timeline.effect.interpolation.pojo.Color)6 SelectedNodeRepository (com.helospark.tactview.ui.javafx.repository.SelectedNodeRepository)6