Skip to content

Commit 8e166bb

Browse files
committed
Enable dynamically changing device color using libmapper object properties.
1 parent 5fbace3 commit 8e166bb

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

js/Graph.js

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,24 @@ NodeArray.prototype = {
9191
let key = obj.key;
9292
if (!key)
9393
return null;
94+
95+
if ('color.rgb' in obj && 3 == obj['color.rgb'].length) {
96+
let rgb = obj['color.rgb'];
97+
let hsl = Raphael.rgb2hsl({r:rgb[0], g:rgb[1], b:rgb[2]});
98+
obj.hue = hsl.h;
99+
}
100+
else if ('color.hue' in obj) {
101+
let hue = obj['color.hue'];
102+
if (Array.isArray(hue))
103+
obj.hue = hue[0];
104+
else
105+
obj.hue = hue;
106+
if (obj.hue > 1) {
107+
// constrain and normalize
108+
obj.hue = (obj.hue & 0xFFFFFF) / 0xFFFFFF;
109+
}
110+
}
111+
94112
if (key in this.contents) {
95113
let prop, existing = this.contents[key];
96114
let updated = false;
@@ -109,23 +127,7 @@ NodeArray.prototype = {
109127
if (this.obj_type == 'device') {
110128
obj.signals = new NodeArray('signal', this.cb_func);
111129

112-
if ('color.rgb' in obj && 3 == obj['color.rgb'].length) {
113-
let rgb = obj['color.rgb'];
114-
let hsl = Raphael.rgb2hsl({r:rgb[0], g:rgb[1], b:rgb[2]});
115-
obj.hue = hsl.h;
116-
}
117-
else if ('color.hue' in obj) {
118-
let hue = obj['color.hue'];
119-
if (1 == hue.length)
120-
obj.hue = hue;
121-
else
122-
obj.hue = hue[0];
123-
if (obj.hue > 1) {
124-
// constrain and normalize
125-
obj.hue = (obj.hue & 0xFFFFFF) / 0xFFFFFF;
126-
}
127-
}
128-
else {
130+
if (!('hue' in obj) || obj.hue == 'undefined') {
129131
// create hue hash
130132
hueHash = function(str) {
131133
var hash = 0, i, chr;

js/ViewManager.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ class ViewManager
227227
if (repaint)
228228
this.views[this.currentView].update('devices');
229229
}
230+
else if (event == 'modified' && repaint)
231+
this.views[this.currentView].update('devices');
230232
else if (event == 'removed' && repaint)
231233
this.views[this.currentView].update('devices');
232234
}

0 commit comments

Comments
 (0)