mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-27 18:09:10 +00:00
Feat/osc feedback (#35)
* Add roll function call to OSC * send finished message * request presenter * handling badly formatted messages * loadeventbyindex add step so that we can pause the titles when loading a new event via an API call (eg. OSC) * broadcast title data * handle empty title fields * send finished message in roll mode * calling stop is same as calling unload
This commit is contained in:
@@ -115,9 +115,9 @@ export class EventTimer extends Timer {
|
|||||||
const reload = 'reload';
|
const reload = 'reload';
|
||||||
const finished = 'finished';
|
const finished = 'finished';
|
||||||
const time = this.timeTag;
|
const time = this.timeTag;
|
||||||
// TODO: Should this be boolean?
|
|
||||||
const overtime = this.current > 0 ? 0 : 1;
|
const overtime = this.current > 0 ? 0 : 1;
|
||||||
const title = this.titles.titleNow;
|
const title = this.titles?.titleNow || '';
|
||||||
|
const presenter = this.titles?.presenterNow || '';
|
||||||
|
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case 'time':
|
case 'time':
|
||||||
@@ -138,11 +138,16 @@ export class EventTimer extends Timer {
|
|||||||
if (err) console.error(err);
|
if (err) console.error(err);
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case 'title':
|
case 'titles':
|
||||||
// Send Title of current event
|
// Send Title of current event
|
||||||
this.oscClient.send(add + '/title', title, (err) => {
|
this.oscClient.send(add + '/title', title, (err) => {
|
||||||
if (err) console.error(err);
|
if (err) console.error(err);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Send presenter data on current event
|
||||||
|
this.oscClient.send(add + '/presenter', presenter, (err) => {
|
||||||
|
if (err) console.error(err);
|
||||||
|
});
|
||||||
break;
|
break;
|
||||||
case 'play':
|
case 'play':
|
||||||
// Play Message
|
// Play Message
|
||||||
@@ -200,6 +205,7 @@ export class EventTimer extends Timer {
|
|||||||
if (this.state === 'start' || this.state === 'roll') {
|
if (this.state === 'start' || this.state === 'roll') {
|
||||||
this.sendOSC('time');
|
this.sendOSC('time');
|
||||||
this.sendOSC('overtime');
|
this.sendOSC('overtime');
|
||||||
|
this.sendOSC('titles');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -228,13 +234,13 @@ export class EventTimer extends Timer {
|
|||||||
update() {
|
update() {
|
||||||
// if there is nothing selected, do nothing
|
// if there is nothing selected, do nothing
|
||||||
if (this.selectedEventId == null && this.state !== 'roll') return;
|
if (this.selectedEventId == null && this.state !== 'roll') return;
|
||||||
|
const now = this._getCurrentTime();
|
||||||
|
|
||||||
// only implement roll here
|
// only implement roll here
|
||||||
if (this.state !== 'roll') {
|
if (this.state !== 'roll') {
|
||||||
super.update();
|
super.update();
|
||||||
} else {
|
} else {
|
||||||
// update timer as usual
|
// update timer as usual
|
||||||
const now = this._getCurrentTime();
|
|
||||||
this.clock = now;
|
this.clock = now;
|
||||||
if (this.selectedEventId && this.current > 0) {
|
if (this.selectedEventId && this.current > 0) {
|
||||||
// something is running, update
|
// something is running, update
|
||||||
@@ -249,6 +255,12 @@ export class EventTimer extends Timer {
|
|||||||
const secondaryRunning =
|
const secondaryRunning =
|
||||||
this.secondaryTimer <= 0 && this.secondaryTimer !== null;
|
this.secondaryTimer <= 0 && this.secondaryTimer !== null;
|
||||||
|
|
||||||
|
if (currentRunning) {
|
||||||
|
// finished an event
|
||||||
|
this.sendOSC('finished');
|
||||||
|
this._finishedFlag = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (currentRunning || secondaryRunning) {
|
if (currentRunning || secondaryRunning) {
|
||||||
// look for events
|
// look for events
|
||||||
this.rollLoad();
|
this.rollLoad();
|
||||||
@@ -258,8 +270,18 @@ export class EventTimer extends Timer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// sendOSC on reaching 0
|
// if event is finished
|
||||||
if (this.current === 0 && this.state === 'start') this.sendOSC('finished');
|
if (
|
||||||
|
this.current <= 0 &&
|
||||||
|
(this.state === 'start' || this.state === 'roll') &&
|
||||||
|
!this._finishedFlag
|
||||||
|
) {
|
||||||
|
if (this._finishedAt === null) {
|
||||||
|
this._finishedAt = now;
|
||||||
|
}
|
||||||
|
this.sendOSC('finished');
|
||||||
|
this._finishedFlag = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_setterManager(action, payload) {
|
_setterManager(action, payload) {
|
||||||
@@ -629,6 +651,12 @@ export class EventTimer extends Timer {
|
|||||||
this.loadEvent(eventIndex, 'load', true);
|
this.loadEvent(eventIndex, 'load', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
loadEventByIndex(eventIndex) {
|
||||||
|
if (eventIndex === -1 || index > this.numEvents) return;
|
||||||
|
this.pause();
|
||||||
|
this.loadEvent(eventIndex, 'load', true);
|
||||||
|
}
|
||||||
|
|
||||||
// Loads a given event
|
// Loads a given event
|
||||||
// load timers
|
// load timers
|
||||||
// load selectedEventIndex
|
// load selectedEventIndex
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ export class Timer {
|
|||||||
_secondaryTarget = null;
|
_secondaryTarget = null;
|
||||||
_finishAt = null;
|
_finishAt = null;
|
||||||
_finishedAt = null;
|
_finishedAt = null;
|
||||||
|
_finishedFlag = false;
|
||||||
_startedAt = null;
|
_startedAt = null;
|
||||||
_pausedAt = null;
|
_pausedAt = null;
|
||||||
_pausedInterval = null;
|
_pausedInterval = null;
|
||||||
@@ -84,9 +85,6 @@ export class Timer {
|
|||||||
console.error('Timer: no playstate on update call', this.state);
|
console.error('Timer: no playstate on update call', this.state);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cleanup
|
|
||||||
if (this.current <= 0 && this._finishedAt == null) this._finishedAt = now;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// helpers
|
// helpers
|
||||||
@@ -129,6 +127,7 @@ export class Timer {
|
|||||||
this._secondaryTarget = null;
|
this._secondaryTarget = null;
|
||||||
this._finishAt = null;
|
this._finishAt = null;
|
||||||
this._finishedAt = null;
|
this._finishedAt = null;
|
||||||
|
this._finishedFlag = false;
|
||||||
this._startedAt = null;
|
this._startedAt = null;
|
||||||
this._pausedAt = null;
|
this._pausedAt = null;
|
||||||
this._pausedInterval = null;
|
this._pausedInterval = null;
|
||||||
|
|||||||
@@ -26,7 +26,15 @@ export const initiateOSC = (config) => {
|
|||||||
const args = msg[1];
|
const args = msg[1];
|
||||||
|
|
||||||
// get first part before (ontime)
|
// get first part before (ontime)
|
||||||
if (address !== 'ontime') return;
|
if (address !== 'ontime') {
|
||||||
|
console.error(`OSC IN: Message address ${address} not recognised`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (path == null) {
|
||||||
|
console.error('OSC IN: No path found');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// get second part (command)
|
// get second part (command)
|
||||||
switch (path.toLowerCase()) {
|
switch (path.toLowerCase()) {
|
||||||
@@ -48,6 +56,7 @@ export const initiateOSC = (config) => {
|
|||||||
global.timer.next();
|
global.timer.next();
|
||||||
break;
|
break;
|
||||||
case 'unload':
|
case 'unload':
|
||||||
|
case 'stop':
|
||||||
console.log('calling unload');
|
console.log('calling unload');
|
||||||
global.timer.unload();
|
global.timer.unload();
|
||||||
break;
|
break;
|
||||||
@@ -57,12 +66,17 @@ export const initiateOSC = (config) => {
|
|||||||
break;
|
break;
|
||||||
case 'roll':
|
case 'roll':
|
||||||
console.log('calling roll');
|
console.log('calling roll');
|
||||||
|
global.timer.roll();
|
||||||
break;
|
break;
|
||||||
case 'delay':
|
case 'delay':
|
||||||
console.log('calling delay with', args);
|
console.log('calling delay with', args);
|
||||||
try {
|
try {
|
||||||
let t = parseInt(args);
|
let t = parseInt(args);
|
||||||
if (!isNaN(t)) global.timer.increment(t * 1000 * 60);
|
if (isNaN(t)) {
|
||||||
|
console.error(`OSC IN: delay time not recognised ${args}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
global.timer.increment(t * 1000 * 60);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('error parsing: ', error);
|
console.log('error parsing: ', error);
|
||||||
}
|
}
|
||||||
@@ -71,16 +85,24 @@ export const initiateOSC = (config) => {
|
|||||||
console.log('calling goto with', args);
|
console.log('calling goto with', args);
|
||||||
try {
|
try {
|
||||||
let eventIndex = parseInt(args);
|
let eventIndex = parseInt(args);
|
||||||
if (isNaN(eventIndex) || eventIndex <= 0 || eventIndex == null)
|
if (isNaN(eventIndex) || eventIndex <= 0 || eventIndex == null) {
|
||||||
return;
|
console.error(
|
||||||
global.timer.loadEvent(eventIndex - 1, undefined, true);
|
`OSC IN: event index not recognised or out of range ${eventIndex}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
global.timer.loadEventByIndex(eventIndex - 1, undefined, true);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('error calling goto: ', error);
|
console.log('error calling goto: ', error);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'gotoid':
|
case 'gotoid':
|
||||||
console.log('calling gotoid with', args);
|
console.log('calling gotoid with', args);
|
||||||
if (args == null) return;
|
if (args == null) {
|
||||||
|
console.error(
|
||||||
|
`OSC IN: event id not recognised or out of range ${args}`
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
global.timer.loadEventById(args.toString().toLowerCase());
|
global.timer.loadEventById(args.toString().toLowerCase());
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -89,7 +111,7 @@ export const initiateOSC = (config) => {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
console.log('Error: not recognised');
|
console.log(`Error: unhandled message ${path}`);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user