Add jsdoc comments AND semi-colons to sequencer module.

This commit is contained in:
mmcwilliams 2019-07-26 19:03:42 -04:00
parent 4023704d31
commit c01f3ceff8
7 changed files with 318 additions and 40 deletions

View File

@ -1,8 +1,17 @@
'use strict'; 'use strict';
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
const Log = require("log"); const Log = require("log");
/** @module lib/sequencer **/
let seq; let seq;
class Sequencer { class Sequencer {
/**
* @constructor
* Create a new sequencer and assign command and UI as private sub-classes
*
* @param {object} cfg Configuration object
* @param {object} cmd Shared command class
* @param {object} ui Electron UI, browser window
**/
constructor(cfg, cmd, ui) { constructor(cfg, cmd, ui) {
this.running = false; this.running = false;
this.paused = false; this.paused = false;
@ -12,27 +21,52 @@ class Sequencer {
this.loops = 1; this.loops = 1;
this.CMDS = {}; this.CMDS = {};
this.id = 'sequence'; this.id = 'sequence';
this.alerted = false;
this.delayed = false;
this.cfg = cfg; this.cfg = cfg;
this.cmd = cmd; this.cmd = cmd;
this.ui = ui; this.ui = ui;
this.cmds(cfg.cmd); this.cmds(cfg.cmd);
this.init(); this.init();
} }
/**
* Take configuration object and assign all commands as keys
* in the internal CMDS object.
*
* @param {object} obj Configuration object
**/
cmds(obj) { cmds(obj) {
let keys = Object.keys(obj); let keys = Object.keys(obj);
for (let key of keys) { for (let key of keys) {
this.CMDS[obj[key]] = key; this.CMDS[obj[key]] = key;
} }
//
//
} }
//currently called by ui /**
* Initialize the class by requiring ipcMain from electron
* and creating logger.
*
**/
async init() { async init() {
this.log = await Log({ label: this.id }); this.log = await Log({ label: this.id });
this.ipc = require('electron').ipcMain; this.ipc = require('electron').ipcMain;
this.listen(); this.listen();
} }
/**
* Bind ipc listener to channel 'sequencer' or current id of
* class.
**/
listen() { listen() {
this.ipc.on(this.id, this.listener.bind(this)); this.ipc.on(this.id, this.listener.bind(this));
} }
/**
* Listener callback function. Called whenever ipc
* message is sent to channel 'sequencer'.
*
* @param {object} event IPC message event
* @param {object} arg Arguments provided in message
**/
async listener(event, arg) { async listener(event, arg) {
if (arg && arg.start) { if (arg && arg.start) {
this.start(arg); this.start(arg);
@ -54,21 +88,43 @@ class Sequencer {
} }
event.returnValue = true; event.returnValue = true;
} }
/**
* Sets the value of the loops in the grid sequence
* to value sent by UI in ipc message.
*
* @param {integer} count Number of loops to set grid sequence to
**/
setLoops(count) { setLoops(count) {
this.gridLoops = count; this.gridLoops = count;
this.log.info(`Set loop count to ${count}`); this.log.info(`Set loop count to ${count}`);
} }
/**
* Sets multiple steps at once
*
* @param {array} steps Array of steps to set or update
**/
setSteps(steps) { setSteps(steps) {
for (let step of steps) { for (let step of steps) {
this.grid[step.x] = step; this.grid[step.x] = step;
} }
} }
/**
* Resets multiple steps to default 'undefined' state
*
* @param {array} steps Array containing the x location of steps to unset
**/
unsetSteps(steps) { unsetSteps(steps) {
for (let x of steps) { for (let x of steps) {
this.grid[x] = undefined; this.grid[x] = undefined;
} }
} }
//new, replaces exec and init /**
* Starts a sequence with the existing grid sequence,
* or if one is provided in the arg object, starts
* that sequence.
*
* @param {object} arg Arguments from ipc message
**/
async start(arg) { async start(arg) {
let startTime = +new Date(); let startTime = +new Date();
let ms; let ms;
@ -101,6 +157,7 @@ class Sequencer {
if (!this.running) { if (!this.running) {
break; break;
} }
//UI initiates pause, not planned
while (this.paused) { while (this.paused) {
await delay(42); await delay(42);
} }
@ -129,12 +186,14 @@ class Sequencer {
this.log.info(`Ended sequence`); this.log.info(`Ended sequence`);
this.ui.send(this.id, { stop: true, ms }); this.ui.send(this.id, { stop: true, ms });
} }
//new /**
* Pauses sequence from UI.
**/
pause() { pause() {
this.paused = true; this.paused = true;
} }
/** /**
* Stop the sequence * Stops the sequence
**/ **/
stop() { stop() {
if (this.cmd.proj.filmout.state.enabled === true) { if (this.cmd.proj.filmout.state.enabled === true) {
@ -143,15 +202,25 @@ class Sequencer {
this.running = false; this.running = false;
//clear? //clear?
} }
/**
* Execute command @ step x. Wrapper with try catch.
*
* @param {integer} x Step to execute command at
**/
async step(x) { async step(x) {
try { try {
await this.cmdMap(x); await this.cmdExec(x);
} }
catch (err) { catch (err) {
throw err; throw err;
} }
} }
async cmdMap(x) { /**
* Locate step @ position x and execute the command.
*
* @param {integer} x Step to execute command at
**/
async cmdExec(x) {
const cmdOriginal = this.arr[x].cmd; const cmdOriginal = this.arr[x].cmd;
const cmd = this.CMDS[cmdOriginal]; const cmd = this.CMDS[cmdOriginal];
this.log.info(`CMD: '${cmdOriginal}' -> ${cmd}`); this.log.info(`CMD: '${cmdOriginal}' -> ${cmd}`);

File diff suppressed because one or more lines are too long

View File

@ -1,8 +1,17 @@
'use strict'; 'use strict';
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
const Log = require("log"); const Log = require("log");
/** @module lib/sequencer **/
let seq; let seq;
class Sequencer { class Sequencer {
/**
* @constructor
* Create a new sequencer and assign command and UI as private sub-classes
*
* @param {object} cfg Configuration object
* @param {object} cmd Shared command class
* @param {object} ui Electron UI, browser window
**/
constructor(cfg, cmd, ui) { constructor(cfg, cmd, ui) {
this.running = false; this.running = false;
this.paused = false; this.paused = false;
@ -12,27 +21,52 @@ class Sequencer {
this.loops = 1; this.loops = 1;
this.CMDS = {}; this.CMDS = {};
this.id = 'sequence'; this.id = 'sequence';
this.alerted = false;
this.delayed = false;
this.cfg = cfg; this.cfg = cfg;
this.cmd = cmd; this.cmd = cmd;
this.ui = ui; this.ui = ui;
this.cmds(cfg.cmd); this.cmds(cfg.cmd);
this.init(); this.init();
} }
/**
* Take configuration object and assign all commands as keys
* in the internal CMDS object.
*
* @param {object} obj Configuration object
**/
cmds(obj) { cmds(obj) {
let keys = Object.keys(obj); let keys = Object.keys(obj);
for (let key of keys) { for (let key of keys) {
this.CMDS[obj[key]] = key; this.CMDS[obj[key]] = key;
} }
//
//
} }
//currently called by ui /**
* Initialize the class by requiring ipcMain from electron
* and creating logger.
*
**/
async init() { async init() {
this.log = await Log({ label: this.id }); this.log = await Log({ label: this.id });
this.ipc = require('electron').ipcMain; this.ipc = require('electron').ipcMain;
this.listen(); this.listen();
} }
/**
* Bind ipc listener to channel 'sequencer' or current id of
* class.
**/
listen() { listen() {
this.ipc.on(this.id, this.listener.bind(this)); this.ipc.on(this.id, this.listener.bind(this));
} }
/**
* Listener callback function. Called whenever ipc
* message is sent to channel 'sequencer'.
*
* @param {object} event IPC message event
* @param {object} arg Arguments provided in message
**/
async listener(event, arg) { async listener(event, arg) {
if (arg && arg.start) { if (arg && arg.start) {
this.start(arg); this.start(arg);
@ -54,21 +88,43 @@ class Sequencer {
} }
event.returnValue = true; event.returnValue = true;
} }
/**
* Sets the value of the loops in the grid sequence
* to value sent by UI in ipc message.
*
* @param {integer} count Number of loops to set grid sequence to
**/
setLoops(count) { setLoops(count) {
this.gridLoops = count; this.gridLoops = count;
this.log.info(`Set loop count to ${count}`); this.log.info(`Set loop count to ${count}`);
} }
/**
* Sets multiple steps at once
*
* @param {array} steps Array of steps to set or update
**/
setSteps(steps) { setSteps(steps) {
for (let step of steps) { for (let step of steps) {
this.grid[step.x] = step; this.grid[step.x] = step;
} }
} }
/**
* Resets multiple steps to default 'undefined' state
*
* @param {array} steps Array containing the x location of steps to unset
**/
unsetSteps(steps) { unsetSteps(steps) {
for (let x of steps) { for (let x of steps) {
this.grid[x] = undefined; this.grid[x] = undefined;
} }
} }
//new, replaces exec and init /**
* Starts a sequence with the existing grid sequence,
* or if one is provided in the arg object, starts
* that sequence.
*
* @param {object} arg Arguments from ipc message
**/
async start(arg) { async start(arg) {
let startTime = +new Date(); let startTime = +new Date();
let ms; let ms;
@ -101,6 +157,7 @@ class Sequencer {
if (!this.running) { if (!this.running) {
break; break;
} }
//UI initiates pause, not planned
while (this.paused) { while (this.paused) {
await delay(42); await delay(42);
} }
@ -129,12 +186,14 @@ class Sequencer {
this.log.info(`Ended sequence`); this.log.info(`Ended sequence`);
this.ui.send(this.id, { stop: true, ms }); this.ui.send(this.id, { stop: true, ms });
} }
//new /**
* Pauses sequence from UI.
**/
pause() { pause() {
this.paused = true; this.paused = true;
} }
/** /**
* Stop the sequence * Stops the sequence
**/ **/
stop() { stop() {
if (this.cmd.proj.filmout.state.enabled === true) { if (this.cmd.proj.filmout.state.enabled === true) {
@ -143,15 +202,25 @@ class Sequencer {
this.running = false; this.running = false;
//clear? //clear?
} }
/**
* Execute command @ step x. Wrapper with try catch.
*
* @param {integer} x Step to execute command at
**/
async step(x) { async step(x) {
try { try {
await this.cmdMap(x); await this.cmdExec(x);
} }
catch (err) { catch (err) {
throw err; throw err;
} }
} }
async cmdMap(x) { /**
* Locate step @ position x and execute the command.
*
* @param {integer} x Step to execute command at
**/
async cmdExec(x) {
const cmdOriginal = this.arr[x].cmd; const cmdOriginal = this.arr[x].cmd;
const cmd = this.CMDS[cmdOriginal]; const cmd = this.CMDS[cmdOriginal];
this.log.info(`CMD: '${cmdOriginal}' -> ${cmd}`); this.log.info(`CMD: '${cmdOriginal}' -> ${cmd}`);

File diff suppressed because one or more lines are too long

View File

@ -1,8 +1,17 @@
'use strict'; 'use strict';
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
const Log = require("log"); const Log = require("log");
/** @module lib/sequencer **/
let seq; let seq;
class Sequencer { class Sequencer {
/**
* @constructor
* Create a new sequencer and assign command and UI as private sub-classes
*
* @param {object} cfg Configuration object
* @param {object} cmd Shared command class
* @param {object} ui Electron UI, browser window
**/
constructor(cfg, cmd, ui) { constructor(cfg, cmd, ui) {
this.running = false; this.running = false;
this.paused = false; this.paused = false;
@ -12,27 +21,52 @@ class Sequencer {
this.loops = 1; this.loops = 1;
this.CMDS = {}; this.CMDS = {};
this.id = 'sequence'; this.id = 'sequence';
this.alerted = false;
this.delayed = false;
this.cfg = cfg; this.cfg = cfg;
this.cmd = cmd; this.cmd = cmd;
this.ui = ui; this.ui = ui;
this.cmds(cfg.cmd); this.cmds(cfg.cmd);
this.init(); this.init();
} }
/**
* Take configuration object and assign all commands as keys
* in the internal CMDS object.
*
* @param {object} obj Configuration object
**/
cmds(obj) { cmds(obj) {
let keys = Object.keys(obj); let keys = Object.keys(obj);
for (let key of keys) { for (let key of keys) {
this.CMDS[obj[key]] = key; this.CMDS[obj[key]] = key;
} }
//
//
} }
//currently called by ui /**
* Initialize the class by requiring ipcMain from electron
* and creating logger.
*
**/
async init() { async init() {
this.log = await Log({ label: this.id }); this.log = await Log({ label: this.id });
this.ipc = require('electron').ipcMain; this.ipc = require('electron').ipcMain;
this.listen(); this.listen();
} }
/**
* Bind ipc listener to channel 'sequencer' or current id of
* class.
**/
listen() { listen() {
this.ipc.on(this.id, this.listener.bind(this)); this.ipc.on(this.id, this.listener.bind(this));
} }
/**
* Listener callback function. Called whenever ipc
* message is sent to channel 'sequencer'.
*
* @param {object} event IPC message event
* @param {object} arg Arguments provided in message
**/
async listener(event, arg) { async listener(event, arg) {
if (arg && arg.start) { if (arg && arg.start) {
this.start(arg); this.start(arg);
@ -54,21 +88,43 @@ class Sequencer {
} }
event.returnValue = true; event.returnValue = true;
} }
/**
* Sets the value of the loops in the grid sequence
* to value sent by UI in ipc message.
*
* @param {integer} count Number of loops to set grid sequence to
**/
setLoops(count) { setLoops(count) {
this.gridLoops = count; this.gridLoops = count;
this.log.info(`Set loop count to ${count}`); this.log.info(`Set loop count to ${count}`);
} }
/**
* Sets multiple steps at once
*
* @param {array} steps Array of steps to set or update
**/
setSteps(steps) { setSteps(steps) {
for (let step of steps) { for (let step of steps) {
this.grid[step.x] = step; this.grid[step.x] = step;
} }
} }
/**
* Resets multiple steps to default 'undefined' state
*
* @param {array} steps Array containing the x location of steps to unset
**/
unsetSteps(steps) { unsetSteps(steps) {
for (let x of steps) { for (let x of steps) {
this.grid[x] = undefined; this.grid[x] = undefined;
} }
} }
//new, replaces exec and init /**
* Starts a sequence with the existing grid sequence,
* or if one is provided in the arg object, starts
* that sequence.
*
* @param {object} arg Arguments from ipc message
**/
async start(arg) { async start(arg) {
let startTime = +new Date(); let startTime = +new Date();
let ms; let ms;
@ -101,6 +157,7 @@ class Sequencer {
if (!this.running) { if (!this.running) {
break; break;
} }
//UI initiates pause, not planned
while (this.paused) { while (this.paused) {
await delay(42); await delay(42);
} }
@ -129,12 +186,14 @@ class Sequencer {
this.log.info(`Ended sequence`); this.log.info(`Ended sequence`);
this.ui.send(this.id, { stop: true, ms }); this.ui.send(this.id, { stop: true, ms });
} }
//new /**
* Pauses sequence from UI.
**/
pause() { pause() {
this.paused = true; this.paused = true;
} }
/** /**
* Stop the sequence * Stops the sequence
**/ **/
stop() { stop() {
if (this.cmd.proj.filmout.state.enabled === true) { if (this.cmd.proj.filmout.state.enabled === true) {
@ -143,15 +202,25 @@ class Sequencer {
this.running = false; this.running = false;
//clear? //clear?
} }
/**
* Execute command @ step x. Wrapper with try catch.
*
* @param {integer} x Step to execute command at
**/
async step(x) { async step(x) {
try { try {
await this.cmdMap(x); await this.cmdExec(x);
} }
catch (err) { catch (err) {
throw err; throw err;
} }
} }
async cmdMap(x) { /**
* Locate step @ position x and execute the command.
*
* @param {integer} x Step to execute command at
**/
async cmdExec(x) {
const cmdOriginal = this.arr[x].cmd; const cmdOriginal = this.arr[x].cmd;
const cmd = this.CMDS[cmdOriginal]; const cmd = this.CMDS[cmdOriginal];
this.log.info(`CMD: '${cmdOriginal}' -> ${cmd}`); this.log.info(`CMD: '${cmdOriginal}' -> ${cmd}`);

File diff suppressed because one or more lines are too long

View File

@ -3,6 +3,8 @@
import uuid from 'uuid/v4'; import uuid from 'uuid/v4';
import Log = require('log'); import Log = require('log');
/** @module lib/sequencer **/
let seq : Sequencer; let seq : Sequencer;
class Sequencer { class Sequencer {
@ -22,6 +24,17 @@ class Sequencer {
private ui : any; private ui : any;
private log : any; private log : any;
private id : string = 'sequence'; private id : string = 'sequence';
private alerted : boolean = false;
private delayed : boolean = false;
/**
* @constructor
* Create a new sequencer and assign command and UI as private sub-classes
*
* @param {object} cfg Configuration object
* @param {object} cmd Shared command class
* @param {object} ui Electron UI, browser window
**/
constructor (cfg : any, cmd : any, ui : any) { constructor (cfg : any, cmd : any, ui : any) {
this.cfg = cfg; this.cfg = cfg;
@ -31,24 +44,47 @@ class Sequencer {
this.init(); this.init();
} }
/**
* Take configuration object and assign all commands as keys
* in the internal CMDS object.
*
* @param {object} obj Configuration object
**/
private cmds (obj : any) { private cmds (obj : any) {
let keys : string[] = Object.keys(obj); let keys : string[] = Object.keys(obj);
for (let key of keys) { for (let key of keys) {
this.CMDS[obj[key]] = key; this.CMDS[obj[key]] = key;
} }
//
//
} }
//currently called by ui /**
* Initialize the class by requiring ipcMain from electron
* and creating logger.
*
**/
private async init () { private async init () {
this.log = await Log({ label : this.id }) this.log = await Log({ label : this.id })
this.ipc = require('electron').ipcMain; this.ipc = require('electron').ipcMain;
this.listen(); this.listen();
} }
/**
* Bind ipc listener to channel 'sequencer' or current id of
* class.
**/
private listen () { private listen () {
this.ipc.on(this.id, this.listener.bind(this)); this.ipc.on(this.id, this.listener.bind(this));
} }
/**
* Listener callback function. Called whenever ipc
* message is sent to channel 'sequencer'.
*
* @param {object} event IPC message event
* @param {object} arg Arguments provided in message
**/
private async listener (event : any, arg : any) { private async listener (event : any, arg : any) {
if (arg && arg.start) { if (arg && arg.start) {
this.start(arg); this.start(arg);
@ -66,24 +102,46 @@ class Sequencer {
event.returnValue = true; event.returnValue = true;
} }
/**
* Sets the value of the loops in the grid sequence
* to value sent by UI in ipc message.
*
* @param {integer} count Number of loops to set grid sequence to
**/
public setLoops (count : number) { public setLoops (count : number) {
this.gridLoops = count; this.gridLoops = count;
this.log.info(`Set loop count to ${count}`); this.log.info(`Set loop count to ${count}`);
} }
/**
* Sets multiple steps at once
*
* @param {array} steps Array of steps to set or update
**/
public setSteps (steps : any[]) { public setSteps (steps : any[]) {
for (let step of steps) { for (let step of steps) {
this.grid[step.x] = step; this.grid[step.x] = step;
} }
} }
/**
* Resets multiple steps to default 'undefined' state
*
* @param {array} steps Array containing the x location of steps to unset
**/
public unsetSteps (steps : number[]) { public unsetSteps (steps : number[]) {
for (let x of steps) { for (let x of steps) {
this.grid[x] = undefined; this.grid[x] = undefined;
} }
} }
//new, replaces exec and init /**
* Starts a sequence with the existing grid sequence,
* or if one is provided in the arg object, starts
* that sequence.
*
* @param {object} arg Arguments from ipc message
**/
public async start (arg : any) { public async start (arg : any) {
let startTime : number = +new Date(); let startTime : number = +new Date();
let ms : number; let ms : number;
@ -104,46 +162,47 @@ class Sequencer {
this.paused = false; this.paused = false;
//start sequence //start sequence
this.log.info(`Starting sequence...`) this.log.info(`Starting sequence...`);
this.ui.send(this.id, { start : true }) this.ui.send(this.id, { start : true });
if (this.cmd.proj.filmout.state.enabled === true) { if (this.cmd.proj.filmout.state.enabled === true) {
await this.cmd.proj.filmout.display.open() await this.cmd.proj.filmout.display.open();
} }
for (let x = 0; x < this.loops; x++) { for (let x = 0; x < this.loops; x++) {
//start loop //start loop
this.log.info(`Starting loop ${x + 1}`) this.log.info(`Starting loop ${x + 1}`);
this.ui.send(this.id, { loop : x, start : true }); this.ui.send(this.id, { loop : x, start : true });
for (let y = 0; y < this.arr.length; y++) { for (let y = 0; y < this.arr.length; y++) {
//start step //start step
if (!this.running) { if (!this.running) {
break break;
} }
//UI initiates pause, not planned
while (this.paused) { while (this.paused) {
await delay(42); await delay(42);
} }
if (typeof this.arr[y] === 'undefined') { if (typeof this.arr[y] === 'undefined') {
continue continue;
} }
this.log.info(`Starting step ${y + 1} of loop ${x + 1}`) this.log.info(`Starting step ${y + 1} of loop ${x + 1}`);
this.ui.send(this.id, { step : y, loop : x, start : true }); this.ui.send(this.id, { step : y, loop : x, start : true });
await this.step(y); await this.step(y);
//end step //end step
this.log.info(`Ended step ${y + 1} of loop ${x + 1}`) this.log.info(`Ended step ${y + 1} of loop ${x + 1}`);
this.ui.send(this.id, { step : y, loop : x, stop : true }); this.ui.send(this.id, { step : y, loop : x, stop : true });
} }
if (!this.running) { if (!this.running) {
break break;
} }
//end loop //end loop
this.log.info(`Ended loop ${x + 1}`) this.log.info(`Ended loop ${x + 1}`);
this.ui.send(this.id, { loop : x, stop : true }); this.ui.send(this.id, { loop : x, stop : true });
} }
@ -153,17 +212,19 @@ class Sequencer {
ms = ( +new Date() ) - startTime; ms = ( +new Date() ) - startTime;
//end sequence //end sequence
this.log.info(`Ended sequence`) this.log.info(`Ended sequence`);
this.ui.send(this.id, { stop : true, ms }) this.ui.send(this.id, { stop : true, ms });
} }
//new /**
* Pauses sequence from UI.
**/
public pause () { public pause () {
this.paused = true; this.paused = true;
} }
/** /**
* Stop the sequence * Stops the sequence
**/ **/
public stop () { public stop () {
if (this.cmd.proj.filmout.state.enabled === true) { if (this.cmd.proj.filmout.state.enabled === true) {
@ -174,15 +235,25 @@ class Sequencer {
} }
private async step (x: number) { /**
* Execute command @ step x. Wrapper with try catch.
*
* @param {integer} x Step to execute command at
**/
private async step ( x: number) {
try { try {
await this.cmdMap(x) await this.cmdExec(x)
} catch (err) { } catch (err) {
throw err; throw err;
} }
} }
private async cmdMap (x : number) { /**
* Locate step @ position x and execute the command.
*
* @param {integer} x Step to execute command at
**/
private async cmdExec (x : number) {
const cmdOriginal : string = this.arr[x].cmd; const cmdOriginal : string = this.arr[x].cmd;
const cmd : string = this.CMDS[cmdOriginal]; const cmd : string = this.CMDS[cmdOriginal];
this.log.info(`CMD: '${cmdOriginal}' -> ${cmd}`); this.log.info(`CMD: '${cmdOriginal}' -> ${cmd}`);