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": [ "triggers": [
{ {
"art": { "art": {
"subnet": 1, "subnet": "4",
"value": 4 "value": "4"
}, },
"time": { "time": {
"lframe": 15, "lframe": "2",
"lseconds": 5, "lseconds": "10",
"lminutes": 0, "lminutes": "0",
"lhours": 0, "lhours": "0",
"lmilliseconds": 5600 "lmilliseconds": 10080
}, },
"id": "c06d59297199" "id": "719be4487857"
}, },
{ {
"art": { "art": {
"subnet": "1", "subnet": "5",
"value": "1" "value": "5"
}, },
"time": { "time": {
"lframe": "1", "lframe": "5",
"lseconds": "1", "lseconds": "5",
"lminutes": "1", "lminutes": "5",
"lhours": "1", "lhours": "5",
"lmilliseconds": 3661040 "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,5 +1,6 @@
//DATABASE
"use strict"; "use strict";
//DATABASE
Object.defineProperty(exports, "__esModule", { value: true });
const low = require("lowdb"); const low = require("lowdb");
var db = low("db.json"); var db = low("db.json");
const sid = require("short-id"); const sid = require("short-id");
@ -92,6 +93,7 @@ class Timecode {
var d = new Date().getTime() - this.startTime; var d = new Date().getTime() - this.startTime;
this.toTrigger.forEach(e => { this.toTrigger.forEach(e => {
if (e.time.milliseconds <= d) { if (e.time.milliseconds <= d) {
console.log(e);
ios.emit("artnet", e.art); ios.emit("artnet", e.art);
artnet.set(universe, e.art.subnet); artnet.set(universe, e.art.subnet);
var i = this.toTrigger.indexOf(e); var i = this.toTrigger.indexOf(e);
@ -106,11 +108,16 @@ class Timecode {
loadTrack(trackid) { loadTrack(trackid) {
this.playing = false; this.playing = false;
var track = db.get(trackid).value(); var track = db.get(trackid).value();
var tr = [];
track.triggers.forEach(t => { 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.activeTrack = track;
this.toTrigger = track.triggers; this.toTrigger = tr;
this.filePlaying = track.file; this.filePlaying = track.file;
this.startTime = 0; this.startTime = 0;
} }
@ -147,7 +154,10 @@ class Track {
var timecode = new Timecode(); var timecode = new Timecode();
ios.on("connection", socket => { ios.on("connection", socket => {
function senddata() { function senddata() {
ios.emit("get_data", db.getState()); ios.emit("get_data", {
tracks: db.getState(),
loaded: timecode.activeTrack
});
} }
console.log("Client", socket.id, "connected"); console.log("Client", socket.id, "connected");
socket.on("load", (id) => { socket.on("load", (id) => {
@ -156,6 +166,7 @@ ios.on("connection", socket => {
return socket.emit("play_error", "Track doesn't exist"); return socket.emit("play_error", "Track doesn't exist");
} }
timecode.loadTrack(id); timecode.loadTrack(id);
senddata();
}); });
socket.on("play", () => { socket.on("play", () => {
if (timecode.playing) { if (timecode.playing) {
@ -189,7 +200,7 @@ ios.on("connection", socket => {
senddata(); senddata();
}); });
socket.on("get", () => { socket.on("get", () => {
socket.emit("get_data", db.getState()); senddata();
}); });
socket.on("delete", (data) => { socket.on("delete", (data) => {
db.get(data.track + ".triggers").remove({ id: data.id }).write(); db.get(data.track + ".triggers").remove({ id: data.id }).write();

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

View File

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