some improvements

This commit is contained in:
Fabian Stamm 2017-06-20 11:15:17 +02:00
parent 9f529422a3
commit 56901e4f33
7 changed files with 286 additions and 231 deletions

46
db.json
View File

@ -5,31 +5,45 @@
"triggers": [
{
"art": {
"subnet": 1,
"value": 4
"subnet": "4",
"value": "4"
},
"time": {
"lframe": 15,
"lseconds": 5,
"lminutes": 0,
"lhours": 0,
"lmilliseconds": 5600
"lframe": "2",
"lseconds": "10",
"lminutes": "0",
"lhours": "0",
"lmilliseconds": 10080
},
"id": "c06d59297199"
"id": "719be4487857"
},
{
"art": {
"subnet": "1",
"value": "1"
"subnet": "5",
"value": "5"
},
"time": {
"lframe": "1",
"lseconds": "1",
"lminutes": "1",
"lhours": "1",
"lmilliseconds": 3661040
"lframe": "5",
"lseconds": "5",
"lminutes": "5",
"lhours": "5",
"lmilliseconds": 18305200
},
"id": "4725a8a0a91d"
"id": "d747ecb81661"
},
{
"art": {
"subnet": "0",
"value": "0"
},
"time": {
"lframe": "15",
"lseconds": "10",
"lminutes": "0",
"lhours": "0",
"lmilliseconds": 10600
},
"id": "1c599cfdb9df"
}
]
},

View File

@ -1 +0,0 @@
{}

View File

@ -1,200 +1,211 @@
//DATABASE
"use strict";
const low = require("lowdb");
var db = low("db.json");
const sid = require("short-id");
sid.configure({ length: 12 });
db.defaults({}).write();
//SOCKETIO
const httpp = require("http");
var http = httpp.createServer();
const io = require("socket.io");
var ioClient = require("socket.io-client")("http://localhost:5000");
var ios = io(http);
const artnetp = require("artnet");
const universe = 21;
var artnet = artnetp({ host: "192.168.1.255" });
class FrameTime {
constructor(millis) {
this.lframe = 0;
this.lseconds = 0;
this.lminutes = 0;
this.lhours = 0;
this.lmilliseconds = 0;
if (Number.isInteger(millis)) {
this.milliseconds = millis;
}
else if (typeof millis === "object") {
if (Number.isInteger(Number(millis.frame)) && Number.isInteger(Number(millis.seconds)) && Number.isInteger(Number(millis.minutes)) && Number.isInteger(Number(millis.hours))) {
this.lframe = millis.frame; //use the local, because its mor performant
this.lseconds = millis.seconds;
this.lminutes = millis.minutes;
this.lhours = millis.hours;
this.calcMillis();
}
else if (Number.isInteger(millis.milliseconds)) {
this.milliseconds = millis.milliseconds;
}
}
}
get milliseconds() {
return this.lmilliseconds;
}
set milliseconds(val) {
this.lmilliseconds = val;
this.millisToFrame();
}
get frame() {
return this.lframe;
}
set frame(val) {
this.lframe = val;
this.calcMillis();
}
get seconds() {
return this.lseconds;
}
set seconds(val) {
this.lseconds = val;
this.calcMillis();
}
get minutes() {
return this.lminutes;
}
set minutes(val) {
this.lminutes = val;
this.calcMillis();
}
get hours() {
return this.lhours;
}
set hours(val) {
this.lhours = val;
this.calcMillis();
}
calcMillis() {
this.lmilliseconds = (this.frame / 25 * 1000) + this.seconds * 1000 + this.minutes * 60 * 1000 + this.hours * 60 * 60 * 1000;
}
millisToFrame() {
var millis = this.lmilliseconds;
this.frame = Math.floor((millis % 1000) * 25 / 1000);
this.seconds = Math.floor((millis / 1000) % 60);
this.minutes = Math.floor((millis / (1000 * 60)) % 60);
this.hours = Math.floor((millis / (1000 * 60 * 60)) % 24);
}
}
class Timecode {
vlcUpdate(vlc) {
this.startTime = new Date().getTime() - vlc.time;
this.filePlaying = vlc.file;
}
update(time) {
var d = new Date().getTime() - this.startTime;
this.toTrigger.forEach(e => {
if (e.time.milliseconds <= d) {
ios.emit("artnet", e.art);
artnet.set(universe, e.art.subnet);
var i = this.toTrigger.indexOf(e);
this.toTrigger.splice(i, 1);
}
});
var data = {};
data.time = new FrameTime(d);
data.track = this.activeTrack.id;
ios.emit("update", data);
}
loadTrack(trackid) {
this.playing = false;
var track = db.get(trackid).value();
track.triggers.forEach(t => {
t.time = new FrameTime(t.time);
});
this.activeTrack = track;
this.toTrigger = track.triggers;
this.filePlaying = track.file;
this.startTime = 0;
}
play() {
if (this.filePlaying) {
ioClient.emit("play", { file: this.filePlaying });
ioClient.on("playing", () => {
this.startTime = new Date().getTime();
});
ioClient.on("update", (data) => {
this.vlcUpdate(data);
});
}
else {
this.startTime = new Date().getTime();
this.playing = true;
}
this.interval = setInterval(this.update.bind(this), 1000 / 25);
}
stop() {
clearInterval(this.interval);
this.playing = false;
if (this.filePlaying) {
ioClient.emit("stop");
ios.emit("stopped");
}
this.startTime = 0;
}
}
class TrackEvent {
}
class Track {
}
var timecode = new Timecode();
ios.on("connection", socket => {
function senddata() {
ios.emit("get_data", db.getState());
}
console.log("Client", socket.id, "connected");
socket.on("load", (id) => {
var track = db.get(id).value();
if (track === undefined) {
return socket.emit("play_error", "Track doesn't exist");
}
timecode.loadTrack(id);
});
socket.on("play", () => {
if (timecode.playing) {
return socket.emit("play_error", "the active track must be stoppen before re-plaing it");
}
timecode.play();
});
socket.on("stop", () => {
timecode.stop();
timecode.loadTrack(timecode.activeTrack.id);
});
socket.on("create", (data) => {
var track = new Track();
track.displayName = data.name;
track.file = data.file;
track.id = sid.generate();
track.triggers = [];
db.set(track.id, track).write();
socket.emit("created", track);
senddata();
});
socket.on("set", (data) => {
var tid = data.track;
var time = new FrameTime(data.time);
var tracke = new TrackEvent();
tracke.art = data.art;
tracke.time = time;
tracke.id = sid.generate();
db.get(tid + ".triggers").push(tracke).write();
socket.emit("set_finished", tracke);
senddata();
});
socket.on("get", () => {
socket.emit("get_data", db.getState());
});
socket.on("delete", (data) => {
db.get(data.track + ".triggers").remove({ id: data.id }).write();
senddata();
});
});
http.listen(5001);
"use strict";
//DATABASE
Object.defineProperty(exports, "__esModule", { value: true });
const low = require("lowdb");
var db = low("db.json");
const sid = require("short-id");
sid.configure({ length: 12 });
db.defaults({}).write();
//SOCKETIO
const httpp = require("http");
var http = httpp.createServer();
const io = require("socket.io");
var ioClient = require("socket.io-client")("http://localhost:5000");
var ios = io(http);
const artnetp = require("artnet");
const universe = 21;
var artnet = artnetp({ host: "192.168.1.255" });
class FrameTime {
constructor(millis) {
this.lframe = 0;
this.lseconds = 0;
this.lminutes = 0;
this.lhours = 0;
this.lmilliseconds = 0;
if (Number.isInteger(millis)) {
this.milliseconds = millis;
}
else if (typeof millis === "object") {
if (Number.isInteger(Number(millis.frame)) && Number.isInteger(Number(millis.seconds)) && Number.isInteger(Number(millis.minutes)) && Number.isInteger(Number(millis.hours))) {
this.lframe = millis.frame; //use the local, because its mor performant
this.lseconds = millis.seconds;
this.lminutes = millis.minutes;
this.lhours = millis.hours;
this.calcMillis();
}
else if (Number.isInteger(millis.milliseconds)) {
this.milliseconds = millis.milliseconds;
}
}
}
get milliseconds() {
return this.lmilliseconds;
}
set milliseconds(val) {
this.lmilliseconds = val;
this.millisToFrame();
}
get frame() {
return this.lframe;
}
set frame(val) {
this.lframe = val;
this.calcMillis();
}
get seconds() {
return this.lseconds;
}
set seconds(val) {
this.lseconds = val;
this.calcMillis();
}
get minutes() {
return this.lminutes;
}
set minutes(val) {
this.lminutes = val;
this.calcMillis();
}
get hours() {
return this.lhours;
}
set hours(val) {
this.lhours = val;
this.calcMillis();
}
calcMillis() {
this.lmilliseconds = (this.frame / 25 * 1000) + this.seconds * 1000 + this.minutes * 60 * 1000 + this.hours * 60 * 60 * 1000;
}
millisToFrame() {
var millis = this.lmilliseconds;
this.frame = Math.floor((millis % 1000) * 25 / 1000);
this.seconds = Math.floor((millis / 1000) % 60);
this.minutes = Math.floor((millis / (1000 * 60)) % 60);
this.hours = Math.floor((millis / (1000 * 60 * 60)) % 24);
}
}
class Timecode {
vlcUpdate(vlc) {
this.startTime = new Date().getTime() - vlc.time;
this.filePlaying = vlc.file;
}
update(time) {
var d = new Date().getTime() - this.startTime;
this.toTrigger.forEach(e => {
if (e.time.milliseconds <= d) {
console.log(e);
ios.emit("artnet", e.art);
artnet.set(universe, e.art.subnet);
var i = this.toTrigger.indexOf(e);
this.toTrigger.splice(i, 1);
}
});
var data = {};
data.time = new FrameTime(d);
data.track = this.activeTrack.id;
ios.emit("update", data);
}
loadTrack(trackid) {
this.playing = false;
var track = db.get(trackid).value();
var tr = [];
track.triggers.forEach(t => {
var te = new TrackEvent();
te.art = t.art;
te.id = t.id;
te.time = new FrameTime(t.time);
tr.push(te);
});
this.activeTrack = track;
this.toTrigger = tr;
this.filePlaying = track.file;
this.startTime = 0;
}
play() {
if (this.filePlaying) {
ioClient.emit("play", { file: this.filePlaying });
ioClient.on("playing", () => {
this.startTime = new Date().getTime();
});
ioClient.on("update", (data) => {
this.vlcUpdate(data);
});
}
else {
this.startTime = new Date().getTime();
this.playing = true;
}
this.interval = setInterval(this.update.bind(this), 1000 / 25);
}
stop() {
clearInterval(this.interval);
this.playing = false;
if (this.filePlaying) {
ioClient.emit("stop");
ios.emit("stopped");
}
this.startTime = 0;
}
}
class TrackEvent {
}
class Track {
}
var timecode = new Timecode();
ios.on("connection", socket => {
function senddata() {
ios.emit("get_data", {
tracks: db.getState(),
loaded: timecode.activeTrack
});
}
console.log("Client", socket.id, "connected");
socket.on("load", (id) => {
var track = db.get(id).value();
if (track === undefined) {
return socket.emit("play_error", "Track doesn't exist");
}
timecode.loadTrack(id);
senddata();
});
socket.on("play", () => {
if (timecode.playing) {
return socket.emit("play_error", "the active track must be stoppen before re-plaing it");
}
timecode.play();
});
socket.on("stop", () => {
timecode.stop();
timecode.loadTrack(timecode.activeTrack.id);
});
socket.on("create", (data) => {
var track = new Track();
track.displayName = data.name;
track.file = data.file;
track.id = sid.generate();
track.triggers = [];
db.set(track.id, track).write();
socket.emit("created", track);
senddata();
});
socket.on("set", (data) => {
var tid = data.track;
var time = new FrameTime(data.time);
var tracke = new TrackEvent();
tracke.art = data.art;
tracke.time = time;
tracke.id = sid.generate();
db.get(tid + ".triggers").push(tracke).write();
socket.emit("set_finished", tracke);
senddata();
});
socket.on("get", () => {
senddata();
});
socket.on("delete", (data) => {
db.get(data.track + ".triggers").remove({ id: data.id }).write();
senddata();
});
});
http.listen(5001);
//# sourceMappingURL=timec.js.map

File diff suppressed because one or more lines are too long

BIN
mongoose-free-6.5.exe Normal file

Binary file not shown.

View File

@ -115,6 +115,7 @@ class Timecode {
var d = new Date().getTime() - this.startTime;
this.toTrigger.forEach(e=>{
if(e.time.milliseconds <= d) {
console.log(e);
ios.emit("artnet", e.art);
artnet.set(universe, e.art.subnet)
var i = this.toTrigger.indexOf(e);
@ -130,11 +131,16 @@ class Timecode {
loadTrack(trackid:string) {
this.playing = false;
var track =<Track>db.get(trackid).value();
var tr = [];
track.triggers.forEach(t=>{
t.time = new FrameTime(t.time);
var te = new TrackEvent();
te.art = t.art;
te.id = t.id;
te.time = new FrameTime(t.time);
tr.push(te);
});
this.activeTrack = track;
this.toTrigger = track.triggers;
this.toTrigger = tr;
this.filePlaying = track.file;
this.startTime = 0;
}
@ -192,7 +198,10 @@ interface VlcUpdate {
var timecode = new Timecode();
ios.on("connection", socket=>{
function senddata(){
ios.emit("get_data", db.getState());
ios.emit("get_data", {
tracks: db.getState(),
loaded: timecode.activeTrack
});
}
console.log("Client", socket.id, "connected");
@ -202,6 +211,7 @@ ios.on("connection", socket=>{
return socket.emit("play_error", "Track doesn't exist");
}
timecode.loadTrack(id);
senddata();
});
socket.on("play", ()=>{
if(timecode.playing){
@ -236,7 +246,7 @@ ios.on("connection", socket=>{
});
socket.on("get", ()=>{
socket.emit("get_data", db.getState());
senddata();
});
socket.on("delete", (data)=>{

View File

@ -11,6 +11,13 @@
<body>
<center><h1>Timecode Abiball2017</h1></center>
<hr>
<div>
<button onclick="stopSequence()">Stop</button>
<button onclick="startSequence()">Play</button>
<label >Loaded: </label>
<label id="loaded"></label>
</div>
<hr>
<div id="track_select_div">
<label for="track_select">Select Preset: </label>
<select id="track_select"></select>
@ -25,9 +32,11 @@
<div id="trdv" style="display:none;">
<center><h2 id="trackname"></h1></center>
<center><h2 id="trackfile"></h2></center>
<button onclick="loadSequence()">Load</button>
<div>
<canvas id="canvas" height="50">
</canvas>
<label id="actualtime"></label>
</div>
<div>
<form onsubmit="f()">
@ -54,19 +63,21 @@
socket.emit("get");
var tracks = {};
var selected = undefined;
var timenow =undefined;
var timenow = undefined;
socket.on("get_data", (data)=>{
console.log("got data", data);
var opt = "<option value=''></option>";
for(var prop in data){
var e = data[prop];
for(var prop in data.tracks){
var e = data.tracks[prop];
opt += '<option value="' + e.id + '">' + e.displayName + '</option>';
}
tracks = data;
tracks = data.tracks;
if(selected){
selected = data[selected.id];
selected = data.tracks[selected.id];
}
$("#track_select").html(opt);
if(data.loaded)
$("#loaded").html(data.loaded.displayName);
drawSelected();
});
@ -82,7 +93,10 @@
});
socket.on("update", (data)=>{
if(!selected) return;
if(selected.id !== data.track) return; //Nur wenn abgespielter track ausgewählt
timenow = data.time.lmilliseconds;
$("#actualtime").html(data.time.lhours + ":" + data.time.lminutes + ":" + data.time.lseconds + ":" + data.time.lframe);
});
$("#track_select").on("change", function () {
@ -132,7 +146,6 @@
return 0;
});
sorted.forEach(e=>{
console.log(e);
t += "<tr>";
t += "<td>" + e.id + "</td>"
t += "<td>" + e.time.lhours + "</td>"
@ -194,9 +207,17 @@
$("#eval").val("");
}
socket.on("set_finished", (e)=>{
socket.emit("get");
});
function loadSequence(){
socket.emit("load", selected.id);
}
function startSequence(){
socket.emit("play");
}
function stopSequence(){
socket.emit("stop");
}
</script>
</body>
</html>