All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.opentimeline.opentime.TimeTransform Maven / Gradle / Ivy

// SPDX-License-Identifier: Apache-2.0
// Copyright Contributors to the OpenTimelineIO Project.

package io.opentimeline.opentime;

import io.opentimeline.LibraryLoader;
import io.opentimeline.OTIOObject;

/**
 * 1D Transform for RationalTime.  Has offset and scale.
 */
public class TimeTransform {

    static {
        LibraryLoader.load("jotio");
    }

    private final RationalTime offset;
    private final double scale;
    private final double rate;

    public TimeTransform() {
        offset = new RationalTime();
        scale = 1;
        rate = -1;
    }

    public TimeTransform(RationalTime offset, double scale, double rate) {
        this.offset = offset;
        this.scale = scale;
        this.rate = rate;
    }

    public TimeTransform(TimeTransform timeTransform) {
        this.offset = timeTransform.getOffset();
        this.scale = timeTransform.getScale();
        this.rate = timeTransform.getRate();
    }

    public TimeTransform(TimeTransform.TimeTransformBuilder timeTransformBuilder) {
        this.offset = timeTransformBuilder.offset;
        this.scale = timeTransformBuilder.scale;
        this.rate = timeTransformBuilder.rate;
    }

    public static class TimeTransformBuilder {
        private RationalTime offset = new RationalTime();
        private double scale = 1;
        private double rate = -1;

        public TimeTransformBuilder() {
        }

        public TimeTransform.TimeTransformBuilder setOffset(RationalTime offset) {
            this.offset = offset;
            return this;
        }

        public TimeTransform.TimeTransformBuilder setScale(double scale) {
            this.scale = scale;
            return this;
        }

        public TimeTransform.TimeTransformBuilder setRate(double rate) {
            this.rate = rate;
            return this;
        }

        public TimeTransform build() {
            return new TimeTransform(offset, scale, rate);
        }
    }

    public RationalTime getOffset() {
        return offset;
    }

    public double getScale() {
        return scale;
    }

    public double getRate() {
        return rate;
    }

    public native TimeRange appliedTo(TimeRange other);

    public native TimeTransform appliedTo(TimeTransform other);

    public native RationalTime appliedTo(RationalTime other);

    public native boolean equals(TimeTransform other);

    @Override
    public boolean equals(Object obj) {
        if (!(obj instanceof TimeTransform))
            return false;
        return this.equals((TimeTransform) obj);
    }

    public native boolean notEquals(TimeTransform other);

    @Override
    public String toString() {
        return this.getClass().getCanonicalName() +
                "(" +
                "offset=" + this.getOffset() +
                ", scale=" + this.getScale() +
                ", rate=" + this.getRate() +
                ")";
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy