Search in sources :

Example 1 with TimelineChannel

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

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

the class MoveByUnitService method moveByOneUnit.

public void moveByOneUnit(Direction direction) {
    List<String> selectedClipIds = selectedNodeRepository.getSelectedClipIds();
    if (selectedClipIds.size() > 0) {
        String firstClipId = selectedClipIds.get(0);
        TimelinePosition startPosition = timelineManagerAccessor.findClipById(firstClipId).get().getInterval().getStartPosition();
        if (direction.equals(Direction.LEFT) || direction.equals(Direction.RIGHT)) {
            String channelId = timelineManagerAccessor.findChannelForClipId(firstClipId).get().getId();
            TimelinePosition newPosition = direction.equals(Direction.LEFT) ? startPosition.subtract(projectRepository.getFrameTime()) : startPosition.add(projectRepository.getFrameTime());
            ClipMovedCommand clipMovedCommand = ClipMovedCommand.builder().withAdditionalClipIds(selectedClipIds).withClipId(firstClipId).withEnableJumpingToSpecialPosition(false).withIsRevertable(true).withMoreMoveExpected(false).withNewPosition(newPosition).withNewChannelId(channelId).withOriginalChannelId(channelId).withPreviousPosition(startPosition).withTimelineManager(timelineManagerAccessor).build();
            commandInterpreter.sendWithResult(clipMovedCommand).join();
        } else {
            String channelId = timelineManagerAccessor.findChannelForClipId(firstClipId).get().getId();
            Integer channelIndex = timelineManagerAccessor.findChannelIndexForClipId(firstClipId).get();
            Integer newChannelIndex = direction.equals(Direction.DOWN) ? channelIndex + 1 : channelIndex - 1;
            Optional<TimelineChannel> newChannel = timelineManagerAccessor.findChannelOnIndex(newChannelIndex);
            if (newChannel.isPresent()) {
                ClipMovedCommand clipMovedCommand = ClipMovedCommand.builder().withAdditionalClipIds(selectedClipIds).withClipId(firstClipId).withEnableJumpingToSpecialPosition(false).withIsRevertable(true).withMoreMoveExpected(false).withNewPosition(startPosition).withNewChannelId(newChannel.get().getId()).withOriginalChannelId(channelId).withPreviousPosition(startPosition).withTimelineManager(timelineManagerAccessor).build();
                commandInterpreter.sendWithResult(clipMovedCommand).join();
            }
        }
    }
}
Also used : TimelineChannel(com.helospark.tactview.core.timeline.TimelineChannel) ClipMovedCommand(com.helospark.tactview.ui.javafx.commands.impl.ClipMovedCommand) TimelinePosition(com.helospark.tactview.core.timeline.TimelinePosition)

Example 3 with TimelineChannel

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

the class CreateChannelCommand method execute.

@Override
public void execute() {
    TimelineChannel channel = timelineManager.createChannel(index);
    this.channelId = channel.getId();
}
Also used : TimelineChannel(com.helospark.tactview.core.timeline.TimelineChannel)

Example 4 with TimelineChannel

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

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

TimelineChannel (com.helospark.tactview.core.timeline.TimelineChannel)19 ArrayList (java.util.ArrayList)7 TimelineClip (com.helospark.tactview.core.timeline.TimelineClip)6 TimelineInterval (com.helospark.tactview.core.timeline.TimelineInterval)6 TimelinePosition (com.helospark.tactview.core.timeline.TimelinePosition)6 StatelessEffect (com.helospark.tactview.core.timeline.StatelessEffect)3 TimelineManagerAccessor (com.helospark.tactview.core.timeline.TimelineManagerAccessor)3 TimelineUiCacheElement (com.helospark.tactview.ui.javafx.uicomponents.canvasdraw.domain.TimelineUiCacheElement)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 Component (com.helospark.lightdi.annotation.Component)2 CloneRequestMetadata (com.helospark.tactview.core.clone.CloneRequestMetadata)2 AddClipRequest (com.helospark.tactview.core.timeline.AddClipRequest)2 AddExistingClipRequest (com.helospark.tactview.core.timeline.AddExistingClipRequest)2 ClipChannelIdPair (com.helospark.tactview.core.timeline.ClipChannelIdPair)2 NotificationMessage (com.helospark.tactview.core.timeline.message.NotificationMessage)2 UiCommandInterpreterService (com.helospark.tactview.ui.javafx.UiCommandInterpreterService)2 AddClipsCommand (com.helospark.tactview.ui.javafx.commands.impl.AddClipsCommand)2 AddExistingClipsCommand (com.helospark.tactview.ui.javafx.commands.impl.AddExistingClipsCommand)2 ClipDragInformation (com.helospark.tactview.ui.javafx.repository.drag.ClipDragInformation)2