tav-media
Version:
Cross platform media editing framework
128 lines (127 loc) • 4.8 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 { Clip } from '../clips/tav-clip';
import { updateNativeIfEffect } from '../types/tav-object';
/**
* Effect takes audiovisual outputs from other clips as its inputs and generate new audiovisual
* outputs from them.
* @category Effects
*/
export class Effect extends Clip {
constructor() {
super(...arguments);
this.type = 'Effect';
this.inputs = [];
}
/**
* Adds a clip as one input source.
* @param clip input clip
*/
addInput(clip) {
this.inputs.push(clip);
}
/**
* Removes the specified clip from input sources.
* @param clip remove clip
*/
removeInput(clip) {
const index = this.inputs.indexOf(clip);
if (index >= 0) {
this.inputs.splice(index, 1);
}
}
/**
* Removes all clips from input sources.
*/
removeAllInputs() {
this.inputs.length = 0;
}
/**
* get all clips
*/
getAllInputs() {
return this.inputs.concat();
}
/**
* @ignore
*/
hasFakeClipNativeInvalidated() {
for (const clip of this.inputs) {
if (clip.hasFakeClipNativeInvalidated()) {
return true;
}
}
return false;
}
build() {
const _super = Object.create(null, {
build: { get: () => super.build }
});
var _a, _b;
return __awaiter(this, void 0, void 0, function* () {
if (this._nativeObject && !this.nativeInvalidated) {
const effect = this.nativeClip;
const inputChanged = !(((_a = effect.inputs) === null || _a === void 0 ? void 0 : _a.length) === this.inputs.length
&& ((_b = effect.inputs) === null || _b === void 0 ? void 0 : _b.every((clip, i) => this.inputs[i].nativeInvalidated === false && this.inputs[i].nativeClip === clip)));
if (inputChanged) {
this.invalidated();
}
this.nativeInvalidated = inputChanged;
}
return yield _super.build.call(this);
});
}
updateClip(effect) {
const _super = Object.create(null, {
updateClip: { get: () => super.updateClip }
});
var _a;
return __awaiter(this, void 0, void 0, function* () {
yield _super.updateClip.call(this, effect);
// eslint-disable-next-line no-param-reassign
effect.inputs = [];
effect.removeAllInputs();
for (const clip of this.inputs) {
const parent = this.parent;
if (parent && !parent.hasChildClip(clip))
parent.addClip(clip);
const nativeClip = yield clip.build();
if (nativeClip) {
effect.addInput(nativeClip);
(_a = effect.inputs) === null || _a === void 0 ? void 0 : _a.push(nativeClip);
}
else {
console.error(`Found unsupported clip with type: ${clip.type}`);
}
}
});
}
attachToParent(parent) {
super.attachToParent(parent);
if (parent) {
this.inputs.forEach(clip => parent.addClip(clip));
}
}
}
__decorate([
updateNativeIfEffect
], Effect.prototype, "addInput", null);
__decorate([
updateNativeIfEffect
], Effect.prototype, "removeInput", null);
__decorate([
updateNativeIfEffect
], Effect.prototype, "removeAllInputs", null);