diff options
author | sternenseemann <git@lukasepple.de> | 2017-08-29 17:56:26 +0200 |
---|---|---|
committer | sternenseemann <git@lukasepple.de> | 2017-08-29 17:56:26 +0200 |
commit | db867465ce1639fd603ffe5ff27b1ba7d74f8622 (patch) | |
tree | 4955ec0c332755e1b4bcda3cf4d5f39708af3c35 /web | |
parent | d0783ecbea42ca433b1c4328f37b4583c3db70f0 (diff) |
Prepare API communication
Diffstat (limited to 'web')
-rw-r--r-- | web/source/main.js | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/web/source/main.js b/web/source/main.js index 7fdab8b..99da938 100644 --- a/web/source/main.js +++ b/web/source/main.js @@ -84,12 +84,28 @@ class Rational { } } +function collectGraphData(nodeDate, edgeData) { + return { + nodes: [... nodeData.values()].map(x => ({ + id: x.nodeData.id, + music: x.music + })), + edges: [... edgeData.values()].map(x => ({ + id: x.edgeData.id, + from: x.edgeData.from, + to: x.edgeData.to, + prob: x.prob + })) + }; +} + // graph code var nodeData = Map(); var edgeData = Map(); var network = null; + function showOverlay(id) { document.getElementById(id).classList.remove('hidden'); } @@ -106,7 +122,7 @@ function genericEditNode(data, callback) { document.getElementById('denominator').value); var music = new Music(duration, document.getElementById('pitch').value, document.getElementById('octave').value); - nodeData = nodeData.set(data.id, music); + nodeData = nodeData.set(data.id, { music: music, nodeData: data }); data.label = music.toString(); clearOverlay(); callback(data); @@ -118,8 +134,9 @@ function genericEditNode(data, callback) { } showOverlay('node-overlay'); - var music = nodeData.get(data.id); - if(music !== undefined) { + var node = nodeData.get(data.id); + if(node !== undefined) { + var music = node.music; document.getElementById('pitch').value = music.pitch; document.getElementById('octave').value = music.octave; document.getElementById('numerator').value = music.dur.num; @@ -148,7 +165,7 @@ function genericEditEdge(data, callback) { var prob = document.getElementById('prob').value / 100; data.label = `${prob * 100}%`; - edgeData = edgeData.set(data.id, prob); + edgeData = edgeData.set(data.id, { prob: prob, edgeData: data } ); clearOverlay(); callback(data); } @@ -159,9 +176,9 @@ function genericEditEdge(data, callback) { } showOverlay('edge-overlay'); - var prob = edgeData.get(data.id); - if(prob !== undefined) { - document.getElementById('prob').value = prob * 100; + var edge = edgeData.get(data.id); + if(edge !== undefined) { + document.getElementById('prob').value = edge.prob * 100; } document.getElementById('edge-save').onclick = saveEdge.bind(this, data, callback); document.getElementById('edge-cancel').onclick = discardEdge.bind(this, callback); @@ -212,6 +229,9 @@ function main() { .reduce((acc, v) => acc + v, ''); document.getElementById('pitch').innerHTML = pitch_selector; + + document.getElementById('gen-midi').onclick = () => + console.log(JSON.stringify(collectGraphData(nodeData, edgeData))); } -document.addEventListener('DOMContentLoaded', _ => main()); +document.addEventListener('DOMContentLoaded', () => main()); |