2019-03-21 18:58:00 +00:00
|
|
|
'use strict';
|
|
|
|
|
2019-06-15 15:06:57 +00:00
|
|
|
import { delay } from 'delay';
|
2019-03-21 18:58:00 +00:00
|
|
|
|
2019-06-18 19:42:30 +00:00
|
|
|
class FilmOut {
|
|
|
|
private id : string = 'filmout';
|
2019-03-21 22:03:53 +00:00
|
|
|
public state : any = {
|
|
|
|
frame : 0,
|
|
|
|
frames : 0,
|
|
|
|
path : null,
|
|
|
|
fileName : null,
|
|
|
|
info : {},
|
|
|
|
dir : true,
|
|
|
|
enabled : false
|
|
|
|
};
|
|
|
|
private display : any;
|
|
|
|
private ffmpeg : any;
|
|
|
|
private ffprobe : any;
|
|
|
|
private light : any;
|
|
|
|
private ipc : any;
|
|
|
|
private ui : any;
|
|
|
|
private log : any;
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
constructor (display : any, ffmpeg : any, ffprobe : any, ui : any, light : any) {
|
|
|
|
this.display = display;
|
|
|
|
this.ffmpeg = ffmpeg;
|
|
|
|
this.ffprobe = ffprobe;
|
|
|
|
this.ui = ui;
|
|
|
|
this.light = light;
|
|
|
|
this.init();
|
2019-03-21 18:58:00 +00:00
|
|
|
}
|
2019-03-21 22:03:53 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
private async init () {
|
2019-06-15 15:06:57 +00:00
|
|
|
const Log = require('log');
|
2019-06-18 19:42:30 +00:00
|
|
|
this.log = await Log({ label : this.id });
|
2019-03-21 22:03:53 +00:00
|
|
|
this.ipc = require('electron').ipcMain;
|
|
|
|
this.listen();
|
2019-03-21 18:58:00 +00:00
|
|
|
}
|
2019-03-21 22:03:53 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
private listen () {
|
2019-06-18 19:42:30 +00:00
|
|
|
this.ipc.on(this.id, this.onConnect.bind(this));
|
2019-06-18 17:47:55 +00:00
|
|
|
this.ipc.on('focus', this.focus.bind(this));
|
2019-06-18 19:42:30 +00:00
|
|
|
this.ipc.on('field', this.field.bind(this));
|
|
|
|
this.ipc.on('meter', this.meter.bind(this));
|
|
|
|
this.ipc.on('filmout_close', this.close.bind(this));
|
2019-06-27 00:08:49 +00:00
|
|
|
this.ipc.on('preview', this.preview.bind(this));
|
2019-06-25 16:13:15 +00:00
|
|
|
this.ipc.on('preview_frame', this.previewFrame.bind(this));
|
2019-06-27 00:08:49 +00:00
|
|
|
this.ipc.on('display', this.onDisplay.bind(this));
|
2019-03-21 22:03:53 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
public set (dir : boolean) {
|
|
|
|
this.state.dir = dir;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
public async move () {
|
|
|
|
let start : number = +new Date();
|
|
|
|
if (this.state.dir) {
|
|
|
|
this.state.frame++;
|
|
|
|
} else {
|
|
|
|
this.state.frame--;
|
|
|
|
}
|
|
|
|
if (this.state.frame < 1) {
|
|
|
|
this.state.frame = 1;
|
|
|
|
}
|
|
|
|
return (+new Date()) - start;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
async start () {
|
|
|
|
try {
|
|
|
|
await this.ffmpeg.clearAll();
|
|
|
|
} catch (err) {
|
2019-06-27 00:08:49 +00:00
|
|
|
this.log.error(err, 'FILMOUT', true, true);
|
2019-03-21 22:03:53 +00:00
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
await this.ffmpeg.frame(this.state, this.light.state);
|
|
|
|
} catch (err) {
|
2019-06-27 00:08:49 +00:00
|
|
|
this.log.error(err, 'FILMOUT', true, true);
|
2019-03-21 22:03:53 +00:00
|
|
|
throw err;
|
|
|
|
}
|
2019-03-22 02:33:30 +00:00
|
|
|
await this.display.show(this.state.frame);
|
2019-03-21 22:03:53 +00:00
|
|
|
await delay(20);
|
2019-03-21 18:58:00 +00:00
|
|
|
}
|
2019-03-21 22:03:53 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
private async end () {
|
|
|
|
await delay(20);
|
2019-03-22 02:33:30 +00:00
|
|
|
this.display.hide();
|
2019-03-21 18:58:00 +00:00
|
|
|
}
|
2019-03-21 22:03:53 +00:00
|
|
|
/**
|
2019-06-18 19:42:30 +00:00
|
|
|
* Use a video file as a film out source on "projector"
|
2019-03-21 22:03:53 +00:00
|
|
|
*
|
|
|
|
**/
|
2019-06-18 19:42:30 +00:00
|
|
|
async onConnect (evt : any, arg : any) {
|
2019-03-21 22:03:53 +00:00
|
|
|
let info;
|
|
|
|
let frames = 0;
|
2019-03-21 18:58:00 +00:00
|
|
|
|
2019-03-21 22:03:53 +00:00
|
|
|
try {
|
|
|
|
info = await this.ffprobe.info(arg.path);
|
|
|
|
} catch (err) {
|
2019-06-18 19:42:30 +00:00
|
|
|
//this.log.error(err, 'FILMOUT', true, true);
|
2019-03-21 22:03:53 +00:00
|
|
|
this.state.enabled = false;
|
2019-06-18 19:42:30 +00:00
|
|
|
await this.ui.send(this.id, { valid : false });
|
2019-03-21 22:03:53 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
frames = await this.ffprobe.frames(arg.path);
|
|
|
|
} catch (err) {
|
2019-06-18 19:42:30 +00:00
|
|
|
this.log.error(err, 'FILMOUT', true, true);
|
2019-03-21 22:03:53 +00:00
|
|
|
this.state.enabled = false;
|
2019-06-18 19:42:30 +00:00
|
|
|
await this.ui.send(this.id, { valid : false });
|
2019-03-21 22:03:53 +00:00
|
|
|
return false;
|
|
|
|
}
|
2019-03-21 18:58:00 +00:00
|
|
|
|
2019-03-21 22:03:53 +00:00
|
|
|
this.state.frame = 0;
|
|
|
|
this.state.path = arg.path;
|
|
|
|
this.state.fileName = arg.fileName;
|
|
|
|
this.state.frames = frames;
|
|
|
|
this.state.info = info;
|
|
|
|
|
2019-06-18 19:42:30 +00:00
|
|
|
this.log.info(`Opened ${this.state.fileName}`, 'FILMOUT', true, true);
|
|
|
|
this.log.info(`Frames : ${frames}`, 'FILMOUT', true, true);
|
2019-03-21 22:03:53 +00:00
|
|
|
this.state.enabled = true;
|
2019-06-18 19:42:30 +00:00
|
|
|
return await this.ui.send(this.id, { valid : true, state : JSON.stringify(this.state) });
|
2019-03-21 22:03:53 +00:00
|
|
|
}
|
2019-06-25 16:13:15 +00:00
|
|
|
|
|
|
|
async previewFrame (evt : any, arg : any) {
|
|
|
|
const state : any = JSON.parse(JSON.stringify(this.state));
|
|
|
|
let path : string;
|
2019-06-27 00:08:49 +00:00
|
|
|
|
2019-06-25 16:13:15 +00:00
|
|
|
state.frame = arg.frame;
|
2019-06-27 00:08:49 +00:00
|
|
|
|
2019-06-25 16:13:15 +00:00
|
|
|
try {
|
|
|
|
path = await this.ffmpeg.frame(state, { color : [255, 255, 255] });
|
|
|
|
} catch (err) {
|
2019-06-27 00:08:49 +00:00
|
|
|
this.log.error(err, 'FILMOUT', true, true);;
|
2019-06-25 16:13:15 +00:00
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
this.ui.send('preview_frame', { path, frame : arg.frame })
|
|
|
|
}
|
|
|
|
|
|
|
|
async preview (evt : any, arg : any) {
|
2019-06-27 00:08:49 +00:00
|
|
|
const state : any = JSON.parse(JSON.stringify(this.state));
|
|
|
|
let path : string;
|
|
|
|
|
|
|
|
state.frame = arg.frame;
|
|
|
|
|
|
|
|
this.log.info(`Previewing frame ${state.frame} of ${state.fileName}`);
|
|
|
|
try {
|
|
|
|
path = await this.ffmpeg.frame(state, { color : [255, 255, 255] });
|
|
|
|
} catch (err) {
|
|
|
|
this.log.error(err, 'FILMOUT', true, true);
|
|
|
|
throw err;
|
|
|
|
}
|
2019-06-25 16:13:15 +00:00
|
|
|
|
2019-06-27 00:08:49 +00:00
|
|
|
try {
|
|
|
|
await this.display.open();
|
|
|
|
await this.display.show(arg.frame);
|
|
|
|
} catch (err) {
|
|
|
|
this.log.error(err, 'FILMOUT', true, true);
|
|
|
|
}
|
2019-06-25 16:13:15 +00:00
|
|
|
}
|
2019-06-27 00:08:49 +00:00
|
|
|
|
2019-06-18 19:42:30 +00:00
|
|
|
async focus (evt : any, arg : any) {
|
2019-06-27 00:08:49 +00:00
|
|
|
this.log.info(`Showing focus screen`);
|
2019-06-18 19:42:30 +00:00
|
|
|
try {
|
|
|
|
await this.display.open();
|
|
|
|
await this.display.focus();
|
|
|
|
} catch (err) {
|
|
|
|
this.log.error(err, 'FILMOUT', true, true);
|
|
|
|
}
|
|
|
|
}
|
2019-06-27 00:08:49 +00:00
|
|
|
|
2019-06-18 19:42:30 +00:00
|
|
|
async field (evt : any, arg : any) {
|
2019-06-27 00:08:49 +00:00
|
|
|
this.log.info(`Showing field guide screen`);
|
2019-06-18 19:42:30 +00:00
|
|
|
try {
|
|
|
|
await this.display.open();
|
|
|
|
await this.display.field();
|
|
|
|
} catch (err) {
|
|
|
|
this.log.error(err, 'FILMOUT', true, true);
|
|
|
|
}
|
|
|
|
}
|
2019-06-27 00:08:49 +00:00
|
|
|
|
2019-06-18 19:42:30 +00:00
|
|
|
async meter (evt : any, arg : any) {
|
2019-06-27 00:08:49 +00:00
|
|
|
this.log.info(`Showing meter screen`);
|
2019-06-18 19:42:30 +00:00
|
|
|
try {
|
|
|
|
await this.display.open();
|
|
|
|
await this.display.meter();
|
|
|
|
} catch (err) {
|
|
|
|
this.log.error(err, 'FILMOUT', true, true);
|
|
|
|
}
|
|
|
|
}
|
2019-06-27 00:08:49 +00:00
|
|
|
|
2019-06-18 19:42:30 +00:00
|
|
|
async close (evt : any, arg : any) {
|
|
|
|
try {
|
|
|
|
await this.display.hide();
|
|
|
|
await this.display.close();
|
|
|
|
} catch (err) {
|
|
|
|
this.log.error(err, 'FILMOUT', true, true);
|
|
|
|
}
|
2019-06-18 17:47:55 +00:00
|
|
|
}
|
2019-06-27 00:08:49 +00:00
|
|
|
|
|
|
|
onDisplay (evt : any, arg : any) {
|
|
|
|
this.display.change(arg.display);
|
|
|
|
this.log.info(`Changing the display to ${arg.display}`);
|
|
|
|
}
|
2019-03-21 18:58:00 +00:00
|
|
|
}
|
|
|
|
|
2019-03-21 22:03:53 +00:00
|
|
|
module.exports = (display : any, ffmpeg : any, ffprobe : any, ui : any, light : any) => {
|
2019-06-18 19:42:30 +00:00
|
|
|
return new FilmOut(display, ffmpeg, ffprobe, ui, light);
|
2019-06-14 15:31:13 +00:00
|
|
|
}
|