Color RGB Values
- KVRian
- 1372 posts since 28 Dec, 2012 from Meredith NH
See;
AbstractTrackBankProxy.COLORS
https://github.com/teotigraphix/Framewo ... nkProxy.js
And this;
And the observer to save the color id;
Mike
AbstractTrackBankProxy.COLORS
https://github.com/teotigraphix/Framewo ... nkProxy.js
And this;
Code: Select all
AbstractTrackBankProxy.getColorEntry = function (colorId)
{
for (var i = 0; i < AbstractTrackBankProxy.COLORS.length; i++)
{
var color = AbstractTrackBankProxy.COLORS[i];
if (color[3] == colorId)
return color;
}
return null;
};
AbstractTrackBankProxy.getColorIndex = function (red, green, blue)
{
for (var i = 0; i < AbstractTrackBankProxy.COLORS.length; i++)
{
var color = AbstractTrackBankProxy.COLORS[i];
if (Math.abs (color[0] - red ) < 0.0001 &&
Math.abs (color[1] - green) < 0.0001 &&
Math.abs (color[2] - blue) < 0.0001)
return color[3];
}
return null;
};
Code: Select all
AbstractTrackBankProxy.prototype.handleColor = function (index, red, green, blue)
{
this.tracks[index].color = AbstractTrackBankProxy.getColorIndex (red, green, blue);
};
Michael Schmalle
http://www.teotigraphix.com
Surfing on sine waves
Maschine4Bitwig - Studio, MK2, MikroMK2, MK1
http://www.teotigraphix.com/bitwig/maschine
http://www.teotigraphix.com
Surfing on sine waves
Maschine4Bitwig - Studio, MK2, MikroMK2, MK1
http://www.teotigraphix.com/bitwig/maschine
- KVRist
- Topic Starter
- 351 posts since 31 Mar, 2015 from Pittsburgh, PA, USA
Thanks Mike. I've been trying to get this to work, I realized its more of an issue with the way I'm calling the array (I think). Heres the code I'm using. For some reason when I do the addColorObserver, the varToStore comes back as the first value in the array ( i.e. 0.3294117748737335 for Dark Gray, 0.47843137383461 for Gray, etc. ) instead of the 3rd value (the int that tells me what color it is). I can't figure out why its returning currentColor[0] instead of currentColor[3] like I'm telling it to.
Code: Select all
trackBank8 = host.createMainTrackBank(8, 8, 8);
for(var t=0; t<8; t++)
{
var track = trackBank8.getChannel(t);
track.getVolume().addValueObserver(126, getTrackObserverFunc(t, volume));
track.getPan().addValueObserver(126, getTrackObserverFunc(t, pan));
//track.getSend(0).addValueObserver(126, getTrackObserverFunc(t, sendA));
//track.getSend(1).addValueObserver(8, getTrackObserverFunc(t, sendB));
track.getMute().addValueObserver(getTrackObserverFunc(t, mute));
track.getSolo().addValueObserver(getTrackObserverFunc(t, solo));
track.addIsSelectedObserver(getTrackObserverFunc(t, isSelected));
track.addColorObserver(getTrackObserverFunc(t, handleColor));
}
Code: Select all
function getTrackObserverFunc(track, varToStore)
{
return function(value)
{
varToStore[track] = value;
}
}
Code: Select all
function handleColor(red, green, blue)
{
for (var i = 0; i < trackColors.length; i++)
{
var currentColor = trackColors[i];
if (Math.abs (currentColor[0] - red ) < 0.0001 && Math.abs (currentColor[1] - green) < 0.0001 && Math.abs (currentColor[2] - blue) < 0.0001)
{
return currentColor[3];
}
}
return null;
}
var trackColors =
[
[ 0.3294117748737335 , 0.3294117748737335 , 0.3294117748737335 , 0], // Dark Gray
[ 0.47843137383461 , 0.47843137383461 , 0.47843137383461 , 0], // Gray
[ 0.7882353067398071 , 0.7882353067398071 , 0.7882353067398071 , 0], // Light Gray
[ 0.5254902243614197 , 0.5372549295425415 , 0.6745098233222961 , 0], // Silver
[ 0.6392157077789307 , 0.4745098054409027 , 0.26274511218070984, 0], // Dark Brown
[ 0.7764706015586853 , 0.6235294342041016 , 0.43921568989753723, 0], // Brown
[ 0.34117648005485535, 0.3803921639919281 , 0.7764706015586853 , 1], // Dark Blue
[ 0.5176470875740051 , 0.5411764979362488 , 0.8784313797950745 , 19], // Light Blue
[ 0.5843137502670288 , 0.2862745225429535 , 0.7960784435272217 , 112], // Purple
[ 0.8509804010391235 , 0.21960784494876862, 0.4431372582912445 , 90], // Pink
[ 0.8509804010391235 , 0.18039216101169586, 0.1411764770746231 , 80], // Red
[ 1 , 0.34117648005485535, 0.0235294122248888 , 75], // Orange
[ 0.8509804010391235 , 0.615686297416687 , 0.062745101749897 , 70], // Light Orange
[ 0.45098039507865906, 0.5960784554481506 , 0.0784313753247261 , 45], // Green
[ 0 , 0.615686297416687 , 0.27843138575553894, 55], // Cold Green
[ 0 , 0.6509804129600525 , 0.5803921818733215 , 35], // Bluish Green
[ 0 , 0.6000000238418579 , 0.8509804010391235 , 19], // Light Blue
[ 0.7372549176216125 , 0.4627451002597809 , 0.9411764740943909 , 110], // Light Purple
[ 0.8823529481887817 , 0.4000000059604645 , 0.5686274766921997 , 100], // Light Pink
[ 0.9254902005195618 , 0.3803921639919281 , 0.34117648005485535, 62], // Skin
[ 1 , 0.5137255191802979 , 0.24313725531101227, 62], // Redish Brown
[ 0.8941176533699036 , 0.7176470756530762 , 0.30588236451148987, 62], // Light Brown
[ 0.6274510025978088 , 0.7529411911964417 , 0.2980392277240753 , 55], // Light Green
[ 0.24313725531101227, 0.7333333492279053 , 0.3843137323856354 , 35], // Bluish Green
[ 0.26274511218070984, 0.8235294222831726 , 0.7254902124404907 , 19], // Light Blue
[ 0.2666666805744171 , 0.7843137383460999 , 1 , 25] // Blue
];
- KVRian
- 1372 posts since 28 Dec, 2012 from Meredith NH
The callback signature for the color observer has 4 arguments and the first is the track index. 
So you need;
function handleColor(index, red, green, blue)
Mike
So you need;
function handleColor(index, red, green, blue)
Mike
Michael Schmalle
http://www.teotigraphix.com
Surfing on sine waves
Maschine4Bitwig - Studio, MK2, MikroMK2, MK1
http://www.teotigraphix.com/bitwig/maschine
http://www.teotigraphix.com
Surfing on sine waves
Maschine4Bitwig - Studio, MK2, MikroMK2, MK1
http://www.teotigraphix.com/bitwig/maschine
- KVRian
- 1372 posts since 28 Dec, 2012 from Meredith NH
My bad, I forgot we are wrapping them with a closure for the track index.
I don't know what to say other than it works and multiple scripts we use.
And yes, it's 3 arguments, rgb.
Have you printed the currentColor to see what it actually is?
Mike
I don't know what to say other than it works and multiple scripts we use.
And yes, it's 3 arguments, rgb.
Have you printed the currentColor to see what it actually is?
Mike
Michael Schmalle
http://www.teotigraphix.com
Surfing on sine waves
Maschine4Bitwig - Studio, MK2, MikroMK2, MK1
http://www.teotigraphix.com/bitwig/maschine
http://www.teotigraphix.com
Surfing on sine waves
Maschine4Bitwig - Studio, MK2, MikroMK2, MK1
http://www.teotigraphix.com/bitwig/maschine
- KVRist
- Topic Starter
- 351 posts since 31 Mar, 2015 from Pittsburgh, PA, USA
GOT IT!!!
My issue was that the return function(value) was only returning a single value from the addColorObserver, when it needed to have 3 arguments. The code above works now. Thanks for your help Mike!
Code: Select all
function getTrackObserverFunc(track, varToStore)
{
if (varToStore == color)
{
return function(r, g, b)
{
handleColor(r, g, b);
varToStore[track] = handleColor(r,g,b);
}
}
else
{
return function(value)
{
varToStore[track] = value;
}
}
}- KVRian
- 1372 posts since 28 Dec, 2012 from Meredith NH
Well, hehe not really I wasn't much help, only told you wrong information! 
Michael Schmalle
http://www.teotigraphix.com
Surfing on sine waves
Maschine4Bitwig - Studio, MK2, MikroMK2, MK1
http://www.teotigraphix.com/bitwig/maschine
http://www.teotigraphix.com
Surfing on sine waves
Maschine4Bitwig - Studio, MK2, MikroMK2, MK1
http://www.teotigraphix.com/bitwig/maschine
