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