Search in sources :

Example 1 with TimelineLength

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;
}
Also used : TimelinePosition(com.helospark.tactview.core.timeline.TimelinePosition) BigDecimal(java.math.BigDecimal) TimelineLength(com.helospark.tactview.core.timeline.TimelineLength)

Example 2 with TimelineLength

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

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

Example 4 with TimelineLength

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;
    }
}
Also used : TimelineDisplayAsyncUpdateRequest(com.helospark.tactview.ui.javafx.DisplayUpdaterService.TimelineDisplayAsyncUpdateRequest) TimelinePosition(com.helospark.tactview.core.timeline.TimelinePosition) TimelineLength(com.helospark.tactview.core.timeline.TimelineLength) AudioVideoFragment(com.helospark.tactview.core.timeline.AudioVideoFragment) AudioFrameResult(com.helospark.tactview.core.timeline.AudioFrameResult)

Example 5 with TimelineLength

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;
}
Also used : TimelineChannelsState(com.helospark.tactview.core.timeline.TimelineChannelsState) Component(com.helospark.lightdi.annotation.Component) AudioMediaMetadata(com.helospark.tactview.core.decoder.AudioMediaMetadata) TimelinePosition(com.helospark.tactview.core.timeline.TimelinePosition) Set(java.util.Set) Collectors(java.util.stream.Collectors) TimelineLength(com.helospark.tactview.core.timeline.TimelineLength) CloneRequestMetadata(com.helospark.tactview.core.clone.CloneRequestMetadata) SubtimelineVisualClip(com.helospark.tactview.core.timeline.subtimeline.video.SubtimelineVisualClip) SubtimelineAudioClip(com.helospark.tactview.core.timeline.subtimeline.audio.SubtimelineAudioClip) TimelineManagerAccessor(com.helospark.tactview.core.timeline.TimelineManagerAccessor) SubtimelineAudioClipFactory(com.helospark.tactview.core.timeline.subtimeline.audio.SubtimelineAudioClipFactory) ProjectRepository(com.helospark.tactview.core.repository.ProjectRepository) SubtimelineVisualClipFactory(com.helospark.tactview.core.timeline.subtimeline.video.SubtimelineVisualClipFactory) SubtimelineVisualMetadata(com.helospark.tactview.core.timeline.subtimeline.video.SubtimelineVisualMetadata) TimelineChannelsState(com.helospark.tactview.core.timeline.TimelineChannelsState) SubtimelineVisualMetadata(com.helospark.tactview.core.timeline.subtimeline.video.SubtimelineVisualMetadata) CloneRequestMetadata(com.helospark.tactview.core.clone.CloneRequestMetadata) SubtimelineVisualClip(com.helospark.tactview.core.timeline.subtimeline.video.SubtimelineVisualClip) TimelineLength(com.helospark.tactview.core.timeline.TimelineLength)

Aggregations

TimelineLength (com.helospark.tactview.core.timeline.TimelineLength)17 TimelinePosition (com.helospark.tactview.core.timeline.TimelinePosition)9 TimelineManagerAccessor (com.helospark.tactview.core.timeline.TimelineManagerAccessor)4 BigDecimal (java.math.BigDecimal)4 Set (java.util.Set)4 Collectors (java.util.stream.Collectors)4 AudioVideoFragment (com.helospark.tactview.core.timeline.AudioVideoFragment)3 TimelineClip (com.helospark.tactview.core.timeline.TimelineClip)3 TimelineInterval (com.helospark.tactview.core.timeline.TimelineInterval)3 Component (com.helospark.lightdi.annotation.Component)2 CloneRequestMetadata (com.helospark.tactview.core.clone.CloneRequestMetadata)2 AudioMediaMetadata (com.helospark.tactview.core.decoder.AudioMediaMetadata)2 ImageMetadataResponse (com.helospark.tactview.core.decoder.opencv.ImageMetadataResponse)2 AudioFrameResult (com.helospark.tactview.core.timeline.AudioFrameResult)2 MoveClipRequest (com.helospark.tactview.core.timeline.MoveClipRequest)2 SubtimelineAudioClip (com.helospark.tactview.core.timeline.subtimeline.audio.SubtimelineAudioClip)2 MessagingService (com.helospark.tactview.core.util.messaging.MessagingService)2 UiCommand (com.helospark.tactview.ui.javafx.commands.UiCommand)2 ClipResizedCommand (com.helospark.tactview.ui.javafx.commands.impl.ClipResizedCommand)2 EffectResizedCommand (com.helospark.tactview.ui.javafx.commands.impl.EffectResizedCommand)2