tav-media
Version:
Cross platform media editing framework
142 lines (141 loc) • 4.69 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import { TAVObject, updateNative } from '../types/tav-object';
import { tav } from '../tav';
/**
* A timed audiovisual resource which provides audio or video outputs.
* @hideconstructor
* @category Clips
*/
export class Clip extends TAVObject {
constructor() {
super(...arguments);
/**
* Returns the type of this output.
*/
this.type = 'Clip';
this._contentTimeInvalid = true;
this._startTime = 0;
this._duration = 0;
}
/**
* Build the native clip object from assets and other properties set on the clip.
* This method is web only.
* @returns The native clip object.
*/
build() {
return __awaiter(this, void 0, void 0, function* () {
if (!this.prepared) {
yield this.prepare();
}
if (this._nativeObject && !this.nativeInvalidated && !this.hasFakeClipNativeInvalidated()) {
return this._nativeObject;
}
const clip = yield tav.webAssemblyQueue.exec(this.createClip, this, null);
if (!clip)
return undefined;
;
yield this.updateClip(clip);
this._nativeObject = clip;
this.nativeInvalidated = false;
return clip;
});
}
/**
* @ignore
*/
hasFakeClipNativeInvalidated() {
return false;
}
/**
* Release the native clip object.
* This method is web only.
*/
release() {
this.nativeClip = null;
}
/**
* @ignore
*/
clone() {
return new Clip();
}
attachToParent(parent) {
this.parent = parent;
}
detachFromParent() {
this.parent = null;
}
removeFromParent() {
var _a;
(_a = this.parent) === null || _a === void 0 ? void 0 : _a.removeClip(this);
}
createClip() {
return __awaiter(this, void 0, void 0, function* () {
return undefined;
});
}
updateClip(clip) {
return __awaiter(this, void 0, void 0, function* () {
yield tav.webAssemblyQueue.exec(clip.setDuration, clip, this.duration || 0);
yield tav.webAssemblyQueue.exec(clip.setStartTime, clip, this.startTime || 0);
});
}
invalidated() {
var _a;
super.invalidated();
(_a = this.parent) === null || _a === void 0 ? void 0 : _a.invalidated();
}
/**
* Get the native clip object.
*/
get nativeClip() {
return this._nativeObject;
}
set nativeClip(clip) {
this._nativeObject = clip;
}
/**
* Get or set the duration of this clip in the composition's timeline.
*/
get duration() {
return this._duration;
}
set duration(time) {
this._duration = time;
this.invalidated();
;
}
/**
* Get or set the start time of this clip in the composition's timeline
*/
get startTime() {
return this._startTime;
}
set startTime(time) {
var _a;
this._startTime = time;
if (!this.nativeClip) {
this.invalidated();
;
return;
}
tav.webAssemblyQueue.exec((_a = this.nativeClip) === null || _a === void 0 ? void 0 : _a.setStartTime, this.nativeClip, time);
}
}
__decorate([
updateNative
], Clip.prototype, "nativeClip", null);