mirror of
https://github.com/cpvalente/ontime.git
synced 2026-09-10 08:39:34 +00:00
send osc
This commit is contained in:
+15
-2
@@ -10,6 +10,7 @@ const adapter = new JSONFile(file);
|
|||||||
export const db = new Low(adapter);
|
export const db = new Low(adapter);
|
||||||
|
|
||||||
// dependencies
|
// dependencies
|
||||||
|
import { Client } from 'node-osc';
|
||||||
import express from 'express';
|
import express from 'express';
|
||||||
import http from 'http';
|
import http from 'http';
|
||||||
import cors from 'cors';
|
import cors from 'cors';
|
||||||
@@ -74,8 +75,21 @@ app.use((err, req, res, next) => {
|
|||||||
// create HTTP server
|
// create HTTP server
|
||||||
const server = http.createServer(app);
|
const server = http.createServer(app);
|
||||||
|
|
||||||
|
// Start OSC Client
|
||||||
|
let oscClient = null;
|
||||||
|
export const startOSCClient = (overrideConfig = null) => {
|
||||||
|
// Setup IP
|
||||||
|
const ipOut = overrideConfig?.ip || config.osc.ipOut;
|
||||||
|
// Setup default port
|
||||||
|
const oscOutPort = overrideConfig?.port || config.osc.portOut;
|
||||||
|
oscClient = new Client(ipOut, oscOutPort);
|
||||||
|
console.log(`OSC Client sending to ${ipOut}:${oscOutPort}`);
|
||||||
|
};
|
||||||
|
|
||||||
|
startOSCClient();
|
||||||
|
|
||||||
// init timer
|
// init timer
|
||||||
global.timer = new EventTimer(server, config);
|
global.timer = new EventTimer(server, oscClient, config);
|
||||||
global.timer.setupWithEventList(data.events);
|
global.timer.setupWithEventList(data.events);
|
||||||
|
|
||||||
// Start server
|
// Start server
|
||||||
@@ -85,5 +99,4 @@ server.listen(port, () =>
|
|||||||
|
|
||||||
// Start OSC server
|
// Start OSC server
|
||||||
import { initiateOSC } from './controllers/OscController.js';
|
import { initiateOSC } from './controllers/OscController.js';
|
||||||
|
|
||||||
initiateOSC(config.osc);
|
initiateOSC(config.osc);
|
||||||
|
|||||||
@@ -15,6 +15,10 @@ export class EventTimer extends Timer {
|
|||||||
|
|
||||||
// Socket IO Object
|
// Socket IO Object
|
||||||
io = null;
|
io = null;
|
||||||
|
|
||||||
|
// OSC Client
|
||||||
|
oscClient = null;
|
||||||
|
|
||||||
_numClients = 0;
|
_numClients = 0;
|
||||||
_interval = null;
|
_interval = null;
|
||||||
|
|
||||||
@@ -57,7 +61,7 @@ export class EventTimer extends Timer {
|
|||||||
numEvents = null;
|
numEvents = null;
|
||||||
_eventlist = null;
|
_eventlist = null;
|
||||||
|
|
||||||
constructor(httpServer, config) {
|
constructor(httpServer, oscClient, config) {
|
||||||
// call super constructor
|
// call super constructor
|
||||||
super();
|
super();
|
||||||
|
|
||||||
@@ -79,11 +83,80 @@ export class EventTimer extends Timer {
|
|||||||
|
|
||||||
// listen to new connections
|
// listen to new connections
|
||||||
this._listenToConnections();
|
this._listenToConnections();
|
||||||
|
|
||||||
|
// set oscClient
|
||||||
|
this.updateOSCClient(oscClient);
|
||||||
|
}
|
||||||
|
|
||||||
|
updateOSCClient(oscClient) {
|
||||||
|
this.oscClient = oscClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
sendOSC(event) {
|
||||||
|
if (this.oscClient == null) return;
|
||||||
|
|
||||||
|
const add = '/ontime';
|
||||||
|
const play = 'play';
|
||||||
|
const pause = 'pause';
|
||||||
|
const stop = 'stop';
|
||||||
|
const prev = 'prev';
|
||||||
|
const next = 'next';
|
||||||
|
const reload = 'reload';
|
||||||
|
|
||||||
|
switch (event) {
|
||||||
|
case 'time':
|
||||||
|
// Send Timetag Message
|
||||||
|
|
||||||
|
this.oscClient.send(add, this.timeTag, (err) => {
|
||||||
|
if (err) console.error(err);
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case 'play':
|
||||||
|
// Play Message
|
||||||
|
this.oscClient.send(add, play, (err) => {
|
||||||
|
if (err) console.error(err);
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case 'pause':
|
||||||
|
// Pause Message
|
||||||
|
this.oscClient.send(add, pause, (err) => {
|
||||||
|
if (err) console.error(err);
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case 'stop':
|
||||||
|
// Stop Message
|
||||||
|
this.oscClient.send(add, stop, (err) => {
|
||||||
|
if (err) console.error(err);
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case 'prev':
|
||||||
|
this.oscClient.send(add, prev, (err) => {
|
||||||
|
if (err) console.error(err);
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case 'next':
|
||||||
|
this.oscClient.send(add, next, (err) => {
|
||||||
|
if (err) console.error(err);
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case 'reload':
|
||||||
|
this.oscClient.send(add, reload, (err) => {
|
||||||
|
if (err) console.error(err);
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// send current timer
|
// send current timer
|
||||||
broadcastTimer() {
|
broadcastTimer() {
|
||||||
|
// through websockets
|
||||||
this.io.emit('timer', this.getObject());
|
this.io.emit('timer', this.getObject());
|
||||||
|
|
||||||
|
// through OSC
|
||||||
|
this.sendOSC('time');
|
||||||
}
|
}
|
||||||
|
|
||||||
// broadcast state
|
// broadcast state
|
||||||
@@ -134,20 +207,6 @@ export class EventTimer extends Timer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
start() {
|
|
||||||
// if there is nothing selected, no nothing
|
|
||||||
if (this.selectedEventId == null) return;
|
|
||||||
super.start();
|
|
||||||
this.broadcastState();
|
|
||||||
}
|
|
||||||
|
|
||||||
pause() {
|
|
||||||
// if there is nothing selected, no nothing
|
|
||||||
if (this.selectedEventId == null) return;
|
|
||||||
super.pause();
|
|
||||||
this.broadcastState();
|
|
||||||
}
|
|
||||||
|
|
||||||
_setterManager(action, payload) {
|
_setterManager(action, payload) {
|
||||||
switch (action) {
|
switch (action) {
|
||||||
/*******************************************/
|
/*******************************************/
|
||||||
@@ -771,19 +830,31 @@ export class EventTimer extends Timer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
start() {
|
start() {
|
||||||
|
// if there is nothing selected, no nothing
|
||||||
|
if (this.selectedEventId == null) return;
|
||||||
|
|
||||||
// call super
|
// call super
|
||||||
super.start();
|
super.start();
|
||||||
|
|
||||||
// broadcast current state
|
// broadcast current state
|
||||||
this.broadcastState();
|
this.broadcastState();
|
||||||
|
|
||||||
|
// send OSC
|
||||||
|
this.sendOSC('play');
|
||||||
}
|
}
|
||||||
|
|
||||||
pause() {
|
pause() {
|
||||||
|
// if there is nothing selected, no nothing
|
||||||
|
if (this.selectedEventId == null) return;
|
||||||
|
|
||||||
// call super
|
// call super
|
||||||
super.pause();
|
super.pause();
|
||||||
|
|
||||||
// broadcast current state
|
// broadcast current state
|
||||||
this.broadcastState();
|
this.broadcastState();
|
||||||
|
|
||||||
|
// send OSC
|
||||||
|
this.sendOSC('pause');
|
||||||
}
|
}
|
||||||
|
|
||||||
stop() {
|
stop() {
|
||||||
@@ -792,6 +863,9 @@ export class EventTimer extends Timer {
|
|||||||
|
|
||||||
// broadcast current state
|
// broadcast current state
|
||||||
this.broadcastState();
|
this.broadcastState();
|
||||||
|
|
||||||
|
// send OSC
|
||||||
|
this.sendOSC('stop');
|
||||||
}
|
}
|
||||||
|
|
||||||
increment(amount) {
|
increment(amount) {
|
||||||
@@ -885,6 +959,9 @@ export class EventTimer extends Timer {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// send OSC
|
||||||
|
this.sendOSC('prev');
|
||||||
|
|
||||||
// change playstate
|
// change playstate
|
||||||
this.pause();
|
this.pause();
|
||||||
|
|
||||||
@@ -905,6 +982,9 @@ export class EventTimer extends Timer {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// send OSC
|
||||||
|
this.sendOSC('next');
|
||||||
|
|
||||||
// change playstate
|
// change playstate
|
||||||
this.pause();
|
this.pause();
|
||||||
|
|
||||||
@@ -932,6 +1012,9 @@ export class EventTimer extends Timer {
|
|||||||
// reset playstate
|
// reset playstate
|
||||||
this.pause();
|
this.pause();
|
||||||
|
|
||||||
|
// send OSC
|
||||||
|
this.sendOSC('reload');
|
||||||
|
|
||||||
// reload data
|
// reload data
|
||||||
this.loadEvent(this.selectedEventIndex);
|
this.loadEvent(this.selectedEventIndex);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,5 +11,7 @@ export const config = {
|
|||||||
},
|
},
|
||||||
osc: {
|
osc: {
|
||||||
port: 8888,
|
port: 8888,
|
||||||
|
ipOut: '127.0.0.1',
|
||||||
|
portOut: 9999,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user