use of com.helospark.tactview.core.timeline.TimelineLength in project tactview by helospark.
the class KeyframeSupportingDoubleInterpolator method integrate.
@Override
public BigDecimal integrate(TimelinePosition from, TimelinePosition to) {
if (!isUsingKeyframes()) {
BigDecimal constantValue = BigDecimal.valueOf(valueAt(from));
BigDecimal toSeconds = to.getSeconds();
BigDecimal fromSeconds = from.getSeconds();
return toSeconds.subtract(fromSeconds).multiply(constantValue);
}
if (integralCache == null) {
synchronized (this) {
if (integralCache == null) {
integralCache = new TreeMap<>();
integralCache.put(TimelinePosition.ofZero(), BigDecimal.ZERO);
}
}
}
// TODO: check below
Entry<TimelinePosition, BigDecimal> startFloorEntry = integralCache.floorEntry(from);
Entry<TimelinePosition, BigDecimal> endFloorEntry = integralCache.floorEntry(to);
BigDecimal resultArea;
synchronized (this) {
// TODO: Use concurrent TreeMap collection somehow
TimelinePosition currentTime;
if (startFloorEntry != null && endFloorEntry != null) {
resultArea = endFloorEntry.getValue().subtract(startFloorEntry.getValue());
currentTime = endFloorEntry.getKey();
} else {
currentTime = TimelinePosition.ofZero();
resultArea = BigDecimal.ZERO;
}
TimelinePosition newTo = to.subtract(new TimelineLength(integralCacheResolution));
while (currentTime.isLessThan(newTo)) {
BigDecimal partialArea = DoubleInterpolator.super.integrate(currentTime, currentTime.add(integralCacheResolution));
resultArea = resultArea.add(partialArea);
currentTime = currentTime.add(integralCacheResolution);
integralCache.put(currentTime, resultArea);
}
resultArea = resultArea.add(DoubleInterpolator.super.integrate(currentTime, to));
}
return resultArea;
}
use of com.helospark.tactview.core.timeline.TimelineLength 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);
}
}
use of com.helospark.tactview.core.timeline.TimelineLength in project tactview by helospark.
the class UiTimelineManager method refreshDisplay.
public void refreshDisplay(boolean invalidateCache) {
if (invalidateCache) {
displayUpdaterService.updateDisplayWithCacheInvalidation(this.getCurrentPosition());
} else {
displayUpdaterService.updateDisplay(this.getCurrentPosition());
}
notifyConsumers();
// TODO: this is also a consumer, but due to playback it would be doublecalled during playback
TimelineLength length = new TimelineLength(projectRepository.getFrameTime());
AudioVideoFragment audioVideoFragment = playbackFrameAccessor.getSingleAudioFrameAtPosition(currentPosition, false, Optional.of(length));
notifyAudioListeners(audioVideoFragment);
audioVideoFragment.free();
}
use of com.helospark.tactview.core.timeline.TimelineLength in project tactview by helospark.
the class UiTimelineManager method playback.
private void playback() {
try {
int frame = 0;
audioStreamService.startPlayback();
while (isPlaying) {
TimelinePosition nextFrame = this.expectedNextFrames(1).get(0);
synchronized (timelineLock) {
currentPosition = nextFrame;
}
boolean isMute = uiPlaybackPreferenceRepository.isMute();
TimelineLength length = new TimelineLength(projectRepository.getFrameTime());
AudioVideoFragment audioVideoFragment = playbackFrameAccessor.getSingleAudioFrameAtPosition(currentPosition, isMute, Optional.of(length));
if (!uiPlaybackPreferenceRepository.getPlaybackSpeedMultiplier().equals(BigDecimal.ONE)) {
AudioFrameResult newResult = changePlaybackRateOfAudio(audioVideoFragment);
audioVideoFragment = audioVideoFragment.butFreeAndReplaceVideoFrame(newResult);
}
byte[] audioFrame = convertToPlayableFormat(audioVideoFragment);
notifyAudioListeners(audioVideoFragment);
audioStreamService.streamAudio(audioFrame);
// finished writing currentPosition to buffer, play this frame
TimelineDisplayAsyncUpdateRequest request = TimelineDisplayAsyncUpdateRequest.builder().withCanDropFrames(true).withCurrentPosition(currentPosition).withExpectedNextPositions(expectedNextFramesWithDroppedFrameModulo(10, CACHE_MODULO, frame + 1)).build();
audioVideoFragment.free();
if (frame % CACHE_MODULO == 0) {
displayUpdaterService.updateDisplayAsync(request);
}
lastTimeScreenUpdated = System.currentTimeMillis();
notifyConsumers();
++frame;
}
} catch (Throwable e) {
e.printStackTrace();
} finally {
audioStreamService.stopPlayback();
isPlaying = false;
}
}
use of com.helospark.tactview.core.timeline.TimelineLength in project tactview by helospark.
the class SubtimelineFromTimelineFactory method createSubtimelineVideoClipFromCurrentTimeline.
public SubtimelineVisualClip createSubtimelineVideoClipFromCurrentTimeline(Set<ExposedDescriptorDescriptor> exposedDescriptors) {
TimelineLength length = timelineManager.findEndPosition().toLength();
SubtimelineVisualMetadata metadata = SubtimelineVisualMetadata.builder().withWidth(projectRepository.getWidth()).withHeight(projectRepository.getHeight()).withResizable(true).withLength(length).build();
CloneRequestMetadata cloneMetadata = CloneRequestMetadata.ofDefault();
TimelineChannelsState clonedState = timelineChannelsState.deepClone(cloneMetadata);
Set<ExposedDescriptorDescriptor> fixedExposedDescriptors = exposedDescriptors.stream().map(a -> a.butWithId(cloneMetadata.getPreviousId(a.getId()))).collect(Collectors.toSet());
SubtimelineVisualClip result = new SubtimelineVisualClip(metadata, clonedState, timelineManagerAccessorFactory, subtimelineHelper, fixedExposedDescriptors, TimelinePosition.ofZero(), length);
result.setCreatorFactoryId(SubtimelineVisualClipFactory.ID);
return result;
}
Aggregations