Merge in 9 months of work on capper branch #71

Merged
mattmcw merged 95 commits from capper into main 2023-02-19 05:28:46 +00:00
4 changed files with 540 additions and 59 deletions
Showing only changes of commit fe61e63e76 - Show all commits

View File

@ -15,14 +15,28 @@ const CMD = [
'P2F',
'P2B',
'PPF',
'PPB'
];
/*
'PPB',
'CFCB',
'CBCF',
'PFPB',
'PBPF'
*/
];
const CAMERA_SECONDARY = [
'C2F',
'C2B',
'CCF',
'CCB',
'CFCB',
'CBCF'
];
const PROJECTOR_SECONDARY = [
'P2F',
'P2B',
'PPF',
'PPB',
'PFPB',
'PBPF'
];
const ALTS = {
'CF': ['CAMERA FORWARD', 'CAM FORWARD'],
'PF': ['PROJECTOR FORWARD', 'PROJ FORWARD'],
@ -40,13 +54,11 @@ const ALTS = {
'P2B': ['PROJECTOR2 BACKWARD', 'PROJ2 BACKWARD', 'PROJECTOR2 BACK', 'PROJ2 BACK'],
'PPF': ['PROJECTORS FORWARD', 'PROJS FORWARD'],
'PPB': ['PROJECTORS BACKWARD', 'PROJS BACKWARD', 'PROJECTORS BACK', 'PROJS BACK'],
'CFCB': [],
'CBCF': [],
'PFPB': [],
'PBPF': []
};
/*
'CFCB' : [ ],
'CBCF' : [ ],
'PFPB' : [ ],
'PBPF' : [ ]
*/
const PAUSE = 'PAUSE';
const ALERT = 'ALERT';
/** helper functions */
@ -91,6 +103,8 @@ class Mscript {
this.loops = [];
this.rec = -1;
this.two = '';
this.three = '';
this.four = '';
this.arr = [];
this.meta = [];
this.target = 0; //move to target using CAM # or PROJ #
@ -123,11 +137,19 @@ class Mscript {
});
for (let line of this.lines) {
this.two = line.substring(0, 2);
if (CMD.indexOf(this.two) !== -1) {
this.basic_cmd(line);
this.three = line.substring(0, 3);
this.four = line.substring(0, 4);
if (CMD.indexOf(this.four) !== -1) {
this.basic_cmd(line, this.four);
}
else if (CMD.indexOf(this.three) !== -1) {
this.basic_cmd(line, this.three);
}
else if (CMD.indexOf(this.two) !== -1) {
this.basic_cmd(line, this.two);
}
else if (startsWith(line, PAUSE)) {
this.pause(line);
//this.pause(line);
}
else if (startsWith(line, ALERT)) {
this.alert(line);
@ -147,9 +169,15 @@ class Mscript {
else if (startsWith(line, 'END')) {
this.end_loop(line);
}
else if (startsWith(line, 'CAM')) { //directly go to that frame (black?)
else if (startsWith(line, 'CAM2')) { //directly go to that frame
this.move_cam2(line);
}
else if (startsWith(line, 'CAM')) { //directly go to that frame
this.move_cam(line);
}
else if (startsWith(line, 'PROJ2')) { //directly go to that frame
this.move_proj2(line);
}
else if (startsWith(line, 'PROJ')) { //directly go to that frame
this.move_proj(line);
}
@ -160,17 +188,18 @@ class Mscript {
//comments
//ignore while parsing
}
else if (startsWith(line, 'ALERT')) {
}
else if (startsWith(line, 'PAUSE')) {
this.pause(line);
}
}
this.output.success = true;
this.output.arr = this.arr; //all instructions
this.output.meta = this.meta; //all metadata for instructions
this.output.cam = this.cam;
this.output.proj = this.proj;
if (this.contains(this.arr, CAMERA_SECONDARY)) {
this.output.cam2 = this.cam2;
}
if (this.contains(this.arr, PROJECTOR_SECONDARY)) {
this.output.proj2 = this.proj2;
}
if (typeof callback !== 'undefined') {
//should only be invoked by running mscript.tests()
callback(this.output);
@ -233,25 +262,26 @@ class Mscript {
* Interpret a basic two character command
*
* @param {string} line Line of script to interpret
* @param {string} short The short command to use
*/
basic_cmd(line) {
basic_cmd(line, short) {
if (this.rec !== -1) {
//hold generated arr in state loop array
this.loops[this.rec].arr
.push.apply(this.loops[this.rec].arr, this.str_to_arr(line, this.two));
.push.apply(this.loops[this.rec].arr, this.str_to_arr(line, short));
this.loops[this.rec].meta
.push.apply(this.loops[this.rec].meta, this.light_to_arr(line, this.two));
.push.apply(this.loops[this.rec].meta, this.light_to_arr(line, short));
}
else {
this.arr.push.apply(this.arr, this.str_to_arr(line, this.two));
this.meta.push.apply(this.meta, this.light_to_arr(line, this.two));
this.arr.push.apply(this.arr, this.str_to_arr(line, short));
this.meta.push.apply(this.meta, this.light_to_arr(line, short));
}
}
/**
* Start a new loop
*
* @param {string} line Line to evaluate as either loop or fade
* @param {boolean} fade Flag as boolean if true
* @param {boolean} fade Flag as true if fade
*/
new_loop(line, fade) {
this.rec++;
@ -260,6 +290,8 @@ class Mscript {
meta: [],
cam: 0,
proj: 0,
cam2: 0,
proj2: 0,
cmd: line + ''
};
if (fade) {
@ -345,6 +377,50 @@ class Mscript {
}
}
}
/**
* Move secondary camera to explicitly-defined frame
*
* @param {string} line Line to interpret with camera move statement
*/
move_cam2(line) {
this.target = parseInt(line.split('CAM2 ')[1]);
if (this.rec !== -1) {
if (this.target > this.cam2) {
this.dist = this.target - this.cam2;
for (let x = 0; x < this.dist; x++) {
this.loops[this.rec].arr.push('C2F');
this.loops[this.rec].meta.push(BLACK);
this.update('C2F');
}
}
else {
this.dist = this.cam2 - this.target;
for (let x = 0; x < this.dist; x++) {
this.loops[this.rec].arr.push('C2B');
this.loops[this.rec].meta.push(BLACK);
this.update('C2B');
}
}
}
else {
if (this.target > this.cam2) {
this.dist = this.target - this.cam2;
for (let x = 0; x < this.dist; x++) {
this.arr.push('C2F');
this.meta.push(BLACK);
this.update('C2F');
}
}
else {
this.dist = this.cam2 - this.target;
for (let x = 0; x < this.dist; x++) {
this.arr.push('C2B');
this.meta.push(BLACK);
this.update('C2B');
}
}
}
}
/**
* Move projector to explicitly-defined frame
*
@ -389,13 +465,63 @@ class Mscript {
}
}
}
/**
* Move projector to explicitly-defined frame
*
* @param {string} line Line containing `move` statement to interpret
*/
move_proj2(line) {
this.target = parseInt(line.split('PROJ2 ')[1]);
if (this.rec !== -1) {
if (this.target > this.proj2) {
this.dist = this.target - this.proj2;
for (let x = 0; x < this.dist; x++) {
this.loops[this.rec].arr.push('P2F');
this.loops[this.rec].meta.push('');
this.update('P2F');
}
}
else {
this.dist = this.proj2 - this.target;
for (let x = 0; x < this.dist; x++) {
this.loops[this.rec].arr.push('P2B');
this.loops[this.rec].meta.push('');
this.update('P2B');
}
}
}
else {
if (this.target > this.proj2) {
this.dist = this.target - this.proj2;
for (let x = 0; x < this.dist; x++) {
this.arr.push('P2F');
this.meta.push('');
this.update('P2F');
}
}
else {
this.dist = this.proj2 - this.target;
for (let x = 0; x < this.dist; x++) {
this.arr.push('P2B');
this.meta.push('');
this.update('P2B');
}
}
}
}
/**
* Set the state of either the cam or projector
*
* @param line {string} String containing set statement
*/
set_state(line) {
if (startsWith(line, 'SET CAM')) {
if (startsWith(line, 'SET CAM2')) {
parseInt(line.split('SET CAM2')[1]);
}
else if (startsWith(line, 'SET PROJ2')) {
this.cam2 = parseInt(line.split('SET PROJ2')[1]);
}
else if (startsWith(line, 'SET CAM')) {
this.cam = parseInt(line.split('SET CAM')[1]);
}
else if (startsWith(line, 'SET PROJ')) {
@ -588,6 +714,118 @@ class Mscript {
this.loops[this.rec].cam -= val;
}
}
else if (cmd === 'C2F') {
if (this.rec === -1) {
this.cam2 += val;
}
else {
this.loops[this.rec].cam2 += val;
}
}
else if (cmd === 'C2B') {
if (this.rec === -1) {
this.cam2 -= val;
}
else {
this.loops[this.rec].cam2 -= val;
}
}
else if (cmd === 'CCF') {
if (this.rec === -1) {
this.cam += val;
this.cam2 += val;
}
else {
this.loops[this.rec].cam2 += val;
this.loops[this.rec].cam2 += val;
}
}
else if (cmd === 'CCB') {
if (this.rec === -1) {
this.cam -= val;
this.cam2 -= val;
}
else {
this.loops[this.rec].cam2 -= val;
this.loops[this.rec].cam2 -= val;
}
}
else if (cmd === 'P2F') {
if (this.rec === -1) {
this.proj2 += val;
}
else {
this.loops[this.rec].proj2 += val;
}
}
else if (cmd === 'P2B') {
if (this.rec === -1) {
this.proj2 -= val;
}
else {
this.loops[this.rec].proj2 -= val;
}
}
else if (cmd === 'PPF') {
if (this.rec === -1) {
this.proj += val;
this.proj2 += val;
}
else {
this.loops[this.rec].proj += val;
this.loops[this.rec].proj2 += val;
}
}
else if (cmd === 'PPB') {
if (this.rec === -1) {
this.proj -= val;
this.proj2 -= val;
}
else {
this.loops[this.rec].proj -= val;
this.loops[this.rec].proj2 -= val;
}
}
else if (cmd === 'CFCB') {
if (this.rec === -1) {
this.cam += val;
this.cam2 -= val;
}
else {
this.loops[this.rec].cam += val;
this.loops[this.rec].cam2 -= val;
}
}
else if (cmd === 'CBCF') {
if (this.rec === -1) {
this.cam -= val;
this.cam2 += val;
}
else {
this.loops[this.rec].cam -= val;
this.loops[this.rec].cam2 += val;
}
}
else if (cmd === 'PFPB') {
if (this.rec === -1) {
this.proj += val;
this.proj2 -= val;
}
else {
this.loops[this.rec].proj += val;
this.loops[this.rec].proj2 -= val;
}
}
else if (cmd === 'PBPF') {
if (this.rec === -1) {
this.proj -= val;
this.proj2 += val;
}
else {
this.loops[this.rec].proj -= val;
this.loops[this.rec].proj2 += val;
}
}
else if (cmd === 'L ') {
}
}
@ -716,6 +954,18 @@ class Mscript {
fail(msg) {
throw new Error(msg);
}
/**
* Determine if array contains matching elements of
* another array
*
* @param {Array} arr Original array to compare
* @param {Array} arr2 Array to compare elements from
*
* @returns {boolean} Whether arr contains elements in arr2
**/
contains(arr, arr2) {
return arr.some(r => arr2.includes(r));
}
}
module.exports = Mscript;
//# sourceMappingURL=index.js.map

File diff suppressed because one or more lines are too long

View File

@ -111,11 +111,13 @@ mse.mscript.compile = function () {
const mscript = new Mscript();
let output = mscript.interpret(data);
let len = output.arr.length;
const cam2 = typeof output.cam2 !== 'undefined' ? `, CAM2 : ${output.cam2}` : '';
const proj2 = typeof output.proj2 !== 'undefined' ? `, PROJ2 : ${output.proj2}` : '';
mse.mscript.raw = data;
mse.mscript.data = output;
//mse.console.print(JSON.stringify(output, null, '\t') + '\n')
mse.console.print(`Sequence contains ${len} step${(len === 1 ? '' : 's')}, CAM: ${output.cam}, PROJ: ${output.proj}`);
mse.console.print(`Sequence contains ${len} step${(len === 1 ? '' : 's')}, CAM: ${output.cam}, PROJ: ${output.proj}${cam2}${proj2}`);
};
mse.mscript.prepare = function () {

View File

@ -7,9 +7,9 @@ interface RGB extends Array<number>{
[index : number] : number;
}
const BLACK = '0,0,0';
const WHITE = '255,255,255';
const CMD = [
const BLACK : string = '0,0,0';
const WHITE : string = '255,255,255';
const CMD : string[] = [
'CF',
'PF',
'BF',
@ -23,16 +23,32 @@ const CMD = [
'P2F',
'P2B',
'PPF',
'PPB'
];
/*
'PPB',
'CFCB',
'CBCF',
'PFPB',
'PBPF'
*/
];
const ALTS = {
const CAMERA_SECONDARY : string[] = [
'C2F',
'C2B',
'CCF',
'CCB',
'CFCB',
'CBCF'
];
const PROJECTOR_SECONDARY : string[] = [
'P2F',
'P2B',
'PPF',
'PPB',
'PFPB',
'PBPF'
];
const ALTS : any = {
'CF' : ['CAMERA FORWARD', 'CAM FORWARD'],
'PF' : ['PROJECTOR FORWARD', 'PROJ FORWARD'],
'BF' : ['BLACK FORWARD', 'BLACK', 'BLANK FORWARD', 'BLANK'],
@ -49,13 +65,13 @@ const ALTS = {
'P2B' : ['PROJECTOR2 BACKWARD', 'PROJ2 BACKWARD', 'PROJECTOR2 BACK', 'PROJ2 BACK'],
'PPF' : ['PROJECTORS FORWARD', 'PROJS FORWARD'],
'PPB' : ['PROJECTORS BACKWARD', 'PROJS BACKWARD', 'PROJECTORS BACK', 'PROJS BACK'],
};
/*
'CFCB' : [ ],
'CBCF' : [ ],
'PFPB' : [ ],
'PBPF' : [ ]
*/
};
const PAUSE = 'PAUSE';
const ALERT = 'ALERT';
@ -92,6 +108,8 @@ class Mscript {
loops : any[];
rec : number;
two : string;
three : string;
four : string;
arr : any[];
meta : string[];
target : number;
@ -119,8 +137,9 @@ class Mscript {
this.color = '';
this.loops = [];
this.rec = -1;
this.two = '';
this.three = '';
this.four = '';
this.arr = [];
this.meta = [];
this.target = 0; //move to target using CAM # or PROJ #
@ -159,10 +178,16 @@ class Mscript {
for (let line of this.lines) {
this.two = line.substring(0, 2);
if (CMD.indexOf(this.two) !== -1) {
this.basic_cmd(line);
this.three = line.substring(0, 3);
this.four = line.substring(0, 4);
if (CMD.indexOf(this.four) !== -1) {
this.basic_cmd(line, this.four);
} else if (CMD.indexOf(this.three) !== -1) {
this.basic_cmd(line, this.three);
} else if (CMD.indexOf(this.two) !== -1) {
this.basic_cmd(line, this.two);
} else if (startsWith(line, PAUSE)) {
this.pause(line);
//this.pause(line);
} else if (startsWith(line, ALERT)) {
this.alert(line);
} else if (startsWith(line, '@') || line.indexOf('@') !== -1) {
@ -175,8 +200,12 @@ class Mscript {
this.new_loop(line, true);
} else if (startsWith(line, 'END')) {
this.end_loop(line);
} else if (startsWith(line, 'CAM')) { //directly go to that frame (black?)
} else if (startsWith(line, 'CAM2')) { //directly go to that frame
this.move_cam2(line);
} else if (startsWith(line, 'CAM')) { //directly go to that frame
this.move_cam(line);
} else if (startsWith(line, 'PROJ2')) { //directly go to that frame
this.move_proj2(line);
} else if (startsWith(line, 'PROJ')) { //directly go to that frame
this.move_proj(line);
} else if (startsWith(line, 'SET')) { //set that state
@ -184,10 +213,6 @@ class Mscript {
} else if (startsWith(line, '#') || startsWith(line, '//')) {
//comments
//ignore while parsing
} else if (startsWith(line, 'ALERT')) {
} else if (startsWith(line, 'PAUSE')) {
this.pause(line);
}
}
@ -196,6 +221,12 @@ class Mscript {
this.output.meta = this.meta; //all metadata for instructions
this.output.cam = this.cam;
this.output.proj = this.proj;
if (this.contains(this.arr, CAMERA_SECONDARY)) {
this.output.cam2 = this.cam2;
}
if (this.contains(this.arr, PROJECTOR_SECONDARY)) {
this.output.proj2 = this.proj2;
}
if (typeof callback !== 'undefined') {
//should only be invoked by running mscript.tests()
@ -263,28 +294,29 @@ class Mscript {
* Interpret a basic two character command
*
* @param {string} line Line of script to interpret
* @param {string} short The short command to use
*/
basic_cmd (line : string) {
basic_cmd (line : string, short : string) {
if (this.rec !== -1) {
//hold generated arr in state loop array
this.loops[this.rec].arr
.push.apply(this.loops[this.rec].arr,
this.str_to_arr(line,
this.two));
short));
this.loops[this.rec].meta
.push.apply(this.loops[this.rec].meta,
this.light_to_arr(line,
this.two));
short));
} else {
this.arr.push.apply(this.arr, this.str_to_arr(line, this.two));
this.meta.push.apply(this.meta, this.light_to_arr(line, this.two));
this.arr.push.apply(this.arr, this.str_to_arr(line, short));
this.meta.push.apply(this.meta, this.light_to_arr(line, short));
}
}
/**
* Start a new loop
*
* @param {string} line Line to evaluate as either loop or fade
* @param {boolean} fade Flag as boolean if true
* @param {boolean} fade Flag as true if fade
*/
new_loop (line : string, fade? : boolean) {
this.rec++;
@ -293,6 +325,8 @@ class Mscript {
meta : [],
cam : 0,
proj : 0,
cam2 : 0,
proj2 : 0,
cmd : line + ''
};
if (fade) {
@ -378,6 +412,49 @@ class Mscript {
}
}
}
/**
* Move secondary camera to explicitly-defined frame
*
* @param {string} line Line to interpret with camera move statement
*/
move_cam2 (line : string) {
this.target = parseInt(line.split('CAM2 ')[1]);
if (this.rec !== -1) {
if (this.target > this.cam2) {
this.dist = this.target - this.cam2;
for (let x = 0; x < this.dist; x++) {
this.loops[this.rec].arr.push('C2F');
this.loops[this.rec].meta.push(BLACK);
this.update('C2F');
}
} else {
this.dist = this.cam2 - this.target;
for (let x = 0; x < this.dist; x++) {
this.loops[this.rec].arr.push('C2B');
this.loops[this.rec].meta.push(BLACK);
this.update('C2B');
}
}
} else {
if (this.target > this.cam2) {
this.dist = this.target - this.cam2;
for (let x = 0; x < this.dist; x++) {
this.arr.push('C2F');
this.meta.push(BLACK);
this.update('C2F');
}
} else {
this.dist = this.cam2 - this.target;
for (let x = 0; x < this.dist; x++) {
this.arr.push('C2B');
this.meta.push(BLACK);
this.update('C2B');
}
}
}
}
/**
* Move projector to explicitly-defined frame
*
@ -419,13 +496,59 @@ class Mscript {
}
}
}
/**
* Move projector to explicitly-defined frame
*
* @param {string} line Line containing `move` statement to interpret
*/
move_proj2 (line : string) {
this.target = parseInt(line.split('PROJ2 ')[1]);
if (this.rec !== -1) {
if (this.target > this.proj2) {
this.dist = this.target - this.proj2;
for (let x = 0; x < this.dist; x++) {
this.loops[this.rec].arr.push('P2F');
this.loops[this.rec].meta.push('');
this.update('P2F');
}
} else {
this.dist = this.proj2 - this.target;
for (let x = 0; x < this.dist; x++) {
this.loops[this.rec].arr.push('P2B');
this.loops[this.rec].meta.push('');
this.update('P2B');
}
}
} else {
if (this.target > this.proj2) {
this.dist = this.target - this.proj2;
for (let x = 0; x < this.dist; x++) {
this.arr.push('P2F');
this.meta.push('');
this.update('P2F');
}
} else {
this.dist = this.proj2 - this.target;
for (let x = 0; x < this.dist; x++) {
this.arr.push('P2B');
this.meta.push('');
this.update('P2B');
}
}
}
}
/**
* Set the state of either the cam or projector
*
* @param line {string} String containing set statement
*/
set_state (line : string) {
if (startsWith(line, 'SET CAM')) {
if (startsWith(line, 'SET CAM2')) {
parseInt(line.split('SET CAM2')[1]);
} else if (startsWith(line, 'SET PROJ2')) {
this.cam2 = parseInt(line.split('SET PROJ2')[1]);
} else if (startsWith(line, 'SET CAM')) {
this.cam = parseInt(line.split('SET CAM')[1]);
} else if (startsWith(line, 'SET PROJ')) {
this.proj = parseInt(line.split('SET PROJ')[1]);
@ -603,6 +726,94 @@ class Mscript {
} else {
this.loops[this.rec].cam -= val;
}
} else if (cmd === 'C2F') {
if (this.rec === -1) {
this.cam2 += val;
} else {
this.loops[this.rec].cam2 += val;
}
} else if (cmd === 'C2B') {
if (this.rec === -1) {
this.cam2 -= val;
} else {
this.loops[this.rec].cam2 -= val;
}
} else if (cmd === 'CCF') {
if (this.rec === -1) {
this.cam += val;
this.cam2 += val;
} else {
this.loops[this.rec].cam2 += val;
this.loops[this.rec].cam2 += val;
}
} else if (cmd === 'CCB') {
if (this.rec === -1) {
this.cam -= val;
this.cam2 -= val;
} else {
this.loops[this.rec].cam2 -= val;
this.loops[this.rec].cam2 -= val;
}
} else if (cmd === 'P2F') {
if (this.rec === -1) {
this.proj2 += val;
} else {
this.loops[this.rec].proj2 += val;
}
} else if (cmd === 'P2B') {
if (this.rec === -1) {
this.proj2 -= val;
} else {
this.loops[this.rec].proj2 -= val;
}
} else if (cmd === 'PPF') {
if (this.rec === -1) {
this.proj += val;
this.proj2 += val;
} else {
this.loops[this.rec].proj += val
this.loops[this.rec].proj2 += val;
}
} else if (cmd === 'PPB') {
if (this.rec === -1) {
this.proj -= val;
this.proj2 -= val;
} else {
this.loops[this.rec].proj -= val
this.loops[this.rec].proj2 -= val;
}
} else if (cmd === 'CFCB') {
if (this.rec === -1) {
this.cam += val;
this.cam2 -= val;
} else {
this.loops[this.rec].cam += val;
this.loops[this.rec].cam2 -= val;
}
} else if (cmd === 'CBCF') {
if (this.rec === -1) {
this.cam -= val;
this.cam2 += val;
} else {
this.loops[this.rec].cam -= val;
this.loops[this.rec].cam2 += val;
}
} else if (cmd === 'PFPB') {
if (this.rec === -1) {
this.proj += val;
this.proj2 -= val;
} else {
this.loops[this.rec].proj += val;
this.loops[this.rec].proj2 -= val;
}
} else if (cmd === 'PBPF') {
if (this.rec === -1) {
this.proj -= val;
this.proj2 += val;
} else {
this.loops[this.rec].proj -= val;
this.loops[this.rec].proj2 += val;
}
} else if (cmd === 'L ') {
}
@ -732,6 +943,19 @@ class Mscript {
fail (msg : string) {
throw new Error(msg);
}
/**
* Determine if array contains matching elements of
* another array
*
* @param {Array} arr Original array to compare
* @param {Array} arr2 Array to compare elements from
*
* @returns {boolean} Whether arr contains elements in arr2
**/
contains (arr : string[], arr2 : string[]) {
return arr.some(r => arr2.includes(r));
}
}
module.exports = Mscript;
@ -742,9 +966,15 @@ module.exports = Mscript;
CAM # - go to camera frame #
PROJ # - go to projector frame #
CAM2 # - go to camera 2 frame #
PROJ # - go to projector 2 frame #
SET CAM # - sets camera count to #
SET PROJ # - sets projector count to #
SET CAM2 # - sets camera 2 count to #
SET PROJ2 # - sets projector 2 count to #
LOOP # - begin loop, can nest recursively, # times
END LOOP - (or END) closes loop
@ -769,6 +999,5 @@ PPF - Both projectors forwards
PPB - Both projectors backwards
ALERT {MESSAGE} - Stop the sequence and requiure user interaction to complete
PAUSE # - Pause the sequence for a # of seconds
*/