2019-06-18 19:25:28 +00:00
|
|
|
'use strict';
|
2020-01-19 05:36:58 +00:00
|
|
|
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());
|
|
|
|
});
|
|
|
|
};
|
2019-07-25 02:00:23 +00:00
|
|
|
/**
|
|
|
|
* Determine the greatest common denominator
|
|
|
|
*/
|
2019-06-25 01:11:14 +00:00
|
|
|
function gcd(a, b) {
|
|
|
|
if (b === 0)
|
|
|
|
return a;
|
|
|
|
return gcd(b, a % b);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Reduce a numerator and denominator to it's smallest, integer ratio using Euclid's Algorithm
|
|
|
|
*/
|
|
|
|
function reduceRatio(numerator, denominator) {
|
|
|
|
// from: http://pages.pacificcoast.net/~cazelais/euclid.html
|
|
|
|
let temp;
|
|
|
|
let divisor;
|
|
|
|
if (!isInteger(numerator) || !isInteger(denominator))
|
|
|
|
return '? : ?';
|
|
|
|
if (numerator === denominator)
|
|
|
|
return '1 : 1';
|
|
|
|
// make sure numerator is always the larger number
|
|
|
|
if (+numerator < +denominator) {
|
|
|
|
temp = numerator;
|
|
|
|
numerator = denominator;
|
|
|
|
denominator = temp;
|
|
|
|
}
|
|
|
|
divisor = gcd(+numerator, +denominator);
|
|
|
|
return 'undefined' === typeof temp ? (numerator / divisor) + ' : ' + (denominator / divisor) : (denominator / divisor) + ' : ' + (numerator / divisor);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Determine whether a value is an integer (ie. only numbers)
|
|
|
|
*/
|
|
|
|
function isInteger(value) {
|
|
|
|
return /^[0-9]+$/.test(value);
|
|
|
|
}
|
2019-06-18 19:25:28 +00:00
|
|
|
let filmout;
|
2019-06-25 01:11:14 +00:00
|
|
|
class FilmOut {
|
|
|
|
constructor() {
|
|
|
|
this.id = 'filmout';
|
2021-02-24 00:54:03 +00:00
|
|
|
this.videoExtensions = ['.mpg', '.mpeg', '.mov', '.mkv', '.avi', '.mp4',
|
|
|
|
'.gif'];
|
2021-02-24 05:22:08 +00:00
|
|
|
this.stillExtensions = ['.tif', '.tiff', '.png', '.jpg', '.jpeg', '.bmp'];
|
2021-02-24 15:05:45 +00:00
|
|
|
this.sequenceExtensions = ['.png', '.jpg', '.jpeg'];
|
2019-06-25 01:11:14 +00:00
|
|
|
this.displays = [];
|
2019-06-25 16:13:15 +00:00
|
|
|
this.state = {
|
2019-06-27 00:08:49 +00:00
|
|
|
frame: 0,
|
|
|
|
display: null
|
2019-06-25 16:13:15 +00:00
|
|
|
};
|
2019-06-25 01:11:14 +00:00
|
|
|
}
|
|
|
|
init() {
|
|
|
|
this.listen();
|
|
|
|
}
|
|
|
|
listen() {
|
|
|
|
ipcRenderer.on(this.id, this.onFilmout.bind(this));
|
|
|
|
ipcRenderer.on('system', this.onSystem.bind(this));
|
2019-06-25 16:13:15 +00:00
|
|
|
ipcRenderer.on('preview_frame', this.onFrame.bind(this));
|
2020-02-21 18:34:22 +00:00
|
|
|
ipcRenderer.on('pre_export', this.onPreExport.bind(this));
|
2020-03-09 19:46:06 +00:00
|
|
|
ipcRenderer.on('pre_export_progress', this.onPreExportProgress.bind(this));
|
2019-06-25 01:11:14 +00:00
|
|
|
}
|
|
|
|
onSystem(evt, args) {
|
|
|
|
let option;
|
|
|
|
for (let display of args.displays) {
|
|
|
|
this.displays.push(display);
|
|
|
|
option = $('<option>');
|
|
|
|
option.val(display.id);
|
|
|
|
option.text(display.name);
|
|
|
|
if (display.primary) {
|
|
|
|
this.setDisplay(display.id);
|
|
|
|
}
|
|
|
|
$('#filmout_displays').append(option);
|
|
|
|
}
|
|
|
|
if (args.displays.length > 1) {
|
|
|
|
$('#filmout_displays').on('change', this.onChange.bind(this));
|
|
|
|
}
|
2019-06-25 16:13:15 +00:00
|
|
|
$('#filmout_position').on('change', this.previewFrame.bind(this));
|
2019-06-25 01:11:14 +00:00
|
|
|
}
|
|
|
|
onChange() {
|
|
|
|
const val = $('#filmout_displays').val();
|
|
|
|
this.setDisplay(val);
|
|
|
|
}
|
|
|
|
setDisplay(id) {
|
|
|
|
const maxW = 800;
|
|
|
|
const maxH = 360;
|
|
|
|
const display = this.displays.find((elem) => {
|
|
|
|
if (elem.id == id)
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
let scale = display.height / maxH;
|
|
|
|
const w = display.width / scale;
|
|
|
|
const elem = $('#filmout_monitor');
|
|
|
|
const aspect = reduceRatio(display.width, display.height);
|
|
|
|
let h;
|
|
|
|
let top;
|
|
|
|
if (w > maxW) {
|
|
|
|
scale = display.width / maxW;
|
|
|
|
h = display.height / scale;
|
|
|
|
top = Math.floor((maxH - h) / 2);
|
|
|
|
elem.height(h);
|
2019-06-27 00:08:49 +00:00
|
|
|
elem.width(maxW - 4);
|
|
|
|
elem.css('top', `${top}px`);
|
2019-06-25 01:11:14 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
elem.width(w);
|
2019-06-27 00:08:49 +00:00
|
|
|
elem.height(maxH - 4);
|
|
|
|
elem.css('top', `0px`);
|
2019-06-25 01:11:14 +00:00
|
|
|
}
|
|
|
|
elem.addClass('on');
|
2019-06-25 16:13:15 +00:00
|
|
|
$('#filmout_stats_monitor_size').text(`${display.width} x ${display.height}`);
|
2019-06-25 01:11:14 +00:00
|
|
|
$('#filmout_stats_monitor_aspect').text(`${aspect}`);
|
2019-06-25 16:13:15 +00:00
|
|
|
$('#filmout_stats_monitor_scale').text(`${parseFloat(display.scale).toFixed(1)} scale factor`);
|
2019-07-07 04:02:01 +00:00
|
|
|
//console.dir(display);
|
2019-06-27 00:08:49 +00:00
|
|
|
this.state.display = id;
|
|
|
|
ipcRenderer.send('display', { display: id });
|
2019-06-25 01:11:14 +00:00
|
|
|
}
|
2021-02-24 00:54:03 +00:00
|
|
|
/**
|
|
|
|
* Select a file from the showOpenDialog method. Save the file
|
|
|
|
* to an <input type=file> element if the selection is valid.
|
|
|
|
**/
|
2019-06-25 01:11:14 +00:00
|
|
|
selectFile() {
|
2020-01-19 05:36:58 +00:00
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
|
const elem = $('#digital');
|
2021-02-24 15:05:45 +00:00
|
|
|
const properties = [`openFile`, `openDirectory`];
|
2020-01-19 05:36:58 +00:00
|
|
|
const options = {
|
|
|
|
title: `Select video or image sequence`,
|
2021-02-24 15:05:45 +00:00
|
|
|
properties,
|
2020-01-19 05:36:58 +00:00
|
|
|
defaultPath: 'c:/',
|
|
|
|
filters: [
|
|
|
|
{
|
|
|
|
name: 'All Files',
|
|
|
|
extensions: ['*']
|
|
|
|
},
|
|
|
|
]
|
|
|
|
};
|
|
|
|
let files;
|
2021-02-22 18:12:27 +00:00
|
|
|
let valid = false;
|
|
|
|
let pathStr;
|
|
|
|
let displayName;
|
|
|
|
let ext;
|
2021-02-24 15:05:45 +00:00
|
|
|
const linuxMessage = `Do you want to use a single file (video or still image) or a folder containing an image sequence?`;
|
|
|
|
const linuxChoices = ['File', 'Folder', 'Cancel'];
|
|
|
|
let linuxChoice = 0;
|
|
|
|
if (process.platform === 'linux') {
|
|
|
|
linuxChoice = yield gui.choice(linuxMessage, linuxChoices);
|
|
|
|
if (linuxChoice === 0) {
|
|
|
|
options.properties = ['openFile'];
|
|
|
|
}
|
|
|
|
else if (linuxChoice === 1) {
|
|
|
|
options.properties = ['openDirectory'];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2020-01-19 05:36:58 +00:00
|
|
|
try {
|
|
|
|
files = yield dialog.showOpenDialog(options);
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
log.error(err);
|
|
|
|
return false;
|
|
|
|
}
|
2019-06-25 01:11:14 +00:00
|
|
|
if (!files)
|
|
|
|
return false;
|
2021-02-24 00:54:03 +00:00
|
|
|
if (files.filePaths.length > 0) {
|
|
|
|
pathStr = files.filePaths[0];
|
|
|
|
displayName = path.basename(pathStr);
|
|
|
|
valid = this.validateSelection(files);
|
2021-02-24 16:50:15 +00:00
|
|
|
if (valid) {
|
|
|
|
log.info(`Selected "${displayName}"`, 'FILMOUT', true);
|
|
|
|
elem.attr('data-file', pathStr);
|
|
|
|
elem.val(displayName);
|
|
|
|
$('#filmout_file').val(displayName);
|
|
|
|
this.useFile();
|
|
|
|
}
|
2019-06-25 01:11:14 +00:00
|
|
|
}
|
2021-03-18 15:27:53 +00:00
|
|
|
if (!valid && typeof files.cancelled !== 'undefined') {
|
2021-02-24 00:54:03 +00:00
|
|
|
gui.warn('Invalid selection', `The selection "${displayName}" is not an accepted video, image or folder containing an image sequence.`);
|
|
|
|
return false;
|
|
|
|
}
|
2019-06-25 01:11:14 +00:00
|
|
|
});
|
|
|
|
}
|
2021-02-24 00:54:03 +00:00
|
|
|
/**
|
|
|
|
* Validate the selection to be of an approved selection or a directory
|
|
|
|
* containing images of an approved extension.
|
2021-02-24 05:22:08 +00:00
|
|
|
*
|
|
|
|
* @param {array} files List of files to validate their types
|
|
|
|
*
|
|
|
|
* @returns {boolean} Whether or not the selection is valid
|
2021-02-24 00:54:03 +00:00
|
|
|
**/
|
|
|
|
validateSelection(files) {
|
|
|
|
let ext;
|
|
|
|
let pathStr;
|
|
|
|
let dir = false;
|
|
|
|
let valid = false;
|
|
|
|
let fileList = [];
|
|
|
|
if (files.filePaths.length === 1) {
|
|
|
|
pathStr = files.filePaths[0];
|
|
|
|
dir = fs.lstatSync(pathStr).isDirectory();
|
|
|
|
if (dir) {
|
|
|
|
log.info('The selection is a directory');
|
|
|
|
fileList = fs.readdirSync(pathStr);
|
|
|
|
fileList = fileList.filter((file) => {
|
|
|
|
let ext = path.extname(file).toLowerCase();
|
2021-02-24 16:50:15 +00:00
|
|
|
if (this.sequenceExtensions.indexOf(ext) !== -1) {
|
2021-02-24 00:54:03 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
if (fileList.length > 0) {
|
|
|
|
valid = true;
|
|
|
|
}
|
2021-02-24 16:50:15 +00:00
|
|
|
else {
|
|
|
|
valid = false;
|
|
|
|
}
|
2021-02-24 00:54:03 +00:00
|
|
|
}
|
2021-02-24 16:50:15 +00:00
|
|
|
else {
|
|
|
|
ext = path.extname(pathStr.toLowerCase());
|
|
|
|
valid = this.videoExtensions.indexOf(ext) === -1;
|
|
|
|
if (!valid) {
|
|
|
|
valid = this.stillExtensions.indexOf(ext) === -1;
|
|
|
|
}
|
2021-02-24 00:54:03 +00:00
|
|
|
}
|
|
|
|
}
|
2021-02-24 05:22:08 +00:00
|
|
|
return valid;
|
2021-02-24 00:54:03 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Prompt the user to use the selected file/files or cancel
|
|
|
|
**/
|
2019-06-25 01:11:14 +00:00
|
|
|
useFile() {
|
2020-02-21 21:58:35 +00:00
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
|
const elem = $('#digital');
|
|
|
|
const filePath = elem.attr('data-file');
|
|
|
|
const fileName = elem.val();
|
|
|
|
let proceed = false;
|
|
|
|
let obj = {
|
|
|
|
path: filePath,
|
|
|
|
fileName
|
|
|
|
};
|
|
|
|
if (filePath && filePath !== '') {
|
2021-02-24 15:05:45 +00:00
|
|
|
proceed = yield gui.confirm(`Are you sure you want to use ${fileName}?`, 'No');
|
2020-02-21 21:58:35 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.selectFile();
|
|
|
|
}
|
|
|
|
if (proceed) {
|
|
|
|
gui.overlay(true);
|
|
|
|
gui.spinner(true, `Getting info about ${fileName}`);
|
2021-03-18 15:27:53 +00:00
|
|
|
ipcRenderer.send(this.id, obj);
|
2020-02-21 21:58:35 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$('#projector_type_digital').prop('checked', 'checked');
|
|
|
|
$('#digital').removeClass('active');
|
|
|
|
}
|
|
|
|
//cancel video
|
|
|
|
});
|
2019-06-25 01:11:14 +00:00
|
|
|
}
|
2020-01-20 06:37:38 +00:00
|
|
|
//callback after
|
2019-06-25 01:11:14 +00:00
|
|
|
onFilmout(evt, args) {
|
|
|
|
let state;
|
|
|
|
let color = [255, 255, 255];
|
|
|
|
gui.spinner(false);
|
|
|
|
gui.overlay(false);
|
|
|
|
if (args.valid && args.valid === true) {
|
|
|
|
state = JSON.parse(args.state);
|
|
|
|
$('#digital').addClass('active');
|
|
|
|
$('#projector_type_digital').prop('checked', 'checked');
|
2020-02-21 18:34:22 +00:00
|
|
|
gui.notify('FILMOUT', `Using video ${state.fileName}`);
|
2019-06-25 01:11:14 +00:00
|
|
|
seq.set(0, 'PF');
|
|
|
|
grid.state(0);
|
|
|
|
seq.set(1, 'CF');
|
|
|
|
seq.setLight(1, color);
|
|
|
|
grid.state(1);
|
|
|
|
if (light.disabled) {
|
2020-01-20 06:37:38 +00:00
|
|
|
//light.enable();
|
2019-06-25 01:11:14 +00:00
|
|
|
}
|
2019-06-25 16:13:15 +00:00
|
|
|
this.state.frame = 0;
|
|
|
|
this.state.frames = state.frames;
|
2020-03-09 19:46:06 +00:00
|
|
|
this.state.seconds = state.seconds;
|
|
|
|
this.state.fps = state.fps;
|
2019-06-25 16:13:15 +00:00
|
|
|
this.state.width = state.info.width;
|
|
|
|
this.state.height = state.info.height;
|
|
|
|
this.state.name = state.fileName;
|
2020-02-21 18:34:22 +00:00
|
|
|
this.state.path = state.path;
|
2021-02-24 05:22:08 +00:00
|
|
|
this.state.directory = state.directory;
|
2019-06-25 01:11:14 +00:00
|
|
|
$('#seq_loop').val(`${state.frames - 1}`).trigger('change');
|
|
|
|
$('#filmout_stats_video_name').text(state.fileName);
|
2019-06-25 16:13:15 +00:00
|
|
|
$('#filmout_stats_video_size').text(`${state.info.width} x ${state.info.height}`);
|
2019-06-25 01:11:14 +00:00
|
|
|
$('#filmout_stats_video_frames').text(`${state.frames} frames`);
|
2021-02-24 16:50:15 +00:00
|
|
|
this.reset();
|
2019-06-25 01:11:14 +00:00
|
|
|
gui.updateState();
|
2019-06-25 16:13:15 +00:00
|
|
|
this.previewFrame();
|
2021-02-24 05:22:08 +00:00
|
|
|
if (!this.state.directory) {
|
|
|
|
this.preExport();
|
|
|
|
}
|
2019-06-25 01:11:14 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$('#projector_type_digital').prop('checked', 'checked');
|
|
|
|
$('#digital').removeClass('active');
|
|
|
|
}
|
|
|
|
}
|
2019-06-25 16:13:15 +00:00
|
|
|
previewFrame() {
|
|
|
|
const frameStr = $('#filmout_position').val();
|
|
|
|
const frame = parseInt(frameStr, 10);
|
|
|
|
this.state.frame = frame;
|
2021-03-18 15:27:53 +00:00
|
|
|
ipcRenderer.send('preview_frame', { frame });
|
2019-06-25 16:13:15 +00:00
|
|
|
}
|
|
|
|
onFrame(evt, args) {
|
|
|
|
const elem = $('#filmout');
|
|
|
|
elem[0].style.backgroundImage = `url('${args.path}')`;
|
|
|
|
elem.addClass('on');
|
|
|
|
}
|
2020-02-21 18:34:22 +00:00
|
|
|
preExport() {
|
2020-02-21 21:58:35 +00:00
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
|
let proceed = false;
|
|
|
|
if (this.state.path && this.state.path !== '') {
|
2021-02-24 15:05:45 +00:00
|
|
|
proceed = yield gui.confirm(`Export all frames of ${this.state.name}? This may take a while, but will allow filmout sequences to run faster.`, 'No');
|
2020-02-21 21:58:35 +00:00
|
|
|
}
|
|
|
|
if (proceed) {
|
|
|
|
gui.overlay(true);
|
2020-03-09 19:46:06 +00:00
|
|
|
gui.spinner(true, `Exporting frames of ${this.state.name}`, true, false);
|
|
|
|
ipcRenderer.send('pre_export', { state: this.state });
|
2020-02-21 21:58:35 +00:00
|
|
|
}
|
|
|
|
});
|
2020-02-21 18:34:22 +00:00
|
|
|
}
|
|
|
|
onPreExport(evt, args) {
|
2020-03-09 19:46:06 +00:00
|
|
|
if (args.completed && args.completed === true) {
|
|
|
|
gui.notify('FILMOUT', `Exported frames of ${this.state.name}`);
|
|
|
|
log.info(`Exported frames of ${this.state.name}`, 'FILMOUT', true);
|
2020-02-21 18:34:22 +00:00
|
|
|
}
|
|
|
|
else {
|
2020-03-09 19:46:06 +00:00
|
|
|
log.info('onPreExport Error');
|
|
|
|
log.error(JSON.stringify(args));
|
2020-02-21 18:34:22 +00:00
|
|
|
}
|
|
|
|
gui.overlay(false);
|
|
|
|
gui.spinner(false);
|
2020-03-09 19:46:06 +00:00
|
|
|
}
|
|
|
|
onPreExportProgress(evt, args) {
|
|
|
|
const elem = $('.progress-bar');
|
|
|
|
let progress = 0;
|
|
|
|
if (args.progress.progress) {
|
|
|
|
progress = args.progress.progress * 100;
|
|
|
|
}
|
|
|
|
elem.attr('aria-valuenow', progress);
|
|
|
|
elem.css('width', `${progress}%`);
|
2020-03-09 19:58:36 +00:00
|
|
|
gui.spinner(true, `Exporting frames of ${this.state.name} in ${humanizeDuration(Math.round(args.progress.estimated) * 1000)}`, true, false);
|
2020-02-21 18:34:22 +00:00
|
|
|
}
|
2019-06-25 16:13:15 +00:00
|
|
|
advance() {
|
|
|
|
this.state.frame++;
|
|
|
|
if (this.state.frame >= this.state.frames) {
|
|
|
|
this.state.frame = 0;
|
|
|
|
}
|
|
|
|
$('#filmout_position').val(this.state.frame).trigger('change');
|
|
|
|
}
|
|
|
|
rewind() {
|
|
|
|
this.state.frame--;
|
|
|
|
if (this.state.frame < 0) {
|
|
|
|
this.state.frame = this.state.frames - 1;
|
|
|
|
}
|
|
|
|
$('#filmout_position').val(this.state.frame).trigger('change');
|
|
|
|
}
|
2021-02-24 16:50:15 +00:00
|
|
|
reset() {
|
|
|
|
this.state.frame = 0;
|
|
|
|
$('#filmout_position').val(this.state.frame).trigger('change');
|
|
|
|
}
|
2019-06-27 00:08:49 +00:00
|
|
|
preview() {
|
|
|
|
const frame = this.state.frame;
|
|
|
|
ipcRenderer.send('preview', { frame });
|
2019-06-25 16:13:15 +00:00
|
|
|
}
|
|
|
|
focus() {
|
|
|
|
ipcRenderer.send('focus', { focus: true });
|
|
|
|
}
|
|
|
|
field() {
|
2019-08-25 19:26:43 +00:00
|
|
|
let ratio = null;
|
|
|
|
if (this.state.name) {
|
|
|
|
ratio = this.state.width / this.state.height;
|
|
|
|
}
|
|
|
|
ipcRenderer.send('field', { field: true, ratio });
|
2019-06-25 16:13:15 +00:00
|
|
|
}
|
|
|
|
meter() {
|
|
|
|
ipcRenderer.send('meter', { meter: true });
|
|
|
|
}
|
|
|
|
close(evt, arg) {
|
|
|
|
}
|
2019-06-25 01:11:14 +00:00
|
|
|
}
|
|
|
|
filmout = new FilmOut();
|
2019-06-18 19:25:28 +00:00
|
|
|
module.exports = filmout;
|
2020-01-10 21:43:12 +00:00
|
|
|
//# sourceMappingURL=filmout.js.map
|